forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

lua_sceGumDrawArray & normals ?...

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
PiLX



Joined: 19 Feb 2007
Posts: 1

PostPosted: Sun Mar 11, 2007 11:34 am    Post subject: lua_sceGumDrawArray & normals ?... Reply with quote

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

ANY help would be greatly appreciated...

Code:
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 (i = 1; i <= n; ++i) {
      // get vertice table
      lua_rawgeti(L, 3, i);
      int n2 = luaL_getn(L, -1);
      if (n2 != quads) {
         free(vertices);
         return luaL_error(L, "wrong number of vertex components");
      }
      int j;
      for (j = 1; j <= n2; ++j) {
         lua_rawgeti(L, -1, j);
         if (j != colorLuaIndex) {
            *vertex = luaL_checknumber(L, -1);
         } else {
            *((Color*) vertex) = *toColor(L, -1);
         }
         lua_pop(L, 1);  // removes 'value'
         vertex++;
      }

      // remove vertice table
      lua_pop(L, 1);
   }
   
   sceKernelDcacheWritebackInvalidateAll();
   sceGumDrawArray(prim, vtype, n, NULL, vertices);
   free(vertices);
   return 0;
}


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....
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group