SBgl 0.1.0
A graphics framework in C99
Loading...
Searching...
No Matches
input_keyboard.c
Go to the documentation of this file.
1#include <sbgl.h>
2#include <stdio.h>
3
4int main(void) {
5 printf("Initializing Input Test (Result Struct API)...\n");
6 printf("Controls: R=Red, G=Green, B=Blue, ESC=Exit\n");
7
8 sbgl_InitResult res = sbgl_Init(800, 600, "SBgl Input Test");
9 if (res.error != SBGL_SUCCESS) {
10 printf("Failed to init: %d\n", res.error);
11 return 1;
12 }
13
14 sbgl_Context* ctx = res.ctx;
15 float r = 0.1f, g = 0.2f, b = 0.3f;
16
17 while (!sbgl_WindowShouldClose(ctx)) {
18 const sbgl_InputState* input = sbgl_GetInputState(ctx);
19
20 if (input->keysDown[SBGL_KEY_R]) {
21 r = 1.0f;
22 g = 0.0f;
23 b = 0.0f;
24 }
25 if (input->keysDown[SBGL_KEY_G]) {
26 r = 0.0f;
27 g = 1.0f;
28 b = 0.0f;
29 }
30 if (input->keysDown[SBGL_KEY_B]) {
31 r = 0.0f;
32 g = 0.0f;
33 b = 1.0f;
34 }
35
36 sbgl_Clear(ctx, r, g, b, 1.0f);
37
39 // Drawing logic here
40 sbgl_EndDrawing(ctx);
41
42 if (input->keysDown[SBGL_KEY_ESCAPE]) {
43 break;
44 }
45 }
46
48 sbgl_Shutdown(ctx);
49 return 0;
50}
int main(void)
API for the SiputBiru Graphics Library (SBgl).
#define SBGL_KEY_R
Definition sbgl.h:59
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
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_KEY_B
Definition sbgl.h:43
#define sbgl_Clear
Backward compatibility alias for sbgl_SetClearColor.
Definition sbgl.h:229
#define SBGL_KEY_G
Definition sbgl.h:48
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