Fixed funny resolution changing.

This commit is contained in:
2026-10-15 05:36:11 +02:00
parent 73b04fc80c
commit ec2efe79f0
+26 -4
View File
@@ -16,7 +16,11 @@ Resolution :: struct {
// Preset window dimensions
RESOLUTIONS := [?]Resolution{
{0, 0, "Fullscreen"},
{1024, 768, "1024x768"},
{1280, 720, "1280x720"},
{1366, 768, "1366x768"},
{1600, 900, "1600x900"},
{1920, 1080, "1920x1080"},
{2560, 1440, "2560x1440"},
{3840, 2160, "3840x2160"},
@@ -55,14 +59,16 @@ gamepad_compat := #load("../gamecontrollerdb.txt", string)
// Game Lifecycle
// ------------------------------------------------------------------------------
game_init :: proc(game: ^Game) {
rl.SetConfigFlags({.WINDOW_ALWAYS_RUN, .MSAA_4X_HINT})
game.res_index = 2
rl.SetConfigFlags({.WINDOW_ALWAYS_RUN, .MSAA_4X_HINT, .WINDOW_RESIZABLE})
game.res_index = 0
game.window_w = RESOLUTIONS[game.res_index].width
game.window_h = RESOLUTIONS[game.res_index].height
rl.InitWindow(game.window_w, game.window_h, WINDOW_TITLE)
rl.SetTargetFPS(60)
rl.SetExitKey(.KEY_NULL)
rl.ToggleBorderlessWindowed()
rl.HideCursor()
gamepad_cstr := strings.clone_to_cstring(gamepad_compat)
defer delete(gamepad_cstr)
@@ -178,7 +184,7 @@ game_render :: proc(game: ^Game) {
render_game_to_window(game)
when DEBUG do rl.DrawFPS(10, game.window_h - 20)
when DEBUG do rl.DrawFPS(10, rl.GetScreenHeight() - 20)
rl.EndDrawing()
}
@@ -209,6 +215,17 @@ game_trigger_shake :: proc(game: ^Game, intensity: f32, duration: f32 = 0.15) {
game_set_resolution :: proc(game: ^Game, res_index: int) {
game.res_index = clamp(res_index, 0, len(RESOLUTIONS) - 1)
borderless := rl.IsWindowState({.BORDERLESS_WINDOWED_MODE})
if game.res_index == 0 {
if !borderless do rl.ToggleBorderlessWindowed()
return
}
if borderless {
rl.ToggleBorderlessWindowed()
rl.RestoreWindow()
}
target_w := RESOLUTIONS[game.res_index].width
target_h := RESOLUTIONS[game.res_index].height
@@ -226,13 +243,18 @@ game_set_resolution :: proc(game: ^Game, res_index: int) {
render_game_to_window :: proc(game: ^Game) {
texture := game.viewport.texture
w, h := f32(rl.GetScreenWidth()), f32(rl.GetScreenHeight())
s := min(w / VIEWPORT_W, h / VIEWPORT_H)
dst := rl.Rectangle{(w - VIEWPORT_W*s)/2, (h - VIEWPORT_H*s)/2, VIEWPORT_W*s, VIEWPORT_H*s}
rl.BeginShaderMode(game.crt_shader)
rl.DrawTexturePro(
texture,
// src: inverted y coordinate flips opengl texture buffer correctly
rl.Rectangle{0, 0, f32(texture.width), -f32(texture.height)},
// dst: scales viewport canvas to fill window resolution
rl.Rectangle{0, 0, f32(game.window_w), f32(game.window_h)},
// rl.Rectangle{0, 0, f32(game.window_w), f32(game.window_h)},
dst,
rl.Vector2{},
0,
rl.WHITE,