[SOLVED] Need help with simple lighting on 3D models December 11, 2014 02:27PM | Registered: 10 years ago Posts: 45 |
Re: Need help with simple lighting on 3D models December 14, 2014 01:51AM | Registered: 13 years ago Posts: 363 |
#define DISPLAYLIST_MEMORY 10000 //it will crash if this value is not high enough to hold the list void *displaylist; //need one for each list u32 displaylist_ret; //need one for each list function draw_model() { engine_3dn(); GRRLIB_ObjectView( pos.x, pos.y, pos.z , 0,0,0, size_half, size_half, size_half ); if( displaylist_ret != -1 ) { GX_CallDispList( displaylist, displaylist_ret); return; //exit now, no need to do the rest }// Draw the box displaylist = memalign(32,DISPLAYLIST_MEMORY ); DCInvalidateRange( displaylist, DISPLAYLIST_MEMORY); GX_BeginDispList( displaylist, DISPLAYLIST_MEMORY ); GX_Begin(GX_QUADS, GX_VTXFMT0, quads); //draw my stuff GX_End(); displaylist_ret = GX_EndDispList(); // Done building the box list if( displaylist_ret == 0 ) { } //error occurred ran out of memory or something }
Re: Need help with simple lighting on 3D models December 14, 2014 04:24PM | Moderator Registered: 15 years ago Posts: 686 |
Re: Need help with simple lighting on 3D models December 15, 2014 09:22AM | Registered: 10 years ago Posts: 45 |
// My model matrix Mtx modelMtx; -- Prepare model matrix... (guMtxIdentity, etc) -- -- Apply camera rotations to modelMtx -- // Apply matrix to GP as normal matrix GX_LoadNrmMtxImm(modelMtx, GX_PNMTX0); -- Apply camera translations to modelMtx and then set it to GP (GX_LoadPosMtxImm) -- // Enable spot lighting to color channel 0 (to apply more than 1 light source, you can OR multiple GX_LIGHT?'s together) GX_SetChanCtrl(GX_COLOR0A0, GX_ENABLE, GX_SRC_REG, GX_SRC_VTX, GX_LIGHT0, GX_DF_CLAMP, GX_AF_SPOT); // Set ambient color GX_SetChanAmbColor(GX_COLOR0A0, (GXColor) { 127, 127, 127, 0xFF}); // Now set the light source for our models to be rendered GXLightObj light; guVector lpos = { -100, 100, 100 }; // Light position (in x,y,z) // Prepare light object and then set it to the GP in GX_LIGHT0 slot guVecMultiply(modelMtx, &lpos, &lpos); GX_InitLightPos(&light, lpos.x, lpos.y, lpos.z); GX_InitLightColor(&light, (GXColor) { 255, 255, 255, 0xFF }); GX_InitLightSpot(&light, 0.0f, GX_SP_OFF); GX_InitLightDistAttn(&light, 20.0f, 1.0f, GX_DA_MEDIUM); // DistAttn = 20.0 & Brightness=1.0f (full) GX_LoadLightObj(&light, GX_LIGHT0); -- Render models (must contain normals) --
Re: Need help with simple lighting on 3D models December 15, 2014 02:03PM | Registered: 13 years ago Posts: 363 |
Re: Need help with simple lighting on 3D models December 15, 2014 04:03PM | Registered: 10 years ago Posts: 45 |
listSize = GX_EndDispList(); realloc(dispList, listSize);No need to reflush/invalidate the display list since realloc won't relocate your memory block nor does it modify it's contents when reducing it's size.
Re: Need help with simple lighting on 3D models December 15, 2014 04:36PM | Registered: 13 years ago Posts: 363 |
Re: [SOLVED] Need help with simple lighting on 3D models December 16, 2014 03:34PM | Moderator Registered: 15 years ago Posts: 686 |