GLBasic forum

Feature request => 2D => Topic started by: Alex_R on 2012-Mar-06

Title: FONT PNG resize
Post by: Alex_R on 2012-Mar-06
In all my 2D games I use pollyvector in order to resize all graphics. My tiled maps, buttons, menu windows, button windows, etc. are pollyvectors. With this methode is easy to adapt the game to every screen resolution. But there is only one thing I can not resize. The text graphics. Of course I can make a lot of PNG's with several sizes. But I wonder if is it possible to load a huge PNG text graphic and resize it after loaded. Someting like this:
Code (glbasic) Select
LOADFONT "font1.png",0
RESIZEFONT 0,sx%,sy%

Thank you!!
Title: Re: FONT PNG resize
Post by: spicypixel on 2012-Mar-06
You could always include the font chars with your texture atlas and print a bitmap font instead would mean you have all the scaling but the downside it will use more of your texture atlas space.

Code (glbasic) Select

// .----------------------------------------------------------------------.
// |                                                                      |
// | Bitmap Print Routine                                                 |
// |                                                                      |
// '----------------------------------------------------------------------'
FUNCTION GE_PrintBMP: text$, textx, texty, textangle, textsx#, textsy#, Centre = FALSE
LOCAL str_length
LOCAL pchar
text$ = UCASE$(text$) // Remove with a full font!
str_length = LEN(text$)

// Centralise Text
IF Centre = TRUE
textx = ((GE_TargetScrX - (str_length * TileWidth% * textsx#))/2) - ((TileWidth% * textsx#)/2)

FOR scr_print = 0 TO (str_length - 1)
pchar = ASC(MID$(text$,scr_print,1))
PolyZoom ((pchar-32), textx + ((scr_print * TileWidth%) * textsx#), texty, textsx#, textsy#)
Title: Re: FONT PNG resize
Post by: Crivens on 2012-Mar-06
The routine I use to dynamically resize (inc. alpha channels) all non-3D graphics (see code snippets for old version) works fine for all graphics except font files. They work but have a lot of overlaps between letters. This leads me to believe the built in font functionality does not just simply work by resizing a working font file.

What I do is use CREATESCREEN to paste my text sentences and resize for the resolution. Then have a sprite per sentence. That way no dynamic resizing when in the main game loop. Only downside is increased memory usage. Not a major big deal. For scores and quickly updating text I use my dynamic resize technique on the whole font file but make sure there are bigger gaps between letters (is an option in the latest font generator). That then gets rid of overlaps but because of the gaps I then have a better routine for printing numbers.

To be honest though in the future it's all 3D for me. Most of my game is 3D anyway (is pseudo 3D in that it looks 2D) which means no resizing of graphics is necessary. Only my menu items are not 3D, and required dynamic resizing. But my next game even the menu items will be 3D too. Only downside is the increased memory footprint because you shouldn't resize the textures as they don't map correctly (why not BTW? Couldn't GLB resize the texture internally if too small for the object? Although I'm guessing that puts the memory footprint back up anyway with the downside that zoomed up a 3D object will look blockier).


Title: Re: FONT PNG resize
Post by: ampos on 2012-Mar-06
Look for Z_PRINT or something similar in code section. I made a routine that loads a font (as font AND sprite) and using polyvector to print with scale, plus some other things.
Title: Re: FONT PNG resize
Post by: Alex_R on 2012-Mar-06
Thank you for your answers and ideas. Very useful!!  :)