Jump to content
  • Advertisement
Sign in to follow this  
ajmas

Status panes in front of scene?

This topic is 3855 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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();
}

Share this post


Link to post
Share on other sites
Just make sure you don't forget to toggle the matrix mode back before drawing ;)
Quote:
Original post by ajmas

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);
gl.glMatrixMode(GL.GL_MODELVIEW);
}

void popOrthographicProjection( GL gl ) {
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glPopMatrix();
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glPopAttrib();
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!