blob: d57a434496aa7cf858f2ee9a0a8a30d6129d0f5d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
#include "input.h"
#include <SDL3/SDL.h>
#include <SDL3/SDL_video.h>
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;
}
|