6 static void process_event(SDL_Event *ev);
8 static SDL_Window *win;
9 static SDL_GLContext ctx;
10 static bool redraw_pending = true;
13 int main(int argc, char **argv)
15 if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) {
16 fprintf(stderr, "failed to initialize SDL\n");
20 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
21 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
22 SDL_GL_SetAttribute(SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1);
24 int x = SDL_WINDOWPOS_UNDEFINED;
25 int y = SDL_WINDOWPOS_UNDEFINED;
26 unsigned int flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI;
29 if(!(win = SDL_CreateWindow("vrfileman", x, y, win_width, win_height, flags))) {
30 fprintf(stderr, "failed to create window\n");
34 if(!(ctx = SDL_GL_CreateContext(win))) {
35 fprintf(stderr, "failed to create OpenGL context\n");
38 SDL_GL_GetDrawableSize(win, &win_width, &win_height);
39 win_aspect = (float)win_width / (float)win_height;
41 if(!app_init(argc, argv)) {
45 app_reshape(win_width, win_height);
51 if(!SDL_WaitEvent(0)) {
52 fprintf(stderr, "error while waiting for events\n");
57 time_msec = app_get_msec();
58 while(SDL_PollEvent(&ev)) {
60 if(quit) goto break_evloop;
64 redraw_pending = false;
82 redraw_pending = true;
85 void app_swap_buffers()
87 SDL_GL_SwapWindow(win);
92 return SDL_GetTicks();
95 static void process_event(SDL_Event *ev)
104 app_keyboard(ev->key.keysym.sym, ev->key.state == SDL_PRESSED);
107 case SDL_MOUSEBUTTONDOWN:
108 case SDL_MOUSEBUTTONUP:
109 app_mouse_button(ev->button.button - SDL_BUTTON_LEFT, ev->button.state == SDL_PRESSED,
110 ev->button.x, ev->button.y);
113 case SDL_MOUSEMOTION:
114 app_mouse_motion(ev->motion.x, ev->motion.y);
117 case SDL_WINDOWEVENT:
118 if(ev->window.event == SDL_WINDOWEVENT_RESIZED) {
119 win_width = ev->window.data1;
120 win_height = ev->window.data2;
121 win_aspect = (float)win_width / (float)win_height;
122 app_reshape(win_width, win_height);