PDA

View Full Version : split screen - how camera work?



apit
07-13-2003, 08:16 AM
i have make a split program using opengl with glut library... the problem is, how did the camera works in split screen? did it use two camera?

abhijeet_maharana
07-13-2003, 09:30 PM
In split screen programs, there aren't two cameras. Just one camera. The projection is changed to different parts of the screen. Check out tutorial 42 at Nehe.gamedev.net. It explains just that. But I suppose the tutorial is in Win32 and not glut.

starman
07-14-2003, 05:24 AM
Yes, as I found out over the weekend, this is very easy to do. Google for "multiple viewports" or check out the example in the Red book.

starman
07-14-2003, 05:33 AM
You can use two "cameras" if you want to show two different things in your split screens. For example, you might want to show the cockpit view from a plane in one split and the view of the plane from outside in the other:

glViewport(...); // Split 1
// Set up view frustum for cockpit view
// Draw cockpit view

glViewport(...); // Split 2
// Set up view frustum for external view
// Draw external view

apit
07-15-2003, 12:10 AM
that mean if we use two glviewport, so there are two camera...glviewport is our camera..is it true?.. do you have a complete code to refer?

john
07-15-2003, 03:17 AM
"glviewport is our camera" is not really what's going on. It's certainly part of the story, but not the whole story.

glviewport describes the map from normalised device coordinates (NDC) to window coordinates. Every point visible to the camera is projected into a cube defined by +/-1 along each of the axis. points with z=1 in the NDC frame are the furthest away from the camera you can get; and points with z=-1 are the closest to the camera. similarly, points on the plane x=1 are the furthest to the right of the visible field of view. Coordinates undergo a transform in order to turn these NDC into a pixel location on the window. This transformation is specified by glviewport. If the call to glviewport was glViewport(A, B, C, D) then NDC points along the plane x=-1 will be mapped to the pixel column A; similarly points along x=1 will be mapped to column (A+C) (width + offset).

So, you should be able to see that you can indeed define any number of cameras and specify different glviewports to describe how what one camera sees is mapped to different parts of the screen... but glViewport isn't THE camera: its only part of the whole transformation.

I hope this helps

cheers
John

starman
07-15-2003, 05:23 AM
Check out Nehe tutorial #42 (I think)...it talks about this topic.
http://nehe.gamedev.net