游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2328|回复: 4

还是OpenGL模拟2D的问题

[复制链接]

96

主题

529

帖子

539

积分

高级会员

Rank: 4

积分
539
发表于 2004-11-29 12:10:00 | 显示全部楼层 |阅读模式
我先设最近可视距离为0.2f的透视投影,画3D物体。
后再设最近可视距离为0.1f的正交投影,画2D文字(2D文字视点距离设为0.11f)。

但是程序运行过程中,我发现当视点移动到离3D物体很近时,2D文字会被3D物体挡住,这是怎么回事,怎么3D物体挡住了2D文字?我明明设置3D物体最近可视距离大于2D文字可视距离的。
应该怎么解决这个问题?

希望高手指点,小弟在此先谢!!!
sf_2004112912108.jpg

190

主题

1801

帖子

2096

积分

金牌会员

Rank: 6Rank: 6

积分
2096
QQ
发表于 2004-11-29 13:06:00 | 显示全部楼层

Re:还是OpenGL模拟2D的问题

改成gluOrtho2D试试?与投影正交那一个环节有关,那个环节我也很弱,但是我手上有个例子,我用了很久没发现这样问题
void setOrthographicProjection() {

        // switch to projection mode
        glMatrixMode(GL_PROJECTION);
        // save previous matrix which contains the
        //settings for the perspective projection
        glPushMatrix();
        // reset matrix
        glLoadIdentity();
        // set a 2D orthographic projection
        gluOrtho2D(0, w, 0, h);
        // invert the y axis, down is positive
        glScalef(1, -1, 1);
        // mover the origin from the bottom left corner
        // to the upper left corner
        glTranslatef(0, -h, 0);
        glMatrixMode(GL_MODELVIEW);
}

void resetPerspectiveProjection() {
        // set the current matrix to GL_PROJECTION
        glMatrixMode(GL_PROJECTION);
        // restore previous settings
        glPopMatrix();
        // get back to GL_MODELVIEW matrix
        glMatrixMode(GL_MODELVIEW);
}
在redraw中
        setOrthographicProjection();
        glPushMatrix();
        glLoadIdentity();
        glColor3f(1.0f,0.5f,0.0f);
        glBegin(GL_LINES);
                        glVertex2f(0.5*w-7, 0.5*h);
                        glVertex2f(0.5*w+7, 0.5*h);
                        glVertex2f(0.5*w, 0.5*h+7);
                        glVertex2f(0.5*w, 0.5*h-7);
        glEnd();
        glPopMatrix();
        resetPerspectiveProjection();

96

主题

529

帖子

539

积分

高级会员

Rank: 4

积分
539
 楼主| 发表于 2004-11-29 17:03:00 | 显示全部楼层

Re:还是OpenGL模拟2D的问题

我用的也就是你这种方法

190

主题

1801

帖子

2096

积分

金牌会员

Rank: 6Rank: 6

积分
2096
QQ
发表于 2004-11-29 17:25:00 | 显示全部楼层

Re:还是OpenGL模拟2D的问题

确实吗?
要不你把代码铁上来

96

主题

529

帖子

539

积分

高级会员

Rank: 4

积分
539
 楼主| 发表于 2004-11-29 18:44:00 | 显示全部楼层

Re:还是OpenGL模拟2D的问题

我已经发现问题了,解决了,只要取消测试深度绘制2D文字,绘制完毕后再恢复测试深度就可以了。不过依然感谢你的指点。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-12-23 11:55

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表