Skip to main content
gamedev.net
🔒 Locked

Depth Test

Started by Holy_Wood Apr 20, 2004 at 11:05 PM 1 replies 250+ views
Original Post
Holy_Wood
Holy_Wood
I wrote a simple program to clarify my problem... This program draws 2 spheres, in two positions, the yellow one in (0,0,-15), and the white one in (0,0,-4). both balls have the same radius, the yellow one should not be rendered since it is positioned behind the other... but it is rendered.. Everything works well when i use glOrtho instead of glPerspective.. why''s that.. /*DepthTest.cpp*/ #include <GL\glut.h> #include <GL\glu.h> void init(void) { GLfloat light_position[] = { 1.0, 1.0, -3, 0.0 }; glClearColor(0.0f, 0.0f, 0.0f, 0); glShadeModel(GL_SMOOTH); glClearDepth(1.0f); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glEnable(GL_COLOR_MATERIAL ); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); } void display(void) { glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glColor3f(1,1,1); glTranslatef (0,0,-4); glutSolidSphere(1.5, 100, 100); glPopMatrix(); glPushMatrix(); glColor3f(1,1,0); glTranslatef (0,0,-15); glutSolidSphere(1.5, 100, 100); glPopMatrix(); glutSwapBuffers(); } void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: exit(0); break; } } void reshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(100.0, (GLfloat) w/(GLfloat) h, 0, 6); // glOrtho(-5, 5, -5, 5,-5,5); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB |GLUT_DEPTH); glutInitWindowSize (600, 600); glutInitWindowPosition (100, 100); glutCreateWindow ("DEPTH TEST !!"); init(); glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutReshapeFunc(reshape); glutMainLoop(); return 0; }
CheeseMonger
CheeseMonger
Do you get the same results when the glDepthFunc is GL_GREATER ?

- CheeseMonger
CheeseMonger
Holy_Wood
Holy_Wood
I found out what''s the problem..never have zNear as 0...
gluPerspective(100.0, (GLfloat) w/(GLfloat) h, 0.1, 6); solved the problem...
Again.. zNear must never be set to 0.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.