Sylvain B.
Sylvain B.

Reputation: 739

opengl strange behavior shadowmap (Bindtexture)

I have a strange bug in opengl I cannot explain. I have "programmed" using copy-paste of tutorials a shadow map. I wanted to display the shadow map, so I wrote a little routine that displays it. It doesn't work (I only get a white square). Finally, by trying a lot, I get the shadow to be almost correct on the main rendering of the scene. But the shadow doesn't render anymore when I un-comment the routine to display the shadowmap. (which goes before the main rendering)

I guess it has to do with glBindTexture(GL_TEXTURE_2D, depthTex) (which is stored in the shadowbuffer). If it is not asked to refer to this depthTex to display the shadow map, then somehow the shadow is built, but when asked to display this depthTex, then the shadow computed is nonsens.

I wonder if once asked glBindTexture(GL_TEXTURE_2D, depthTex) for the displaying of the shadowMap, the depthTex is not anymore able to be linked for the computation of the shadow shader.

I don't understand if glBindTexture is for reading or for writing... This depthTex is indeed defined as the texture in which is stored the shadowmap.

to sum up : two pieces of code interfere, so that the rendering of a texture appears to become more complicated than simply giving the regular opengl commands to display a texture. Just as if glBindTexture(GL_TEXTURE_2D, depthTex) could be called only once.

If I ask in the displaying of the shadow map routine to display another texture of the program (such as "floor"), then the shadow is ok on the main rendered scene, but when i ask to display "depthTex", then the shadow doesn't works anymore.

Upvotes: 0

Views: 125

Answers (1)

datenwolf
datenwolf

Reputation: 162289

I have a strange bug in opengl I cannot explain. I have "programmed" using copy-past of tutorials a shadow map.

In short: You're cargo culting. Read some good OpenGL tutorial(s), understand what they teach and then you'll make some progress.

I don't understand if glBindTexture is for reading or for writing... This depthTex is indeed defined as the texture in which is stored the shadowmap.

It's for both. It selects the texture bound to the active texture unit. When texturing is enabled or a shader bound that samples from the texture unit the bound texture is read. Calling one of the glTex…Image functions will write to it.

Upvotes: 2

Related Questions