PDA

View Full Version : Borders on multiple viewports



NTense
02-04-2004, 09:32 AM
Hi,
I'm experimenting with multiple viewports, and got them to work, but not quite the way I was hoping for. First, here's my display function (pretty simple):



void display()
{
glEnable(GL_SCISSOR_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glViewport(0,0, (cxClient/2)-2, cyClient);
glScissor(0,0, (cxClient/2)-2, cyClient);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (GLfloat)(cxClient/2)/(GLfloat)cyClient, 1.0f, 1000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glScalef(1.0, 2.0, 1.0); // modeling transformation
testtriangle();
// Force the draw
glFlush();

glViewport((cxClient/2)+2, 0, (cxClient/2)-2, cyClient);
glScissor((cxClient/2)+2, 0, (cxClient/2)-2, cyClient);
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (GLfloat)(cxClient/2)/(GLfloat)cyClient, 1.0f, 1000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glScalef(1.0, 2.0, 1.0); // modeling transformation
testtriangle();

// Force the draw and swap
glFlush();
SwapBuffers(g_HDC);
}


Like I said I got the two viewports running, but I wanted ~ 2 pixel border the native window background color around each viewport. I defined the background color in the WNDCLASSEX structure, and it displays fine when I don't call this display function. I thought the offset with both the viewport and Scissor test would restrict the OGL drawing into their respective regions, but I still lose the windows background color. Does anyone have any ideas? (I really don't want to manually draw the color in if I don't have to).

Here's the screenshots of with and without the display function:

http://www.forestmarkstudios.com/ss1.jpg

http://www.forestmarkstudios.com/SS2.jpg

[This message has been edited by NTense (edited 02-04-2004).]

dorbie
02-05-2004, 03:35 PM
It's probably something to do with calling glClear before you set the scissor dimensions :-).
There is also no way of guaranteeing the background contents when you get your context AFAIK, so to ensure you get what you want you should probably use clear color and do a clear of the background (with a 0,0,width,height viewport). Ultimately this should be safe to disable after rendering a couple or three frames, but again no guarantees. I'd be tempted to just call clear swap clear swap clear swap on creation or resize (yes I chose 3 not 2 for a reason just incase you wind up with something tripple buffering, so it's marginally safer code), then get on with the rest of your rendering without the clear.

Even if it looks OK without the full clear you're in for a nasty surprise on a resize after you begin I'll bet unless you do the clear.

NTense
02-05-2004, 06:08 PM
Thanks, I'll give it a shot.