// Render a vertex to Gecko (used by glEnd) void UploadVertex(int index){ GX_Position3f32( _vertexelements[index].x, _vertexelements[index].y, _vertexelements[index].z); GX_Normal3f32(_normalelements[index].x, _normalelements[index].y, _normalelements[index].z); //when using GL_FLAT only one color is allowed!!! //GL_SMOOTH allows for an color to be specified at each vertex GX_Color3f32( _colorelements[index].r, _colorelements[index].g, _colorelements[index].b); //glmaterialfv call instead when glcolormaterial call is used GX_TexCoord2f32(_texcoordelements[index].s,_texcoordelements[index].t); };
int BuildLists(GXTexObj texture) { // Make the new display list // For display lists, each command has an associated "cost" in bytes. // Add all these up to calculate the size of your display list before rounding up. // eke-eke says GX_Begin() costs 3 bytes (u8 + u16) // According to my research: // GX_Position3f32() is 12 bytes (f32*3) // GX_Normal3f32() is 12 bytes (f32*3) // GX_Color3f32() is actually 3 bytes ((f32 -> u8) * 3) // GX_TexCoord2f32() is 8 bytes (f32*2) // GX_End() seems to cost zero (there's no actual code in it) // Size -must- be multiple of 32, so (12*24) + (12*24) + (3*24) + (8*24) + 3 = 843 // Rounded up to the nearest 32 is 864. // NOTE: Actual size may be up to 63 bytes -larger- than you calculate it to be due to padding and cache alignment. for (int i=0; i<5;i++) { boxList[i] = memalign(32,896); memset(boxList[i],0,896); DCInvalidateRange(boxList[i],896); GX_BeginDispList(boxList[i],896); GX_Begin(GX_QUADS,GX_VTXFMT0,24); // Start drawing // Bottom face GX_Position3f32(-1.0f,-1.0f,-1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1); GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(1.0f,1.0f); // Top right GX_Position3f32( 1.0f,-1.0f,-1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1); GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(0.0f,1.0f); // Top left GX_Position3f32( 1.0f,-1.0f, 1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1); GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(0.0f,0.0f); // Bottom left GX_Position3f32(-1.0f,-1.0f, 1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1); GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(1.0f,0.0f); // Bottom right // Front face GX_Position3f32(-1.0f,-1.0f, 1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1); GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(0.0f,0.0f); // Bottom left GX_Position3f32( 1.0f,-1.0f, 1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1); GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(1.0f,0.0f); // Bottom right GX_Position3f32( 1.0f, 1.0f, 1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1); GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(1.0f,1.0f); // Top right GX_Position3f32(-1.0f, 1.0f, 1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1); GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(0.0f,1.0f); // Top left // Back face GX_Position3f32(-1.0f,-1.0f,-1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1); GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(1.0f,0.0f); // Bottom right GX_Position3f32(-1.0f, 1.0f,-1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1); GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(1.0f,1.0f); // Top right GX_Position3f32( 1.0f, 1.0f,-1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1); GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(0.0f,1.0f); // Top left GX_Position3f32( 1.0f,-1.0f,-1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1); GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(0.0f,0.0f); // Bottom left // Right face GX_Position3f32( 1.0f,-1.0f,-1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1); GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(1.0f,0.0f); // Bottom right GX_Position3f32( 1.0f, 1.0f,-1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1); GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(1.0f,1.0f); // Top right GX_Position3f32( 1.0f, 1.0f, 1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1); GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(0.0f,1.0f); // Top left GX_Position3f32( 1.0f,-1.0f, 1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1); GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(0.0f,0.0f); // Bottom left // Left face GX_Position3f32(-1.0f,-1.0f,-1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1); GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(0.0f,0.0f); // Bottom right GX_Position3f32(-1.0f,-1.0f, 1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1); GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(1.0f,0.0f); // Top right GX_Position3f32(-1.0f, 1.0f, 1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1); GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(1.0f,1.0f); // Top left GX_Position3f32(-1.0f, 1.0f,-1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1); GX_Color3f32(BoxColors[i][0],BoxColors[i][1],BoxColors[i][2]); GX_TexCoord2f32(0.0f,1.0f); // Bottom left // Top face GX_Position3f32(-1.0f, 1.0f,-1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1); GX_Color3f32(TopColors[i][0],TopColors[i][1],TopColors[i][2]); GX_TexCoord2f32(0.0f,1.0f); // Top left GX_Position3f32(-1.0f, 1.0f, 1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1); GX_Color3f32(TopColors[i][0],TopColors[i][1],TopColors[i][2]); GX_TexCoord2f32(0.0f,0.0f); // Bottom left GX_Position3f32( 1.0f, 1.0f, 1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1); GX_Color3f32(TopColors[i][0],TopColors[i][1],TopColors[i][2]); GX_TexCoord2f32(1.0f,0.0f); // Bottom rught GX_Position3f32( 1.0f, 1.0f,-1.0f); GX_Normal3f32((f32)0,(f32)0,(f32)1); GX_Color3f32(TopColors[i][0],TopColors[i][1],TopColors[i][2]); GX_TexCoord2f32(1.0f,1.0f); // Top right GX_End(); // Done drawing quads // GX_EndDispList() returns the size of the display list, so store that value and use it with GX_CallDispList(). boxSize[i] = GX_EndDispList(); // Done building the box list if (boxSize[i] == 0) return 1; } // setup texture coordinate generation // args: texcoord slot 0-7, matrix type, source to generate texture coordinates from, matrix to use GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY); // Set up TEV to paint the textures properly. GX_SetTevOp(GX_TEVSTAGE0,GX_MODULATE); GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); // Load up the textures (just one this time). GX_LoadTexObj(&texture, GX_TEXMAP0); return 0; }
MF_API void MFSetNormal(float x, float y, float z) { GX_Normal3f32(x, y, z); }
// Perform the actual scene drawing. void DrawScene(Mtx v, GXTexObj texture) { // Draw things // FIXME: Need to clear first? // FIXME: Check datatype sizes f32 x_m,y_m,z_m,u_m,v_m; // Float types for temp x, y, z, u and v vertices f32 xtrans = -xpos; // Used for player translation on the x axis f32 ztrans = -zpos; // Used for player translation on the z axis f32 ytrans = -walkbias-0.25f; // Used for bouncing motion up and down f32 sceneroty = 360.0f - yrot; // 360 degree angle for player direction int numtriangles; // Integer to hold the number of triangles Mtx m; // Model matrix Mtx mt; // Model rotated matrix Mtx mv; // Modelview matrix guVector axis; // Vector for axis we're rotating on SetLight(v,LightColors[0],LightColors[1],LightColors[2]); // Set up TEV to paint the textures properly. GX_SetTevOp(GX_TEVSTAGE0,GX_MODULATE); GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); // Load up the textures (just one this time). GX_LoadTexObj(&texture, GX_TEXMAP0); //glRotatef(lookupdown,1.0f,0,0); axis.x = 1.0f; axis.y = 0; axis.z = 0; guMtxIdentity(m); guMtxRotAxisDeg(m, &axis, lookupdown); guMtxConcat(m,v,mv); //glrotatef(sceneroty,0,1.0f,0); axis.x = 0; axis.y = 1.0f; axis.z = 0; guMtxIdentity(m); guMtxRotAxisDeg(m, &axis, sceneroty); guMtxConcat(mv,m,mv); // Translate the camera view guMtxApplyTrans(mv,mt,xtrans,ytrans,ztrans); //glTranslatef(xtrans,ytrans,ztrans); //guMtxIdentity(m); //guMtxTrans(m, xtrans, ytrans, ztrans); //guMtxConcat(v,m,v); // load the modelview matrix into matrix memory GX_LoadPosMtxImm(mt, GX_PNMTX0); numtriangles = sector1.numtriangles; // HACK: v tex coord is inverted so textures are rightside up. for (int loop_m = 0; loop_m < numtriangles; loop_m++) { GX_Begin(GX_TRIANGLES,GX_VTXFMT0,3); x_m = sector1.triangle[loop_m].vertex[0].x; y_m = sector1.triangle[loop_m].vertex[0].y; z_m = sector1.triangle[loop_m].vertex[0].z; u_m = sector1.triangle[loop_m].vertex[0].u; v_m = sector1.triangle[loop_m].vertex[0].v; GX_Position3f32(x_m,y_m,z_m); GX_Normal3f32((f32)0,(f32)0,(f32)1); //GX_Color3f32(0.7f,0.7f,0.7f); GX_TexCoord2f32(u_m,-v_m); x_m = sector1.triangle[loop_m].vertex[1].x; y_m = sector1.triangle[loop_m].vertex[1].y; z_m = sector1.triangle[loop_m].vertex[1].z; u_m = sector1.triangle[loop_m].vertex[1].u; v_m = sector1.triangle[loop_m].vertex[1].v; GX_Position3f32(x_m,y_m,z_m); GX_Normal3f32((f32)0,(f32)0,(f32)1); //GX_Color3f32(0.7f,0.7f,0.7f); GX_TexCoord2f32(u_m,-v_m); x_m = sector1.triangle[loop_m].vertex[2].x; y_m = sector1.triangle[loop_m].vertex[2].y; z_m = sector1.triangle[loop_m].vertex[2].z; u_m = sector1.triangle[loop_m].vertex[2].u; v_m = sector1.triangle[loop_m].vertex[2].v; GX_Position3f32(x_m,y_m,z_m); GX_Normal3f32((f32)0,(f32)0,(f32)1); //GX_Color3f32(0.7f,0.7f,0.7f); GX_TexCoord2f32(u_m,-v_m); GX_End(); } return; }