Status panes in front of scene?
I am wanting to create a scene and at the same time draw some panes in front of the scene which would allow the user to change certain settings. In doing so I want to ensure that any manipulattion of my scene does not interfere with my panes.
Can anyone suggest how to do this or point me towards some examples?
Thanks for the reply and for the link.
In reality I am more interested in learning the mechanics of doing it myself for the moment. I am still learning OpenGL and feel that I would rather understand how this is done in OpenGL, before using a ready built solution.
In reality I am more interested in learning the mechanics of doing it myself for the moment. I am still learning OpenGL and feel that I would rather understand how this is done in OpenGL, before using a ready built solution.
The basics of a 2D overlay/HUD are to render your 3D scene with a perspective projection and then switch to an orthographic projection (with glOrtho) to render your status panel. There's also a nice entry in the forum FAQ about 2D with OpenGL.
I actually just worked this out myself. Here is some psuedocode of what I did:
pushPerspectiveProjection();
while(running)
pushOrthographicProjection();
drawUI();
popProjection();
drawScene();
end
pushOrthographicProjection()
glPushAttrib(GL_TRANSFORM_BIT);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0.0f, width, 0.0f, height, -1.0f, 1.0f);
glPopAttrib();
end
pushPerspectiveProjection();
while(running)
pushOrthographicProjection();
drawUI();
popProjection();
drawScene();
end
pushOrthographicProjection()
glPushAttrib(GL_TRANSFORM_BIT);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0.0f, width, 0.0f, height, -1.0f, 1.0f);
glPopAttrib();
end
Thanks, this work beautifully. Some actual code, in Java using JOGL, for anyone else who happens to come along this thread:
void pushOrthographicProjection( GL gl ) { gl.glPushAttrib(GL.GL_TRANSFORM_BIT); gl.glMatrixMode(GL.GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glOrtho(0.0f, getWidth(), 0.0f, getHeight(), -1.0f, 1.0f); } void popOrthographicProjection( GL gl ) { gl.glPopMatrix(); gl.glPopAttrib(); }
Just make sure you don't forget to toggle the matrix mode back before drawing ;)
Quote:Original post by ajmasvoid pushOrthographicProjection( GL gl ) { gl.glPushAttrib(GL.GL_TRANSFORM_BIT); gl.glMatrixMode(GL.GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glOrtho(0.0f, getWidth(), 0.0f, getHeight(), -1.0f, 1.0f); gl.glMatrixMode(GL.GL_MODELVIEW); } void popOrthographicProjection( GL gl ) { gl.glMatrixMode(GL.GL_PROJECTION); gl.glPopMatrix(); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPopAttrib(); }
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement