Switch between 2D and 3D
Hi
I want to draw a 2D interface in front of my 3D world. So I wanted to switch into 2D (via gluOrtho2D) after some research I came up with the following code - sadly it doesn''t work.
It draws something but right in between of it all and defenetly not as it should be (somehow screwed up
Can you see the problem or do you have another idea to do a 2D interface - thanx in advance!
//switch to 2D
glPushAttrib(GL_CURRENT_BIT);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0, _display->getWidth(), 0, _display->getHeight());
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
//return to 3D
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopAttrib();
You may have switched the projection matrix to a 2d setup, but you''ve probably left depth testing enabled, so your 3d depths are interfering with your 2d drawing. Either disable the depth test, or call glClear() and reset the depth buffer before your 2d drawing.
[size="1"][[size="1"]TriangularPixels.com[size="1"]] [[size="1"]Rescue Squad[size="1"]] [[size="1"]Snowman Village[size="1"]] [[size="1"]Growth Spurt[size="1"]]
Tried both and it didn''t change anything.
Are there any other possibilities to do a descent HUD?
Are there any other possibilities to do a descent HUD?
glPushAttrib(GL_CURRENT_BIT);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0, _display->getWidth(), 0, _display->getHeight());
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0, _display->getWidth(), 0, _display->getHeight());
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
Game Core
Thanx to both of you. Implemented that the same way as above and then wanted to draw a rectangle (maybe I should add that my GL display is 800x600):
glColor3f(0.0f, 0.6f, 0.0f);
glBegin(GL_QUADS);
glVertex2i(0, 0);
glVertex2i(0, 600);
glVertex2i(400, 600);
glVertex2i(400, 0);
glEnd();
The weird thing is that the rectangle has the wrong size (much too thin) and that it draws it behind a model that''s also in the scene (when I disable the model the shape doesn''t change so it should not be caused by any code from that part). So I added glDisable(GL_DEPTH_TEST) but still no change.
I guess it is a error from somewhere else that causes this defunct - but every test I could do (disable some part of the code and stuff) didn''t cause any change. *scratches his head*
Any suggestions?
glColor3f(0.0f, 0.6f, 0.0f);
glBegin(GL_QUADS);
glVertex2i(0, 0);
glVertex2i(0, 600);
glVertex2i(400, 600);
glVertex2i(400, 0);
glEnd();
The weird thing is that the rectangle has the wrong size (much too thin) and that it draws it behind a model that''s also in the scene (when I disable the model the shape doesn''t change so it should not be caused by any code from that part). So I added glDisable(GL_DEPTH_TEST) but still no change.
I guess it is a error from somewhere else that causes this defunct - but every test I could do (disable some part of the code and stuff) didn''t cause any change. *scratches his head*
Any suggestions?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement