Renderer - Horizon-NTH/HorizonGUI GitHub Wiki

Renderer

Overview

The Renderer class, located in the hgui namespace, is a fundamental component for rendering and displaying graphical content in your graphical application. This class provides functions for drawing, setting background color, and managing rendering loops. It's responsible for rendering graphics on the screen, including handling post-processing effects. The class can be found in the header file Renderer.h.

Member Functions

  • void draw(const std::vector<std::string>& tags = {}, const effects& postProcessingOption = effects::CLASSIC): Renders graphical content based on specified tags and post-processing effects.

Note: Passing no tags will result in the rendering of all the created widgets. You must know that you can render a list of tags with the classic rendering effect, and simultaneously render another list with a special effect. Then, it's important to note that you can apply only one post-processing effect at a time, ensuring that multiple post-processing effects are not supported. However, you can change the tags rendered and the type of effect at any time by just calling the draw function another time.

  • void loop(): Starts the rendering loop, which continuously redraws the graphics on the screen.

Note: This function is an infinite loop and the code write after it will not be reached until you call the end function or all the windows are destroyed.

  • void set_background_color(const color& newColor): Sets the background color for the rendering.

  • const color& get_background_color() const: Retrieves the current background color.

  • void set_draw_callback(const std::function<void()>& function): Set a custom function that will be called inside the render loop.

Example Usage

#include <hgui/Renderer.h>

// Example Usage of Renderer class

// Render graphics with specific tags and apply post-processing effects
std::vector<std::string> tags = { "background", "objects" };
hgui::Renderer::draw(tags[0], hgui::effects::BLUR);
hgui::Renderer::draw(tags[1]);
// Here the background will be blurred and all the objects will be rendered normally

// Set the background color to black
hgui::color backgroundColor(0.0f, 0.0f, 0.0f);
hgui::Renderer::set_background_color(backgroundColor);

// Get the current background color
hgui::color currentBackgroundColor = hgui::Renderer::get_background_color();

// Start the rendering loop
hgui::Renderer::loop();

Note: In the "Example Usage" section, we demonstrate how to use the Renderer class to render graphics with specific tags and apply post-processing effects. The loop function starts the rendering loop to continuously refresh the display. You can set and retrieve the background color for your rendering environment using this class. The Renderer class is a crucial component for rendering and displaying graphics in your graphical application.

⚠️ **GitHub.com Fallback** ⚠️