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 4 of 4

Thread: How should I set up frustrums and matrices to achive this?

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2002
    Location
    Sweden
    Posts
    2

    How should I set up frustrums and matrices to achive this?

    I want to render a scene half the screen at the time. Like this:

    Code :
    Screen:
    +-------+-------+
    |       |       |
    |   1   |   2   |
    |       |       |
    +-------+-------+
    At the moment I'm doing like this:
    Code :
    gluPerspective(55.0,(float)(xres/2)/(float)yres, 0.01f, 100.0f);
    glPushMatrix();
    glViewport(0,0,xres/2,yres); 
    DrawScene();
    glPopMatrix();
    glPushMatrix();
    glViewport(xres/2,0,xres/2,yres); 
    DrawScene();
    glPopMatrix();
    But this doesn't provide a seemless render, instead I get the "middle" of the scene rendered twice. How do I set it up so that the end result will look just like if I had done like this:

    Code :
    gluPerspective(55.0,(float)(xres)/(float)yres, 0.01f, 100.0f);
    glViewport(0,0,xres,yres); 
    glPushMatrix();
    DrawScene();
    glPopMatrix();
    And, yes there is a reason that I want to render this in two steps like this

    [This message has been edited by Sdw (edited 03-01-2003).]

  2. #2
    Junior Member Regular Contributor
    Join Date
    Jan 2001
    Posts
    238

    Re: How should I set up frustrums and matrices to achive this?

    What you want to do is look at the definition of what gluPersepctive does. (It is in either the red or blue book) It creates parameters that it passes to glFrustum. You need to create the same parameters for the whole view, and then so that the left parameter is kept for the left screen half, but the right parameter is replaced by (left+right)/2. The right side is generated with similar parameter modifications.

    -Evan

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Apr 2000
    Location
    Melbourne,Victoria,Australia
    Posts
    767

    Re: How should I set up frustrums and matrices to achive this?

    glViewPort defines the area of the screen your scene will render in. Your "view vector" will be centered in the rectangle you define.

    What you actually want is to leave glViewPort alone and use glScissor().

    So your code will probably look something like this:

    Code :
    glEnable(GL_SCISSOR_TEST);
    gluPerspective(55.0,(float)(xres/2)/(float)yres, 0.01f, 100.0f);
    glPushMatrix();
    glScissor(0,0,xres/2,yres); 
    DrawScene();
    glPopMatrix();
    glPushMatrix();
    glScissor(xres/2,0,xres/2,yres); 
    DrawScene();
    glPopMatrix();
    When you clear your buffer (if you need to clear your buffer) turn scissor testing off and do a single glClear().

  4. #4
    Junior Member Newbie
    Join Date
    Jun 2002
    Location
    Sweden
    Posts
    2

    Re: How should I set up frustrums and matrices to achive this?

    Thank you very much! That glScissor solution worked perfectly! I had started implementing a cumbersome thing using the stencil buffer and clip planes, but this was just so much more elegant. Thanks again!

Posting Permissions

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