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

Thread: glOrtho not displays a Triangle

  1. #1
    Intern Newbie
    Join Date
    Jun 2010
    Posts
    34

    glOrtho not displays a Triangle

    Dear Experts,
    triangle is not drawn when glOrtho z range between 0 and 1.

    glMatrixMode( GL_PROEJCTION );
    glLoadIdendity();
    glOrtho( -1,1,-1,1,-1,1 );


    glMatrixMode( GL_MODELVIEW );
    glLoadIdendity();


    // Draw a triagnle in z -0.5
    glBegin( GL_TRIANGLES );
    glColor3f( 1, 0, 0 );
    glVertex3f( -0.5, -0.5, 0.5 );
    glVertex3f( 0.5, -0.5, 0.5 );
    glVertex3f( 0.0, 0.5, 0.5 );
    glEnd();


    It displays a red triangle. Its fine for me.


    But when I change near clipping plane to 0, It displays nothing.
    Traingle is drawing with z 0.5, and near and far is between 0 and 1.
    But Traingle is not drawn why ?
    Please give any information..
    Thanks in advance..


    glMatrixMode( GL_PROEJCTION );
    glLoadIdendity();
    glOrtho( -1,1,-1,1,0,1 );


    glMatrixMode( GL_MODELVIEW );
    glLoadIdendity();


    // Draw a triagnle in z -0.5
    glBegin( GL_TRIANGLES );
    glColor3f( 1, 0, 0 );
    glVertex3f( -0.5, -0.5, 0.5 );
    glColor3f( 0, 1, 0 );
    glVertex3f( 0.5, -0.5, 0.5 );
    glColor3f( 0, 0, 1 );
    glVertex3f( 0.0, 0.5, 0.5 );
    glEnd();

  2. #2
    Member Regular Contributor Nowhere-01's Avatar
    Join Date
    Feb 2011
    Location
    Novosibirsk
    Posts
    251
    cause legacy OpenGL functions for transformation operate in right-handed coordinate system. it means "camera" looks into negative-Z. even comments in your own code suggest drawing at z=-0.5, yet you draw at z=0.5. when you set near plane to -1.0, it shows geometry "behind" view origin. but with near plane = 0.0, it renders only stuff in front of it.

  3. #3
    Intern Newbie
    Join Date
    Jun 2010
    Posts
    34
    Quote Originally Posted by Nowhere-01 View Post
    cause legacy OpenGL functions for transformation operate in right-handed coordinate system. it means "camera" looks into negative-Z. even comments in your own code suggest drawing at z=-0.5, yet you draw at z=0.5. when you set near plane to -1.0, it shows geometry "behind" view origin. but with near plane = 0.0, it renders only stuff in front of it.
    Hi nowhere,
    Thanks for your quick reply. Still I have few doubts, please help me.

    Is glOrtho( -1,1, -1,1, 0, 1 ) is valid ? From books it gives an idea that near and far clipping planes. Therefore objects between this z should displayed in scene.
    Sorry for the wrong comment in the code. All objects are drawn in positive z.( 0.5 ). But it displays triangle when near clipping plane is -1, and do not displays triangle when near clipping plane is 0.

    Do I need to do something else( gluLookAt, or transformation to display this triangle ).
    Thanks in advance.

  4. #4
    Member Regular Contributor Nowhere-01's Avatar
    Join Date
    Feb 2011
    Location
    Novosibirsk
    Posts
    251
    Sorry for the wrong comment in the code.
    the comment in your code is actually correct and you ignored it for some reason. glOrtho( -1,1, -1,1, 0, 1 ) is valid, in your case, it will draw everything with Z-coordinates in range of 0 to -1. it's because in legacy opengl, "camera" "looks" along NEGATIVE Z-Axis. it draws your triangle with glOrtho( -1,1, -1,1, -1, 1), cause near plane is -1, thus it includes some area behind view origin.

    i can't explain that all, cause my english is not so good and i have no time, but here's some reading on projections:
    http://www.songho.ca/opengl/gl_projectionmatrix.html

    i recommend you to read some basic tutorials on opengl as well.
    Last edited by Nowhere-01; 05-26-2013 at 11:58 AM. Reason: missed some words

  5. #5
    Intern Newbie
    Join Date
    Jun 2010
    Posts
    34
    Quote Originally Posted by Nowhere-01 View Post
    the comment in your code is actually correct and you ignored it for some reason. glOrtho( -1,1, -1,1, 0, 1 ), in your case, it will draw everything with Z-coordinates in range of 0 to -1. it's because in legacy opengl, "camera" "looks" along NEGATIVE Z-Axis. it draws your triangle with glOrtho( -1,1, -1,1, -1, 1), cause near plane is -1, thus it includes some area behind view origin.

    i can't explain that all, cause my english is not so good and i have no time, but here's some reading on projections:
    http://www.songho.ca/opengl/gl_projectionmatrix.html

    i recommend you to read some basic tutorials on opengl as well.

    // Draw a triagnle in z 0.5
    glBegin( GL_TRIANGLES );
    glColor3f( 1, 0, 0 );
    glVertex3f( -0.5, -0.5, 0.5 );
    glVertex3f( 0.5, -0.5, 0.5 );
    glVertex3f( 0.0, 0.5, 0.5 );
    glEnd();

    This is my code to display the Triangle. It displays when I set glOrtho, zNear as -1 and zFar as +1.
    But it donot displays when I set glOrtho, zNear as
    0 and zFar as +1.

  6. #6
    Intern Contributor
    Join Date
    Jul 2006
    Posts
    72
    Repeating your original question does no good when it was already answered ... twice.

Posting Permissions

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