Thursday, May 19, 2011

GL_DEPTH_TEST example c c++ objc python

[GL_DEPTH_TEST example] In 3D Graphics, depth-buffer (as known as z-buffer) is used to sort pixel orders. The mechanism is simple, if new pixel's depth value is lower(that is closer to the screen) than current pixel's depth value, then new pixel value becomes new current pixel value. Otherwise, the current pixel value simply remains. You can control z-buffering by calling glEnable(GL_DEPTH_TEST) or glDisable(GL_DEPTH_TEST)

example - in python)

{
             //...
mat_specular = [ 1.0, 0.5, 1.0, 1.0 ]
        mat_shininess = [ 50.0 ]

        light_ambient = [ 0.0, 0.0, 0.0, 1.0 ]
        light_diffuse = [ 1.0, 1.0, 1.0, 1.0 ]
        light_specular = [ 1.0, 1.0, 1.0, 1.0 ]
        light_position = [ 1.0, 1.0, 1.0, 0.0 ]
        
        glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
        glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

        glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient)
        glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse)
        glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular)
        glLightfv(GL_LIGHT0, GL_POSITION, light_position)
        glEnable(GL_LIGHTING)
        glEnable(GL_LIGHT0)
        glEnable(GL_DEPTH_TEST) # With this line, the cube is weird lines that change when you move. Without this line the cube is partially transparent.

}