This commit is contained in:
John Alanbrook 2023-05-31 22:33:04 +00:00
parent 5d7b7880ef
commit 33a56e4dc5
4 changed files with 20 additions and 12 deletions

View file

@ -176,7 +176,8 @@ void tex_draw(struct Texture *tex, HMM_Vec2 pos, float angle, HMM_Vec2 size, HMM
HMM_Vec2 t_scale = { HMM_Vec2 t_scale = {
tex->width * st_s_w(r) * size.X, 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++) { 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_MulV2(sposes[i], t_scale);
sposes[i] = HMM_MulM2V2(rot, sposes[i]); sposes[i] = HMM_MulM2V2(rot, sposes[i]);
sposes[i] = HMM_AddV2(sposes[i], pos); sposes[i] = HMM_AddV2(sposes[i], pos);
verts[i].pos = sposes[0]; verts[i].pos = sposes[i];
verts[i].color = color; verts[i].color = color;
} }

View file

@ -154,14 +154,17 @@ var GUI = {
image(path,pos) { image(path,pos) {
let wh = cmd(64,path); let wh = cmd(64,path);
gui_img(path,screen2world(pos)); gui_img(path,pos.slice().sub(wh), 1.0, 0.0);
return cwh2bb([0,0], cmd(64,path)); return cwh2bb([0,0], wh);
}, },
column(items,pos) { column(items,pos, defn) {
defn ??= {};
defn.padding ??= 5;
items.forEach(function(item) { items.forEach(function(item) {
let bb = item(pos); let bb = item(pos);
pos.y += bb.b; pos.y += bb.b;
pos.y -= defn.padding*2;
}); });
}, },
}; };

View file

@ -1,12 +1,14 @@
#version 330 core #version 330 core
in vec2 texcoords; in vec2 texcoords;
in vec4 fcolor;
out vec4 color; out vec4 color;
uniform sampler2D image; uniform sampler2D image;
uniform vec3 spriteColor;
void main() void main()
{ {
color = vec4(spriteColor, 1.f) * texture(image, texcoords); color = fcolor * texture(image, texcoords);
if (color.a <= 0.1f) if (color.a <= 0.1f)
discard; discard;

View file

@ -2,13 +2,15 @@
layout (location = 0) in vec2 vertex; layout (location = 0) in vec2 vertex;
layout (location = 1) in vec2 uv; layout (location = 1) in vec2 uv;
layout (location = 2) in vec4 vColor; layout (location = 2) in vec4 vColor;
out vec2 texcoords; out vec2 texcoords;
out vec4 fcolor;
uniform mat4 proj; uniform mat4 proj;
uniform mat4 mpv;
void main() void main()
{ {
texcoords = uv; fcolor = vColor;
gl_Position = mpv * proj * vec4(vertex, 0.0, 1.0); texcoords = uv;
gl_Position = proj * vec4(vertex, 0.0, 1.0);
} }