void sprite_drawquad(struct pack_picture *picture, const struct srt *srt, const struct sprite_trans *arg) { struct matrix tmp; struct vertex_pack vb[4]; int i,j; if (arg->mat == NULL) { matrix_identity(&tmp); } else { tmp = *arg->mat; } matrix_srt(&tmp, srt); int *m = tmp.m; for (i=0;i<picture->n;i++) { struct pack_quad *q = &picture->rect[i]; int glid = texture_glid(q->texid); if (glid == 0) continue; shader_texture(glid, 0); for (j=0;j<4;j++) { int xx = q->screen_coord[j*2+0]; int yy = q->screen_coord[j*2+1]; float vx = (xx * m[0] + yy * m[2]) / 1024 + m[4]; float vy = (xx * m[1] + yy * m[3]) / 1024 + m[5]; float tx = q->texture_coord[j*2+0]; float ty = q->texture_coord[j*2+1]; screen_trans(&vx,&vy); vb[j].vx = vx; vb[j].vy = vy; vb[j].tx = tx; vb[j].ty = ty; } shader_draw(vb, arg->color, arg->additive); } }
static void draw_quad(const struct vertex_pack *vbp, uint32_t color, uint32_t additive, int max, int index) { struct vertex_pack vb[4]; int i; vb[0] = vbp[0]; // first point for (i=1;i<4;i++) { int j = i + index; int n = (j <= max) ? j : max; vb[i] = vbp[n]; } shader_draw(vb, color, additive); }
/* int texture table float[16] uint32_t color uint32_t additive */ static int ldraw(lua_State *L) { int tex = (int)luaL_checkinteger(L,1); int texid = texture_glid(tex); if (texid == 0) { lua_pushboolean(L,0); return 1; } luaL_checktype(L, 2, LUA_TTABLE); uint32_t color = 0xffffffff; if (!lua_isnoneornil(L,3)) { color = (uint32_t)lua_tounsigned(L,3); } uint32_t additive = (uint32_t)luaL_optunsigned(L,4,0); shader_program(PROGRAM_PICTURE,additive); shader_texture(texid); int n = lua_rawlen(L, 2); int point = n/4; if (point * 4 != n) { return luaL_error(L, "Invalid polygon"); } #if !defined(_MSC_VER) float vb[n]; #else msvc::dynarray<float> vb(n); #endif int i; for (i=0;i<point;i++) { lua_rawgeti(L, 2, i*2+1); lua_rawgeti(L, 2, i*2+2); lua_rawgeti(L, 2, point*2+i*2+1); lua_rawgeti(L, 2, point*2+i*2+2); float tx = lua_tonumber(L, -4); float ty = lua_tonumber(L, -3); float vx = lua_tonumber(L, -2); float vy = lua_tonumber(L, -1); lua_pop(L,4); screen_trans(&vx,&vy); texture_coord(tex, &tx, &ty); vb[i*4+0] = vx + 1.0f; vb[i*4+1] = vy - 1.0f; vb[i*4+2] = tx; vb[i*4+3] = ty; } if (point == 4) { shader_draw(vb, color); } else { shader_drawpolygon(point, vb, color); } return 0; }
static void draw_rect(const struct dfont_rect *rect, int size, struct matrix *mat, uint32_t color) { float vb[16]; int w = (rect->w -1) * size / FONT_SIZE ; int h = (rect->h -1) * size / FONT_SIZE ; set_point(vb+0, mat->m, 0,0, rect->x, rect->y); set_point(vb+4, mat->m, w*SCREEN_SCALE,0, rect->x+rect->w-1, rect->y); set_point(vb+8, mat->m, w*SCREEN_SCALE,h*SCREEN_SCALE, rect->x+rect->w-1, rect->y+rect->h-1); set_point(vb+12, mat->m, 0,h*SCREEN_SCALE, rect->x, rect->y+rect->h-1); shader_draw(vb, color); }
static void draw_rect(const struct dfont_rect *rect, int size, struct matrix *mat, uint32_t color, uint32_t additive) { struct vertex_pack vb[4]; int w = (rect->w -1) * size / FONT_SIZE ; int h = (rect->h -1) * size / FONT_SIZE ; set_point(&vb[0], mat->m, 0,0, rect->x, rect->y); set_point(&vb[1], mat->m, w*SCREEN_SCALE,0, rect->x+rect->w-1, rect->y); set_point(&vb[2], mat->m, w*SCREEN_SCALE,h*SCREEN_SCALE, rect->x+rect->w-1, rect->y+rect->h-1); set_point(&vb[3], mat->m, 0,h*SCREEN_SCALE, rect->x, rect->y+rect->h-1); shader_draw(vb, color, additive); }
/* int texture table float[16] uint32_t color uint32_t additive */ static int ldraw(lua_State *L) { int tex = (int)luaL_checkinteger(L,1); int texid = texture_glid(tex); if (texid == 0) { lua_pushboolean(L,0); return 1; } luaL_checktype(L, 2, LUA_TTABLE); uint32_t color = 0xffffffff; if (!lua_isnoneornil(L,3)) { color = (uint32_t)lua_tounsigned(L,3); } uint32_t additive = (uint32_t)luaL_optunsigned(L,4,0); shader_program(PROGRAM_PICTURE); shader_texture(texid); int n = lua_rawlen(L, 2); int point = n/4; if (point * 4 != n) { return luaL_error(L, "Invalid polygon"); } ARRAY(struct vertex_pack, vb, point); int i; for (i=0;i<point;i++) { lua_rawgeti(L, 2, i*2+1); lua_rawgeti(L, 2, i*2+2); lua_rawgeti(L, 2, point*2+i*2+1); lua_rawgeti(L, 2, point*2+i*2+2); float tx = lua_tonumber(L, -4); float ty = lua_tonumber(L, -3); float vx = lua_tonumber(L, -2); float vy = lua_tonumber(L, -1); uint16_t u,v; lua_pop(L,4); screen_trans(&vx,&vy); texture_coord(tex, tx, ty, &u, &v); vb[i].vx = vx + 1.0f; vb[i].vy = vy - 1.0f; vb[i].tx = u; vb[i].ty = v; } if (point == 4) { shader_draw(vb, color, additive); } else { shader_drawpolygon(point, vb, color, additive); } return 0; }
void sprite_drawquad(struct pack_picture *picture, struct pack_picture *mask, const struct srt *srt, const struct sprite_trans *arg) { struct matrix tmp; float vb[16]; int i,j; if (arg->mat == NULL) { matrix_identity(&tmp); } else { tmp = *arg->mat; } matrix_srt(&tmp, srt); int *m = tmp.m; for (i=0;i<picture->n;i++) { struct pack_quad *q = &picture->rect[i]; int glid = texture_glid(q->texid); if (glid == 0) continue; shader_texture(glid); for (j=0;j<4;j++) { int xx = q->screen_coord[j*2+0]; int yy = q->screen_coord[j*2+1]; float vx = (xx * m[0] + yy * m[2]) / 1024 + m[4]; float vy = (xx * m[1] + yy * m[3]) / 1024 + m[5]; float tx = q->texture_coord[j*2+0]; float ty = q->texture_coord[j*2+1]; screen_trans(&vx,&vy); texture_coord(q->texid, &tx, &ty); vb[j*4+0] = vx; vb[j*4+1] = vy; vb[j*4+2] = tx; vb[j*4+3] = ty; } if(!enable_visible_test || !screen_is_poly_invisible(vb,4,4)) { if (mask != NULL) { float tx = mask->rect[0].texture_coord[0]; float ty = mask->rect[0].texture_coord[1]; texture_coord(mask->rect[0].texid, &tx, &ty); float delta_tx = tx - vb[2]; float delta_ty = ty - vb[3]; shader_mask(delta_tx, delta_ty); } shader_draw(vb, arg->color); } } }