Using Ortho rendering inside a 3D GUI

Hi all,

I have a slightly unusual question, so please read carefully. I’ll try to explain it as best I can, with some pictures.

I’m writing a CAD package, which uses a GUI rendered entirely in OpenGL. The windows and controls etc of the GUI are rendered in world space, and are observed with a camera, which can zoom in and out of the GUI. This is so the user can move around the large desktop, and zoom in to look at very small details and information. The camera always looks directly down on the GUI, so the edges of the windows are always horizontal or vertical.
See attached images.

My problem is this:

Inside some of these windows, I want to render 3D solid objects, with no perspective.

Currently, I’m using this code to setup the matrices before rendering the windows and controls of the GUI:

    glViewport(0, 0, (GLint)w, (GLint)h);
    gluPerspective(45,ratio, 1.0f, 30000.0f);
    glTranslatef(-camera.x, -camera.y, -camera.z);
    // now render the windows in world space.

Can I now use a glOrtho call to set up a projection which will let me render my 3D object inside a given window?

Many thanks for your help.

Hugo Elias

yes you can,

but you’d better not use ‘glPushMatrix’ before ‘glOrtho’,
because the number of matrices in projection matrix stack is limited ( in my opinion, it’s 2 ),
as a result, too many ‘glPushMatrix’ may cause matrix stack overflowed.

so just do it directly :

glMatrixMode( GL_PROJECTION );
glOrtho( left, right, bottom, top, znear, zfar )