PDA

View Full Version : Where are the near and far clipping planes?



kabir
09-27-2001, 01:16 PM
Ok, so I've gotten myself completely confused about the clipping volume.

First, some context: I'm trying to draw text into my OpenGL scene using wgl* functions and glCallLists(). So far so good, I can get the text to show up, etc. However, I'd like my text to be in front of my scene at all times, which means I need to draw it near the "near" clipping plane.

Now the problem: This works out for my ok in an orthographic projection, as I understand where the "near" plane is, but when I make a perpective projection (gluPerspective() or glFrustrum()) I don't seem to be correctly understanding where the near and far clipping planes actually are. The near and far values I give to gluPerspective() are distances to the planes from the camera, but I don't correctly understand their relationship to the coordinate system.

I can see how this lack of understanding is going to be a problem for many things, so I'd like to get it corrected now. The various books I've got (SuperBible, Red and Blue books) haven't helped me figure it out so far, so any help you can offer would be much appreciated.

thanks
kabir

Satanic Dogus
09-27-2001, 01:23 PM
Yes! Good question....I've never been able to figure out clipping...
I had to use something like.....

glPushMatrix();
glTranslatef(1.0, 3.0, 2.0); /* get away from atom */
glGetFloatv(GL_COLOR_CLEAR_VALUE, color);
if (color[0] < 0.01) glColor3f(1.0, 1.0, 1.0);
else glColor3f(0.0, 0.0, 0.0);
glDepthRange(0.0, 0.0); /* ensure text is in front */
glRasterPos3f(0.0, 0.0, 0.0);
sprintf(buff, "Atom %d", n+1);
printString(buff);
glDepthRange(0.0, 1.0);
glPopMatrix();


to keep my text in front

kabir
09-27-2001, 03:30 PM
Originally posted by kabir:
Ok, so I've gotten myself completely confused about the clipping volume.

Right, so I have partially unconfused myself. With the help of a blurb in the Red book (p121 - under the description of glFrustrum) that I'm sure I read before but I guess just didn't register.

Now, however, I'm confused about something else (consistency is good, right? http://www.opengl.org/discussion_boards/ubb/wink.gif ). I set my perpective projection as follows:




glViewport( 0, 0, w, h );
gluPerspective( 45.0f, w/h, 1, 500);


but if I draw a bitmap at (-10,0,-1) it looks the same as if I draw it at (-10,0,-499). I thought that the coordinates for the bitmap were transformed by the projection matrix. Have I gotten that wrong somehow?


[This message has been edited by kabir (edited 09-27-2001).]

john
09-27-2001, 05:32 PM
Hello,

the near and far planes lie in the eye-coordinate space z = -f and z = -n for some scalars, f & n to represent the far and near planes respectively. They work exactly the same as the near and far planes in orthogonal projection; its just the frustum is not a box.

ABout your bitmap question;

You're using glDrawPixels, right? glDrawPixels *isn't* affected by perspective calculations, but the raster position *is*. That is, the position of the lower left hand corner of the bitmap is transformed and projected like any other vertex, but the pixels are copied across without further perspective calcs.

I hope this helps

cheers,
John

kabir
09-27-2001, 05:46 PM
Originally posted by john:
You're using glDrawPixels, right? glDrawPixels *isn't* affected by perspective calculations, but the raster position *is*. That is, the position of the lower left hand corner of the bitmap is transformed and projected like any other vertex, but the pixels are copied across without further perspective calcs.

Thanks! That's what I suspected, but confirmation is always a good thing http://www.opengl.org/discussion_boards/ubb/wink.gif

:kabir