Does OpenGL performs Visibilty algorithms based on z-index? Or we have to write our own algorithms. Mainly I'm referring to z-buffer algorithm. Is it in-built?


Yes, OpenGL (or really, the GPU hardware that OpenGL is used to access) has built-in support for depth testing via z-buffers. To enable it, you just have to ensure your OpenGL context includes a depth buffer when it's created (the details of this depend on what OS or toolkit you're using). Then, insert these calls in your render function prior to drawing any geometry:


and add GL_DEPTH_BUFFER_BIT to your glClear call. That should be all you need to do to enable z-buffering. For more information, see this tutorial.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.