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 { Game :: struct {
viewport: rl.RenderTexture2D, viewport: rl.RenderTexture2D,
bg_texture: rl.Texture2D, bg_texture: rl.Texture2D,
crt_shader: rl.Shader,
scene_stack: [dynamic]Scene, scene_stack: [dynamic]Scene,
should_close: bool, should_close: bool,
audio: Audio_Manager, audio: Audio_Manager,
@@ -65,8 +66,8 @@ game_init :: proc(game: ^Game) {
game.scene_stack = make([dynamic]Scene, 0, 8) game.scene_stack = make([dynamic]Scene, 0, 8)
game.viewport = rl.LoadRenderTexture(VIEWPORT_W, VIEWPORT_H) game.viewport = rl.LoadRenderTexture(VIEWPORT_W, VIEWPORT_H)
// Force nearest neighbor point filtering on the viewport texture // Look into texture filters
rl.SetTextureFilter(game.viewport.texture, .POINT) rl.SetTextureFilter(game.viewport.texture, .BILINEAR)
// Generate soft CRT background radial texture once on startup // Generate soft CRT background radial texture once on startup
bg_center := rl.Color{22, 28, 36, 255} 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) bg_img := rl.GenImageGradientRadial(VIEWPORT_W, VIEWPORT_H, 0.3, bg_center, bg_corner)
game.bg_texture = rl.LoadTextureFromImage(bg_img) game.bg_texture = rl.LoadTextureFromImage(bg_img)
rl.UnloadImage(bg_img) // Free CPU memory 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 game.should_close = false
set_root_scene(game, make_main_menu()) set_root_scene(game, make_main_menu())
@@ -121,6 +123,7 @@ game_render :: proc(game: ^Game) {
game_quit :: proc(game: ^Game) { game_quit :: proc(game: ^Game) {
audio_manager_quit(&game.audio) audio_manager_quit(&game.audio)
rl.UnloadShader(game.crt_shader)
rl.UnloadTexture(game.bg_texture) rl.UnloadTexture(game.bg_texture)
rl.UnloadRenderTexture(game.viewport) rl.UnloadRenderTexture(game.viewport)
delete(GLOBAL_EVENTS) delete(GLOBAL_EVENTS)
@@ -156,6 +159,7 @@ game_set_resolution :: proc(game: ^Game, res_index: int) {
render_game_to_window :: proc(game: ^Game) { render_game_to_window :: proc(game: ^Game) {
texture := game.viewport.texture texture := game.viewport.texture
rl.BeginShaderMode(game.crt_shader)
rl.DrawTexturePro( rl.DrawTexturePro(
texture, texture,
// src: inverted y coordinate flips opengl texture buffer correctly // src: inverted y coordinate flips opengl texture buffer correctly
@@ -166,5 +170,5 @@ render_game_to_window :: proc(game: ^Game) {
0, 0,
rl.WHITE, rl.WHITE,
) )
rl.EndShaderMode()
} }