Light | Dark

# docs.GL

OpenGL 4
OpenGL 3
OpenGL ES 3
OpenGL ES 2

# glGenRenderbuffers

## Name

glGenRenderbuffers — generate renderbuffer object names

## C Specification

`void glGenRenderbuffers(` | GLsizei n,
| GLuint *renderbuffers`)`;

## Parameters

`n`

  Specifies the number of renderbuffer object names to generate.

`renderbuffers`

  Specifies an array in which the generated renderbuffer object names are stored.

## Description

`glGenRenderbuffers` returns `n` renderbuffer object names in `renderbuffers`. There is no guarantee that the names form a contiguous set of integers; however, it is guaranteed that none of the returned names was in use immediately before the call to `glGenRenderbuffers`.

Renderbuffer object names returned by a call to `glGenRenderbuffers` are not returned by subsequent calls, unless they are first deleted with glDeleteRenderbuffers.

The names returned in `renderbuffers` are marked as used, for the purposes of `glGenRenderbuffers` only, but they acquire state and type only when they are first bound.

## Errors

`GL_INVALID_VALUE` is generated if `n` is negative.

## 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);

## Tutorials

Songho - OpenGL Frame Buffer Object (FBO)
open.gl - Framebuffers
opengl-tutorial.org - Tutorial 14 : Render To Texture

## Version Support

| OpenGL Version
--- | ---
Function / Feature Name | 2.0 | 2.1 | 3.0 | 3.1 | 3.2 | 3.3 | 4.0 | 4.1 | 4.2 | 4.3 | 4.4 | 4.5
`glGenRenderbuffers` | - | - | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔

## See Also

glFramebufferRenderbuffer, glDeleteRenderbuffers

## Copyright

Copyright © 2010-2014 Khronos Group. This material may be distributed subject to the terms and conditions set forth in the Open Publication License, v 1.0, 8 June 1999. https://opencontent.org/openpub/.

Think you can improve this page? Edit this page on GitHub.