PDA

View Full Version : glOrtho and visibility


fortikur
2005.04.12, 04:09 PM
I just tried out to draw using glOrtho. According to the RedBook, the help, forums, etc. glOrtho's Near and Far values only define two clipping planes, which means, if I set Near to 0 and far to 100, everything that is between 0 and 100 will be drawn. Things that are closer (behind) or further won't be drawn. Is this correct?
If it is, can somebody pls tell me, why I cannot see anything on the screen, if the quad's z coordinate is at 99?
Suprisingly, if i set it to -99 (!) it becomes visible. But wait! Near and far are 0 and 100, and z is -99...



glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);

glOrtho(0,800,600,0, 0, 100);

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, backgr);
glBegin(GL_QUADS);
glNormal3f(0.0f, 0.0f, 1.0f);
glTexCoord2f(0, 1);
glVertex3d(50, 50, 99);
glTexCoord2f(0, 0);
glVertex3d(150, 50, 99);
glTexCoord2f(1, 0);
glVertex3d( 150, 150, 99);
glTexCoord2f(1, 1);
glVertex3d( 50, 150, 99);
glEnd();

glEnable(GL_LIGHTING);
glDisable(GL_BLEND);

glMatrixMode(GL_PROJECTION);
glPopMatrix();

SwapBuffers(DCvalue);


Just one thing: I need depth test, so pls. don't ask me to try it out without depth test. By the way, using or disabling it give the same result.

Can pls. someone tell me why this code isn't correct?

Thx in advance

ThemsAllTook
2005.04.12, 04:32 PM
The near and far clipping plane values you pass to glOrtho are essentially backward; in other words, they're distances on the -Z axis.

man glOrtho

- Alex Diener

Puzzler183
2005.04.12, 05:17 PM
Yep... And so you know, if you don't need that much range, don't use it since it reduces the precision of the Z-buffer.

DoG
2005.04.12, 05:26 PM
The coordinates only seem to be backward, as the camera is looking down along -z, and the coordinates in glOrtho specify the distance of the clip planes in the viewing direction.

fortikur
2005.04.12, 05:37 PM
Now i got it. If i set ortho to ...0, -1000), this means, that the 1000 unit long 'segment' is clamped (i hope this is the right word) to 1.
So, if I set a 3d object (without ortho) to a z value of 99 and i want to draw the ortho-ed quad behind it, i just use 991 or more (1000 max.), or to place it in front of it 989 or less.
And it works. I tried it.
Thanks for the help :)