Results 1 to 5 of 5

Thread: Zooming: GL_MODELVIEW or GL_PROJECTION?

  1. #1
    Junior Member Newbie rogxx's Avatar
    Join Date
    Oct 2010
    Posts
    9

    Zooming: GL_MODELVIEW or GL_PROJECTION?

    Hello everybody!

    I am beginning to write a very very little and simple 3D
    cad application (mainly using glOrtho()).

    My first target is to be sure of my viewing transformations.

    I have read, from the Red Book, chapter 3, "The Camera Analogy":

    1) Setting up your tripod and pointing the camera at the scene
    (viewing transformation).

    2) Arranging the scene to be photographed into the desired composition
    (modeling transformation).

    3) Choosing a camera lens or adjusting the zoom
    (projection transformation).

    4) Determining how large you want the final photograph to be -
    for example, you might want it enlarged
    (viewport transformation).
    So, after some tries, I have a piece of code where I do rotations
    and translations with glMatrixMode(GL_MODELVIEW);

    and, as You can read in point 3), scaling (zooming) in mode GL_PROJECTION,
    changing the parameters of glOrtho().

    Now the question, especially for zooming:

    Is this the best way to do this things?

    Will I have problems in the future with this approach?

    Thanks in advance,
    Rogxx

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,654

    Re: Zooming: GL_MODELVIEW or GL_PROJECTION?

    Quote Originally Posted by rogxx
    as You can read in point 3), scaling (zooming) in mode GL_PROJECTION, changing the parameters of glOrtho().

    Now the question, especially for zooming:

    Is this the best way to do this things?

    Will I have problems in the future with this approach?
    Sounds like you're generally on the right track, but it's unclear exactly what you're loading on the PROJECTION matrix. glOrtho, gluOrtho2D, glFrustum, gluPerspective. Any of these (alone on top of an glLoadIdentity) is good. glScale? Now that's not good. That's called "Projection Abuse".

    http://www.sjbaker.org/steve/omniv/p...ion_abuse.html

    Just to be clear, there are a few ways to "zoom" on object (i.e. make something appear bigger on the screen. One is to reduce the size of the frustum. You can do that with the Ortho or Frustum calls (on the PROJECTION stack of course) reducing right-left and/or top-bottom. Or you can do it with Frustum (again, on PROJECTION stack) by pushing near out. Or you can do it with Perspective in the obvious way of reducing fovy and/or aspect.

    Another way to "zoom" (when you have a perspective transform active on the PROJECTION stack) is to just use the MODELVIEW stack to move the eyepoint closer to the object (i.e. change the VIEWING transform) or move the object closer to the eyepoint (i.e. change the MODELING transform). Then its apparent size increases in your field of view. You could do the former with gluLookAt and the latter with glTranslate on the MODELVIEW stack (at the appropriate time).

    Yet another way to make an object bigger is to change it's size via a scale transform on the MODELVIEW stack when you're rendering your object. You could do this with glScale on the MODELVIEW stack for instance. I generally avoid this because it means you have to tell the GPU to normalize normals to get your lighting to work in your shader, not to mention that most real world objects don't physically grow and shrink, but you can definitely do this.

    Any of these are fine. Which one is better depends on your specific requirements for how things need to look in your application. For instance, how do other objects in the scene need to appear when you're "zooming" that specific object?

  3. #3
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,674

    Re: Zooming: GL_MODELVIEW or GL_PROJECTION?

    Or you can do it with Frustum (again, on PROJECTION stack) by pushing near out.
    That doesn't really cause zooming though. It just cuts out more stuff in front.

  4. #4
    Junior Member Newbie rogxx's Avatar
    Join Date
    Oct 2010
    Posts
    9

    Re: Zooming: GL_MODELVIEW or GL_PROJECTION?

    Thank You very much for the replies.

    Dark Photon wrote:
    but it's unclear exactly what you're loading on the PROJECTION matrix. glOrtho, gluOrtho2D, glFrustum, gluPerspective.
    I mainly prefer to use glOrtho(), to have a "parallel projection view", like users of mechanical cad applications often prefer. I have to study better glFrustum, to add the option of a perspective view.

    You can do that with the Ortho or Frustum calls (on the PROJECTION stack of course) reducing right-left and/or top-bottom.
    Yes, when the user interact with the mouse to get zooming, it changes a zooming parameter that modify the right-left and top-bottom values of the call to glOrtho (and near-far too, because of clipping), with respect of the aspect ratio between height and width (glViewport).

    Yet another way to make an object bigger is to change it's size via a scale transform on the MODELVIEW stack when you're rendering your object.
    ...
    ...
    For instance, how do other objects in the scene need to appear when you're "zooming" that specific object?
    I prefer not to use this approach, because I want to manage separately the viewing transformation to render the scene (using Opengl) from the mathematical rapresentation of my objects (not using Opengl), ie if I want to scale an object I change it's mathematical definition, it is not a viewing problem.
    For zooming, my doubt was between using the glOrtho/glFrustum/GL_PROJECTION approach or the glScale/GL_MODELVIEW approach(but for the entire scene),

    Regards,
    rogxx

  5. #5
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,654

    Re: Zooming: GL_MODELVIEW or GL_PROJECTION?

    Quote Originally Posted by Alfonse Reinheart
    Or you can do it with Frustum (again, on PROJECTION stack) by pushing near out.
    That doesn't really cause zooming though. It just cuts out more stuff in front.
    No, think about it. Where are the L,R,B,T values defined with a perspective Frustum transform? On the near clip plane. Push the near clip plane out (while leaving L,R,B,T alone), and you just reduced your FOV (which of course makes things in the center of the frustum bigger in the new FOV).



    ...unless I'm missing something obvious which is certainly possible.

Similar Threads

  1. glOrtho in GL_PROJECTION vs GL_MODELVIEW?
    By wmelgaard in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 03-23-2014, 12:51 PM
  2. speed of GL_PROJECTION vs GL_MODELVIEW?
    By sparkster in forum OpenGL: Advanced Coding
    Replies: 8
    Last Post: 04-20-2005, 07:01 AM
  3. Diference between GL_MODELVIEW and GL_PROJECTION
    By The mexican in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 06-09-2004, 11:06 PM
  4. Problem with GL_PROJECTION / GL_MODELVIEW matrices
    By Marmotte in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 12-10-2002, 02:31 AM
  5. GL_MODELVIEW & GL_PROJECTION
    By imported_robert in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 11-02-2000, 04:37 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