You are not logged in.

#1 2009-09-05 02:24:39

BlueChip
Moderator

Drop Shadows

My font routine is nearing completion.

The font format supported is the same used by several big-name games companies, including (the) CodeMasters and the font generator is free as in, "you get the app, not the source code"

The print routines include support for:
# Multiple font support (limited by RAM)
# Full unicode support
# Binary search algorithm for speed
# Stateful screen coordinates [just for you, Xane]
# Print or do-not-print half-characters (ie. when part of the character is off-screen)
# Support for '\n'
# Auto-CRLF (when EOL is reached)
# Print strings*  (which may include '\n')
# Tracking
# Leading [led'ing, not lee'ding]

* I have deliberately chosen not to implement printf() due to memory considerations ...use snprintf() yourself smile

ToDo List:
# Text Alignment [it will happen soon, I need it for my game]

The last thing (well, the /next/ "last thing) I want to do before releasing this code is add a drop shadow option.
The way I want to this is thus:   Display the character, but reduce every colour to black & multiply the opacity by {0 < N <= 1.0}
I really think I should be able to do this by applying some terribly clever matrix (or such) with a GX_foo() call
But I really have no idea even where to start looking.

Please Help smile

Final Note.
I know that others are also working on font routines to add to GRRLIB ...When I release my code I am happy for it to go in to GRRLIB, and I am also happy to release it as a separate library - I will not be offended either way wink

BC

Last edited by BlueChip (2009-09-05 02:37:12)


I can be found on efnet, freenode, msn, gtalk, aim, ychat & icq ...PM me for details

Offline

 

#2 2009-09-05 03:11:14

elisherer
Member

Re: Drop Shadows

Does it rely on freetype?
and if not...make sure it stays under 2MB cause freetype is the largest lib today!!!

Offline

 

#3 2009-09-05 03:28:41

BlueChip
Moderator

Re: Drop Shadows

Does it rely on freetype?
and if not...make sure it stays under 2MB cause freetype is the largest lib today!!!

No!  This supports full-colour w/ alpha fonts generated with BMFGenerator from AngelCode

I've not compiled to .a yet, but the .o (with every function inside it) comes in a just under 8K


I can be found on efnet, freenode, msn, gtalk, aim, ychat & icq ...PM me for details

Offline

 

#4 2009-09-05 04:19:15

BlueChip
Moderator

Re: Drop Shadows

Problem resolved thanks to comex & rewt on #wiidev @ efnet smile


I can be found on efnet, freenode, msn, gtalk, aim, ychat & icq ...PM me for details

Offline

 

#5 2009-09-05 10:57:37

JustWoody
Member

Re: Drop Shadows

Why not just draw the shadow by drawing the character with a colour like 0x77222222 (if using 0xaarrggbb format)?

I would imagine that this should look the part

You may have to modify the drawing routine to support specify colour to this detail

Not sure if you have thought about it, but you might want to be able to user specify x and y offsets of the shadow and maybe allow for changeable shadow scale to try to give depth

Last edited by JustWoody (2009-09-05 11:01:47)

Offline

 

#6 2009-09-05 21:02:34

BlueChip
Moderator

Re: Drop Shadows

Thanks Woody - that's almost exactly what I did in the end smile
BMF_shadow(font, x_offset, y_offset, alpha_level);  // configure font shadow
...When I have time I will look at doing the alpha as a percentage of the alpha of the character ...but I need to spend more time with the TEV documentation

Code:

void  BMF_drawc (f32 x, f32 y, const BMF_Font* font, const BMF_Char* chr)
{
    GXTexObj  texObj;
    Mtx       m, m1, m2, mv;

    GX_InitTexObj(&texObj, font->tex->data, font->tex->w, font->tex->h,
                  GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE);

    if (GRRLIB_Settings.antialias == false)
        GX_InitTexObjLOD(&texObj, GX_NEAR, GX_NEAR,
                         0.0f, 0.0f, 0.0f, 0, 0, GX_ANISO_1);

    GX_LoadTexObj(&texObj,      GX_TEXMAP0);
    GX_SetTevOp  (GX_TEVSTAGE0, GX_MODULATE);
    GX_SetVtxDesc(GX_VA_TEX0,   GX_DIRECT);

    guMtxIdentity  (m1);
    guMtxScaleApply(m1, m1, 1.0f, 1.0f, 1.0f);
    guMtxRotAxisDeg(m2, &axis, 0.0f);
    guMtxConcat    (m2, m1, m);
    guMtxConcat    (GXmodelView2D, m, mv);

    x += chr->xoff;
    y += chr->yoff;

    if (font->shadow) {
        x += font->shad_x;
        y += font->shad_y;

        GX_LoadPosMtxImm(mv, GX_PNMTX0);
        GX_Begin(GX_QUADS, GX_VTXFMT0, 4);
            GX_Position3f32(x,         y,         0);
            GX_Color1u32   (font->shad_a);
            GX_TexCoord2f32(chr->idx[BMF_TL].x, chr->idx[BMF_TL].y);

            GX_Position3f32(x +chr->w, y,         0);
            GX_Color1u32   (font->shad_a);
            GX_TexCoord2f32(chr->idx[BMF_TR].x, chr->idx[BMF_TR].y);

            GX_Position3f32(x +chr->w, y +chr->h, 0);
            GX_Color1u32   (font->shad_a);
            GX_TexCoord2f32(chr->idx[BMF_BR].x, chr->idx[BMF_BR].y);

            GX_Position3f32(x,         y +chr->h, 0);
            GX_Color1u32   (font->shad_a);
            GX_TexCoord2f32(chr->idx[BMF_BL].x, chr->idx[BMF_BL].y);
        GX_End();

        x -= font->shad_x;
        y -= font->shad_y;
    }

    GX_Begin(GX_QUADS, GX_VTXFMT0, 4);
        GX_Position3f32(x,         y,         0);
        GX_Color1u32   (0xFFFFFFFF);
        GX_TexCoord2f32(chr->idx[BMF_TL].x, chr->idx[BMF_TL].y);

        GX_Position3f32(x +chr->w, y,         0);
        GX_Color1u32   (0xFFFFFFFF);
        GX_TexCoord2f32(chr->idx[BMF_TR].x, chr->idx[BMF_TR].y);

        GX_Position3f32(x +chr->w, y +chr->h, 0);
        GX_Color1u32   (0xFFFFFFFF);
        GX_TexCoord2f32(chr->idx[BMF_BR].x, chr->idx[BMF_BR].y);

        GX_Position3f32(x,         y +chr->h, 0);
        GX_Color1u32   (0xFFFFFFFF);
        GX_TexCoord2f32(chr->idx[BMF_BL].x, chr->idx[BMF_BL].y);
    GX_End();
    GX_LoadPosMtxImm(GXmodelView2D, GX_PNMTX0);

    GX_SetTevOp  (GX_TEVSTAGE0, GX_PASSCLR);
    GX_SetVtxDesc(GX_VA_TEX0,   GX_NONE);
}

all improvements welcome

BC


I can be found on efnet, freenode, msn, gtalk, aim, ychat & icq ...PM me for details

Offline

 

Board footer

Powered by FluxBB