Splitting the view with glViewport doesn't work.

glViewport seems to have no effect in a glut window.

I’m writing a CAD program here and I want to split my view in quarters and render 4 different perspectives.

It’d be perfect if I could just redefine the viewport 4 times between calling glutSwapBuffers, you know?

It works fine for me with glut, maybe post some code so we can see what you are doing wrong…

Originally posted by Rad:
[b]glViewport seems to have no effect in a glut window.

I’m writing a CAD program here and I want to split my view in quarters and render 4 different perspectives.

It’d be perfect if I could just redefine the viewport 4 times between calling glutSwapBuffers, you know?[/b]

The key lines of code from below are:

glViewport(0, 0, SCREEN_WIDTH/2, SCREEN_HEIGHT);
glOrtho(-2,2,-3,3,4,4000);

I would expect this to render on the left half of my window but it stretches the image across the full width of the window instead. Am I doing something wrong?

int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);

glutInitWindowPosition(100,100);
glutInitWindowSize(SCREEN_WIDTH,SCREEN_HEIGHT);
glutCreateWindow(“Boogie Bar”);

glutDisplayFunc(renderScene);
glutIdleFunc(renderScene);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

	glViewport(0, 0, SCREEN_WIDTH/2, SCREEN_HEIGHT);

glOrtho(-2,2,-3,3,4,4000);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0,0,-5);

glEnable(GL_DEPTH_TEST);
glClearColor(0, 0, 0, 0.0);
glutSetCursor(GLUT_CURSOR_CROSSHAIR);

initLighting();

glutMainLoop();

return(0);
}

The entire screen wil get cleared to the clear color that you set with the code that you have. However, if you draw a square or something in that viewport, you will notice that it is only being drawn to the left.

  • Halcyon

Yeah, this still looks like it should work.

I started rendering in the full 640x480 window… the geometry shows up right where it should.
glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
glOrtho(-4,4,-3,3,4,4000);

Then I updated those lines like they appear in my previous post:
glViewport(0, 0, SCREEN_WIDTH/2, SCREEN_HEIGHT); glOrtho(-2,2,-3,3,4,4000);

So you guys agree that this change should render just on the left half of the screen? Its just stretching the image across the whole window.

You’ll need to define a callback in glutReshapeFunc() that sets your viewport correctly. As you haven’t done this in the code above, the default handler will reset your viewport to the whole screen when the window gets a resize event.

That was is it, now the viewport isn’t being reset every frame and my 4 viewports are rendering fine!

I didn’t have a broad enough picture of how this works to see this problem coming, I’m learning though.