Results 1 to 2 of 2

Thread: combining frustum and ortho views

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2009
    Posts
    7

    combining frustum and ortho views

    Hi,

    I have been developing a set of tools for visualizing sound models in OpenGL, right now in python. I have a system that works loosely as follows: frames are added to a main class, which all do basic drawing commands. Within the frames lay objects for drawing. Each (including the frame) have a draw() function that will make opengl calls. At the beginning of each frame, a glViewport() call is made with the dimensions for that frame, thereafter normalizing the dimensions within the frame for other objects.

    The problem I now need to overcome is how to allow for some frames to draw using frustrum view and others in ortho (or perspective I suppose). Before, I was calling the following in the main resize method:

    glFrustum (0.0, 1.0, 0.0, 1.0, 1., 100.0)
    gluLookAt (0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)

    But, this makes everything frustum and nothing can be in 3d. I would like the frames to all be drawn in 2 dimensions, but I would like their contents to be optionally 3d.

    So, I tried adding the following to the beginning of the draw() method of the frames:

    glViewport(self.x, self.y, self.width, self.height)
    glLoadIdentity()
    glMatrixMode(GL_PROJECTION)
    if self.Ortho:
    glOrtho (0.0, 1.0, 0.0, 1.0, 1., 100.0)
    else:
    glFrustum (0.0, 1.0, 0.0, 1.0, 1., 100.0)
    glMatrixMode(GL_MODELVIEW)

    But, then I can see nothing in the frame, whether self.Ortho is true or false.

    Can anyone tell me if I am on the right track? I am indeed quite new to opengl programming, so it is difficult to know why I am not seeing anything.

    regards,
    Rich

  2. #2
    Senior Member Regular Contributor strattonbrazil's Avatar
    Join Date
    Jun 2007
    Location
    Los Angeles, CA
    Posts
    305

    Re: combining frustum and ortho views

    Hey Rich,

    ortho is the opposite of perspective. In perspective, things get smaller when they are drawn farther from the camera. With ortho, they are not.

    If you look at your code, you have GL_MODELVIEW set as the last matrix mode. When you come back around it will still be in that mode and you'll load the identity into it, but you never clear the GL_PROJECTION matrix, which means you're multiplying the glOrtho matrix or glFrustum matrix against itself again and again.

    glLoadIdentity() # clears the last matrix, looks to be modelview
    glMatrixMode(GL_PROJECTION) # switch to projection
    if self.Ortho:
    glOrtho(0.0, 1.0, 0.0, 1.0, 1., 100.0) # multiply the projection matrix by this new matrix. If you haven't cleared it, it will probably give you an unusable matrix
    else:
    glFrustum (0.0, 1.0, 0.0, 1.0, 1., 100.0) # same issue here
    glMatrixMode(GL_MODELVIEW) # switch to modelview

    What you might want to do to make it a little cleaner...

    glViewport(self.x, self.y, self.width, self.height)
    glMatrixMode(GL_PROJECTION) # switch to projection
    glLoadIdentity() # clear out the projection
    if self.Ortho:
    ... set a projection
    else:
    ... set a projection

    All the matrix functions like glFrustum multiply against the current matrix that is there from last time. If you multiply two of these together, you get results you don't expect. Like glFrustum will project the projection over and over and if you see it slow enough, you'll see your scene fly off into the distance.
    glMatrixMode(GL_MODELVIEW) # switch to modelview
    glLoadIdentity() # clear out the modelview
    ... do your camera pointing stuff here

Similar Threads

  1. Converting over from Ortho to Frustum
    By Fezziwig in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 03-18-2012, 03:16 PM
  2. Point in frustum in Ortho projection mode
    By devdept in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 12-21-2009, 07:39 AM
  3. Ortho and frustum question.
    By Anon5710 in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 07-28-2008, 06:16 AM
  4. Switching between ortho and perspective views
    By nexusone in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 10-08-2002, 05:34 PM
  5. Custom projection matrix: part ortho, part frustum
    By joelsk in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 11-30-2000, 07:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean