|
|
@@ -13,6 +13,17 @@ static SDL_Texture *framebuffer = NULL;
|
|
|
static uint32_t* fb;
|
|
|
static luat_sdl2_conf_t sdl_conf;
|
|
|
|
|
|
+static void luat_sdl2_pump_events(void) {
|
|
|
+ SDL_Event e;
|
|
|
+ while (SDL_PollEvent(&e)) {
|
|
|
+ if (e.type == SDL_QUIT) {
|
|
|
+ // Graceful exit on window close
|
|
|
+ exit(0);
|
|
|
+ }
|
|
|
+ // Other events are ignored; important is to pump to keep window responsive
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
int luat_sdl2_init(luat_sdl2_conf_t *conf) {
|
|
|
if (framebuffer != NULL) {
|
|
|
LLOGD("SDL2 aready inited");
|
|
|
@@ -28,13 +39,14 @@ int luat_sdl2_init(luat_sdl2_conf_t *conf) {
|
|
|
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
|
|
conf->width, conf->height, 0);
|
|
|
|
|
|
- renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
|
|
+ renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
|
|
framebuffer = SDL_CreateTexture(renderer,
|
|
|
SDL_PIXELFORMAT_ARGB8888,
|
|
|
SDL_TEXTUREACCESS_STREAMING,
|
|
|
conf->width,
|
|
|
conf->height);
|
|
|
// fb = luat_heap_malloc(sizeof(uint32_t) * conf->width * conf->height);
|
|
|
+ luat_sdl2_pump_events();
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
@@ -67,4 +79,5 @@ void luat_sdl2_flush(void) {
|
|
|
SDL_RenderCopy(renderer, framebuffer, NULL, NULL);
|
|
|
SDL_RenderPresent(renderer);
|
|
|
}
|
|
|
+ luat_sdl2_pump_events();
|
|
|
}
|