You are not logged in.
I know this function is suppose to change but meanwhile...
You don't need to use strlen in the GRRLIB_Printf function because vsprintf return the number of characters written.
For more information on vsprintf: http://msdn.microsoft.com/en-us/library … S.71).aspx
The variable size was not used in the "for" loop, so I change strlen(tmp) to size.
void GRRLIB_Printf(f32 xpos, f32 ypos, u8 data[], u32 color, f32 zoom, const char *text,...){ int i, size; 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*8*zoom, ypos, 8, 8, data, 0, zoom, zoom, c, 128, col); } }
Last edited by Crayon (2008-07-17 07:25:55)
Offline
I added the support for carriage return, I needed that for my word wrapping function:
void GRRLIB_Printf(f32 xpos, f32 ypos, u8 data[], u32 color, f32 zoom, const char *text,...){ int i, size, n = 0; char tmp[1024]; u16 charHeight = 8, charWidth = 8; 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++, n++) { if(tmp[i] == '\n') { ypos += (charHeight + 2); // 2 pixels between each line n = -1; } else { GRRLIB_DrawChar(xpos+n*charWidth*zoom, ypos, charWidth, charHeight, data, 0, zoom, zoom, tmp[i], 128, col ); } } }
Offline
hi crayon,
i think you shouldnt use 2 pixels space hardcode but also the zoom factor to calculate your line space.
ps: can you explain the syntax you used for your "for(i=0; i<size; i++, n++)" i never used this kind of call (with a 4th param).
Offline
NoNameNo wrote:
i think you shouldnt use 2 pixels space hardcode but also the zoom factor to calculate your line space.
Hi, you are right, I was thinking of using something like (char height * zoom) * 20%, like that any size would look nice. It's just that I know you did modification to the lib and I don't want to make something that will be useless in the new version. Anyway in the 3.0.1a version font could not larger than 8 pixels (1024 limit).
NoNameNo wrote:
ps: can you explain the syntax you used for your "for(i=0; i<size; i++, n++)" i never used this kind of call (with a 4th param).
The third parameter is a list of things to do after each loop. In that case it increment i and n. It's the same thing has putting n++ at the last line of code in the loop.
Offline
The whole point of the zoom matrix is supposed to be for avoiding your multiplying stuff :-/
This will make a bunch of quads next to each of "width" and "height", and put them like you did above
All that's needed is for you to supply the texture coordinates for your text, which using scaleTexCoordManual(16,16) or whatever, would end up being (character & 0x0F)(character>>4 & 0x0F) for upper left, the others are just ones like x+1, y+1
int count = 0; PositionMatrix = Translate(startX,startY)->scale(desired character width, desired character height,1) foreach character in String if(character = \n) { count=0; PositionMatrix = positionMatrix.translate(0,1+(linebreak%),0); } else { DrawChar[x](quad:(0,0)(1,0)(1,1)(0,1)) PositionMatrix.applyTranslate (count++,0,0) }
Last edited by RedShade (2008-07-17 19:51:38)
Offline
I just recalled how you could avoid the thing regarding manual texture scale. If you set the vertex format for textures to
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, U8, 4);
then
u8 s = desiredText[x]&0x0F; u8 t = (desiredText[x]>>4)&0x0F;
The resulting texture coordinates you need to use afterward are
GX_TexCoord2u8(s , t); GX_TexCoord2u8(s+1, t); GX_TexCoord2u8(s+1,t+1); GX_TexCoord2u8(s ,t+1);
Last edited by RedShade (2008-07-19 22:44:26)
Offline