Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualtrotlinebeercan

Posted 24 May 2012 - 09:00 PM

Your call to gluPerspective is not correct. You cannot give znear a value of 0.

http://www.opengl.or...depthbuffer.htm

EDIT: mathematical explanation.

gluPerspective constructs the projection matrix as such: (a = width / height)

e 0 0 0
0 ea 0 0
0 0 -(f+n)/(f-n) 2fn/(f-n)
0 0 -1 0

resulting in the depth value being computed as: (in HCC)

z' = x*0 + y*0 - z(600)/(600) + w*0/(600) = -z
w' = x*0 + y*0 + z*-1 + w * 0 = -z


During perspective division, the value for the depth to be stored in the depth buffer (in NDC) would be computed as:

Z = z / w = -z / -z = 1

which, in this case, since n was set to 0, would always be 1, and therefore outside the range of depth and never rendered, or never stored in the depth buffer. All calls to gluUnProject would then return 0.

#3trotlinebeercan

Posted 24 May 2012 - 08:56 PM

Your call to gluPerspective is not correct. You cannot give znear a value of 0.

http://www.opengl.or...depthbuffer.htm

EDIT: mathematical explanation.

gluPerspective constructs the projection matrix as such: (a = width / height)

e 0 0 0
0 ea 0 0
0 0 -(f+n)/(f-n) 2fn/(f-n)
0 0 -1 0

resulting in the depth value being computed as: (in HCC)

z' = x*0 + y*0 - z(600)/(600) + w*0/(600) = -z
w' = x*0 + y*0 + z*-1 + w * 0 = -z


During perspective division, the value for the depth to be stored in the depth buffer (in NDC) would be computed as:

Z = z / w = -z / -z = 1

which, in this case, since n was set to 0, would always be 1, and therefore outside the range of depth and never rendered, or never stored in the depth buffer and returned incorrectly from gluUnProject.

#2trotlinebeercan

Posted 24 May 2012 - 08:50 PM

Your call to gluPerspective is not correct. You cannot give znear a value of 0.

http://www.opengl.or...depthbuffer.htm

EDIT: mathematical explanation.

gluPerspective constructs the projection matrix as such: (a = width / height)

e 0 0 0
0 ea 0 0
0 0 -(f+n)/(f-n) 2fn/(f-n)
0 0 -1 0

resulting in the depth value being computed as: (in HCC)

z' = x*0 + y*0 - z(600)/(600) + 0/ (600) = -1

which, in this case, since n was set to 0, would always be -1, and therefore outside the range of clip coordinates and never rendered, or never stored in the depth buffer and returned incorrectly from gluUnProject.

#1trotlinebeercan

Posted 24 May 2012 - 08:38 PM

Your call you gluPerspective is not correct. You cannot give znear a value of 0.

http://www.opengl.org/archives/resources/faq/technical/depthbuffer.htm

PARTNERS