SBgl 0.1.0
A graphics framework in C99
Loading...
Searching...
No Matches
input_mouse.c File Reference
#include <sbgl.h>
#include <stdio.h>
Include dependency graph for input_mouse.c:

Go to the source code of this file.

Functions

int main (void)
 

Function Documentation

◆ main()

int main ( void )

Definition at line 4 of file input_mouse.c.

4 {
5 printf("Initializing SBgl Mouse Input Test...\n");
6 printf("Controls: Move Mouse to change color, ESC=Exit\n");
7
8 int width = 800;
9 int height = 600;
10 sbgl_InitResult res = sbgl_Init(width, height, "SBgl Mouse Color Map");
11 if (res.error != SBGL_SUCCESS) {
12 printf("Failed to init: %d\n", res.error);
13 return 1;
14 }
15
16 sbgl_Context* ctx = res.ctx;
17
18 while (!sbgl_WindowShouldClose(ctx)) {
19 // Fetch current input state once per frame (DOD Batch Access)
20 const sbgl_InputState* input = sbgl_GetInputState(ctx);
21
22 // Update window size in case it was resized
23 sbgl_GetWindowSize(ctx, &width, &height);
24
25 // Calculate color based on mouse position
26 // Map X to Red (0.0 to 1.0)
27 // Map Y to Green (0.0 to 1.0)
28 float r = (float)input->mouseX / (float)width;
29 float g = (float)input->mouseY / (float)height;
30 float b = 0.5f; // Constant blue
31
32 // Clamp values just in case
33 if (r < 0.0f) {
34 r = 0.0f;
35 }
36 if (r > 1.0f) {
37 r = 1.0f;
38 }
39 if (g < 0.0f) {
40 g = 0.0f;
41 }
42 if (g > 1.0f) {
43 g = 1.0f;
44 }
45
46 // Apply dynamic clear color
47 sbgl_Clear(ctx, r, g, b, 1.0f);
48
50 // Add additional rendering here if needed
51 sbgl_EndDrawing(ctx);
52
53 if (input->keysDown[SBGL_KEY_ESCAPE]) {
54 break;
55 }
56 }
57
59 sbgl_Shutdown(ctx);
60 return 0;
61}
sbgl_InitResult sbgl_Init(int w, int h, const char *title)
Initializes the engine and opens a window.
Definition sbgl_core.c:193
void sbgl_GetWindowSize(sbgl_Context *ctx, int *w, int *h)
Retrieves the current window dimensions.
Definition sbgl_core.c:252
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
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
@ 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 keysDown[SBGL_SCANCODE_MAX]
Definition sbgl_input.h:166