Claude Chappe' Curse - A C Game
Logo Institut d'Informatique Claude Chappe Logo Université de Le Mans Logo Raeptor Production
 
Loading...
Searching...
No Matches
Window Management

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.
 

Detailed Description

Functions and structures for managing the SDL window and OpenGL context.

Enumeration Type Documentation

◆ WindowFlags

Enumeration for window flags.

This enumeration defines various flags that can be used to describe the state of a window.

Enumerator
WINDOW_NO_FLAGS 

No flags set. This indicates that the window has no special state.

WINDOW_PRERENDER_PASS 

Flag indicating that the window is in prerender pass. This is used to specify that the window is currently in the prerendering phase.

WINDOW_RESIZED 

Flag indicating that the window has been resized. This flag is set when the window's dimensions have changed.

Function Documentation

◆ create_window()

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.

Parameters
[in]titleThe title of the window.
[in]xThe x-coordinate of the window's position on the screen.
[in]yThe y-coordinate of the window's position on the screen.
[in]widthThe width of the window in pixels.
[in]heightThe height of the window in pixels.
[in]flagsFlags to configure the window's behavior (e.g., fullscreen, resizable).
[out]windowPointer to the Window structure to be initialized.
Returns
Returns 0 on success, or -1 on failure.

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.

◆ refresh_resolution()

void refresh_resolution ( )

Refreshes the window resolution.

◆ update_window()

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.

Parameters
[in]windowPointer to the Window structure containing the window's state and timing information.
[in]scenePointer to the Node structure representing the scene to be rendered.
[in]cPointer to the Camera structure used for rendering the scene.
[in]shadersPointer to the WorldShaders structure used for rendering.
[in]depthMapPointer to the DepthMap structure that handles depth information for rendering.
[in]screenPlanePointer to the Mesh structure representing the screen plane.
Returns
This function does not return a value.

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.

◆ refresh_ui()

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.

Parameters
[in]windowPointer to the Window structure that represents the window to be refreshed.

◆ free_window()

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.

Parameters
[in]windowPointer to the Window structure to be freed. This should be a valid pointer to a previously created Window structure.