PDA

View Full Version : couple questions about nehe tuts



paneb
03-24-2003, 05:01 AM
gluPerspective (45.0f, (float)width/(float)height, 0.1f, 100.0f)


what exactly does this do to the matrix? nehe just says it add the perspective..

also, when i do these:




glClearDepth (1.0f);
glEnable (GL_DEPTH_TEST);
glDepthFunc (GL_LEQUAL);


whats the point of the test here? in the sdn it says that the test compares the incoming z-value to the one stored in the buffer..now what exactly do they mean by the incoming z-value? and what the point of such a test?
i just cant figure those 2 things out..
thanks for any help http://www.opengl.org/discussion_boards/ubb/smile.gif

jebus
03-24-2003, 05:10 AM
gluPerspective does what NeHe said, it's an easy way to set up OpenGL's Projection matrix. another way to set up the matrix is to use glFrustum. for the ZBuffer question, the incoming z-value is the vertex being currently transformed in the pipeline. it looks at a vertex/pixel and, in your example, looks to see if it is less than or equal to the z-value in the frame buffer. if so, it gets clipped (ie not drawn) there are other comparisons you can pass to glDepthFunc() depending on how you want your z-buffer. BTW, i am totally wingin it here, so if someone who knows more can point out flaws in my description, please do so! i don't know too much about z-buffer, but then i don't have to use it in my engine cause the BSP orders all my polys correctly.

jebus

nexusone
03-24-2003, 05:16 AM
I don't know the math but perspective view gives depth to the scene, by that I mean objects get smaller as the Z axis distance increases from the screen.

Ortho view, object size does not change as the distance changes from the screen.

Depth test, without Depth test openGL draws the object in the order in which you draw then. When a near object is drawn first and far object drawn after it the far object would be drawn in front of the near object.

With depth_test on openGL sorts object by distance on the Z axis.

The other option is how openGL sorts the depth test objects.

incoming Z.

object_1_z = -1
object_2_z = 1

Object 2 based on its Z will be in front of object 1, since 1 comes before -1

Note -Z is back into the monitor, while +Z is heading away from the monitor.




gluPerspective (45.0f, (float)width/(float)height, 0.1f, 100.0f)


what exactly does this do to the matrix? nehe just says it add the perspective..

also, when i do these:




glClearDepth (1.0f);
glEnable (GL_DEPTH_TEST);
glDepthFunc (GL_LEQUAL);


whats the point of the test here? in the sdn it says that the test compares the incoming z-value to the one stored in the buffer..now what exactly do they mean by the incoming z-value? and what the point of such a test?
i just cant figure those 2 things out..
thanks for any help http://www.opengl.org/discussion_boards/ubb/smile.gif[/B]<HR></BLOCKQUOTE>



[This message has been edited by nexusone (edited 03-24-2003).]

kehziah
03-24-2003, 07:38 AM
"Incoming z value" means : z value of the incoming fragment.

When you send a triangle to GL, its vertices are transformed by projection and modelview matrix to get them in screen space. These computed screen space coordinates have x , y and z components. x and y are mapped with vertical and horizontal screen directions, and z indicates "how deep" is the vertex in the scene (relative to your "viewpoint").

Now you have a triangle in screen space, you send it to a scanline algo, which takes your 3 vertices and "fills" the corresponding area of the screen. This algo will find all the pixels covered by your triangle, and fill them with you triangle's color (to be more precise, with the interpolated color for each fragment, which can come from material, lighting, texture etc..). Each fragment (you can think of a fragment as a pixel that is not written in the framebuffer yet) has its z value, which is tested against the corresponding z-Buffer value. What is in the z buffer? The z value of the last fragment actually written in the frame buffer. The nature of the test is set with glDepthFunc (less or equal, equal etc...). If the test succeeds, the fragment is written : its color is written in the framebuffer, and its z value is written in the z buffer. If the test fails, the fragment is discarded.