return 1;
}
+ SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
+ SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
+ SDL_GL_SetAttribute(SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1);
+
int x = SDL_WINDOWPOS_UNDEFINED;
int y = SDL_WINDOWPOS_UNDEFINED;
unsigned int flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI;
return 1;
}
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
- SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1);
-
if(!(ctx = SDL_GL_CreateContext(win))) {
fprintf(stderr, "failed to create OpenGL context\n");
return 1;
}
SDL_GL_GetDrawableSize(win, &win_width, &win_height);
+ win_aspect = (float)win_width / (float)win_height;
+
+ if(!app_init(argc, argv)) {
+ SDL_Quit();
+ return 1;
+ }
app_reshape(win_width, win_height);
while(!quit) {
return 0;
}
+void app_resize(int x, int y)
+{
+ SDL_SetWindowSize(win, x, y);
+}
+
+void app_fullscreen(int fs)
+{
+ SDL_SetWindowFullscreen(win, fs ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
+}
+
+void app_quit()
+{
+ quit = true;
+}
+
void app_redraw()
{
redraw_pending = true;
{
return SDL_GetTicks();
}
+
+static void process_event(SDL_Event *ev)
+{
+ switch(ev->type) {
+ case SDL_QUIT:
+ quit = true;
+ break;
+
+ case SDL_KEYDOWN:
+ case SDL_KEYUP:
+ app_keyboard(ev->key.keysym.sym, ev->key.state == SDL_PRESSED);
+ break;
+
+ case SDL_MOUSEBUTTONDOWN:
+ case SDL_MOUSEBUTTONUP:
+ app_mouse_button(ev->button.button - SDL_BUTTON_LEFT, ev->button.state == SDL_PRESSED,
+ ev->button.x, ev->button.y);
+ break;
+
+ case SDL_MOUSEMOTION:
+ app_mouse_motion(ev->motion.x, ev->motion.y);
+ break;
+
+ case SDL_WINDOWEVENT:
+ if(ev->window.event == SDL_WINDOWEVENT_RESIZED) {
+ win_width = ev->window.data1;
+ win_height = ev->window.data2;
+ win_aspect = (float)win_width / (float)win_height;
+ app_reshape(win_width, win_height);
+ }
+ break;
+ }
+}