Exemple #1
0
/*
	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;
}
Exemple #2
0
/*
	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;
}
Exemple #3
0
void
sprite_drawpolygon(struct pack_polygon *poly, const struct srt *srt, const struct sprite_trans *arg) {
	struct matrix tmp;
	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<poly->n;i++) {
		struct pack_poly *p = &poly->poly[i];
		int glid = texture_glid(p->texid);
		if (glid == 0)
			continue;
		shader_texture(glid);
		int pn = p->n;

		ARRAY(float, vb, 4 * pn);

		for (j=0;j<pn;j++) {
			int xx = p->screen_coord[j*2+0];
			int yy = p->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 = p->texture_coord[j*2+0];
			float ty = p->texture_coord[j*2+1];

			screen_trans(&vx,&vy);
	
			texture_coord(p->texid, &tx, &ty);
			vb[j*4+0] = vx;
			vb[j*4+1] = vy;
			vb[j*4+2] = tx;
			vb[j*4+3] = ty;
		}
		shader_drawpolygon(pn, vb, arg->color);
	}
}