Texture baking
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
|
||||
-- ── Runners ─────────────────────────────────────────────
|
||||
-- :Run — picker, :Run <name> [args] — specific command,
|
||||
-- <leader>dr = :Run run.
|
||||
require("custom.runner").setup({
|
||||
commands = {
|
||||
run = function()
|
||||
|
||||
@@ -16,7 +16,7 @@ Scene :: struct {
|
||||
camera: rl.Camera2D,
|
||||
enemies: hm.Static_Handle_Map(128, Enemy, ent_handle),
|
||||
atlas: Atlas,
|
||||
tiles: [MAX_TILES]Tile,
|
||||
map_tex: rl.RenderTexture2D,
|
||||
}
|
||||
|
||||
|
||||
@@ -66,11 +66,29 @@ create_scene :: proc() -> Scene {
|
||||
draw_scene :: proc(scene: ^Scene) {
|
||||
rl.BeginMode2D(scene.camera)
|
||||
|
||||
rl.DrawTexturePro(
|
||||
scene.map_tex.texture,
|
||||
rl.Rectangle {
|
||||
0,
|
||||
0,
|
||||
cast(f32)scene.map_tex.texture.width,
|
||||
cast(f32)scene.map_tex.texture.height,
|
||||
},
|
||||
rl.Rectangle {
|
||||
0,
|
||||
0,
|
||||
cast(f32)scene.map_tex.texture.width * TILE_MULT,
|
||||
cast(f32)scene.map_tex.texture.height * TILE_MULT,
|
||||
},
|
||||
rl.Vector2{0, 0},
|
||||
0,
|
||||
rl.WHITE,
|
||||
)
|
||||
|
||||
for tile in scene.tiles {
|
||||
if tile.atlas == nil do continue
|
||||
draw_tile(tile)
|
||||
}
|
||||
// for tile in scene.tiles {
|
||||
// if tile.atlas == nil do continue
|
||||
// draw_tile(tile)
|
||||
// }
|
||||
|
||||
rl.DrawCircle(
|
||||
cast(i32)scene.player.position.x,
|
||||
@@ -89,6 +107,57 @@ draw_scene :: proc(scene: ^Scene) {
|
||||
rl.EndMode2D()
|
||||
}
|
||||
|
||||
render_map :: proc(atlas: ^Atlas) -> rl.RenderTexture2D {
|
||||
map_data := [16][16]i32 {
|
||||
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
|
||||
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
|
||||
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
|
||||
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
|
||||
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
|
||||
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
|
||||
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
|
||||
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
|
||||
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
|
||||
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
|
||||
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
|
||||
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
|
||||
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
|
||||
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
|
||||
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
|
||||
{16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 18},
|
||||
}
|
||||
width := i32(atlas.tile_size.x) * 16
|
||||
height := i32(atlas.tile_size.y) * 16
|
||||
tex := rl.LoadRenderTexture(width, height)
|
||||
rl.BeginTextureMode(tex)
|
||||
for row, i in map_data {
|
||||
for col, j in row {
|
||||
offset := get_offset(atlas, col)
|
||||
fmt.printf("offset: %v, frame: %v\n", offset, col)
|
||||
rl.DrawTexturePro(
|
||||
atlas^.tex,
|
||||
rl.Rectangle {
|
||||
offset.x,
|
||||
offset.y,
|
||||
atlas.tile_size.x,
|
||||
atlas.tile_size.y,
|
||||
},
|
||||
rl.Rectangle {
|
||||
f32(j) * atlas.tile_size.x,
|
||||
f32(i) * atlas.tile_size.y,
|
||||
atlas.tile_size.x,
|
||||
atlas.tile_size.y,
|
||||
},
|
||||
rl.Vector2{0, 0},
|
||||
0,
|
||||
rl.WHITE,
|
||||
)
|
||||
}
|
||||
}
|
||||
rl.EndTextureMode()
|
||||
return tex
|
||||
}
|
||||
|
||||
|
||||
update_scene :: proc(scene: ^Scene, dt: f32) {
|
||||
update_player(&scene.player, dt)
|
||||
@@ -116,35 +185,7 @@ main :: proc() {
|
||||
|
||||
//WARN: Add a destructor to free (handlemap dangling)
|
||||
scene := create_scene()
|
||||
|
||||
map_data := [16][16]i32 {
|
||||
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
|
||||
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
|
||||
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
|
||||
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
|
||||
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
|
||||
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
|
||||
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
|
||||
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
|
||||
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
|
||||
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
|
||||
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
|
||||
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
|
||||
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
|
||||
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
|
||||
{8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10},
|
||||
{16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 18},
|
||||
}
|
||||
for row, i in map_data {
|
||||
for col, j in row {
|
||||
scene.tiles[i * 16 + j] = Tile {
|
||||
atlas = &scene.atlas,
|
||||
pos = rl.Vector2{f32(j) * 16, f32(i) * 16},
|
||||
frame = col,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
scene.map_tex = render_map(&scene.atlas)
|
||||
|
||||
for !rl.WindowShouldClose() {
|
||||
dt := rl.GetFrameTime()
|
||||
|
||||
Reference in New Issue
Block a user