commit 2b431fb
uint
·
2026-07-21 20:03:07 +0000 UTC
parent 061e549
add SDL, GL checks, logging
2 files changed,
+13,
-2
+4,
-0
1@@ -7,7 +7,11 @@ typedef enum { /* TODO: rename to MG_EC_... */
2 MG_ERR_EXIT_SUCCESS,
3 MG_ERR_EXIT_FAILURE,
4
5+ MG_ERR_SDL_INIT,
6+ MG_ERR_SDL_CREATE_WIN,
7+
8 MG_ERR_GL_CTX_CREATE,
9+ MG_ERR_GL_CTX_ACTIVATE,
10
11 MG_ERR_REN_CREATE,
12
+9,
-2
1@@ -11,7 +11,8 @@ void platform_get_drawable_size(MGContext* ctx, i32* width, i32* height)
2 void platform_init(MGContext* ctx)
3 {
4 (void) ctx;
5- SDL_Init(SDL_INIT_VIDEO);
6+ if (SDL_Init(SDL_INIT_VIDEO) != 0)
7+ mg_die(MG_ERR_SDL_INIT, "SDL_Init failed: %s", SDL_GetError());
8
9 /* TODO: OpenGL specifis */
10 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
11@@ -71,10 +72,16 @@ void platform_window_create(MGContext* ctx)
12 SDL_WINDOW_RESIZABLE|SDL_WINDOW_ALLOW_HIGHDPI|SDL_WINDOW_OPENGL
13 );
14
15+ if (!ctx->win)
16+ mg_die(MG_ERR_SDL_CREATE_WIN, "Failed to create window: %s", SDL_GetError());
17+
18 ctx->vbe.gl = SDL_GL_CreateContext(ctx->win);
19 if (!ctx->vbe.gl)
20 mg_die(MG_ERR_GL_CTX_CREATE, "Failed to initialise GL Context");
21- SDL_GL_MakeCurrent(ctx->win, ctx->vbe.gl);
22+
23+ if (SDL_GL_MakeCurrent(ctx->win, ctx->vbe.gl) != 0)
24+ mg_die(MG_ERR_GL_CTX_ACTIVATE, "Failed to activate GL Context: %s", SDL_GetError());
25+
26 SDL_GL_SetSwapInterval(1);
27 }
28