draw the depth value in opengl using shaders
问题 I want to draw the depth buffer in the fragment shader, I do this: Vertex shader: varying vec4 position_; gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; position_ = gl_ModelViewProjectionMatrix * gl_Vertex; Fragment shader: float depth = ((position_.z / position_.w) + 1.0) * 0.5; gl_FragColor = vec4(depth, depth, depth, 1.0); But all I print is white, what am I doing wrong? 回答1: In what space do you want to draw the depth? If you want to draw the window-space depth, you can do this: