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();

even comment says “Draw a triangle in z -0.5” and you persist drawing at z=0.5(which is behind view). in OpenGL, legacy functions for transformation operate strictly in right-handed coordinates. it means that “camera” looks into negative-Z.

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.

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.

[QUOTE=Nowhere-01;1251124]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.[/QUOTE]

// 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.

Repeating your original question does no good when it was already answered … twice.