Order of operations to render VBO to FBO texture and then rendering FBO texture full quad
Posted
by
cyberdemon
on Game Development
See other posts from Game Development
or by cyberdemon
Published on 2012-11-22T16:35:52Z
Indexed on
2012/11/22
17:12 UTC
Read the original article
Hit count: 443
I've just started using OpenGL with C# via the OpenTK library.
I've managed to successfully render my game world using VBOs.
I now want to create a pixellated affect by rendering the frame to an offscreen FBO with a size half of my GameWindow size and then render that FBO to a full screen quad.
I've been looking at the OpenTK example here: http://www.opentk.com/doc/graphics/frame-buffer-objects
...but the result is a black form. I'm not sure which parts of the example code belongs in the OnLoad
event and OnRenderFrame
.
Can someone please tell me if the below code shows the correct order of operations?
OnLoad
{
// VBO.
// DataArrayBuffer
GenBuffers/BindBuffer/BufferData
// ElementArrayBuffer
GenBuffers/BindBuffer/BufferData
// ColourArrayBuffer
GenBuffers/BindBuffer/BufferData
// FBO.
// ColourTexture
GenTextures/BindTexture/TexParameterx4/TexImage2D
// Create FBO.
// Textures
Ext.GenFramebuffers/Ext.BindFramebuffer/Ext.FramebufferTexture2D/Ext.FramebufferRenderbuffer
}
OnRenderFrame
{
// Use FBO buffer.
Ext.BindFramebuffer(FBO)
GL.Clear
// Set viewport to FBO dimensions.
GL.DrawBuffer((DrawBufferMode)FramebufferAttachment.ColorAttachment0Ext)
// Bind VBO arrays.
GL.BindBuffer(ColourArrayBuffer)
GL.ColorPointer
GL.EnableClientState(ColorArray)
GL.BindBuffer(DataArrayBuffer)
// If world changed GL.BufferData(DataArrayBuffer)
GL.VertexPointer
GL.EnableClientState(VertexArray)
GL.BindBuffer(ElementArrayBuffer)
// Render VBO.
GL.DrawElements
// Bind visible buffer.
GL.Ext.BindFramebuffer(0)
GL.DrawBuffer(Back)
GL.Clear
// Set camera to view texture.
GL.BindTexture(ColourTexture)
// Render FBO texture
GL.Begin(Quads)
// Draw texture on quad
// TexCoord2/Vertex2
GL.End
SwapBuffers
}
© Game Development or respective owner