void gdl::Font::DrawText(const char *text, short x, short y, float scale, u_int col) { float tx; GXColor textCol; Mtx tempMatrix; if (vList == NULL) return; if (tList == NULL) return; if ((x == gdl::Centered) || (x == gdl::PCentered)) { tx = gdl::ScreenCenterX-((gdl::Font::CalcStrLen(text)*scale)/2)+(scale/2); } else { tx = x; } textCol.r = RED(col); textCol.g = GREEN(col); textCol.b = BLUE(col); textCol.a = ALPHA(col); GX_LoadTexObj(gdl::Font::charSheet.TexObj(), GX_TEXMAP0); GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE); GX_ClearVtxDesc(); GX_SetVtxDesc(GX_VA_POS, GX_INDEX16); GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX16); GX_SetArray(GX_VA_POS, gdl::Font::vList, 2*sizeof(s16)); GX_SetArray(GX_VA_TEX0, gdl::Font::tList, 2*sizeof(f32)); GX_SetChanCtrl(GX_COLOR0A0, GX_DISABLE, GX_SRC_VTX, GX_SRC_REG, 0, GX_DF_NONE, GX_AF_NONE); GX_SetChanMatColor(GX_COLOR0A0, textCol); guMtxCopy(gdl::wii::ModelMtx, tempMatrix); guMtxApplyTrans(tempMatrix, tempMatrix, tx, y, 0); guMtxApplyScale(tempMatrix, tempMatrix, scale, scale, 0); GX_LoadPosMtxImm(tempMatrix, GX_PNMTX0); for(int i=0; text[i]!=0x00; i++) { int tc=4*((u_char)text[i]); GX_Begin(GX_QUADS, GX_VTXFMT0, 4); GX_Position1x16(tc); GX_TexCoord1x16(tc); GX_Position1x16(tc+1); GX_TexCoord1x16(tc+1); GX_Position1x16(tc+2); GX_TexCoord1x16(tc+2); GX_Position1x16(tc+3); GX_TexCoord1x16(tc+3); GX_End(); guMtxApplyTrans(tempMatrix, tempMatrix, gdl::Font::charWidth[(u_char)text[i]], 0, 0); GX_LoadPosMtxImm(tempMatrix, GX_PNMTX0); } GX_LoadPosMtxImm(gdl::wii::ModelMtx, GX_PNMTX0); GX_SetChanCtrl(GX_COLOR0A0, GX_DISABLE, GX_SRC_VTX, GX_SRC_VTX, 0, GX_DF_NONE, GX_AF_NONE); }
// 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; }
void gdl::FFont::DrawText(const char *text, short x, short y, float scale, u32 col) { // Draws text using the current font set by gdl_SetCurrentFont() float tx; int c,tc; Mtx TempMatrix; GXColor TempCol; if (vList == NULL) return; if ((x == gdl::Centered) || (x == gdl::PCentered)) { tx = gdl::ScreenCenterX - ((((cw+1)*strlen(text))*scale)/2)+(scale/2); } else { tx = x; } TempCol.r = RED(col); TempCol.g = GREEN(col); TempCol.b = BLUE(col); TempCol.a = ALPHA(col); GX_LoadTexObj(charTexObj, GX_TEXMAP0); GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE); GX_ClearVtxDesc(); GX_SetVtxDesc(GX_VA_POS, GX_INDEX8); GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX16); GX_SetArray(GX_VA_POS, vList, 2*sizeof(s16)); GX_SetArray(GX_VA_TEX0, tList, 2*sizeof(f32)); guMtxCopy(gdl::wii::ModelMtx, TempMatrix); guMtxApplyTrans(TempMatrix, TempMatrix, tx, y, 0); guMtxApplyScale(TempMatrix, TempMatrix, scale, scale, 0); GX_LoadPosMtxImm(TempMatrix, GX_PNMTX0); GX_SetChanCtrl(GX_COLOR0A0, GX_DISABLE, GX_SRC_VTX, GX_SRC_REG, 0, GX_DF_NONE, GX_AF_NONE); GX_SetChanMatColor(GX_COLOR0A0, TempCol); for(c=0; text[c] != 0x00; c++) { tc = 4*((u_char*)text)[c]; GX_Begin(GX_QUADS, GX_VTXFMT0, 4); GX_Position1x8(0); GX_TexCoord1x16(tc); GX_Position1x8(1); GX_TexCoord1x16(tc+1); GX_Position1x8(2); GX_TexCoord1x16(tc+2); GX_Position1x8(3); GX_TexCoord1x16(tc+3); GX_End(); guMtxApplyTrans(TempMatrix, TempMatrix, cw+1, 0, 0); GX_LoadPosMtxImm(TempMatrix, GX_PNMTX0); } GX_LoadPosMtxImm(gdl::wii::ModelMtx, GX_PNMTX0); GX_SetChanCtrl(GX_COLOR0A0, GX_DISABLE, GX_SRC_VTX, GX_SRC_VTX, 0, GX_DF_NONE, GX_AF_NONE); }