-
Notifications
You must be signed in to change notification settings - Fork 0
Rendering Guide
The bRenderer and bWindow classes are designed to simplify the process of rendering graphics and managing windows using SDL. This tutorial aims to guide you through the essential features of these classes.
To create a window, instantiate the bWindow class and call its createWindow() method.
bWindow* window = new bWindow("My Window", 0, 0, 800, 600);
bRenderer* renderer = window->createWindow();Optional Window Flags
window->toggleResizable(); // Makes the window resizable.
window->toggleHighDPI(); // Enables high DPI mode.The renderer is automatically initialized when you create a window. You can set the background color using the background() method.
renderer->background(255, 255, 255, 255);Before continue I would like to describing the process of how rendering should be done using this library.
In the bRenderer class, a buffer serves as a hidden stage where all the drawing takes place. This buffer is an SDL texture, and it's where textures, sprites, and other graphical elements are rendered before being shown on the screen.
When you call methods like drawTexture or drawSprite, you're essentially drawing these elements onto this hidden buffer. They are not immediately visible on the screen.
bTexture texture = renderer->initTexture("path/to/texture.png", {0, 0, 128, 128});
bRect dest = {10, 10, 128, 128};
renderer->drawTexture(texture, dest); // This draws onto the buffer, not directly to the screen.Before each new frame, it's crucial to clear the buffer to remove the remnants of the previous frame. This is done using the clearBuffer() method.
renderer->clearBuffer(); // Clears the buffer for the next frame.The presentBuffer() method is the final part. It takes everything that has been drawn onto the buffer and presents it onto the actual screen. This is when the you finally gets to see the visual elements.
renderer->presentBuffer(); // Presents the buffer onto the screen.Here's how a typical rendering sequence might look:
// Clear the buffer
renderer->clearBuffer();
// Draw textures, sprites, etc.
renderer->drawTexture(texture, dest);
// Present the buffer
renderer->presentBuffer();To draw a texture or sprite, you first need to initialize it.
bTexture texture = renderer->initTexture("path/to/texture.png", {0, 0, 128, 128});Drawing the Texture
bRect dest = {10, 10, 128, 128};
renderer->drawTexture(texture, dest);You can set the camera's position, scale, and angle using the setCameraTransformations() method.
renderer->setCameraTransformations({0, 0}, {1.0, 1.0}, 0.0);To resize the canvas, you can use the setCanvasSize() or resizeToWindow() methods.
renderer->setCanvasSize({1024, 768});
renderer->resizeToWindow();