FNTTexture

Syntax

#include <revolution/fnt.h>

typedef struct
{
    void*       image;
    s8          left;
    u8          glyphWidth;
    s8          charWidth;
    u8          charHeight;
    GXTexFmt    texFormat;
    u16         texWidth;
    u16         texHeight;
    u16         cellX;
    u16         cellY;
} FNTTexture;

Elements

image Pointer to a texture image sheet.
left Left space width of the character (in texels).
glyphWidth Text glyph width (in texels). (A glyph is the visually recognizable shape of a character.)
charWidth Character width (=left space width + glyph width + right space width) in texels.
charHeight Font height (in texels).
texFormat Format of the texture image sheet.
texWidth Texture image sheet width (in texels).
texHeight Texture image sheet height (in texels).
cellX Horizontal coordinate of a character in the texture image sheet.
cellY Vertical coordinate of a character in the texture image sheet.

Description

This structure stores texture information used to draw a single character using the font.

An example of code that loads the texture according to information in the FNTTexture structure and draws the associated polygons is given below.

void DrawCharacter( f32 x, f32 y, f32 z, const FNTTexture* tex )
{
    f32 posLeft   = x + tex->left;
    f32 posTop    = y;
    f32 posRight  = posLeft + tex->glyphWidth;
    f32 posBottom = posTop  + tex->charHeight;
    f32 texLeft   = (f32)tex->cellX / tex->texWidth;
    f32 texTop    = (f32)tex->cellY / tex->texHeight;
    f32 texRight  = (f32)(tex->cellX + tex->glyphWidth) / tex->texWidth;
    f32 texBottom = (f32)(tex->cellY + tex->charHeight) / tex->texHeight;
    GXTexObj tobj;

    GXInitTexObj(&tobj, tex->image, tex->texWidth, tex->texHeight,
        tex->texFormat, GX_CLAMP, GX_CLAMP, GX_FALSE);
    GXInitTexObjLOD(&tobj, GX_LINEAR, GX_LINEAR, 0, 0, 0,
        GX_DISABLE, GX_DISABLE, GX_ANISO_1);
    GXLoadTexObj(&tobj, GX_TEXMAP0);

    GXBegin(GX_QUADS, GX_VTXFMT0, 4);
    {
        GXPosition3f32(posLeft, posTop, z);
        GXTexCoord2f32(texLeft, texTop);

        GXPosition3f32(posRight, posTop, z);
        GXTexCoord2f32(texRight, texTop);

        GXPosition3f32(posRight, posBottom, z);
        GXTexCoord2f32(texRight, texBottom);

        GXPosition3f32(posLeft, posBottom, z);
        GXTexCoord2f32(texLeft, texBottom);
    }
    GXEnd();
}

See Also

FNTGetTexture

Revision History

2006/10/01 Initial version.


CONFIDENTIAL