PDA

View Full Version : Splitting the view with glViewport doesn't work.



Rad
04-27-2003, 04:26 PM
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?

nexusone
04-27-2003, 04:43 PM
It works fine for me with glut, maybe post some code so we can see what you are doing wrong....


Originally posted by Rad:
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?

Rad
04-27-2003, 04:58 PM
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);
}

HalcyonBlaze
04-27-2003, 05:33 PM
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

Rad
04-27-2003, 06:13 PM
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.

Rog
04-27-2003, 10:29 PM
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.

Rad
04-28-2003, 12:10 AM
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.