Archived

This topic is now archived and is closed to further replies.

Depth Test

This topic is 4983 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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; }

Share this post


Link to post
Share on other sites