问题描述
我设置了一个移动的 3d 场景,我想制作一个始终位于顶部的固定 2d GUI 叠加层,当我尝试制作 2d 形状时,我什么也看不到.当我打电话时:glMatrixMode(GL_PROJECTION);我的 3d 场景消失了,只剩下一个空白窗口...
这是我用于覆盖的代码
更新代码
glMatrixMode(GL_MODELVIEW);glLoadIdentity();glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(-100, 100, -100, 100);glDisable(GL_DEPTH_TEST);glDisable(GL_CULL_FACE);glDisable(GL_TEXTURE_2D);glDisable(GL_LIGHTING);glColor3f(1, 1, 1);glPushMatrix();glBegin(GL_QUADS);glVertex3f(-5.0f, 5.0f, 0.0f);glVertex3f(-5.0f, -5.0f, 0.0f);glVertex3f(5.0f, -5.0f, 0.0f);glVertex3f(5.0f, 5.0f, 0.0f);glEnd();glPopMatrix();glEnable(GL_DEPTH_TEST);glutSwapBuffers();
您必须以其他顺序绘制四边形.默认情况下,OpenGL 使用逆时针正面多边形.这意味着您看不到多边形,因为您只看到了它的背面.
您可以查看 glFrontFace.>
此外,如果这不起作用,您可以尝试禁用以下状态:
glMatrixMode(GL_MODELVIEW);glLoadIdentity();glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(-100, 100, -100, 100);glDisable(GL_DEPTH_TEST);glDisable(GL_CULL_FACE);glDisable(GL_BLENDING);glDisable(GL_TEXTURE_2D);glDisable(GL_LIGHTING);
您可能需要使用 glPushAttrib
和 glPopAttrib
以免弄乱您的状态.
I have a moving 3d scene set up, and I want to make a stationary 2d GUI overlay that is always on top, when I try making 2d shapes I don't see anything. When I call: glMatrixMode(GL_PROJECTION); my 3d scene disappears and I'm left with a blank window...
here is the code I'm using for the overlay
EDIT: updated code
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-100, 100, -100, 100);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glDisable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
glColor3f(1, 1, 1);
glPushMatrix();
glBegin(GL_QUADS);
glVertex3f(-5.0f, 5.0f, 0.0f);
glVertex3f(-5.0f, -5.0f, 0.0f);
glVertex3f(5.0f, -5.0f, 0.0f);
glVertex3f(5.0f, 5.0f, 0.0f);
glEnd();
glPopMatrix();
glEnable(GL_DEPTH_TEST);
glutSwapBuffers();
You must draw your quad in the other order. By default, OpenGL use counterclockwise front facing polygons. That means that you don't see your polygon because you see only its back face.
You might take a look at glFrontFace.
EDIT:
Also, if that doesn't work, you could try to disable the following states:
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-100, 100, -100, 100);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glDisable(GL_BLENDING);
glDisable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
You might want use glPushAttrib
and glPopAttrib
in order not to mess your state.
这篇关于Opengl 在 3d 场景问题上绘制 2d 叠加层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!