Two views in One Window

Can anybody tell me how to create two separate views in one window? I want to write a game of two players in a same environment and each player will have its own view of the environment in half of the window.

Hello,

glViewport(…) will do this. (It doesn’t HAVE to fill the entire window, after all)

cheers,
John

How actually would one do that though?

I tried it but I can’t figure out how to reference each viewport when drawing.

thanks…

phenotic

If memory serves me correctly…

glViewport(0, 0, (GLsizei) 400, (GLsizei)400);
drawplayer1();
glViewport((GLsizei)400, (GLsizei)400, (GLsizei) 800, (GLsizei)800);
drawplayer1();

don’t know if there is a way to reference the viewports and then alter them in a similar way to windows in glut?

gav

but all the transformation applied on the projection matrix and modelview matrix are applied to both viewports. To have different annimation in different viewports, I guess we have to load differen projection and modelview matrix for both viewports.

The scissor test also helps. Today I implemented a 4 panel split screen for a level editor (top down, front, side and 3d views). I found that as well as using the viewport a scissor test was needed to stop the clear command clearing the entire screen instead of just the view panel.
I think the code is this:
glEnable(GL_SCISSOR_TEST); // this goes in your init function

glScissor(x,y,width,height); // set this up with the same inputs as the glViewport function

Tell me if you need more help.

Hmmm,

I just tried this as well and I can’t seem to get it to work. This would be perfect for what I’m doing. I’m new to this GL thing and I have a feeling i’m not coding this right. Could you point me to some source code?

BTW How efficient is the scissors? Does the entire scene get computed and the extra pixels just get clipped in the end or does having a large area snipped cut down on rendering time?

Thanks!

here is a snippet of code:

glLoadIdentity();
// ***************top left view XY
// Reset The Current Viewport
glViewport(0, height/2, width/2, height/2); // setup top left viewport
glScissor(0, height/2, width/2, height/2);
SetProjection(0);// set projection to ortho
glClearColor(bgcolourred2d, bgcolourgreen2d,bgcolourblue2d , 1.0f); // This Will change th Back groung color
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// Clear The Screen And The Depth Buffer

glLineWidth(3.0);glColor3f(0.0,0.0,0.0
glVertex3f(…) // draw a grid or what ever you want
// ******************** end top left view XY

// ***************top right view YZ
// Reset The Current Viewport

glViewport(width/2, height/2, width/2, height/2); // setup top left viewport
glScissor(width/2, height/2, width/2, height/2);
SetProjection(0);// set projection to ortho
glClearColor(bgcolourred2d, bgcolourgreen2d,bgcolourblue2d , 1.0f); // This Will change th Back groung color
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer

glScalef(m_Zoom,m_Zoom,m_Zoom);
//scale/zoom in
glRotatef(90,0.0,-1.0,0.0); // rotate to look in correct direction

glBegin(GL_LINES);
glVertex3f(…); // draw some more

 this is heavily cut down but you see waht I mean. I use 

glViewport(0, height/2, width/2, height/2); and
glScissor(0, height/2, width/2, height/2);

height and width are setup when the window is made also not that the screen is defined
from bottom left to top right. So the first value for the top left viewport is start viewport x = 0, start height = middle of screen, width is half the screen and height is half the screens height.