PDA

View Full Version : glDepthFunc(GL_GREATER) Function



iris_raj
05-16-2007, 10:34 PM
Dear OpenglProgrammers,

Below is a picec code for displaying two simple primiitives. Initially I choose GL_LESS as my
DepthFunc, Polygon got rendered first and then triangle.But When I choose GL_GREATER, nothing is getting rendered.

What is the reason?

Also I want to know which Hidden Surface Removal algorithm is being used internally by Opengl .



void InitGL(int Width, int Height)
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0);
glDepthFunc(GL_LESS);
//glDepthFunc(GL_GREATER);
glEnable(GL_DEPTH_TEST);
}
void DrawGLScene()
{
glClear(GL_COLOR_BUFFER_BIT | DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(-1.5f,0.0f,-6.0f);
/* draw a square (quadrilateral)*/
glColor3f(0.5f,0.5f,1.0f); /* set color to a blue shade.*/
glBegin(GL_QUADS); /* start drawing a polygon (4 sided)*/
glVertex3f(-1.0f, 1.0f, 0.0f); /* Top Left*/
glVertex3f( 1.0f, 1.0f, 0.0f); /* Top Right*/
glVertex3f( 1.0f,-1.0f, 0.0f); /* Bottom Right*/
glVertex3f(-1.0f,-1.0f, 0.0f); /* Bottom Left */
glEnd(); /* done with the polygon*/

/* draw a triangle (in smooth coloring mode)*/

glTranslatef(-1.0f,0.0f,0.0f); glBegin(GL_POLYGON); /* start drawing a polygon */
glColor3f(1.0f,0.0f,0.0f); /* Set The Color To Red */
glVertex3f( 0.0f, 1.0f, -1.0f); /* Top*/
glColor3f(0.0f,1.0f,0.0f); /* Set The Color To Green*/
glVertex3f( 1.0f,-1.0f, -1.0f); /* Bottom Right*/
glColor3f(0.0f,0.0f,1.0f); /* Set The Color To Blue*/
glVertex3f(-1.0f,-1.0f, -1.0f); /* Bottom Left */
glEnd(); glutSwapBuffers();

}
Thanks in advance
RAJESH.R

Bob
05-17-2007, 12:34 AM
You clear the depth buffer with the value 1.0. When setting depth test function to GL_GREATER, you tell OpenGL you only want to draw objects with depth buffer values greater that 1.0.

Since the depth buffer values maps 0.0 to the near clip plane, and 1.0 to the far clip plane, there is no chance for any object under any situation to have a depth buffer value above 1.0. If it has, it's beyond the far clip plane and will be clipped instead. If it's not, it's value is less than 1.0 and is rejected by the depth buffer test.