You are not logged in.

  • Index
  •  » General Help
  •  » Problem while using TTF font and drawing a textured 3D Cube

#1 2010-04-05 06:09:44

goofster1020
Member

Problem while using TTF font and drawing a textured 3D Cube

My problem is when I try to use TTF font to display text on the screent using GRRLIB_PrintfTTF() and setting a texture to a cube and displaying this cube and the font at the same time. When I put the font displaying code before the cube drawing code, I get just a black cube (visible only because I have a background image displaying). When I put the font displaying code after the cube drawing code, I get a transparent black cube. My problem is that I lose the texture on the cube! Any ideas? If you need me to paste code, just ask. wink

Offline

 

#2 2010-04-05 08:01:10

NoNameNo
Administrator

Re: Problem while using TTF font and drawing a textured 3D Cube

yeah, we need code to help on this wink

Offline

 

#3 2010-04-05 08:42:56

goofster1020
Member

Re: Problem while using TTF font and drawing a textured 3D Cube

Alrighty here it is... I'm just gonna paste it tongue

Code:

/*===========================================
        GRRLIB (GX Version)
        - Template Code -

        Minimum Code To Use GRRLIB
============================================*/
#include <grrlib.h>

#include <gccore.h>
#include <stdlib.h>
#include <wiiuse/wpad.h>
#include <asndlib.h>
#include <mp3player.h>
#include <ogc/lwp_watchdog.h>
#include <unistd.h>

#include "michigan_block_m.h"
#include "desmond_howard.h"
#include "victors_mp3.h"
#include "arial_ttf.h"

#define GRRLIB_SetBackgroundColor        GRRLIB_SetBackgroundColour

int main(void)
{

    // Initialise the Graphics & Video subsystem
    GRRLIB_Init();
    
    ASND_Init();
    MP3Player_Init();
    MP3Player_Volume(255);
    
    // Initialise the Wiimotes
    WPAD_Init();
    
    GRRLIB_texImg* tBlockM = GRRLIB_LoadTexture(michigan_block_m);
    GRRLIB_texImg* tDesmond = GRRLIB_LoadTexture(desmond_howard);
    GRRLIB_ttfFont* ttfFont = GRRLIB_LoadTTF(arial_ttf, arial_ttf_size);
    
    GRRLIB_SetBackgroundColor(0x00, 0x00, 0x00, 0xFF);
    GRRLIB_Camera3dSettings(0.0f,0.0f,13.0f, 0,1,0, 0,0,0);
    
    MP3Player_PlayBuffer(victors_mp3, victors_mp3_size, NULL);
    time_t tmSongStart = time(NULL);
    
    float fScale[3] = {    1.0f,
                        1.0f,
                        1.0f
                      };
    float fRot = 0;
    bool bReset = false;
    int nLoopCount = 0;
    
    while(true) {
        
        if(!MP3Player_IsPlaying()) {
            
            MP3Player_PlayBuffer(victors_mp3, victors_mp3_size, NULL);
            tmSongStart = time(NULL);
        }
        
        WPAD_ScanPads();  // Scan the wiimotes
        
        // If [HOME] was pressed on the first Wiimote, break out of the loop
        if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME)  break;
        
        if (WPAD_ButtonsHeld(0) & WPAD_BUTTON_B) fScale[0] += .1f;
        if (WPAD_ButtonsHeld(0) & WPAD_BUTTON_1) fScale[1] += .1f;
        if (WPAD_ButtonsHeld(0) & WPAD_BUTTON_2) fScale[2] += .1f;
        
        if (WPAD_ButtonsDown(0) & WPAD_BUTTON_A) bReset = true;
        
        for(nLoopCount = 0; nLoopCount < 3; nLoopCount++) {
            if(fScale[nLoopCount] > 5.0f) fScale[nLoopCount] = .1f;
        }
        
        GRRLIB_2dMode();
        
        GRRLIB_DrawImg(    0,
                        0,
                        tDesmond,
                        0,
                        1,
                        1,
                        0xFFFFFFFF
                      );
        
        /*time_t tmNow = time(NULL);
        if((tmNow - tmSongStart >= 0) && (tmNow - tmSongStart <= 80)) { // 55 seconds is when the chorus is sung and stops at 80 seconds
            
            GRRLIB_PrintfTTF(    (640-(8 * 28))/2,
                                320 + 18 * 0,
                                ttfFont,
                                "Hail! to the victors valiant",
                                16,
                                0x000000FF
                            );
            GRRLIB_PrintfTTF(    (640-(8 * 30))/2,
                                320 + 18 * 1,
                                ttfFont,
                                "Hail! to the conqu'ring heroes",
                                16,
                                0x000000FF
                            );
            GRRLIB_PrintfTTF(    (640-(8 * 23))/2,
                                320 + 18 * 2,
                                ttfFont,
                                "Hail! Hail! to Michigan",
                                16,
                                0x000000FF
                            );
            GRRLIB_PrintfTTF(    (640-(8 * 21))/2,
                                320 + 18 * 3,
                                ttfFont,
                                "The leaders and best!",
                                16,
                                0x000000FF
                            );
            GRRLIB_PrintfTTF(    (640-(8 * 28))/2,
                                320 + 18 * 4,
                                ttfFont,
                                "Hail! to the victors valiant",
                                16,
                                0x000000FF
                            );
            GRRLIB_PrintfTTF(    (640-(8 * 30))/2,
                                320 + 18 * 5,
                                ttfFont,
                                "Hail! to the conqu'ring heroes",
                                16,
                                0x000000FF
                            );
            GRRLIB_PrintfTTF(    (640-(8 * 24))/2,
                                320 + 18 * 6,
                                ttfFont,
                                "Hail! Hail! to Michigan,",
                                16,
                                0x000000FF
                            );
            GRRLIB_PrintfTTF(    (640-(8 * 26))/2,
                                320 + 18 * 7,
                                ttfFont,
                                "The champions of the West!",
                                16,
                                0x000000FF
                            );
            
        }*/
        
        if(bReset) for(nLoopCount = 0; nLoopCount < 3; nLoopCount++) fScale[nLoopCount] = 1.0f;
        
        GRRLIB_SetTexture(tBlockM, false);
        GRRLIB_Camera3dSettings(0.0f,0.0f,13.0f, 0,1,0, 0,0,0);
        GRRLIB_3dMode(    0.1, /* Maximum Zoom */
                        1000, /* Minimum Zoom */
                        45, /*Viewing Angle (in degrees)*/
                        false, /* Color mode */
                        true, /* Texture mode */
                        false /* Normal mode */
                     );
        
        GRRLIB_ObjectView(    0, /* X position */
                            0, /* Y position */
                            0, /* Z position */
                            fRot, /* Rotation amoung the X axis */
                            fRot*2, /* Rotation amoung the Y axis */
                            fRot*3, /* Rotation amoung the Z axis */
                            fScale[0], /* Scaling amoung the X axis */
                            fScale[1], /* Scaling amoung the Y axis */
                            fScale[2]  /* Scaling amoung the Z axis */
                         );
        
        GX_Begin(    GX_QUADS, /* Tell GX to make quadrilaterals */
                    GX_VTXFMT0, /* Vertex format 0 */
                    24 /* Total number of vertices to be drawn */
                );
        
        //{ Drawing code:
            
            GX_Position3f32(-1.0f,1.0f,1.0f);
            GX_TexCoord2f32(0.0f,0.0f);
            GX_Position3f32(1.0f,1.0f,1.0f);
            GX_TexCoord2f32(1.0f,0.0f);
            GX_Position3f32(1.0f,-1.0f,1.0f);
            GX_TexCoord2f32(1.0f,1.0f);
            GX_Position3f32(-1.0f,-1.0f,1.0f);
            GX_TexCoord2f32(0.0f,1.0f);

            GX_Position3f32(1.0f,1.0f,-1.0f);
            GX_TexCoord2f32(0.0f,0.0f);
            GX_Position3f32(-1.0f,1.0f,-1.0f);
            GX_TexCoord2f32(1.0f,0.0f);
            GX_Position3f32(-1.0f,-1.0f,-1.0f);
            GX_TexCoord2f32(1.0f,1.0f);
            GX_Position3f32(1.0f,-1.0f,-1.0f);
            GX_TexCoord2f32(0.0f,1.0f);

            GX_Position3f32(1.0f,1.0f,1.0f);
            GX_TexCoord2f32(0.0f,0.0f);
            GX_Position3f32(1.0f,1.0f,-1.0f);
            GX_TexCoord2f32(1.0f,0.0f);
            GX_Position3f32(1.0f,-1.0f,-1.0f);
            GX_TexCoord2f32(1.0f,1.0f);
            GX_Position3f32(1.0f,-1.0f,1.0f);
            GX_TexCoord2f32(0.0f,1.0f);

            GX_Position3f32(-1.0f,1.0f,-1.0f);
            GX_TexCoord2f32(0.0f,0.0f);
            GX_Position3f32(-1.0f,1.0f,1.0f);
            GX_TexCoord2f32(1.0f,0.0f);
            GX_Position3f32(-1.0f,-1.0f,1.0f);
            GX_TexCoord2f32(1.0f,1.0f);
            GX_Position3f32(-1.0f,-1.0f,-1.0f);
            GX_TexCoord2f32(0.0f,1.0f);

            GX_Position3f32(-1.0f,1.0f,-1.0f);
            GX_TexCoord2f32(0.0f,0.0f);
            GX_Position3f32(1.0f,1.0f,-1.0f);
            GX_TexCoord2f32(1.0f,0.0f);
            GX_Position3f32(1.0f,1.0f,1.0f);
            GX_TexCoord2f32(1.0f,1.0f);
            GX_Position3f32(-1.0f,1.0f,1.0f);
            GX_TexCoord2f32(0.0f,1.0f);

            GX_Position3f32(1.0f,-1.0f,-1.0f);
            GX_TexCoord2f32(0.0f,0.0f);
            GX_Position3f32(-1.0f,-1.0f,-1.0f);
            GX_TexCoord2f32(1.0f,0.0f);
            GX_Position3f32(-1.0f,-1.0f,1.0f);
            GX_TexCoord2f32(1.0f,1.0f);
            GX_Position3f32(1.0f,-1.0f,1.0f);
            GX_TexCoord2f32(0.0f,1.0f);
            
            
        //} End drawing code
        GX_End();
        
        fRot += 0.5f;
        bReset = false;
        
        GRRLIB_2dMode();
        
        time_t tmNow = time(NULL);
        if((tmNow - tmSongStart >= 55) && (tmNow - tmSongStart <= 80)) { // 55 seconds is when the chorus is sung and stops at 80 seconds
            
            GRRLIB_PrintfTTF(    (640-(7 * 28))/2,
                                320 + 18 * 0,
                                ttfFont,
                                "Hail! to the victors valiant",
                                16,
                                0x000000FF
                            );
            GRRLIB_PrintfTTF(    (640-(7 * 30))/2,
                                320 + 18 * 1,
                                ttfFont,
                                "Hail! to the conqu'ring heroes",
                                16,
                                0x000000FF
                            );
            GRRLIB_PrintfTTF(    (640-(7 * 23))/2,
                                320 + 18 * 2,
                                ttfFont,
                                "Hail! Hail! to Michigan",
                                16,
                                0x000000FF
                            );
            GRRLIB_PrintfTTF(    (640-(7 * 21))/2,
                                320 + 18 * 3,
                                ttfFont,
                                "The leaders and best!",
                                16,
                                0x000000FF
                            );
            GRRLIB_PrintfTTF(    (640-(7 * 28))/2,
                                320 + 18 * 4,
                                ttfFont,
                                "Hail! to the victors valiant",
                                16,
                                0x000000FF
                            );
            GRRLIB_PrintfTTF(    (640-(7 * 30))/2,
                                320 + 18 * 5,
                                ttfFont,
                                "Hail! to the conqu'ring heroes",
                                16,
                                0x000000FF
                            );
            GRRLIB_PrintfTTF(    (640-(7 * 24))/2,
                                320 + 18 * 6,
                                ttfFont,
                                "Hail! Hail! to Michigan,",
                                16,
                                0x000000FF
                            );
            GRRLIB_PrintfTTF(    (640-(7 * 26))/2,
                                320 + 18 * 7,
                                ttfFont,
                                "The champions of the West!",
                                16,
                                0x000000FF
                            );
            
        }
        
        GRRLIB_Render();  // Render the frame buffer to the TV
    }
    
    GRRLIB_2dMode();
    
    int nVolume = 255;
    for(nLoopCount = 0; nLoopCount <= 255; nLoopCount++) {
        
        MP3Player_Volume(nVolume);
        
        GRRLIB_Rectangle(    0,
                            0,
                            640,
                            480,
                            RGBA(0,0,0,nLoopCount),
                            true
                        );
        GRRLIB_Render();
        usleep(100);
        
        nVolume--;
    }
    
    MP3Player_Stop();
    GRRLIB_Exit(); // Be a good boy, clear the memory allocated by GRRLIB
    
    GRRLIB_FreeTTF(ttfFont);
    GRRLIB_FreeTexture(tBlockM);
    GRRLIB_FreeTexture(tDesmond);
    
    exit(0);  // Use exit() to exit a program, do not use 'return' from main()
}

Haha don't make fun of my noobish programming... Oh also, when I exit, I have it fade away the music and supposedly the screen but it doesn't work. It just goes black instantly. Look in the last for loop for that one.

Offline

 

#4 2010-04-05 08:52:54

NoNameNo
Administrator

Re: Problem while using TTF font and drawing a textured 3D Cube

first for your fadeout, its normal since in your fade out loop you only draw the black square and nothing more wink
for the other problem, i will have a look later coding a sample to test.

Offline

 

#5 2010-04-05 08:57:27

goofster1020
Member

Re: Problem while using TTF font and drawing a textured 3D Cube

Oh, duh.. Haha, how did I not know that... Thanks NNN for your quick reply! Oh, and if it is necessary to know, I'm using GRRLIB SVN rev333.

Last edited by goofster1020 (2010-04-05 09:06:57)

Offline

 

#6 2010-04-05 16:45:27

NoNameNo
Administrator

Re: Problem while using TTF font and drawing a textured 3D Cube

After some test, it seems there is mem leak somewhere in ttf support, need more time to investigate with crayon. i will inform you if we get something.

Offline

 

#7 2010-04-05 21:12:04

NoNameNo
Administrator

Re: Problem while using TTF font and drawing a textured 3D Cube

hi, after some investigation with Crayon, we found the problem wink

in fact by default, vertex color are white, so its ok for the texture of the cube, but since we call a draw routine when we ask ttf display, the default vertex color, is the one of the latest displayed by the ttf display call wink

simply add : GX_Color1u32(0xFFFFFFFF);  for each vertex wink


GX_Position3f32(-1.0f,1.0f,1.0f);
GX_Color1u32(0xFFFFFFFF);
GX_TexCoord2f32(0.0f,0.0f);
....

tell me if it resolve your problem wink

Regards

Offline

 

#8 2010-04-06 04:38:41

goofster1020
Member

Re: Problem while using TTF font and drawing a textured 3D Cube

Okay, it works! And a note for people who will have a problem like this eventually: In GRRLIB_3dMode(...), you have to set "Color Mode" to true also (along with "Textured Mode" being set to true), otherwise it will not display the graphics and will crash. You will have to shut down your Wii the hard way by holding the power button... Thanks a lot NNN and Crayon... I enjoy your library a lot! Oh, I also figured out how to have it fade out... Just used good ol' Screen2Texture and captured it. Then I put it in my for loop. And I have another couple little questions while we're talking here... Haha, I'm sorry. I'm such a noob, I need all the help I can get! Well:
1. How can I center the TTF font in the middle of the screen because I can't seem to do it with the equation - (640-([font width] * [number of characters]))/2. I'm not sure what to put for the font width. I suppose that it is 16 because 12pt font is the "normal size" for fonts but I tried this and it's way off. Do TTF fonts not have a fixed width? Is that my problem?
2. When I print the TTF on the screen, it runs really slow. (The cube rotates slowly) Any ideas? Is this normal? Anything I can do to my code to fix this?

Thank you again! You guys are awesome!

I'll post my final code again so that it can help you guys with the questions and for a little tutorial maybe (I commented the heck outta it):

Code:

#include <grrlib.h>
#include <gccore.h>
#include <stdlib.h>
#include <wiiuse/wpad.h>
#include <asndlib.h>
#include <mp3player.h>
#include <ogc/lwp_watchdog.h>
#include <unistd.h>

#include "michigan_block_m.h"
#include "desmond_howard.h"
#include "victors_mp3.h"
#include "arial_ttf.h"

#define GRRLIB_SetBackgroundColor        GRRLIB_SetBackgroundColour

int main(void)
{

    // Initialise the Graphics & Video subsystem
    GRRLIB_Init();
    
    // Initialize sound necessities.
    ASND_Init();
    MP3Player_Init();
    MP3Player_Volume(255);
    
    // Initialize the Wiimotes
    WPAD_Init();
    
    // Load textures.
    GRRLIB_texImg* tBlockM = GRRLIB_LoadTexture(michigan_block_m);
    GRRLIB_texImg* tDesmond = GRRLIB_LoadTexture(desmond_howard);
    GRRLIB_ttfFont* ttfFont = GRRLIB_LoadTTF(arial_ttf, arial_ttf_size);
    GRRLIB_texImg* tScreen = GRRLIB_CreateEmptyTexture(rmode->fbWidth, rmode->xfbHeight);
    
    GRRLIB_SetBackgroundColor(0x00, 0x00, 0x00, 0xFF);
    
    GRRLIB_Camera3dSettings(    0.0f, /* X Position */
                                0.0f, /* Y Position */
                                13.0f, /* Z Position */
                                0, /* X Alpha Component */
                                1, /* Y Alpha Component */
                                0, /* Z Alpha Component */
                                0, /* X Up-looking Position */
                                0, /* Y Up-looking Position */
                                0 /* Z Up-looking Position */
                           );
    
    // Play "Hail to the Victors"
    MP3Player_PlayBuffer(victors_mp3, victors_mp3_size, NULL);
    time_t tmSongStart = time(NULL);
    
    // Declare needed variables.
    float fScale[3] = {    1.0f,
                        1.0f,
                        1.0f
                      };
    float fRot = 0;
    bool bReset = false;
    int nLoopCount = 0;
    
    bool bBreak = false;
    
    while(true) {
        
        // Cause an infinite loop for the music.
        if(!MP3Player_IsPlaying()) {
            
            MP3Player_PlayBuffer(victors_mp3, victors_mp3_size, NULL);
            tmSongStart = time(NULL); // Get new starting time.
        }
        
        // Scan them pads, boy!
        WPAD_ScanPads();
        
        // Break the loop. [See line 292]
        if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) bBreak = true;
        
        // Increase scaling.
        if (WPAD_ButtonsHeld(0) & WPAD_BUTTON_B) fScale[0] += .1f;
        if (WPAD_ButtonsHeld(0) & WPAD_BUTTON_1) fScale[1] += .1f;
        if (WPAD_ButtonsHeld(0) & WPAD_BUTTON_2) fScale[2] += .1f;
        
        // Reset the scaling. [See line 108]
        if (WPAD_ButtonsDown(0) & WPAD_BUTTON_A) bReset = true;
        
        // Make sure we don't get too big or too small.
        for(nLoopCount = 0; nLoopCount < 3; nLoopCount++) {
            if(fScale[nLoopCount] > 5.0f) fScale[nLoopCount] = .1f;
        }
        
        // Make sure we're in 2D mode.
        GRRLIB_2dMode();
        
        // Draw the bacground image of Desmond Howard.
        GRRLIB_DrawImg(    0, /* X Position */
                        0, /* Y Position */
                        tDesmond, /* Texture */
                        0, /* Rotation (in degrees) */
                        1, /* X Scale (or flip) */
                        1, /* Y Scale (or flip) */
                        0xFFFFFFFF /* Color */
                      );
        
        // Set the cube back to normal scale if the A button was pressed.
        if(bReset) for(nLoopCount = 0; nLoopCount < 3; nLoopCount++) fScale[nLoopCount] = 1.0f;
        
        GRRLIB_SetTexture(tBlockM, false);
        GRRLIB_Camera3dSettings(0.0f,0.0f,13.0f, 0,1,0, 0,0,0);
        GRRLIB_3dMode(    0.1, /* Maximum Zoom */
                        1000, /* Minimum Zoom */
                        45, /*Viewing Angle (in degrees)*/
                        true, /* Color mode */
                        true, /* Texture mode */
                        false /* Normal mode */
                     );
        
        GRRLIB_ObjectView(    0, /* X position */
                            0, /* Y position */
                            0, /* Z position */
                            fRot, /* Rotation amoung the X axis */
                            fRot*2, /* Rotation amoung the Y axis */
                            fRot*3, /* Rotation amoung the Z axis */
                            fScale[0], /* Scaling amoung the X axis */
                            fScale[1], /* Scaling amoung the Y axis */
                            fScale[2]  /* Scaling amoung the Z axis */
                         );
        
        GX_Begin(    GX_QUADS, /* Tell GX to make quadrilaterals */
                    GX_VTXFMT0, /* Vertex format 0 */
                    24 /* Total number of vertices to be drawn */
                );
        
        //{ Drawing code:
            
            GX_Position3f32(-1.0f,1.0f,1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,0.0f);
            GX_Position3f32(1.0f,1.0f,1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,0.0f);
            GX_Position3f32(1.0f,-1.0f,1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,1.0f);
            GX_Position3f32(-1.0f,-1.0f,1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,1.0f);

            GX_Position3f32(1.0f,1.0f,-1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,0.0f);
            GX_Position3f32(-1.0f,1.0f,-1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,0.0f);
            GX_Position3f32(-1.0f,-1.0f,-1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,1.0f);
            GX_Position3f32(1.0f,-1.0f,-1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,1.0f);

            GX_Position3f32(1.0f,1.0f,1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,0.0f);
            GX_Position3f32(1.0f,1.0f,-1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,0.0f);
            GX_Position3f32(1.0f,-1.0f,-1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,1.0f);
            GX_Position3f32(1.0f,-1.0f,1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,1.0f);

            GX_Position3f32(-1.0f,1.0f,-1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,0.0f);
            GX_Position3f32(-1.0f,1.0f,1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,0.0f);
            GX_Position3f32(-1.0f,-1.0f,1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,1.0f);
            GX_Position3f32(-1.0f,-1.0f,-1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,1.0f);

            GX_Position3f32(-1.0f,1.0f,-1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,0.0f);
            GX_Position3f32(1.0f,1.0f,-1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,0.0f);
            GX_Position3f32(1.0f,1.0f,1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,1.0f);
            GX_Position3f32(-1.0f,1.0f,1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,1.0f);

            GX_Position3f32(1.0f,-1.0f,-1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,0.0f);
            GX_Position3f32(-1.0f,-1.0f,-1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,0.0f);
            GX_Position3f32(-1.0f,-1.0f,1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(1.0f,1.0f);
            GX_Position3f32(1.0f,-1.0f,1.0f);
            GX_Color1u32(0xFFFFFFFF);
            GX_TexCoord2f32(0.0f,1.0f);
            
            
        //} End drawing code
        GX_End();
        
        // Give it a little more rotation and make sure you can continue reforming the cube.
        fRot += 0.5f;
        bReset = false;
        
        // Bring her back to 2D!
        GRRLIB_2dMode();
        
        // Get the current time and see if it's time to display the lyrics yet.
        time_t tmNow = time(NULL);
        if((tmNow - tmSongStart >= 55) && (tmNow - tmSongStart <= 80)) { // 55 seconds is when the chorus is sung and stops at 80 seconds
            
            // Let's go Blue!
            GRRLIB_PrintfTTF(    (640-(7 * 28))/2,
                                320 + 18 * 0,
                                ttfFont,
                                "Hail! to the victors valiant",
                                16,
                                0x000000FF
                            );
            GRRLIB_PrintfTTF(    (640-(7 * 30))/2,
                                320 + 18 * 1,
                                ttfFont,
                                "Hail! to the conqu'ring heroes",
                                16,
                                0x000000FF
                            );
            GRRLIB_PrintfTTF(    (640-(7 * 23))/2,
                                320 + 18 * 2,
                                ttfFont,
                                "Hail! Hail! to Michigan",
                                16,
                                0x000000FF
                            );
            GRRLIB_PrintfTTF(    (640-(7 * 21))/2,
                                320 + 18 * 3,
                                ttfFont,
                                "The leaders and best!",
                                16,
                                0x000000FF
                            );
            GRRLIB_PrintfTTF(    (640-(7 * 28))/2,
                                320 + 18 * 4,
                                ttfFont,
                                "Hail! to the victors valiant",
                                16,
                                0x000000FF
                            );
            GRRLIB_PrintfTTF(    (640-(7 * 30))/2,
                                320 + 18 * 5,
                                ttfFont,
                                "Hail! to the conqu'ring heroes",
                                16,
                                0x000000FF
                            );
            GRRLIB_PrintfTTF(    (640-(7 * 24))/2,
                                320 + 18 * 6,
                                ttfFont,
                                "Hail! Hail! to Michigan,",
                                16,
                                0x000000FF
                            );
            GRRLIB_PrintfTTF(    (640-(7 * 26))/2,
                                320 + 18 * 7,
                                ttfFont,
                                "The champions of the West!",
                                16,
                                0x000000FF
                            );
            
        }
        
        // Time to go!
        if (bBreak) {
            
            // Grab a picture of the screen and store it in the texture tScreen.
            GRRLIB_Screen2Texture(    0, /* X Start */
                                    0, /* Y Start */
                                    tScreen, /* Destination Texture */
                                    false /* Clear Screen? */
                                 );
            break;
        }
        
        // Render the frame buffer to the TV
        GRRLIB_Render();
    }
    
    // Bring it back to 2D Mode if it hasn't (somehow) been in it already. (It should be though)
    GRRLIB_2dMode();
    
    int nVolume = 255;
    for(nLoopCount = 0; nLoopCount <= 255; nLoopCount++) {
        
        // Change the volume.
        MP3Player_Volume(nVolume);
        
        // Show the newly-snapped picture of the previous screen.
        GRRLIB_DrawImg(    0, /* X Position */
                        0, /* Y Position */
                        tScreen, /* Texture */
                        0, /* Rotation (in degrees) */
                        1, /* X Scale (or flip) */
                        1, /* Y Scale (or flip) */
                        0xFFFFFFFF /* Color */
                      );
        
        // Use GRRLIB_FillScreen to fade out.
        GRRLIB_FillScreen( RGBA(0,0,0,nLoopCount) );
        
        // Render the frame buffer to the TV
        GRRLIB_Render();
        
        // Slow down the fading process.
        usleep(100);
        
        // Decrement the volume.
        nVolume--;
    }
    
    // Stop playing music.
    MP3Player_Stop();
    
    // Say goodbye to GRRLIB.
    GRRLIB_Exit();
    
    // Free all textures used.
    GRRLIB_FreeTTF(ttfFont);
    GRRLIB_FreeTexture(tBlockM);
    GRRLIB_FreeTexture(tDesmond);
    GRRLIB_FreeTexture(tScreen);
    
    // Return to the loader.
    exit(0);
}

Offline

 

#9 2010-04-06 04:56:34

Crayon
Bad Mother Fucker

Re: Problem while using TTF font and drawing a textured 3D Cube

To get the size of a string you could call GRRLIB_WidthTTF. This is a slow function, I'm trying to make a function called PrintfTTFBox. This function will have a parameter called align with the following values:

Code:

#define GRRLIB_LEFT     0   /**< The reference point will be on the left edge of the bounding rectangle. */
#define GRRLIB_RIGHT    1   /**< The reference point will be on the right edge of the bounding rectangle. */
#define GRRLIB_HCENTER  2   /**< The reference point will be aligned horizontally with the center of the bounding rectangle. */
#define GRRLIB_TOP      0   /**< The reference point will be on the top edge of the bounding rectangle. */
#define GRRLIB_BOTTOM   4   /**< The reference point will be on the bottom edge of the bounding rectangle. */
#define GRRLIB_VCENTER  8   /**< The reference point will be aligned vertically with the center of the bounding rectangle. */

What you could do for now is print your text once in a texture and draw this texture in the loop with GRRLIB_DrawImg.

Offline

 
  • Index
  •  » General Help
  •  » Problem while using TTF font and drawing a textured 3D Cube

Board footer

Powered by FluxBB