glDepthFunc

Started by
3 comments, last by Hexed 21 years, 4 months ago
Could someone please explain the purpose of glDepthFunc and what it could be used for? Thanks.
Advertisement
DepthFunc decides which pixels should be display to the screen. For example, if you have the DepthFunc set to GL_LEQUAL, and then draw one triangle behind another triangle, the triangle closer to you will still be rendered. But for instance, if DepthTesting is not enabled at all, everything will be rendered to the screen in the order in which it was drawn.
ie you can draw a big quad that fills the screen, then a triangle that is behind it, and the triangle will still show up. DepthFunc controls this.

Look up DepthFunc on MSDN for the available modes
void glDepthFunc(GLEnum func)

the value of func determines the way the depth test is done:
GL_NEVER: depth test never passes
GL_ALWAYS: depth test always passes
GL_LEQUAL: depth test passes if new depth value is less than or
equal to the stored depth value
GL_GEQUAL: depth test passes if new depth value is greater than or equal to the stored depth value
GL_LESS: depth test passes if new depth value is less than the stored depth value
GL_GREATER: depth test passes if new depth value is greater than
the stored depth value
GL_EQUAL: depth test passes if new depth value equals the stored depth value
GL_NOTEQUAL: depth test passes if new depth value is not equal to the stored depth value


you have to enable the depth test with glEnable(GL_DEPTH_TEST) (it''s disabled by default) and your rendering contextmust have a depth buffer.
Depth buffering is a simple but universal method for hidden-surface removal. If you set the depth test to GL_LESS, only pixels nearer than the already rendered pixel are stored in the frame buffer.
Before you start rendering you have to initialize the depth buffer by ORing the argument of glClear with GL_DEPTH_BUFFER_BIT.
you can set the default depth value with glClearDepth(GLclampd depth), the argument is clamped to [0,1].

GA
Visit our homepage: www.rarebyte.de.stGA
In which case does the pixel get stored in the frame buffer? I assume it is when the depth test passes.
I like pie! - weebl.
Oneiric - Another graphics engine in the works.
Thanks very much, that''s the information I was needing. I have read the function description on MSDN, but it didn''t make sense to me. All I needed was someone to translate it into English for me.

This topic is closed to new replies.

Advertisement