PDA

View Full Version : How should I set up frustrums and matrices to achive this?



Sdw
03-01-2003, 01:07 PM
I want to render a scene half the screen at the time. Like this:




Screen:
+-------+-------+
| | |
| 1 | 2 |
| | |
+-------+-------+


At the moment I'm doing like this:



gluPerspective(55.0,(float)(xres/2)/(float)yres, 0.01f, 100.0f);
glPushMatrix();
glViewport(0,0,xres/2,yres);
DrawScene();
glPopMatrix();
glPushMatrix();
glViewport(xres/2,0,xres/2,yres);
DrawScene();
glPopMatrix();


But this doesn't provide a seemless render, instead I get the "middle" of the scene rendered twice. How do I set it up so that the end result will look just like if I had done like this:




gluPerspective(55.0,(float)(xres)/(float)yres, 0.01f, 100.0f);
glViewport(0,0,xres,yres);
glPushMatrix();
DrawScene();
glPopMatrix();


And, yes there is a reason that I want to render this in two steps like this http://www.opengl.org/discussion_boards/ubb/smile.gif

[This message has been edited by Sdw (edited 03-01-2003).]

ehart
03-01-2003, 01:40 PM
What you want to do is look at the definition of what gluPersepctive does. (It is in either the red or blue book) It creates parameters that it passes to glFrustum. You need to create the same parameters for the whole view, and then so that the left parameter is kept for the left screen half, but the right parameter is replaced by (left+right)/2. The right side is generated with similar parameter modifications.

-Evan

rgpc
03-01-2003, 03:59 PM
glViewPort defines the area of the screen your scene will render in. Your "view vector" will be centered in the rectangle you define.

What you actually want is to leave glViewPort alone and use glScissor().

So your code will probably look something like this:




glEnable(GL_SCISSOR_TEST);
gluPerspective(55.0,(float)(xres/2)/(float)yres, 0.01f, 100.0f);
glPushMatrix();
glScissor(0,0,xres/2,yres);
DrawScene();
glPopMatrix();
glPushMatrix();
glScissor(xres/2,0,xres/2,yres);
DrawScene();
glPopMatrix();


When you clear your buffer (if you need to clear your buffer) turn scissor testing off and do a single glClear().

Sdw
03-02-2003, 12:11 AM
Thank you very much! That glScissor solution worked perfectly! I had started implementing a cumbersome thing using the stencil buffer and clip planes, but this was just so much more elegant. Thanks again!