commit 9743d43

uint  ·  2026-07-21 16:54:27 +0000 UTC
parent 092b67a
add platform_shutdown
3 files changed,  +21, -1
+1, -0
1@@ -33,6 +33,7 @@ typedef struct {
2 
3 /* initialise resources */
4 void platform_init(MGContext* ctx);
5+void platform_shutdown(MGContext* ctx);
6 
7 /* create window */
8 void platform_window_create(MGContext* ctx);
+1, -0
1@@ -16,6 +16,7 @@ int main(void)
2 	platform_init(&ctx);
3 	platform_window_create(&ctx);
4 
5+	platform_shutdown(&ctx);
6 	return MG_ERR_EXIT_SUCCESS;
7 }
8 
+19, -1
 1@@ -17,9 +17,27 @@ void platform_init(MGContext* ctx)
 2 	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
 3 }
 4 
 5+void platform_shutdown(MGContext* ctx)
 6+{
 7+	if (!ctx)
 8+		return;
 9+
10+	if (ctx->vbe.gl) {
11+		SDL_GL_DeleteContext(ctx->vbe.gl);
12+		ctx->vbe.gl = NULL;
13+	}
14+
15+	if (ctx->win) {
16+		SDL_DestroyWindow(ctx->win);
17+		ctx->win = NULL;
18+	}
19+
20+	SDL_Quit();
21+}
22+
23 void platform_window_create(MGContext* ctx)
24 {
25-	ctx->win = (MGWindow*) SDL_CreateWindow(
26+	ctx->win = SDL_CreateWindow(
27 		ctx->title, ctx->x, ctx->y, ctx->width, ctx->height,
28 		SDL_WINDOW_RESIZABLE|SDL_WINDOW_ALLOW_HIGHDPI|SDL_WINDOW_OPENGL
29 	);