Results 1 to 4 of 4

Thread: FBO and stencil

  1. #1
    Member Newbie
    Join Date
    Jan 2009
    Posts
    41

    FBO and stencil


    Hello,

    how to use the stencil buffer inside an FBO ? Do you have any examples or good lectures ?

    Thanks.

  2. #2
    Junior Member Newbie
    Join Date
    Oct 2002
    Location
    norway
    Posts
    17

    Re: FBO and stencil

    You can use a FBO that has a GL_DEPTH24_STENCIL8 render buffer attachment.

    Code :
    const GLint FBO_WIDTH = 1024;
    const GLint FBO_HEIGHT = 768;
     
    GLuint color_buffer_id, depth_stencil_id, fbo_id;
    GLenum status;
     
    // create a texture we use as the color buffer
    glGenTextures(1, &color_buffer_id);
    glEnable(GL_TEXTURE2D);
    glBindTexture(GL_TEXTURE_2D, &color_buffer_id);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, FBO_WIDTH, FBO_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
    glBindTexture(GL_TEXTURE_2D, 0);
     
    // create a renderbuffer for the depth/stencil buffer
    glGenRenderbuffers(1, &depth_stencil_id);
    glBindRenderbuffer(GL_RENDERBUFFER, depth_stencil_id);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, FBO_WIDTH, FBO_HEIGHT);
    glBindRenderbuffer(GL_RENDERBUFFER, 0);
     
    glGenFramebuffers(1, &fbo_id);
    glBindFramebuffer(GL_FRAMEBUFFER, fbo_id);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT_0, GL_TEXTURE_2D, color_buffer_id, 0);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depth_stencil_id);
     
    status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
    if ( GL_FRAMEBUFFER_COMPLETE != status )
     
    {
        // something went wrong :(
    }
    else
    {
        // profit :)
    }
     
    glBindFramebuffer(GL_FRAMEBUFFER, 0);

  3. #3
    Member Newbie
    Join Date
    Jan 2009
    Posts
    41

    Re: FBO and stencil

    Well thanks !

    And now, in the "else" part, can I use it as in a normal stencil test ?

  4. #4
    Junior Member Newbie
    Join Date
    Oct 2002
    Location
    norway
    Posts
    17

    Re: FBO and stencil

    That's right.

Similar Threads

  1. Replies: 1
    Last Post: 09-11-2013, 11:35 AM
  2. copy app generated stencil data to stencil buffer
    By guilder in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 12-23-2010, 06:46 PM
  3. Coping from FBO's stencil to main stencil buffer ?
    By gregory_x in forum OpenGL: Advanced Coding
    Replies: 6
    Last Post: 08-30-2010, 01:09 AM
  4. depth-stencil texture: read stencil value.
    By kRogue in forum OpenGL: General
    Replies: 1
    Last Post: 05-23-2009, 04:22 AM
  5. How to clear stencil buffer after stencil test?
    By in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 06-14-2003, 09:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean