Advertisement Jump to content
Sign in to follow this  
fread

OpenGL cubemap depth FBO rendering only to all faces the same view?

This topic is 1792 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello guys

As seen in OpenGL debugger, my code renders the camera view to all 6x faces of FBO (everytime it overwites all the faces), while it should render first to first face, second to second face, etc.

What's the problem?

Here's my code:


?/*
     


bool ShadowMapFBO::Init(unsigned int WindowWidth, unsigned int WindowHeight)
{
    // Create the FBO
    glGenFramebuffers(1, &m_fbo);


    // Create the depth buffer
    glGenTextures(1, &m_depth);
    glBindTexture(GL_TEXTURE_CUBE_MAP, m_depth);
    
    for (uint i = 0 ; i < 6 ; i++) {
        glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_DEPTH_COMPONENT32, WindowWidth, WindowHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    }


    glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X, m_depth, 0);


    // Disable writes to the color buffer
    glDrawBuffer(GL_NONE);
    
    GLExitIfError();
       
    // Disable reads from the color buffer
    glReadBuffer(GL_NONE);
    
    GLExitIfError();


    GLenum Status = glCheckFramebufferStatus(GL_FRAMEBUFFER);


    if (Status != GL_FRAMEBUFFER_COMPLETE) {
        printf("FB error, status: 0x%x\n", Status);
        return false;
    }


    return GLCheckError();
}




void ShadowMapFBO::BindForWriting(GLenum CubeFace)
{
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbo);
    glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X+CubeFace, m_depth, 0);
}


void ShadowMapFBO::BindForReading(GLenum TextureUnit, int CubeFace)
{
    glBindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo);    
    GLExitIfError();        
    glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X+CubeFace, m_depth, 0);    
    GLExitIfError();           
}



Edited by fread

Share this post


Link to post
Share on other sites
Advertisement

You don't even show your render code?

 

Assuming you're using something like

BindForWriting(0);
render();
BindForWriting(1);
render();
BindForWriting(2);
render();
BindForWriting(3);
render();
BindForWriting(4);
render();
BindForWriting(5);
render();

You have to set up the proper view in render() . . . Ie, glLookAt() or etc. like I did in the cubeFrustum() example I pasted you.

 

Also, you're not using glBindTexture() correctly . . . You need to call it INDIVIDUALLY for EACH cubemap side, ie, WITHIN your for() loop - not above it. And you need to save each value (or just the starting value, then increment each time) ... Not just one "m_depth" value. And then you'll also need to bind it before rendering.

Edited by 3TATUK2

Share this post


Link to post
Share on other sites

Yes I am settings a proper view after bindForWriting.

for(int i = 0; i < 6; i++)
{
       CubeMapDepthFBO.BeginWriting(i);
       
       glViewport( .... )
       glClear
       
       glMatrixMode( GL_MODELVIEW )
       glLoadMatrix ( ... )
       glMatrixMode( GL_PROJECTION)
       glLoadMatrix( ... )

       RenderScene();
}

The problem is that *every* call to RenderScene is updating all six sides of cubemap.

I mean: after drawing with i=0, all six sides of cubemap contain depth from i=0 point from view.

After i=1, all six sides of cubemap contain depth from i=1 point from view.

I used gDEBugger GL tool to check it.

So each pass is updating all six sides of cubemap instead of specified one.

but hey, maybe its a gDEBugger bug? 

is there any simple way I can display my cubemap on opengl window to check it contents?

Share this post


Link to post
Share on other sites

Hm. The only difference I can see it to suggest trying GL_FRAMEBUFFER instead of GL_DRAW_FRAMEBUFFER but I doubt this would fix it. Can't hurt to try.

 

Yeah maybe it's something weird with gDEBUGGER.

 

Just render a textured quad with the cubemap bound.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!