To render to multiple textures, you still use the glDrawBuffers function. However, you use the enums from GL_EXT_framebuffer_object.
Example:
GLenum buffers[] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT };
glDrawBuffers(2, buffers);
If a framebuffer object is bound with textures attached to GL_COLOR_ATTACHMENT0_EXT and GL_COLOR_ATTACHMENT1_EXT, they will both be rendered to now.
Showing posts with label framebuffer object. Show all posts
Showing posts with label framebuffer object. Show all posts
Tuesday, December 12, 2006
Thursday, December 7, 2006
Render to Texture
OpenGL supports fast crossplatform offscreen rendering through the GL_EXT_framebuffer_object extension.
To render to a texture using the framebuffer object you must
1) Create a framebuffer object
glGenFramebuffersEXT(1, &myFBO);
2) Bind the framebuffer object
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, myFBO);
3) Attach a texture to the FBO
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, myTexture, 0);
4) If you need depth testing, create and attach a depth renderbuffer
// Gen renderbuffer
glGenRenderbuffersEXT(1, &myRB);
// Bind renderbuffer
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, myRB);
// Init as a depth buffer
glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, width, height);
// Attach to the FBO for depth
glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, myRB);
5) Render just like you normally would.
6) Unbind the FBO (and renderbuffer if necessary). glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
7) Use the texture you rendered to!
NOTES:
All textures and renderbuffers attached to the framebuffer object must have the same dimensions.
You must use the GL_EXT_packed_depth_stencil extension to use stencil testing with framebuffer objects.
You can only render to RGB, RGBA, and depth textures using framebuffer objects.
References:
Framebuffer object specification
To render to a texture using the framebuffer object you must
1) Create a framebuffer object
glGenFramebuffersEXT(1, &myFBO);
2) Bind the framebuffer object
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, myFBO);
3) Attach a texture to the FBO
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, myTexture, 0);
4) If you need depth testing, create and attach a depth renderbuffer
// Gen renderbuffer
glGenRenderbuffersEXT(1, &myRB);
// Bind renderbuffer
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, myRB);
// Init as a depth buffer
glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, width, height);
// Attach to the FBO for depth
glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, myRB);
5) Render just like you normally would.
6) Unbind the FBO (and renderbuffer if necessary). glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
7) Use the texture you rendered to!
NOTES:
All textures and renderbuffers attached to the framebuffer object must have the same dimensions.
You must use the GL_EXT_packed_depth_stencil extension to use stencil testing with framebuffer objects.
You can only render to RGB, RGBA, and depth textures using framebuffer objects.
References:
Framebuffer object specification
Labels:
FBO,
framebuffer object,
render to texture
Subscribe to:
Posts (Atom)