Skip to content

Commit

Permalink
Impl video_reinit so video_menu takes effect right away
Browse files Browse the repository at this point in the history
  • Loading branch information
Nopey committed Nov 5, 2024
1 parent 96ba692 commit c816f94
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/video/sdl_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ bool create_window(SDL_Window **window, int width, int height, bool fullscreen)
return true;
}

bool resize_window(SDL_Window *window, int width, int height, bool fullscreen) {
SDL_SetWindowSize(window, width, height);
if(SDL_SetWindowFullscreen(window, fullscreen ? SDL_WINDOW_FULLSCREEN : 0) < 0) {
PERROR("Could not set fullscreen mode: %s", SDL_GetError());
return false;
}
return true;
}

bool set_vsync(bool enable) {
// If we don't want to enable vsync, just log and okay out.
if(!enable) {
Expand Down
1 change: 1 addition & 0 deletions src/video/sdl_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

bool create_gl_context(SDL_GLContext **context, SDL_Window *window);
bool create_window(SDL_Window **window, int width, int height, bool fullscreen);
bool resize_window(SDL_Window *window, int width, int height, bool fullscreen);
bool set_vsync(bool enable);
void ortho2d(float *matrix, float left, float right, float bottom, float top);

Expand Down
12 changes: 11 additions & 1 deletion src/video/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,17 @@ void video_reinit_renderer(void) {
}

int video_reinit(int window_w, int window_h, bool fullscreen, bool vsync) {
return 0;
g_video_state.screen_w = window_w;
g_video_state.screen_h = window_h;
g_video_state.fullscreen = fullscreen;
g_video_state.vsync = vsync;
bool success = resize_window(g_video_state.window, window_w, window_h, fullscreen);
success = set_vsync(g_video_state.vsync) && success;

// Fetch viewport size which may be different from window size.
SDL_GL_GetDrawableSize(g_video_state.window, &g_video_state.viewport_w, &g_video_state.viewport_h);

return success;
}

// Called on every game tick
Expand Down

0 comments on commit c816f94

Please sign in to comment.