Functions and structures for managing the SDL window and OpenGL context. More...
Classes | |
struct | Window |
Structure representing the SDL window and its associated OpenGL context. More... | |
Enumerations | |
enum | WindowFlags { WINDOW_NO_FLAGS = 0 , WINDOW_PRERENDER_PASS = 1 << 0 , WINDOW_RESIZED = 1 << 1 } |
Enumeration for window flags. More... | |
Functions | |
s8 | create_window (char *title, s32 x, s32 y, s32 width, s32 height, u32 flags, Window *window) |
Creates a new SDL window with an OpenGL context. | |
void | refresh_resolution () |
Refreshes the window resolution. | |
void | update_window (Window *window, struct Node *scene, struct Camera *c, struct WorldShaders *shaders, struct DepthMap *depthMap, struct Mesh *screenPlane) |
Updates the window by rendering the scene and swapping the buffers. | |
void | refresh_ui (Window *window) |
Refreshes the UI of the window. | |
void | free_window (Window *window) |
Frees the resources associated with the window. | |
Functions and structures for managing the SDL window and OpenGL context.
enum WindowFlags |
Enumeration for window flags.
This enumeration defines various flags that can be used to describe the state of a window.
Creates a new SDL window with an OpenGL context.
[in] | title | The title of the window. |
[in] | x | The x-coordinate of the window's position on the screen. |
[in] | y | The y-coordinate of the window's position on the screen. |
[in] | width | The width of the window in pixels. |
[in] | height | The height of the window in pixels. |
[in] | flags | Flags to configure the window's behavior (e.g., fullscreen, resizable). |
[out] | window | Pointer to the Window structure to be initialized. |
This function initializes the SDL2 library and creates a window with an OpenGL context. It sets various OpenGL attributes, including enabling double-buffering and depth testing. The window's start time and initial timing values are also initialized. If window creation or surface retrieval fails, an error message is printed and -1 is returned.
void refresh_resolution | ( | ) |
Refreshes the window resolution.
void update_window | ( | Window * | window, |
struct Node * | scene, | ||
struct Camera * | c, | ||
struct WorldShaders * | shaders, | ||
struct DepthMap * | depthMap, | ||
struct Mesh * | screenPlane | ||
) |
Updates the window by rendering the scene and swapping the buffers.
[in] | window | Pointer to the Window structure containing the window's state and timing information. |
[in] | scene | Pointer to the Node structure representing the scene to be rendered. |
[in] | c | Pointer to the Camera structure used for rendering the scene. |
[in] | shaders | Pointer to the WorldShaders structure used for rendering. |
[in] | depthMap | Pointer to the DepthMap structure that handles depth information for rendering. |
[in] | screenPlane | Pointer to the Mesh structure representing the screen plane. |
This function calculates the time elapsed since the last update, updates the window's state accordingly, and calls the draw_screen function to render the scene's content. It also enables relative mouse mode for capturing mouse movements. Finally, it swaps the OpenGL buffers to display the rendered content on the window.
void refresh_ui | ( | Window * | window | ) |
Refreshes the UI of the window.
This function updates the graphical user interface of the specified window. It should be called whenever the window needs to be redrawn or updated.
[in] | window | Pointer to the Window structure that represents the window to be refreshed. |
void free_window | ( | Window * | window | ) |
Frees the resources associated with the window.
This function releases all the resources allocated for the given window, ensuring that there are no memory leaks.