Results 1 to 3 of 3

Thread: glOrtho in GL_PROJECTION vs GL_MODELVIEW?

  1. #1
    Member Newbie
    Join Date
    Apr 2014
    Posts
    47

    glOrtho in GL_PROJECTION vs GL_MODELVIEW?

    I have a model xmin = -264.000000, xmax = 384.000000; ymin = -263.942993, ymax = 330.480591; zmin = 673.751099, zmax = 1345.000000
    If I include glOrtho((xmin -margin), (xmax +margin), (ymin -margin), (ymax +margin), -1.0, 1.0); in model view, everything works dandy.

    Why is the Z parameter (-1.0, 1.0) instead of (zmin, zmax)?

    What difference does it make if I put the glOrtho command in model view vs projection

  2. #2
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,214
    Before going any further, please read this.
    You should not call glOrtho while GL_MODELVIEW_MATRIX stack is selected.

    If you do that, matrix at the top of MODELVIEW stack is multiplied with parallel-projection matrix looking like this.
    That produces some kind of scaling and translation that probably fixes some other transformation in your modeling approach.

    Ah, I see! By setting z-scaling factor to -1 you actually translate model down the negative Z-axis, making it visible.
    In OpenGL viewer is in (0,0,0) looking down the negative Z-axis, and your model is behind it (positive Z coordinates).

    Please, read the Chapter 3 from the old Red book (first link).

  3. #3
    Member Newbie
    Join Date
    Apr 2014
    Posts
    47
    From the tutorial, "do you want to move the camera in one direction, or move the object in the opposite direction?" All of the examples in Chapter 3 move the model. Nate Robins' robot arm is drawn in widget coordinate system, and then pasted into the model via transformation.
    In my case, all elements are located and drawn in a global coordinate system which is not under control of the programmer (yeah, the programmer can transform it wherever he wants to, but it doesn't start out that way), and is almost certainly not centered at 0, 0, 0. All new elements are pasted into the model without any transformation whatsoever, in accordance with the original global coordinate system.

    If I put the glOrtho command in GL_PROJECTION, do I also need to translate the camera while in projection mode? Or should I leave well enough alone and leave the glOrtho command in GL_MODEL_VIEW?

    Quote Originally Posted by Aleksandar View Post
    Before going any further, please read this.
    You should not call glOrtho while GL_MODELVIEW_MATRIX stack is selected.

    If you do that, matrix at the top of MODELVIEW stack is multiplied with parallel-projection matrix looking like this.
    That produces some kind of scaling and translation that probably fixes some other transformation in your modeling approach.

    Ah, I see! By setting z-scaling factor to -1 you actually translate model down the negative Z-axis, making it visible.
    In OpenGL viewer is in (0,0,0) looking down the negative Z-axis, and your model is behind it (positive Z coordinates).

    Please, read the Chapter 3 from the old Red book (first link).

Similar Threads

  1. Zooming: GL_MODELVIEW or GL_PROJECTION?
    By rogxx in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 01-13-2011, 04:31 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