What I'm trying to accomplish: Draw a depth map of my scene on top of my scene (so that objects closer are darker, and then easier)
Problem: I don't seem to understand how to pass the correct texture coordinates from my vertex shader to my fragment shader.
So, I created my FBO and the texture on which the depth map is drawn ... not that I'm completely sure what I'm doing, but whatever it is, it works. I tested drawing a texture using a fixed functionality pipeline and it looks as intended (depth map).
But trying to use it in my shaders just doesn't work ...
Here is the part from my render method that binds the texture:
glActiveTexture(GL_TEXTURE7); glBindTexture(GL_TEXTURE_2D, depthTextureId); glUniform1i(depthMapUniform, 7); glUseProgram(shaderProgram); look(); //updates my viewing matrix box.render(); //renders box VBO
So ... I think this is correct? May be? I donβt know why texture 7, it was what was in the textbook that I checked ...
And here is the important thing from my vertex shader:
out vec4 ShadowCoord; void main() { gl_Position = PMatrix * (VMatrix * MMatrix) * gl_Vertex;
Aaand, fragment shader:
in vec4 ShadowCoord; in vec3 Color;
Now the problem is that the coordinate that the fragment shader receives for the texture is always (0,0) or the lower left corner. I tried changing it to ShadowCoord = gl_MultiTexCoord7, because I thought maybe this is something due to the fact that I put the texture in slot number 7 ... but, alas, the problem persists. When the color (0, 0) changes, the color of the whole scene, not the color change, is only for the corresponding pixel / fragment.
And this is what I hope to get some idea of ββhow to convey the correct coordinates (I would like the corners of the texture to be the same coordinates as the corners of my screen). And yes, this is a newbie question ... but I looked in the Orange Book, and the problem with it is that it is excellent in GLSL, but the OpenGL side is very missing in the examples that I could really use ...