Add a CRT shader effect over the game.
This commit is contained in:
+18
-14
@@ -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,15 +159,16 @@ game_set_resolution :: proc(game: ^Game, res_index: int) {
|
||||
render_game_to_window :: proc(game: ^Game) {
|
||||
texture := game.viewport.texture
|
||||
|
||||
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.Vector2{},
|
||||
0,
|
||||
rl.WHITE,
|
||||
)
|
||||
|
||||
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.Vector2{},
|
||||
0,
|
||||
rl.WHITE,
|
||||
)
|
||||
rl.EndShaderMode()
|
||||
}
|
||||
Reference in New Issue
Block a user