glViewport

Hi, I am trying to slpit the screen between two views. A 3D view for navigation, and a 2D one for indcators, gauges and such.
I use glViewport to split the screen in half. The problem is that the 2D indcators don’t get shown, unless I don’t show the 3D enviroment.
When I comment the 3D methods, the indcators show up fine, but when both are working, only the 3D eviroment gets displayed in its half of the screen.

Is there anything I can do about that? Is there anything wrong with the code I’m using?

Any help would be much appreciated. Thanks!


glViewport (0, 0, GetSystemMetrics(SM_CXFULLSCREEN), GetSystemMetrics(SM_CYFULLSCREEN)/2);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 840.0, 0.0, 380.0);

/* 2D methods */

glViewport (0, GetSystemMetrics(SM_CYFULLSCREEN)/2, GetSystemMetrics(SM_CXFULLSCREEN), GetSystemMetrics(SM_CYFULLSCREEN)/2+100);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0,1.0,1,20000000);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

/* 3D methods */

glFlush();
glutSwapBuffers();
glutTimerFunc(10,myTimer,1);

You don’t use the scissor test. It means when you call glClear the entire window is cleared. You have to enable the scissor test on the relevant part of the window. glViewport just set a transformation but draw commands like glClear don’t take glViewport into account:

glScissor(left,bottom,width,height);
glEnable(GL_SCISSOR_TEST);
// draw commands here

Thanks for your reply. I have replaced view port with scissor test. It looks better, view port stretched the 3D environment to fit half the screen, distorting the aspect ratio. Scissor test removed the lower half, which is what I wanted.
But still the 2D methods don’t get displayed. Now, however, they disappear after the first redisplay, instead of not being displayed at all.

Well, seems something your 3D scene is doing is keeping your 2D objs from rendering. Could be a number of things (the pipeline “tests” most likely), but before rendering your 2D objs, try:

glDisable( GL_DEPTH_TEST );
glDisable( GL_ALPHA_TEST );
glDisable( GL_STENCIL_TEST );
glDisable( GL_SCISSOR_TEST );

Still nothing, 2D drawings show up, then disappear.

Now the code is:


glScissor(0,0,GetSystemMetrics(SM_CXFULLSCREEN), GetSystemMetrics(SM_CYFULLSCREEN)/2);
glEnable(GL_SCISSOR_TEST);
glDisable(GL_DEPTH_TEST);
glDisable(GL_ALPHA_TEST);
glDisable(GL_STENCIL_TEST);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 840.0, 0.0, 380.0);

/* 2D methods */

glScissor(0, GetSystemMetrics(SM_CYFULLSCREEN)/2, GetSystemMetrics(SM_CXFULLSCREEN), GetSystemMetrics(SM_CYFULLSCREEN)/2+100);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0,1.0,1,20000000);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

/*3D methods */

glDisable(GL_SCISSOR_TEST);
glFlush();
glutSwapBuffers();
glutTimerFunc(10,myTimer,1);

And the 2D drawings disappear after the first redisplay. Is there something wrong with the code?

Just to make sure, you do realize that scissor test affects the operation of glClear. Disable scissor test before you clear unless you do intend to do a viewport clear. And you didn’t disable scissor test before drawing the 2D stuff, so that’s a possible cause. Disable scissor test and see if your 2D stuff comes back.

Also, try changing your first glClear(GL_COLOR_BUFFER_BIT) to glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT), and change
your next glClear from glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) to glClear(GL_DEPTH_BUFFER_BIT).

Scissor test and the glClears of the color buffer are the two most likely things I see that might be killing your 2D stuff.

Thanks for your help, but still nothing…

Post a little stand-alone test prog with the above and some really simple 2D/3D drawing so folks can compile and help you diagnose.

OK it worked, yes it was a problem with the glClear(). Thanks for all your help.