Frame Buffer - Horizon-NTH/HorizonGUI GitHub Wiki
The FrameBuffer
class in the hgui::kernel
namespace provides a means to work with OpenGL Frame buffers.
Frame buffers are widely used in computer graphics for off-screen rendering and rendering to textures.
This class enables the creation, binding, management, and manipulation of Frame buffers,
making it suitable for advanced rendering techniques. The class requires an active OpenGL context.
The class can be found in the header file FrameBuffer.h
.
-
FrameBuffer()
: Constructs aFrameBuffer
object, generating a new Framebuffer ID.
-
void bind() const
: Binds the Framebuffer to the current OpenGL context, making it the active Framebuffer for rendering operations. -
void unbind() const
: Unbinds the currently bound Framebuffer, restoring the default state for rendering operations. -
void clear() const
: Clears the contents of the Framebuffer, typically used to clear the color, depth, and stencil attachments. -
GLuint get_id() const
: Retrieves the ID of the Framebuffer. -
bool is_complete() const
: Checks if the Framebuffer is complete and ready for rendering. -
void attach_texture(const std::shared_ptr<Texture>& texture) const
: Attaches a texture to the Framebuffer, enabling rendering into the provided texture. -
void attach_render_buffer(const std::shared_ptr<RenderBuffer>& renderBuffer) const
: Attaches a Render Buffer to the Framebuffer, allowing depth and stencil information storage.
#include <hgui/header/FrameBuffer.h>
// Example Usage of FrameBuffer class
hgui::kernel::FrameBuffer framebuffer;
// Bind the Framebuffer
framebuffer.bind();
// Attach a texture
std::shared_ptr<hgui::kernel::Texture> texture = /* initialize texture */;
framebuffer.attach_texture(texture);
// Check Framebuffer completeness
if (framebuffer.is_complete()) {
// Perform rendering operations using the Framebuffer
// Clear the Framebuffer
framebuffer.clear();
}
// Unbind the Framebuffer when done
framebuffer.unbind();
Note: In the "Example Usage" section, you should bind the Framebuffer, attach textures or Render Buffers as needed, perform rendering operations, and clear the Framebuffer if required. Always unbind the Framebuffer when finished to avoid interfering with subsequent rendering operations.