From 482ea0261cb9f0def49ce3df542b2a7f811262d1 Mon Sep 17 00:00:00 2001 From: Daniel Hader Date: Sun, 14 Jun 2026 12:58:14 -0500 Subject: build and test environment using makefile and basic SDL3 setup --- src/main.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/main.c (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..d57a434 --- /dev/null +++ b/src/main.c @@ -0,0 +1,67 @@ +#include "input.h" +#include +#include + +struct LEO_App { + SDL_Window *window; + SDL_GLContext gl_context; +}; + +int LEO_App_init(struct LEO_App *app) +{ + if (!SDL_InitSubSystem(SDL_INIT_VIDEO)) { + return 1; + } + + app->window = SDL_CreateWindow("title", 640, 480, SDL_WINDOW_OPENGL); + if (app->window == NULL) { + return 2; + } + + app->gl_context = SDL_GL_CreateContext(app->window); + if (app->gl_context == NULL) { + return 3; + } + + return 0; +} + +void LEO_App_run(struct LEO_App *app) +{ + SDL_Event event; + while (true) { + while (SDL_PollEvent(&event)) + LEO_Input_update(event); + + if (LEO_Input_quit()) + break; + + SDL_GL_SwapWindow(app->window); + + SDL_Delay(10); + } +} + +void LEO_App_free(struct LEO_App *app) +{ + if (app->gl_context != NULL) + SDL_GL_DestroyContext(app->gl_context); + + if (app->window != NULL) + SDL_DestroyWindow(app->window); + + SDL_Quit(); +} + +int main(int argc, char **argv) +{ + struct LEO_App app; + if (LEO_App_init(&app)) { + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "failed to init app: %s", SDL_GetError()); + } + + LEO_App_run(&app); + + LEO_App_free(&app); + return 0; +} -- cgit v1.2.3