PDA

View Full Version : Multiple Viewport Hell



torrey
12-08-2000, 08:53 AM
Howdy,
I need some help http://www.opengl.org/discussion_boards/ubb/confused.gif. I am trying to display an object in multiple viewports, using an Orthographic persective to show different sides. I have four view ports, basically a window broken into four quads. Object being drawn is very simple: basically a cube made out of polygons. I can't use the cube function because there is one extra face (slice).

Prior to drawing in each quad, I reset the viewport to a size a quarter of the screen, using the lower lefthand corner of my window as 0,0. I then call out an Ortho view, such that the view is a 4x4x4 cube (-2 to 2 in each direction). When I draw my front view, my cube is perfectly centered in the viewport (lower left hand quad). Note that in this quad, Z goes into and out of the screen. But when I draw one of the other views, my cube is offset in the Z direction by approximately 0.5 units in what appears to be the negative Z direction. I have tried for 5 hours to correct this, and cannot find anything that helps. I am including my code a code snippet to detail my issue. Any insight or guidance towards the light would be appreciated.

**Starts here, draws the Front View, then Top View **

// Enable depth testing
glEnable(GL_DEPTH_TEST);

// Tell OpenGL which side of each face is the front facing face
glFrontFace(GL_CCW);

// Tell OpenGL to not apply some functions to faces that will be hidden
glEnable(GL_CULL_FACE);


// Redefine the viewport to the lower lefthand quadrant
glViewport(0,0,iViewportWidth/2,iViewportHeight/2);

//Setup the projection view and the coordinate system to display the view
glMatrixMode(GL_PROJECTION);

glLoadIdentity();

glOrtho(-2.0f, 2.0f, -2.0f, 2.0f, 2.0f, -2.0f);


//Prepare to draw object in the view
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glPushMatrix();

myDrawPolygon();

glPopMatrix();

glFlush();


//Phase 3 - Show the block model's Top View in the upper left hand quandrant


glClear(GL_DEPTH_BUFFER_BIT);

// Redefine the viewport to the upper lefthand quadrant
glViewport(0,iViewportHeight/2,iViewportWidth/2,iViewportHeight);

//Setup the projection view and the coordinate system to display the view
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glOrtho(-2.0f, 2.0f, -2.0f, 2.0f, 2.0f, -2.0f);



//Prepare to draw object in the view
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

//use this rotation to move position faces in Ortho views
glPushMatrix();

glRotatef(90.0f, 1.0f, 0.0f, 0.0f);

myDrawPolygon();

glPopMatrix();

glFlush();


[This message has been edited by torrey (edited 12-08-2000).]

Siwko
12-08-2000, 10:32 AM
Your best bet is to "preprocess" the window and break it up into 4 distinct windows. Essentially, create 4 different views, each with its own RC.

You'll obvously need a message route to coordinate action across windows, but this is the legit way to handle it.

Siwko

Crunch
12-09-2000, 09:51 AM
Is the center of your cube at 0,0,0? Is your camera rotating about 0,0,0 as well? If a corner of your cube is at 0,0,0 and you rotated it in your second viewport then the cube would have pivoted on an edge rather than rotating about its center.

I personally would have rotated the camera (projection mtx) and not the object (model mtx) when forming each viewport.

Crunch
12-09-2000, 09:58 AM
I suggest you also draw a set if lines to represent the x,y,z axis you universe and another smaller set for each object to help with your debugging. Use the stippled lines to show the negative side of each axis. Red for x, green for y and blue for z.

CS
12-09-2000, 10:08 AM
Found something ...

// Redefine the viewport to the upper lefthand quadrant
glViewport(0,iHeight/2,iWidth/2,iHeight);

Should be ...

glViewport(0,iHeight/2,iWidth/2,iHeight/2);

// comment.
// glViewPort(StartX,StartY,Width,Height);

[CS]

torrey
12-09-2000, 06:20 PM
Thanx to all for your help and insight. I ended up bailing on the multiviewport idea, and broke a single viewport into quads. Then just moved the origin to the center of each quad and did some rotations to show the sides I needed to. But thank you for taking the time to suggest some alts. This won't be my only adventure in OpenGL, so I am sure I will use these in the future. Thanx!! http://www.opengl.org/discussion_boards/ubb/biggrin.gif