PDA

View Full Version : Two views in One Window



openglNewbie
02-28-2001, 02:58 PM
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.

john
02-28-2001, 06:24 PM
Hello,

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

cheers,
John

phenotic
02-28-2001, 08:28 PM
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

Gavin
03-01-2001, 12:58 AM
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

Fastian
03-01-2001, 05:49 AM
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.

Tim Stirling
03-01-2001, 09:14 AM
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. http://www.opengl.org/discussion_boards/ubb/smile.gif

phenotic
03-01-2001, 09:22 AM
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!

Tim Stirling
03-03-2001, 09:15 AM
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.