SBgl 0.1.0
A graphics framework in C99
Loading...
Searching...
No Matches
mouse_mode.c
Go to the documentation of this file.
1#include <sbgl.h>
2#include <stdio.h>
3
4/*
5 * This example demonstrates the different mouse modes available in SBgl.
6 * The system supports three primary modes:
7 * - NORMAL: Cursor is visible and behaves normally.
8 * - HIDDEN: Cursor is invisible but can still leave the window area.
9 * - CAPTURED: Cursor is invisible and locked to the window center,
10 * providing continuous relative motion (ideal for first-person cameras).
11 */
12
13int main(void) {
14 /* Initialize the library and create a window. */
15 sbgl_InitResult res = sbgl_Init(800, 600, "SBgl Mouse Mode Test");
16 if (res.error != SBGL_SUCCESS)
17 return 1;
18 sbgl_Context* ctx = res.ctx;
19
20 printf("--- Mouse Mode Controls ---\n");
21 printf("1: NORMAL (Visible, Free)\n");
22 printf("2: HIDDEN (Invisible, Free)\n");
23 printf("3: CAPTURED (Invisible, Locked)\n");
24 printf("ESC: Exit\n");
25
26 /* Main application loop. */
27 while (!sbgl_WindowShouldClose(ctx)) {
28 /* Clear the background with a dark blue color. */
29 sbgl_Clear(ctx, 0.1f, 0.1f, 0.15f, 1.0f);
31
32 /* Retrieve the current input state to check for key presses. */
33 const sbgl_InputState* input = sbgl_GetInputState(ctx);
34
35 /* Toggle between mouse modes based on user input. */
36 if (input->keysPressed[SBGL_KEY_1]) {
37 printf("Mode: NORMAL\n");
39 }
40 if (input->keysPressed[SBGL_KEY_2]) {
41 printf("Mode: HIDDEN\n");
43 }
44 if (input->keysPressed[SBGL_KEY_3]) {
45 printf("Mode: CAPTURED\n");
47 }
48
49 /* Exit the application if the Escape key is pressed. */
50 if (input->keysDown[SBGL_KEY_ESCAPE])
51 break;
52
53 /* Mouse movement deltas are tracked regardless of the current mode. */
54 if (input->mouseDeltaX != 0 || input->mouseDeltaY != 0) {
55 /* Delta information can be printed here for debugging purposes. */
56 }
57
58 /* Finalize the current frame and present it. */
59 sbgl_EndDrawing(ctx);
60 }
61
63 /* Clean up resources and shut down the context. */
64 sbgl_Shutdown(ctx);
65 return 0;
66}
@ SBGL_MOUSE_MODE_NORMAL
Definition sbgl_input.h:154
@ SBGL_MOUSE_MODE_CAPTURED
Definition sbgl_input.h:156
@ SBGL_MOUSE_MODE_HIDDEN
Definition sbgl_input.h:155
int main(void)
Definition mouse_mode.c:13
API for the SiputBiru Graphics Library (SBgl).
sbgl_InitResult sbgl_Init(int w, int h, const char *title)
Initializes the engine and opens a window.
Definition sbgl_core.c:193
bool sbgl_WindowShouldClose(sbgl_Context *ctx)
Checks if the user or OS has requested to close the window.
Definition sbgl_core.c:238
const sbgl_InputState * sbgl_GetInputState(sbgl_Context *ctx)
Retrieves the input state for the current frame.
Definition sbgl_core.c:413
#define SBGL_KEY_1
Definition sbgl.h:69
#define SBGL_KEY_3
Definition sbgl.h:71
void sbgl_SetMouseMode(sbgl_Context *ctx, sbgl_MouseMode mode)
Sets the cursor behavior and visibility.
Definition sbgl_core.c:422
void sbgl_EndDrawing(sbgl_Context *ctx)
Finalizes the current frame and presents it to the screen.
Definition sbgl_core.c:315
#define SBGL_KEY_ESCAPE
Definition sbgl.h:84
#define sbgl_Clear
Backward compatibility alias for sbgl_SetClearColor.
Definition sbgl.h:229
void sbgl_DeviceWaitIdle(sbgl_Context *ctx)
Synchronizes the CPU with the GPU, waiting for all commands to complete.
Definition sbgl_core.c:391
void sbgl_Shutdown(sbgl_Context *ctx)
Gracefully shuts down the engine and releases all resources.
Definition sbgl_core.c:204
void sbgl_BeginDrawing(sbgl_Context *ctx)
Prepares the engine for a new frame of drawing.
Definition sbgl_core.c:262
#define SBGL_KEY_2
Definition sbgl.h:70
@ SBGL_SUCCESS
Definition sbgl_types.h:215
Engine context.
Definition sbgl_types.h:268
Result structure for initialization.
Definition sbgl_types.h:339
sbgl_Context * ctx
Definition sbgl_types.h:340
sbgl_Result error
Definition sbgl_types.h:341
Represents the real-time state of physical inputs.
Definition sbgl_input.h:165
bool keysPressed[SBGL_SCANCODE_MAX]
Definition sbgl_input.h:167
bool keysDown[SBGL_SCANCODE_MAX]
Definition sbgl_input.h:166