Jump to content
  • Advertisement

Recommended Posts

Posted (edited)

The OpenGL documentation for glDepthRange() states that:

Quote

"After clipping and division by w, depth coordinates range from -1 to 1, corresponding to the near and far clipping planes. glDepthRange specifies a linear mapping of the normalized depth coordinates in this range to window depth coordinates. Regardless of the actual depth buffer implementation, window coordinate depth values are treated as though they range from 0 through 1 (like color components). Thus, the values accepted by glDepthRange are both clamped to this range before they are accepted."

If I am trying to render two squares made up of the following vertices:

std::array<float, 12> RedSquareVertices
=	{
  	 0.25F,-0.50F, 0.99F,
  	 0.25F, 0.25F, 0.99F,
  	-0.50F, 0.25F, 0.99F,
  	-0.50F,-0.50F, 0.99F
	};

std::array<float, 12> BlueSquareVertices
=	{
  	 0.50F,-0.25F,-0.99F,
  	 0.50F, 0.50F,-0.99F,
  	-0.25F, 0.50F,-0.99F,
  	-0.25F,-0.25F,-0.99F
	};

Then would it be correct to say that OpenGL will first convert the z values into a range between 0 and 1 before starting the depth test? Or have I interpreted the quoted description incorrectly? 

Edited by calioranged

Share this post


Link to post
Share on other sites
Advertisement
Quote

Then would it be correct to say that OpenGL will first convert the z values into a range between 0 and 1 before starting the depth test? Or have I interpreted the quoted description incorrectly? 

That happens indeed, it happens by the projection matrix. The projection matrix transforms 3D positions into 2D screen position from -1 to 1, and a depth position from 0 to 1

See: http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/#the-projection-matrix

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!