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

@ -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);

View file

@ -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;
});
},
};

View file

@ -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;

View file

@ -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);
}