Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 8 of 8

Thread: Two views in One Window

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2005
    Posts
    3

    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.

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2000
    Location
    Adelaide, South Australia, Australia
    Posts
    839

    Re: Two views in One Window

    Hello,

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

    cheers,
    John

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2001
    Location
    Newark, DE
    Posts
    10

    Re: Two views in One Window

    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

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Aug 2000
    Location
    Cardiff University
    Posts
    668

    Re: Two views in One Window

    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

  5. #5
    Junior Member Regular Contributor
    Join Date
    Feb 2001
    Posts
    136

    Re: Two views in One Window

    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.

  6. #6
    Member Regular Contributor
    Join Date
    Nov 2000
    Location
    Dunblane, Scotland
    Posts
    353

    Re: Two views in One Window

    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.
    Reality is for idiots only the best over come it!

  7. #7
    Junior Member Newbie
    Join Date
    Mar 2001
    Location
    Newark, DE
    Posts
    10

    Re: Two views in One Window

    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!

  8. #8
    Member Regular Contributor
    Join Date
    Nov 2000
    Location
    Dunblane, Scotland
    Posts
    353

    Re: Two views in One Window

    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.
    Reality is for idiots only the best over come it!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •