tiling sprites; line drawing
This commit is contained in:
parent
beee0c50f3
commit
5df1670538
|
@ -104,8 +104,8 @@ component.sprite.impl = {
|
|||
set angle(x) { cmd(218,this.id,x); },
|
||||
get scale() { return cmd(215, this.id); },
|
||||
set scale(x) { cmd(216, this.id, x); },
|
||||
set layer(x) { cmd(60, this.id, x); },
|
||||
get layer() { return undefined; },
|
||||
get drawmode() { return cmd(220,this.id); },
|
||||
set drawmode(x) { cmd(219,this.id,x); },
|
||||
emissive(x) { cmd(170, this.id, x); },
|
||||
pickm() { return this; },
|
||||
move(d) { this.pos = this.pos.add(d); },
|
||||
|
|
|
@ -44,6 +44,12 @@ var Shape = {
|
|||
},
|
||||
|
||||
poly(points, color) { cmd_points(0,points,color); },
|
||||
|
||||
rectangle(lowerleft, upperright, color) {
|
||||
var pos = lowerleft.add(upperright).map(x=>x/2);
|
||||
var wh = [upperright.x-lowerleft.x,upperright.y-lowerleft.y];
|
||||
Shape.box(pos,wh,color);
|
||||
},
|
||||
|
||||
box(pos, wh, color) {
|
||||
color ??= Color.white;
|
||||
|
|
|
@ -768,8 +768,6 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
|||
break;
|
||||
|
||||
case 60:
|
||||
if (!id2sprite(js2int(argv[1]))) break;
|
||||
id2sprite(js2int(argv[1]))->layer = js2int(argv[2]);
|
||||
break;
|
||||
|
||||
case 61:
|
||||
|
@ -1366,6 +1364,12 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
|||
case 218:
|
||||
js2sprite(argv[1])->t.angle = js2number(argv[2]);
|
||||
break;
|
||||
case 219:
|
||||
js2sprite(argv[1])->drawmode = js2number(argv[2]);
|
||||
break;
|
||||
case 220:
|
||||
ret = num2js(js2sprite(argv[1])->drawmode);
|
||||
break;
|
||||
}
|
||||
|
||||
if (str)
|
||||
|
|
|
@ -58,9 +58,10 @@ int make_sprite(gameobject *go) {
|
|||
.emissive = {0,0,0,0},
|
||||
.tex = texture_pullfromfile(NULL),
|
||||
.go = go,
|
||||
.layer = 0,
|
||||
.next = -1,
|
||||
.enabled = 1};
|
||||
.enabled = 1,
|
||||
.drawmode = DRAW_SIMPLE
|
||||
};
|
||||
int id;
|
||||
freelist_grab(id, sprites);
|
||||
sprites[id] = sprite;
|
||||
|
@ -182,7 +183,7 @@ void sprite_initialize() {
|
|||
});
|
||||
}
|
||||
|
||||
void tex_draw(struct Texture *tex, HMM_Mat3 m, struct glrect r, struct rgba color, int wrap, HMM_Vec2 wrapoffset, float wrapscale, struct rgba emissive) {
|
||||
void tex_draw(struct Texture *tex, HMM_Mat3 m, struct glrect r, struct rgba color, int wrap, HMM_Vec2 wrapoffset, HMM_Vec2 wrapscale, struct rgba emissive) {
|
||||
struct sprite_vert verts[4];
|
||||
float w = tex->width*st_s_w(r);
|
||||
float h = tex->height*st_s_h(r);
|
||||
|
@ -200,6 +201,11 @@ void tex_draw(struct Texture *tex, HMM_Mat3 m, struct glrect r, struct rgba colo
|
|||
verts[i].emissive = emissive;
|
||||
}
|
||||
|
||||
if (wrap) {
|
||||
r.s1 *= wrapscale.x;
|
||||
r.t1 *= wrapscale.y;
|
||||
}
|
||||
|
||||
verts[0].uv.X = r.s0;
|
||||
verts[0].uv.Y = r.t1;
|
||||
verts[1].uv.X = r.s1;
|
||||
|
@ -223,14 +229,14 @@ void sprite_draw(struct sprite *sprite) {
|
|||
HMM_Mat3 m = t_go2world(sprite->go);
|
||||
HMM_Mat3 sm = transform2d2mat(sprite->t);
|
||||
|
||||
tex_draw(sprite->tex, HMM_MulM3(m, sm), sprite->frame, sprite->color, 0, (HMM_Vec2){0,0}, 0, sprite->emissive);
|
||||
tex_draw(sprite->tex, HMM_MulM3(m, sm), sprite->frame, sprite->color, sprite->drawmode, (HMM_Vec2){0,0}, sprite->t.scale, sprite->emissive);
|
||||
}
|
||||
|
||||
void gui_draw_img(const char *img, transform2d t, int wrap, HMM_Vec2 wrapoffset, float wrapscale, struct rgba color) {
|
||||
sg_apply_pipeline(pip_sprite);
|
||||
sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, SG_RANGE_REF(hudproj));
|
||||
struct Texture *tex = texture_pullfromfile(img);
|
||||
tex_draw(tex, transform2d2mat(t), tex_get_rect(tex), color, wrap, wrapoffset, wrapscale, (struct rgba){0,0,0,0});
|
||||
tex_draw(tex, transform2d2mat(t), tex_get_rect(tex), color, wrap, wrapoffset, (HMM_Vec2){wrapscale,wrapscale}, (struct rgba){0,0,0,0});
|
||||
}
|
||||
|
||||
void slice9_draw(const char *img, HMM_Vec2 pos, HMM_Vec2 dimensions, struct rgba color)
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
#include "transform.h"
|
||||
#include "gameobject.h"
|
||||
|
||||
#define DRAW_SIMPLE 0
|
||||
#define DRAW_TILE 1
|
||||
|
||||
struct sprite {
|
||||
transform2d t;
|
||||
struct rgba color;
|
||||
|
@ -15,8 +18,8 @@ struct sprite {
|
|||
struct Texture *tex;
|
||||
struct glrect frame;
|
||||
int enabled;
|
||||
int layer;
|
||||
int next;
|
||||
int drawmode;
|
||||
};
|
||||
|
||||
int make_sprite(gameobject *go);
|
||||
|
|
|
@ -31,10 +31,6 @@ uniform sampler smp;
|
|||
void main()
|
||||
{
|
||||
color = texture(sampler2D(image,smp), texcoords);
|
||||
|
||||
if (color.a <= 0.1f)
|
||||
discard;
|
||||
|
||||
color *= fcolor;
|
||||
color.xyz = mix(color.xyz, femissive.xyz, femissive.a);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue