tags:

views:

128

answers:

4

I'd like to try and implement some HCI for my existing OpenGL application. If possible, the menus should appear infront of my 3D graphics which would be in the background.

I was thinking of drawing a square directly in front of the "camera", and then drawing either textures or more primatives on top of the "base" square.

While the menus are active the camera can't move, so that the camera doesn't look away from the menus.

Does this sound far feteched to anyone or am I on the right tracks? How would everyone else do it?

+1  A: 

I would just glPushMatrix, glLoadIdentity, do your drawing, then glPopMatrix and not worry about where your camera is.

You'll also need to disable and re-enable depth test, lighting and such

cobbal
+1  A: 

There is the GLUI library to do this (no personal experience)
Or if you are using Qt there are ways of rendering Qt widgets transparently on top of the OpenGL model, there is also beta support for rendering all of Qt in opengl.

Martin Beckett
+1  A: 

You could also do all your 3d Rendering, then switch to orthographic projection and draw all your menu objects. This would be much easier than putting it all on a large billboarded quad as you suggested.

Check out this exerpt, specifically the heading "Projection Transformations".

Brandorf
+1  A: 

As stated here, you need to apply a translation of 0.375 in x and y to get pixel perfect alignment:

glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, width, 0, height);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.375, 0.375, 0.0);
/* render all primitives at integer positions */

The algorithm is simple:

  1. Draw your 3D scene, presumably with depth testing enabled.
  2. Disable depth testing so that your GUI elements will draw over the 3D stuff.
  3. Use glPushMatrix to store you current model view and projection matrices (assuming you want to restore them - otherwise, just trump on them)
  4. Set up your model view and projection matrices as described in the above code
  5. Draw your UI stuff
  6. Use glPushMatrix to restore your pushed matrices (assuming you pushed them)

Doing it like this makes the camera position irrelevant - in fact, as the camera moves, the 3D parts will be affected as normal, but the 2D overlay stays in place. I'm expecting that this is the behaviour you want.

Daniel Paull