Changing to a pixel art style with crt bg.
This commit is contained in:
+25
-7
@@ -3,8 +3,10 @@ package game
|
|||||||
import "core:strings"
|
import "core:strings"
|
||||||
import rl "vendor:raylib"
|
import rl "vendor:raylib"
|
||||||
|
|
||||||
VIEWPORT_W :: 1280
|
// VIEWPORT_W :: 1280
|
||||||
VIEWPORT_H :: 720
|
// VIEWPORT_H :: 720
|
||||||
|
VIEWPORT_W :: 640
|
||||||
|
VIEWPORT_H :: 360
|
||||||
WINDOW_TITLE :: "Pong"
|
WINDOW_TITLE :: "Pong"
|
||||||
|
|
||||||
Resolution :: struct {
|
Resolution :: struct {
|
||||||
@@ -22,10 +24,11 @@ RESOLUTIONS := [?]Resolution{
|
|||||||
}
|
}
|
||||||
|
|
||||||
Game :: struct {
|
Game :: struct {
|
||||||
viewport: rl.RenderTexture2D,
|
viewport: rl.RenderTexture2D,
|
||||||
scene_stack: [dynamic]Scene,
|
bg_texture: rl.Texture2D,
|
||||||
should_close: bool,
|
scene_stack: [dynamic]Scene,
|
||||||
audio: Audio_Manager,
|
should_close: bool,
|
||||||
|
audio: Audio_Manager,
|
||||||
|
|
||||||
// resolution state
|
// resolution state
|
||||||
window_w: i32,
|
window_w: i32,
|
||||||
@@ -61,6 +64,18 @@ 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
|
||||||
|
rl.SetTextureFilter(game.viewport.texture, .POINT)
|
||||||
|
|
||||||
|
// Generate soft CRT background radial texture once on startup
|
||||||
|
bg_center := rl.Color{22, 28, 36, 255}
|
||||||
|
bg_corner := rl.Color{6, 8, 12, 255}
|
||||||
|
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.should_close = false
|
game.should_close = false
|
||||||
set_root_scene(game, make_main_menu())
|
set_root_scene(game, make_main_menu())
|
||||||
}
|
}
|
||||||
@@ -86,7 +101,7 @@ game_render :: proc(game: ^Game) {
|
|||||||
rl.ClearBackground(rl.BLACK)
|
rl.ClearBackground(rl.BLACK)
|
||||||
|
|
||||||
rl.BeginTextureMode(game.viewport)
|
rl.BeginTextureMode(game.viewport)
|
||||||
rl.ClearBackground(rl.BLACK)
|
rl.DrawTexture(game.bg_texture, 0, 0, rl.WHITE)
|
||||||
|
|
||||||
// @note: fine for now but probably not a good idea...
|
// @note: fine for now but probably not a good idea...
|
||||||
// Render all scenes in the stack from bottom to top
|
// Render all scenes in the stack from bottom to top
|
||||||
@@ -98,6 +113,7 @@ game_render :: proc(game: ^Game) {
|
|||||||
|
|
||||||
render_game_to_window(game)
|
render_game_to_window(game)
|
||||||
|
|
||||||
|
rl.DrawFPS(10, game.window_h - 20)
|
||||||
rl.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,6 +121,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.UnloadTexture(game.bg_texture)
|
||||||
rl.UnloadRenderTexture(game.viewport)
|
rl.UnloadRenderTexture(game.viewport)
|
||||||
delete(GLOBAL_EVENTS)
|
delete(GLOBAL_EVENTS)
|
||||||
delete(game.scene_stack)
|
delete(game.scene_stack)
|
||||||
@@ -149,4 +166,5 @@ render_game_to_window :: proc(game: ^Game) {
|
|||||||
0,
|
0,
|
||||||
rl.WHITE,
|
rl.WHITE,
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user