diff --git a/source/engine/sprite.c b/source/engine/sprite.c index 7bcb8c8..37a68c4 100644 --- a/source/engine/sprite.c +++ b/source/engine/sprite.c @@ -173,10 +173,11 @@ void tex_draw(struct Texture *tex, HMM_Vec2 pos, float angle, HMM_Vec2 size, HMM }; HMM_Mat2 rot = HMM_RotateM2(angle); - + HMM_Vec2 t_scale = { tex->width * st_s_w(r) * size.X, - tex->height * st_s_h(r) * size.Y}; + tex->height * st_s_h(r) * size.Y + }; for (int i = 0; i < 4; i++) { @@ -184,7 +185,7 @@ void tex_draw(struct Texture *tex, HMM_Vec2 pos, float angle, HMM_Vec2 size, HMM sposes[i] = HMM_MulV2(sposes[i], t_scale); sposes[i] = HMM_MulM2V2(rot, sposes[i]); sposes[i] = HMM_AddV2(sposes[i], pos); - verts[i].pos = sposes[0]; + verts[i].pos = sposes[i]; verts[i].color = color; } @@ -196,7 +197,7 @@ void tex_draw(struct Texture *tex, HMM_Vec2 pos, float angle, HMM_Vec2 size, HMM verts[2].uv.v = r.t0 * USHRT_MAX; verts[3].uv.u = r.s1 * USHRT_MAX; verts[3].uv.v = r.t0 * USHRT_MAX; - + bind_sprite.fs_images[0] = tex->id; sg_append_buffer(bind_sprite.vertex_buffers[0], SG_RANGE_REF(verts)); sg_apply_bindings(&bind_sprite); diff --git a/source/scripts/engine.js b/source/scripts/engine.js index 00b17ed..6d097f0 100644 --- a/source/scripts/engine.js +++ b/source/scripts/engine.js @@ -154,14 +154,17 @@ var GUI = { image(path,pos) { let wh = cmd(64,path); - gui_img(path,screen2world(pos)); - return cwh2bb([0,0], cmd(64,path)); + gui_img(path,pos.slice().sub(wh), 1.0, 0.0); + return cwh2bb([0,0], wh); }, - column(items,pos) { + column(items,pos, defn) { + defn ??= {}; + defn.padding ??= 5; items.forEach(function(item) { let bb = item(pos); pos.y += bb.b; + pos.y -= defn.padding*2; }); }, }; diff --git a/source/shaders/spritefrag.glsl b/source/shaders/spritefrag.glsl index a131395..0889d8e 100644 --- a/source/shaders/spritefrag.glsl +++ b/source/shaders/spritefrag.glsl @@ -1,12 +1,14 @@ #version 330 core in vec2 texcoords; +in vec4 fcolor; + out vec4 color; + uniform sampler2D image; -uniform vec3 spriteColor; void main() { - color = vec4(spriteColor, 1.f) * texture(image, texcoords); + color = fcolor * texture(image, texcoords); if (color.a <= 0.1f) discard; diff --git a/source/shaders/spritevert.glsl b/source/shaders/spritevert.glsl index 5427a8f..9c26de9 100644 --- a/source/shaders/spritevert.glsl +++ b/source/shaders/spritevert.glsl @@ -2,13 +2,15 @@ layout (location = 0) in vec2 vertex; layout (location = 1) in vec2 uv; layout (location = 2) in vec4 vColor; + out vec2 texcoords; +out vec4 fcolor; uniform mat4 proj; -uniform mat4 mpv; void main() { - texcoords = uv; - gl_Position = mpv * proj * vec4(vertex, 0.0, 1.0); + fcolor = vColor; + texcoords = uv; + gl_Position = proj * vec4(vertex, 0.0, 1.0); }