lua_sceGumDrawArray & normals ?...

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
PiLX
Posts: 1
Joined: Mon Feb 19, 2007 4:58 am

lua_sceGumDrawArray & normals ?...

Post by PiLX »

i need normals (for lighting) .....and im totally lost .. how can i mod this to use normals... ?

ANY help would be greatly appreciated...

Code: Select all

static int lua_sceGumDrawArray(lua_State *L) {
	int argc = lua_gettop(L);
	if (argc != 3) return luaL_error(L, "wrong number of arguments");

	int prim = luaL_checkint(L, 1);
	int vtype = luaL_checkint(L, 2);
	if (lua_type(L, 3) != LUA_TTABLE) return luaL_error(L, "vertices table missing");
	int n = luaL_getn(L, 3);

	int quads = 0;
	int colorLuaIndex = -1;
	if (vtype & GU_TEXTURE_32BITF) quads += 2;
	if (vtype & GU_COLOR_8888) {
		quads++;
		colorLuaIndex = quads;
	}
	if (vtype & GU_NORMAL_32BITF) quads += 3;
	if (vtype & GU_VERTEX_32BITF) quads += 3;

	void* vertices = memalign(16, n * quads*4);
	float* vertex = (float*) vertices;
	int i;
	for &#40;i = 1; i <= n; ++i&#41; &#123;
		// get vertice table
		lua_rawgeti&#40;L, 3, i&#41;;
		int n2 = luaL_getn&#40;L, -1&#41;;
		if &#40;n2 != quads&#41; &#123;
			free&#40;vertices&#41;;
			return luaL_error&#40;L, "wrong number of vertex components"&#41;;
		&#125;
		int j;
		for &#40;j = 1; j <= n2; ++j&#41; &#123;
			lua_rawgeti&#40;L, -1, j&#41;;
			if &#40;j != colorLuaIndex&#41; &#123;
				*vertex = luaL_checknumber&#40;L, -1&#41;;
			&#125; else &#123;
				*&#40;&#40;Color*&#41; vertex&#41; = *toColor&#40;L, -1&#41;;
			&#125;
			lua_pop&#40;L, 1&#41;;  // removes 'value'
			vertex++;
		&#125;

		// remove vertice table
		lua_pop&#40;L, 1&#41;;
	&#125;
	
	sceKernelDcacheWritebackInvalidateAll&#40;&#41;;
	sceGumDrawArray&#40;prim, vtype, n, NULL, vertices&#41;;
	free&#40;vertices&#41;;
	return 0;
&#125;
EDIT: when i use the light functions..everything in my scene disappears..so thats why i figured it was a problem within the drawarray function....
Post Reply