From 3375d712e40cce1d17198ba20839f58a2a77d202 Mon Sep 17 00:00:00 2001 From: Xander Swan Date: Fri, 5 Dec 2025 09:27:12 -0500 Subject: add platforms and AABB collision --- src/draw/draw.odin | 60 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 12 deletions(-) (limited to 'src/draw/draw.odin') diff --git a/src/draw/draw.odin b/src/draw/draw.odin index d67e16c..1762b25 100644 --- a/src/draw/draw.odin +++ b/src/draw/draw.odin @@ -1,6 +1,5 @@ package draw -import "core:fmt" import "core:math/linalg" import "core:math" @@ -20,8 +19,8 @@ Mat4 :: matrix[4, 4]f32 Color :: [4]f32 -SCREEN_WIDTH :: 256 -SCREEN_HEIGHT :: 256 +SCREEN_WIDTH :: 480 +SCREEN_HEIGHT :: 360 Renderer :: struct { screen: Framebuffer, @@ -34,6 +33,8 @@ Renderer :: struct { view: sg.View, sampler: sg.Sampler, + white_1x1: sg.Image, + projection: Mat4, current_batch: Batch, @@ -69,6 +70,18 @@ init :: proc(r: ^Renderer) { }, } + white := [?]u8{255, 255, 255, 255} + + r.white_1x1 = sg.make_image({ + width = 1, + height = 1, + data = { + mip_levels = { + 0 = {ptr=&white, size=size_of(white)}, + }, + }, + }) + init_framebuffer( &r.screen, SCREEN_WIDTH, SCREEN_HEIGHT, @@ -125,7 +138,7 @@ end_frame :: proc(r: ^Renderer) { (f32(sapp.height()) - (SCREEN_HEIGHT * scale)) / 2, } - draw_texture( + texture( r, r.screen.img, screen_start, @@ -210,12 +223,37 @@ batch_vertices :: proc( append(&b.vertices, ..vertices) } -draw_texture :: proc{ - draw_texture_full, - draw_texture_quad, +rect :: proc( + r: ^Renderer, + rect: Rect, + color := Color{1, 1, 1, 1}, +) { + assert(rect.size.x > 0 && rect.size.y > 0) + + batch := request_batch(r, r.white_1x1) + + start := rect.start + end := rect.start + rect.size + + vertices := [?]Vertex{ + {start, {0, 0}, r.tint}, + {{end.x, start.y}, {1, 0}, r.tint}, + {{start.x, end.y}, {0, 1}, r.tint}, + + {{end.x, start.y}, {1, 0}, r.tint}, + {{start.x, end.y}, {0, 1}, r.tint}, + {end, {1, 1}, r.tint}, + } + + batch_vertices(batch, vertices[:]) +} + +texture :: proc{ + texture_full, + texture_quad, } -draw_texture_quad :: proc( +texture_quad :: proc( r: ^Renderer, img: sg.Image, quad: Rect, @@ -252,7 +290,7 @@ draw_texture_quad :: proc( batch_vertices(batch, vertices[:]) } -draw_texture_full :: proc( +texture_full :: proc( r: ^Renderer, img: sg.Image, pos: Vec2, @@ -263,7 +301,5 @@ draw_texture_full :: proc( f32(sg.query_image_width(img)), f32(sg.query_image_height(img)), } - draw_texture_quad(r, img, Rect{Vec2{0, 0}, size}, pos, offset, scale) + texture_quad(r, img, Rect{Vec2{0, 0}, size}, pos, offset, scale) } - - -- cgit v1.3-2-g0d8e