PDA

View Full Version : Overlapping Viewports



McWare
01-29-2004, 06:25 AM
Hi,
I'm having some problems with my Viewports.
I have a window with 2 viewports in it. The main viewport draws the scene, then the 2nd viewport draws the world orientation.

My problem is that after a rotation/translate, I immediately call my draw routine to redraw the views. When I do this, the main scene is now drawn in the world orientation viewport, and the main viewport is blank.
Here's the pseudo:

OnDraw {
PushMatrix();
DrawScene();

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
//Setup small overlapping viewport in lower corner. (glOrtho)
glMatrixMode(GL_MODELVIEW);

glLoadIdentity();
DrawOrientation();

glMatrixMode(GL_PROJECTION);
glPopMatrix(); //Reset to large viewport
glMatrixMode(GL_MODELVIEW);

glPopMatrix();

}

Am I missing something? Let me know if this needs clarification.

dorbie
01-29-2004, 08:18 AM
I don't see any viewport or scissor calls. That's what you want to look at. These have nothing to do with the matrix, so basically you're showing us the wrong code.

You probably have a viewport call (and maybe scissor call too) in your draw orientation function somewhere and so you're exiting that function with the orientation viewport.

You should probably take the viewport code from your onSize callback and place it in front of your draw, or in your DrawScene callback.

McWare
01-29-2004, 09:07 AM
I pulled the OnSize viewport code to the start of the OnDraw as well now, here's what I have:

glLoadIdentity();
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45, width/height, 0.1f, 100f)
glMatrixMode(GL_MODELVIEW);

//Draw Scene

glViewport(0, 0, width/4, height/4);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, width/4, height, height/4, -200, 200);
glMatrixMode(GL_MODELVIEW);

//Draw Orientation

glMatrixMode(GL_PROJECTION);
glPopMatrix(); //reset viewports.
glMatrixMode(GL_MODELVIEW);

everywhere I've looked, this seems to be correct settings, but now I don't get the Orientation window drawn at all.....

am I not storing a matrix somewhere? am I overwriting something before I draw it properly?

Thanks.

dorbie
01-29-2004, 09:50 AM
Did you look fro glScissor calls in the routine?

McWare
01-29-2004, 11:11 AM
I enabled GL_SCISSOR_TEST

Created a glScissor() with the same dimensions as my orientation viewport, drew
the viewport, then disabled GL_SCISSOR_TEST before I swapped the buffers.

Still nothing displaying in the corner. The main scene doesnt get blocked in that area either.

McWare
01-30-2004, 04:32 AM
It's working now. For some reason, the Ortho Projection for the Orientation didn't have the Origin at the centre of the viewport. It was in the bottom left corner. Don't know why.

Thanks for all the help http://www.opengl.org/discussion_boards/ubb/smile.gif

Relic
01-30-2004, 05:29 AM
Because parameters "left" specifies the left border and "bottom" the bottom. http://www.opengl.org/discussion_boards/ubb/wink.gif