[CHG] TTF example is more complete

[BUG] In the 3D test branch the model could be draw with color and texture (order is: position / normal / color / texture)
[CHG] In the 3D test branch the example is now using lights
This commit is contained in:
Crayon2000 2010-01-06 04:56:37 +00:00
parent 25876beeb9
commit 42d7917d0d
2 changed files with 42 additions and 19 deletions

View file

@ -92,17 +92,17 @@ void GRRLIB_3dMode(f32 minDist, f32 maxDist, f32 fov, bool colormode, bool textu
GX_ClearVtxDesc();
GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
if(normalmode==TRUE) GX_SetVtxDesc(GX_VA_NRM, GX_DIRECT);
if(colormode==TRUE) GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
if(texturemode==TRUE) GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
if(normalmode) GX_SetVtxDesc(GX_VA_NRM, GX_DIRECT);
if(colormode) GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
if(texturemode) GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
if(normalmode==TRUE) GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_NRM, GX_NRM_XYZ, GX_F32, 0);
if(colormode==TRUE) GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
if(texturemode==TRUE ) GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
if(normalmode) GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_NRM, GX_NRM_XYZ, GX_F32, 0);
if(colormode) GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
if(texturemode) GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
if(texturemode==FALSE) GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
else GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
if(texturemode) GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
else GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
}
/**
@ -206,7 +206,7 @@ void GRRLIB_InitLight(u8 id, guVector lpos, u32 lcol) {
GXLightObj MyLight;
guVecMultiply(_GRR_view, &lpos, &lpos);
GX_InitLightPos(&MyLight, lpos.x, lpos.y, lpos.z);
GX_InitLightColor(&MyLight, (GXColor) { R(lcol), G(lcol),B(lcol), A(lcol) });
GX_InitLightColor(&MyLight, (GXColor) { R(lcol), G(lcol), B(lcol), A(lcol) });
GX_InitLightAttn(&MyLight, 1.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F);
GX_LoadLightObj(&MyLight, id);
}

View file

@ -9,23 +9,45 @@
// Font
#include "FreeMonoBold_ttf.h"
extern GXRModeObj *rmode;
int main(int argc, char **argv) {
// Initialise the Graphics & Video subsystem
GRRLIB_Init();
GRRLIB_ttfFont *myFont = GRRLIB_LoadTTF(FreeMonoBold_ttf, FreeMonoBold_ttf_size);
GRRLIB_texImg *CopiedImg = GRRLIB_CreateEmptyTexture(rmode->fbWidth, rmode->efbHeight);
// Initialise the Wii Remotes
WPAD_Init();
// Load the font from memory
GRRLIB_ttfFont *myFont = GRRLIB_LoadTTF(FreeMonoBold_ttf, FreeMonoBold_ttf_size);
// Create an empty texture to store a copy of the screen
GRRLIB_texImg *CopiedImg = GRRLIB_CreateEmptyTexture(rmode->fbWidth, rmode->efbHeight);
// Fill a table with characters
u32 i, n = 0;
wchar_t charTable[450];
for(i=33; i<=126; i++) { // 0 to 93
charTable[n++] = i;
}
for(i=161; i<=516; i++) { // 94 to 449
charTable[n++] = i;
}
// Seed the random-number generator with current time so that
// the numbers will be different every time we run.
srand(time(NULL));
wchar_t Letter[2] = L""; // A character + terminal NULL
// To have a cool effect anti-aliasing is turned on
GRRLIB_Settings.antialias = true;
// Black background
GRRLIB_SetBackgroundColour(0x00, 0x00, 0x00, 0xFF);
// Loop forever
while(1) {
GRRLIB_DrawImg(0, 0, CopiedImg, 0, 1, 1, 0xFFFFFFFF);
char Letter[2] = {rand() % 93 + 32, '\0'};
GRRLIB_PrintfTTF(rand() % rmode->fbWidth - 50,
Letter[0] = charTable[rand() % 449];
GRRLIB_PrintfTTFW(rand() % rmode->fbWidth - 50,
rand() % rmode->efbHeight - 50,
myFont,
Letter,
@ -37,19 +59,20 @@ int main(int argc, char **argv) {
WPAD_ScanPads(); // Scan the Wii Remotes
if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME)
if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) {
break;
}
if (WPAD_ButtonsDown(0) & WPAD_BUTTON_A) {
GRRLIB_Rectangle(0, 0, rmode->fbWidth, rmode->efbHeight, 0x000000FF, 1);
GRRLIB_Screen2Texture(0, 0, CopiedImg, false);
}
if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_1 && WPAD_ButtonsHeld(0) & WPAD_BUTTON_2) {
WPAD_Rumble(0, true); // Rumble on
GRRLIB_ScrShot("sd:/grrlib_ttf.png");
GRRLIB_ScrShot("sd:/grrlib_ttf.png"); // Needs to be after GRRLIB_Render()
WPAD_Rumble(0, false); // Rumble off
}
}
GRRLIB_FreeTexture(CopiedImg);
GRRLIB_FreeTTF(myFont);
GRRLIB_Exit(); // Be a good boy, clear the memory allocated by GRRLIB