1
\$\begingroup\$

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?

\$\endgroup\$
6
\$\begingroup\$

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:

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glClearDepth(1.0f);

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 | |
\$\endgroup\$

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.