Light | Dark

glBindRenderbuffer

Name

glBindRenderbuffer — bind a renderbuffer to a renderbuffer target

C Specification

void glBindRenderbuffer(GLenum target,
GLuint renderbuffer);

Parameters

target

Specifies the renderbuffer target of the binding operation. target must be GL_RENDERBUFFER.

renderbuffer

Specifies the name of the renderbuffer object to bind.

Description

glBindRenderbuffer binds the renderbuffer object with name renderbuffer to the renderbuffer target specified by target. target must be GL_RENDERBUFFER. renderbuffer is the name of a renderbuffer object previously returned from a call to glGenRenderbuffers, or zero to break the existing binding of a renderbuffer object to target.

Errors

GL_INVALID_ENUM is generated if target is not GL_RENDERBUFFER.

GL_INVALID_OPERATION is generated if renderbuffer is not zero or the name of a renderbuffer previously returned from a call to glGenRenderbuffers.

Examples

Create a framebuffer object with a renderbuffer-based color attachment and a renderbuffer-based depth attachment.
// fbo_width and fbo_height are the desired width and height of the FBO.
// For Opengl <= 4.4 or if the GL_ARB_texture_non_power_of_two extension
// is present, fbo_width and fbo_height can be values other than 2^n for
// some integer n.

// Build the texture that will serve as the color attachment for the framebuffer.
GLuint color_renderbuffer;
glGenRenderbuffers(1, &color_renderbuffer);
glBindRenderbuffer( GL_RENDERBUFFER, (GLuint)color_renderbuffer );
glRenderbufferStorage( GL_RENDERBUFFER, GL_RGBA8, fbo_width, fbo_height );
glBindRenderbuffer( GL_RENDERBUFFER, 0 );

// Build the texture that will serve as the depth attachment for the framebuffer.
GLuint depth_renderbuffer;
glGenRenderbuffers(1, &depth_renderbuffer);
glBindRenderbuffer( GL_RENDERBUFFER, (GLuint)depth_renderbuffer );
glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH_COMPONENT, fbo_width, fbo_height );
glBindRenderbuffer( GL_RENDERBUFFER, 0 );

// Build the framebuffer.
GLuint framebuffer;
glGenFramebuffers(1, &framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, (GLuint)framebuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, color_renderbuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth_renderbuffer);

GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE)
    // Error

glBindFramebuffer(GL_FRAMEBUFFER, 0);
Think you can improve this page? Edit this page on GitHub.