No. OpenGL comes built-in with Z-buffer "hidden surface removal" support. To use it:
Originally Posted by maximspb
- Allocate a depth buffer (aka Z buffer) with your render target
- Each frame, clear the depth buffer (i.e. glClear( GL_DEPTH_BUFFER_BIT ))
- Enable depth testing: glEnable( GL_DEPTH_TEST ) and set the depth comparison function you want -- by default it is glDepthFunc( GL_LESS ).
- When you define your PROJECTION transform, set up your NEAR and FAR clip planes to sandwich the objects in your scene (e.g. gluPerspective or glFrustum for perspective projection, or glOrtho or gluOrtho2D for orthographic projection).
- Now just draw stuff, and only the closest at each pixel (or sample) will be kept.
For high quality, allocate a render target with multisampling (MSAA) or supersampling (SSAA) capability. This gives you multiple samples per pixel, which get downsampled into a nice antialiased result in the end.
Last edited by Dark Photon; 09-29-2012 at 06:40 PM.
Thanks a lot, Dark Photon!!!