shadowmaps with framebuffer objects

this is a tiny bit of topic since it s a plain opengl question. i just had a chance to look at framebuffer objects and it s very beautiful and straight forward and everything:


        /* create framebuffer */
        int[] myFrameBufferConainter = new int[1];
        gl.glGenFramebuffersEXT(1, myFrameBufferConainter);
        int _myFrameBufferID = myFrameBufferConainter[0];

        /* create depthbuffer */
        int[] myDepthRenderBufferConainter = new int[1];
        gl.glGenRenderbuffersEXT(1, myDepthRenderBufferConainter);
        int _myDepthRenderBufferID = myDepthRenderBufferConainter[0];
        
        /* create texture */
        int[] myTextureConainter = new int[1];
        gl.glGenTextures(1, myTextureConainter);
        int _myTextureID = myTextureConainter[0];

        /* attach texture to fbo */
        gl.glBindTexture(GL.GL_TEXTURE_2D, _myTextureID);

        gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
        gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
        gl.glTexImage2D(GL.GL_TEXTURE_2D,
                        0,
                        GL.GL_RGBA,
                        theWidth,
                        theHeight,
                        0,
                        GL.GL_RGBA,
                        GL.GL_UNSIGNED_BYTE,
                        (byte[]) null);

        gl.glFramebufferTexture2DEXT(GL.GL_FRAMEBUFFER_EXT,
                GL.GL_COLOR_ATTACHMENT0_EXT,
                GL.GL_TEXTURE_2D,
                _myTextureID,
                0);

        /* attach depth renderbuffer to fbo */
        gl.glBindRenderbufferEXT(GL.GL_RENDERBUFFER_EXT, _myDepthRenderBufferID);
        gl.glRenderbufferStorageEXT(GL.GL_RENDERBUFFER_EXT, GL.GL_DEPTH_COMPONENT24, theWidth, theHeight);
        gl.glFramebufferRenderbufferEXT(GL.GL_FRAMEBUFFER_EXT,
                                        GL.GL_DEPTH_ATTACHMENT_EXT,
                                        GL.GL_RENDERBUFFER_EXT,
                                        _myDepthRenderBufferID);

i was now moving on to implement a shadowmap with framebuffer objects but ran into the problem that i couldn t figure out how to set up the framebuffer, the texture and the renderbuffer. my question is now, has anyone successfully used framebuffer objects to create a shadowmap texure?

Hi d3,

  • Create a DEPTH_COMPONENT texture
  • Create a new FBO
  • Bind the FBO and do this:
glReadBuffer(GL_NONE);
glDrawBuffer(GL_NONE);
  • Attach the texture to DEPTH_ATTACHMENT_EXT and check for errors.

Two warnings:

  1. On NV hardware, with drivers prior to 80.40, you’ll get an unsupported error. You’ll need to also bind a color texture, although nothing gets rendered to it (speedwise it’s the same thing, because DrawBuffer is NONE, you lose a lot of memory though). With the leaked 80.40 it works with just the depth texture.

  2. On ATI hardware, only DEPTH_COMPONENT16 textures are supported (although DEPTH_COMPONENT24 & DEPTH_COMPONENT32 render buffers work fine).