[英]2D overlay over 3D scene not working
I am attempting to create a 2D overlay over a 3D scene! 我正在尝试在3D场景上创建2D叠加! I have tried all the solutions I can find on GameDev and StackOverflow, however they have not seemed to work!
我已经尝试了在GameDev和StackOverflow上可以找到的所有解决方案,但是它们似乎没有用!
My current code: 我当前的代码:
static void ready3D()
{
glViewport(0, 0, Display.getWidth(),Display.getHeight());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
GLU.gluPerspective(45, (float) Display.getWidth()/Display.getHeight(), 0.1f, 5000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
}
static void ready2D()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
GLU.gluOrtho2D(0.0f, Display.getWidth(), Display.getHeight(), 0.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.375f, 0.375f, 0.0f);
glDisable(GL_DEPTH_TEST);
}
And, 和,
glPushMatrix();
//Overlay start - This is in my render method BTW.
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
ready2D();
glBegin(GL_QUADS);
glColor3f(1, 1, 1);
glVertex2f(0, 0); // bottom-left
glVertex2f(0, 1); // top-left
glVertex2f(1, 1); // top-right
glVertex2f(1, 0); // bottom-right
glEnd();
glPopMatrix();
ready3D();
However the 2D box thing that I am trying to draw does not draw! 但是我尝试绘制的2D盒子没有画! Obviously I eventually hope to have complicated objects/icons on an overlay, but first things first.
显然,我最终希望在覆盖层上具有复杂的对象/图标,但首先要考虑的是第一件事。
The 3D world still draws totally fine. 3D世界仍然完全可以绘制。
Is anyone able to tell me what I am doing wrong? 有人能告诉我我在做什么错吗?
The order of the vertices in the 2D quad look a bit suspicious to me, if I'm reading that rightly it's going: bottom-left, top-right, bottom-right, top-left, which results in a sort of cross rather than a quad. 如果我没看错的话,2D方形中的顶点顺序对我来说有点可疑:左下,右上,右下,左上,这会导致某种交叉比四分之一。
Try this: 尝试这个:
glVertex2f(0, 0); // bottom-left
glVertex2f(0, 1); // top-left
glVertex2f(1, 1); // top-right
glVertex2f(1, 0); // bottom-right
Note the clockwise ordering which I believe OpenGL is expecting by default for front-facing quads. 请注意,我相信OpenGL默认会针对正面四边形按顺时针方向排序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.