Add missing changes that causes failures
This commit is contained in:
+8
-4
@@ -287,16 +287,14 @@ destroy_frames :: proc(frames: []^image.Image) {
|
||||
delete(frames)
|
||||
}
|
||||
|
||||
opaque_bounds :: proc(img: ^image.Image, alpha_min: u8 = 1) -> (x, y, w, h: int) {
|
||||
iw, ih := int(img.width), int(img.height)
|
||||
pixels := bytes.buffer_to_bytes(&img.pixels)
|
||||
|
||||
opaque_bounds_rgba :: proc(pixels: []u8, iw, ih: int, alpha_min: u8 = 1) -> (x, y, w, h: int) {
|
||||
min_x, min_y := iw, ih
|
||||
max_x, max_y := -1, -1
|
||||
|
||||
for py in 0 ..< ih {
|
||||
for px in 0 ..< iw {
|
||||
i := (py * iw + px) * 4
|
||||
if i + 3 >= len(pixels) do continue
|
||||
a := pixels[i + 3]
|
||||
if a >= alpha_min {
|
||||
if px < min_x do min_x = px
|
||||
@@ -313,6 +311,12 @@ opaque_bounds :: proc(img: ^image.Image, alpha_min: u8 = 1) -> (x, y, w, h: int)
|
||||
return min_x, min_y, max_x - min_x + 1, max_y - min_y + 1
|
||||
}
|
||||
|
||||
opaque_bounds :: proc(img: ^image.Image, alpha_min: u8 = 1) -> (x, y, w, h: int) {
|
||||
iw, ih := int(img.width), int(img.height)
|
||||
pixels := bytes.buffer_to_bytes(&img.pixels)
|
||||
return opaque_bounds_rgba(pixels, iw, ih, alpha_min)
|
||||
}
|
||||
|
||||
pack_atlas :: proc(frames: []^image.Image) -> Atlas {
|
||||
PADDING :: 1
|
||||
|
||||
|
||||
+44
-18
@@ -112,19 +112,15 @@ draw_sprite :: proc(app: ^App, sprite: ^Sprite) {
|
||||
viewport := Vec2{f32(app.swapchain_w), f32(app.swapchain_h)}
|
||||
feet := world_to_screen(app.camera, sprite.position, viewport)
|
||||
|
||||
canvas_top := feet.y - src_h * pivot[1]
|
||||
x0_px, y0_px: f32
|
||||
if sprite.flip_x {
|
||||
canvas_left := feet.x - (1.0 - pivot[0]) * src_w
|
||||
x0_px = canvas_left + (src_w - trim_x - fw)
|
||||
y0_px = canvas_top + trim_y
|
||||
} else {
|
||||
canvas_left := feet.x - src_w * pivot[0]
|
||||
x0_px = canvas_left + trim_x
|
||||
y0_px = canvas_top + trim_y
|
||||
}
|
||||
x1_px := x0_px + fw
|
||||
y1_px := y0_px + fh
|
||||
x0_px, y0_px, x1_px, y1_px := sprite_feet_quad(
|
||||
feet,
|
||||
src_w,
|
||||
src_h,
|
||||
{trim_x, trim_y},
|
||||
{fw, fh},
|
||||
pivot,
|
||||
sprite.flip_x,
|
||||
)
|
||||
|
||||
sw := f32(app.swapchain_w)
|
||||
sh := f32(app.swapchain_h)
|
||||
@@ -135,11 +131,7 @@ draw_sprite :: proc(app: ^App, sprite: ^Sprite) {
|
||||
|
||||
tex_w := f32(sprite.data.width)
|
||||
tex_h := f32(sprite.data.height)
|
||||
u0 := f32(frame.rect[0]) / tex_w
|
||||
v0 := f32(frame.rect[1]) / tex_h
|
||||
u1 := f32(frame.rect[0] + frame.rect[2]) / tex_w
|
||||
v1 := f32(frame.rect[1] + frame.rect[3]) / tex_h
|
||||
if sprite.flip_x do u0, u1 = u1, u0
|
||||
u0, v0, u1, v1 := frame_uvs(frame.rect, tex_w, tex_h, sprite.flip_x)
|
||||
|
||||
verts := [SPRITE_VERT_COUNT]Vertex {
|
||||
{pos = p0, uv = {u0, v0}},
|
||||
@@ -170,6 +162,40 @@ sprite_quad_origin :: proc(position: Vec2, size: Vec2, pivot: [2]f32) -> Vec2 {
|
||||
return {position.x - size.x * pivot[0], position.y - size.y * pivot[1]}
|
||||
}
|
||||
|
||||
frame_uvs :: proc(rect: [4]int, tex_w, tex_h: f32, flip_x: bool) -> (u0, v0, u1, v1: f32) {
|
||||
u0 = f32(rect[0]) / tex_w
|
||||
v0 = f32(rect[1]) / tex_h
|
||||
u1 = f32(rect[0] + rect[2]) / tex_w
|
||||
v1 = f32(rect[1] + rect[3]) / tex_h
|
||||
if flip_x do u0, u1 = u1, u0
|
||||
return
|
||||
}
|
||||
|
||||
sprite_feet_quad :: proc(
|
||||
feet: Vec2,
|
||||
src_w, src_h: f32,
|
||||
trim: Vec2,
|
||||
size: Vec2,
|
||||
pivot: [2]f32,
|
||||
flip_x: bool,
|
||||
) -> (
|
||||
x0, y0, x1, y1: f32,
|
||||
) {
|
||||
canvas_top := feet.y - src_h * pivot[1]
|
||||
if flip_x {
|
||||
canvas_left := feet.x - (1.0 - pivot[0]) * src_w
|
||||
x0 = canvas_left + (src_w - trim.x - size.x)
|
||||
y0 = canvas_top + trim.y
|
||||
} else {
|
||||
canvas_left := feet.x - src_w * pivot[0]
|
||||
x0 = canvas_left + trim.x
|
||||
y0 = canvas_top + trim.y
|
||||
}
|
||||
x1 = x0 + size.x
|
||||
y1 = y0 + size.y
|
||||
return
|
||||
}
|
||||
|
||||
set_sprite_flip_x :: proc(sprite: ^Sprite, flip: bool) {
|
||||
if sprite == nil do return
|
||||
sprite.flip_x = flip
|
||||
|
||||
Reference in New Issue
Block a user