1
\$\begingroup\$

I've successfully implemented shadow mapping for a specific direction as you can see in the image below:

enter image description here

Now I want to do omnidirectional shadow mapping but without using a cube map.

My first step was to turn my frame buffer object to an array of frame buffer objects and the same with my texture map (so I can get 6 shadow maps, one for every direction). This is the plan, but I'm stuck much earlier. Replacing my variable framebufferFBO with framebufferFBO[0] and my texture variable depthMap with depthmap[0] the program runs exactly the same ( as expected ) . However, when I try to do the following, and I mean only the following, as I'm already in the debugging phase , all I get is a black image .

for (int i = 0; i < 2; i++) {
    glGenTextures(1, &depthMap[i]);
    glBindTexture(GL_TEXTURE_2D, depthMap[i]);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, shadow_width, shadow_height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

    glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO[i]);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthMap[i], 0);
    glDrawBuffer(GL_NONE);
    glReadBuffer(GL_NONE);
    glBindFramebuffer(GL_FRAMEBUFFER, 0);
}

The only change is that it goes on for 2 loops. If I just do one loop my first shadow map works fine. If I leave it as it is the map you see in the first picture gets ruined.

So what is wrong with this loop? Am I doing something that is not allowed?

Edit: It seems that the problem is glDrawBuffer(GL_NONE).If it's not executed in the second loop, my first shadow map is still fine.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.