Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: glDepthFunc(GL_GREATER) Function

  1. #1
    Junior Member Regular Contributor
    Join Date
    Jul 2003
    Location
    Bangalore, Karnataka, India
    Posts
    123

    glDepthFunc(GL_GREATER) Function

    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 .

    Code :
    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

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    3,115

    Re: glDepthFunc(GL_GREATER) Function

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •