View Full Version : What is z-buffering?
I'm new to OpenGl, 3 days exactly. I know C++ though, but what i'm asking is what in the world is z-buffering?
Rob The Bloke
05-16-2000, 01:47 PM
its a depth test. It ensures that objects in your world are drawn in the right order.
ie, stuff at the back, isn't drawn over whats in the front.
05-16-2000, 11:04 PM
This means you do not have to sort for depth.
You can draw your objects in whatever order you like and the foremost should be visible anyway.
The z-buffer simply stores the depth value of each pixel and compares with this upon rendering.
so how do i code for this?
05-17-2000, 11:35 PM
Well... are you using glut or win32 api?
You must first of all request a depthbuffer (z-buffer). In win32 api you set the cDepthBits members in the PIXELFORMATDESCRIPTOR structure to something like 16,24 or 32. I dont know exactly with glut but you should pass a GL_DEPTH_BUFFER or similar parameter when you initialize your window.
You must also enable depth testing with glEnable(GL_DEPTH_TEST) and you should set up an appropriate depthtest function with either glDepthFunc(GL_LESS) or glDepthFunc(GL_GREATER) depending on what fits your app.
Just a minor note to Humus post. In GLUT you pass GLUT_DEPTH to glutInitDisplayMode() to get a depthbuffer.
Thanks for the help, I was looking at NeHe's tutorial and i believe he uses z-buffering so i get how to do it now.
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.