Add a CRT shader effect over the game.

This commit is contained in:
2026-09-29 07:53:43 +02:00
parent ce142a2d02
commit f345b0a5f4
+8 -4
View File
@@ -26,6 +26,7 @@ RESOLUTIONS := [?]Resolution{
Game :: struct {
viewport: rl.RenderTexture2D,
bg_texture: rl.Texture2D,
crt_shader: rl.Shader,
scene_stack: [dynamic]Scene,
should_close: bool,
audio: Audio_Manager,
@@ -65,8 +66,8 @@ game_init :: proc(game: ^Game) {
game.scene_stack = make([dynamic]Scene, 0, 8)
game.viewport = rl.LoadRenderTexture(VIEWPORT_W, VIEWPORT_H)
// Force nearest neighbor point filtering on the viewport texture
rl.SetTextureFilter(game.viewport.texture, .POINT)
// Look into texture filters
rl.SetTextureFilter(game.viewport.texture, .BILINEAR)
// Generate soft CRT background radial texture once on startup
bg_center := rl.Color{22, 28, 36, 255}
@@ -74,7 +75,8 @@ game_init :: proc(game: ^Game) {
bg_img := rl.GenImageGradientRadial(VIEWPORT_W, VIEWPORT_H, 0.3, bg_center, bg_corner)
game.bg_texture = rl.LoadTextureFromImage(bg_img)
rl.UnloadImage(bg_img) // Free CPU memory
// rl.SetTextureFilter(game.bg_texture, .BILINEAR)
game.crt_shader = rl.LoadShader(nil, "assets/shaders/crt.fs")
game.should_close = false
set_root_scene(game, make_main_menu())
@@ -121,6 +123,7 @@ game_render :: proc(game: ^Game) {
game_quit :: proc(game: ^Game) {
audio_manager_quit(&game.audio)
rl.UnloadShader(game.crt_shader)
rl.UnloadTexture(game.bg_texture)
rl.UnloadRenderTexture(game.viewport)
delete(GLOBAL_EVENTS)
@@ -156,6 +159,7 @@ game_set_resolution :: proc(game: ^Game, res_index: int) {
render_game_to_window :: proc(game: ^Game) {
texture := game.viewport.texture
rl.BeginShaderMode(game.crt_shader)
rl.DrawTexturePro(
texture,
// src: inverted y coordinate flips opengl texture buffer correctly
@@ -166,5 +170,5 @@ render_game_to_window :: proc(game: ^Game) {
0,
rl.WHITE,
)
rl.EndShaderMode()
}