Frame Buffer Object - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

Frame Buffer Object

Description:

Frame Buffer Object. CG2 Repetitorium 2, SS08. Veronika Solteszova ... GLuint img; glGenTextures(1, &img) ... glBindTexture(GL_TEXTURE_2D, img); And not only that... – PowerPoint PPT presentation

Number of Views:321
Avg rating:3.0/5.0
Slides: 14
Provided by: insit9
Category:
Tags: buffer | frame | img | object

less

Transcript and Presenter's Notes

Title: Frame Buffer Object


1
Frame Buffer Object
  • CG2 Repetitorium 2, SS08Veronika Solteszova

Institute of Computer Graphics and
Algorithms Vienna University of Technology
2
What for?
  • What is normally rendered to the screen
  • ?
  • Save as a texture (with color and depth
    attachments)
  • Use the texture in further passes (shadow map,
    mini-map, showing different views of the scene

3
What is an FBO actually ?
  • FBO is an encapsulation of attachments
  • Attachments can be color or renderbuffers
  • Renderbuffers are objects that support off-screen
    rendering without an assigned texture
  • Depth buffer and stencil buffer
  • There can be up to 8 color attachments
  • Number depends on your HW
  • More than one is advanced stuff
  • Wont deal with it too much

4
Setup FBO
  • Some code you have to use for setup
  • Create and validate its handle
  • Bind it

GLuint fbo glGenFramebuffersEXT(1, fbo)
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo)
5
Setup renderbuffer (depth buffer)
  • Attaching renderable objects (like depth buffer -
    DB)
  • Create its handle
  • Bind it

GLuint depthbuffer glGenRenderbuffersEXT(1,
depthbuffer)
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT,
depthbuffer)
6
Creating storage space
  • We define its size
  • Last creators job attaching DB to FBO

glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,
GL_DEPTH_COMPONENT, width, height)
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT,
depthbuffer)
7
Attaching a texture T to render to
  • Assumption a handle to a texture
  • NOTE width and height are the same as those of
    FBO!

GLuint img glGenTextures(1, img)
glBindTexture(GL_TEXTURE_2D, img)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width,
height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL)
8
Attaching a texture T to render to
  • We set the target of the FBO

glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, img, 0)
9
Status checking
  • If everything worked out correctly

GLenum status glCheckFramebufferStatusEXT(GL_FRA
MEBUFFER_EXT)
10
Rendering to the texture T
  • Bind render unbind
  • // render scene
  • Note keep the same height and width of T for the
    viewport size

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo)
glPushAttrib(GL_VIEWPORT_BIT) glViewport(0,0,wid
th, height)
glPopAttrib() glBindFramebufferEXT(GL_FRAMEBUFFE
R_EXT, 0)
11
Using the texture T
  • Just bind it like a regular texture
  • Note dont forget about texture filtering stuff!

glBindTexture(GL_TEXTURE_2D, img)
12
And not only that
  • With an FBO, you can render into more than 1
    textures simultaneously
  • Check the tutorials about more color attachments
    and DrawBuffers extension at www.gamedev.net
  • http//www.gamedev.net/reference/programming/featu
    res/fbo2/

13
Cleaning up (the mess?)
  • Clean up, unbinding, deleting is done by
  • Cleaning of render buffers
  • Delete also all textures associated with FBO
  • Source www.gamedev.net

glDeleteFramebuffersEXT(1, fbo)
glDeleteRenderbuffersEXT(1, depthbuffer)
Write a Comment
User Comments (0)
About PowerShow.com