You are not logged in.
This is a replacement for the function GRRLIB_DrawChar and GRRLIB_Printf that I made this morning modifiing the original functions a little, i have tested it and works fine.
For this to work you need to use this fonts (actualy they are the old fonts from GRRLIB, but modified to work with this) -> http://www.filedropper.com/fonts_3
(this is not compatible with the font that comes with GRRLIB 3.0.1a though)
I also included Crayon's Improvement ;D
font*.c comes with the width and height of the fonts... it should work the same way as it did in the older versions of GRRLIB
GRRLIB.c
inline void GRRLIB_DrawChar(f32 xpos, f32 ypos, u16 width, u16 height, u8 data[], float degrees, float scaleX, f32 scaleY, u8 frame, GXColor c ){ GXTexObj texObj; f32 s1= ((frame %16)) /16.0; f32 s2= ((frame %16)+1) /16.0; f32 t1= ((frame /16)) /16.0; f32 t2= ((frame /16)+1) /16.0; GX_InitTexObj(&texObj, data, width*16,height*16, GX_TF_RGBA8,GX_CLAMP, GX_CLAMP,GX_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); Mtx m,m1,m2,mv; width *=.5; height*=.5; guMtxIdentity (m1); guMtxScaleApply(m1,m1,scaleX,scaleY,1.0); Vector axis =(Vector) {0,0,1}; guMtxRotAxisDeg (m2, &axis, degrees); guMtxConcat(m2,m1,m); guMtxTransApply(m,m, xpos+width,ypos+height,0); guMtxConcat (GXmodelView2D, m, mv); GX_LoadPosMtxImm (mv, GX_PNMTX0); GX_Begin(GX_QUADS, GX_VTXFMT0,4); GX_Position3f32(-width, -height, 0); GX_Color4u8(c.r,c.g,c.b,c.a); GX_TexCoord2f32(s1, t1); GX_Position3f32(width, -height, 0); GX_Color4u8(c.r,c.g,c.b,c.a); GX_TexCoord2f32(s2, t1); GX_Position3f32(width, height, 0); GX_Color4u8(c.r,c.g,c.b,c.a); GX_TexCoord2f32(s2, t2); GX_Position3f32(-width, height, 0); GX_Color4u8(c.r,c.g,c.b,c.a); GX_TexCoord2f32(s1, t2); GX_End(); GX_LoadPosMtxImm (GXmodelView2D, GX_PNMTX0); GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR); GX_SetVtxDesc (GX_VA_TEX0, GX_NONE); } void GRRLIB_Printf(f32 xpos, f32 ypos, u8 font[],u16 font_width ,u16 font_height , u32 color, f32 zoom, char *text,...){ int i,size=0; char tmp[1024]; va_list argp; va_start(argp, text); size = vsprintf(tmp, text, argp); va_end(argp); GXColor col = GRRLIB_Splitu32(color); for(i=0;i<size;i++){ u8 c = tmp[i]; GRRLIB_DrawChar(xpos+i * font_width * zoom, ypos, font_width, font_height, font, 0, zoom, zoom, c, col ); } }
GRRLIB.h
inline void GRRLIB_DrawChar(f32 xpos, f32 ypos, u16 width, u16 height, u8 data[], float degrees, float scaleX, f32 scaleY, u8 frame, GXColor c ); void GRRLIB_Printf(f32 xpos, f32 ypos, u8 font[],u16 font_width ,u16 font_height , u32 color, f32 zoom, char *text,...);
[EDIT]
Modified to align fonts to support ASCII positioning (upper left == char 0, upper right char == 15, lower right == char 255 ) and added libosk font (i think it was made by _patch, but not sure)
Last edited by grillo (2008-07-04 19:20:59)
Offline
fixed a little bug while trying to call GRRLIB_DrawChar alone to draw a char (not that i know that someone uses it raw, but it's better this way), the font format changed though
Offline
Can you tell me how to use it please. No font works with it.
Offline
f32 s1= (frame>>4) & 0x0F ; f32 s2= ((frame>>4)& 0x0F)+1; f32 t1=frame & 0x0F ; f32 t2= (frame & 0x0F)+1 ;
Update: this will do the auto scaling, regardless of texture size as long as it is 16x16 tiles (and if you want different numbers, I think you can see what value you change there ;-) )
Mtx texMtx; guMtxScale(texMtx,1.0/16.0,1.0/16.0,1.0); GX_LoadTexMtxImm(texMtx,GX_TEXMTX0,GX_MTX3x4);
set this where ever you want to draw the font:
GX_SetTexCoordGen(GX_TEXCOORD0,GX_TG_MTX3x4, GX_TG_TEX0, GX_TEXMTX0);
and to turn back, change it back to identity
GX_SetTexCoordGen(GX_TEXCOORD0,GX_TG_MTX3x4, GX_TG_TEX0, GX_IDENTITY);
Last edited by RedShade (2008-08-08 08:15:34)
Offline
Can somebody make an example please... My homebrew is near release but all the printf-Functions are not working yet...
Offline
if you followed the instructions, it should be enough to call
GRRLIB_Printf( 50,50, //Position tex_font8,font8_char_width,font8_char_high, //Font Data (you must include font8.h that comes in the font pack 0xFFFFFFFF, //Font Color 4, //Font Size x 4 "I love Writing Text ñañañaña %d",32); //The Text ;D
that should write the text in the buffer at position 50,50
Offline
There is no font8.h in your package. That's the problem. And my own Fonts don't work.
I have an idea... Doesn't it work with GRRLib Converter?
Last edited by DarkChris (2008-08-10 01:55:32)
Offline
http://www.filedropper.com/fonts_3 << tried downloading this font pack???
Offline
Yes but there were only some normal ttf's and other normal font types. Not only one single *.h oder *.c. And converting them doesn't work, too.
I think you uploaded a wrong RAR-File or this is the wrong link.
Last edited by DarkChris (2008-08-10 02:25:36)
Offline
you're right. the hosting site expired the file and overwrote the link, here is the right zip
http://www.mediafire.com/?sharekey=199b … b9a8902bda
Offline
Thank you
I hope it works. I'll try it later.
Offline
Hi,
I'm spanish and i'm making a game. I have to show letters like ñ, ¿ and á é í ...
So i tried this metod, but i wasn't able to make it work.
Can you upload a working example, with lib modified, and all files included? It would help me a lot.
I hope you can help me.
p.s. excuse me for my bad english
Offline