FONT PNG resize

Previous topic - Next topic

Alex_R

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!!

spicypixel

#1
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)
ENDIF

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#)
NEXT
ENDFUNCTION
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

Crivens

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).

Cheers

Cheers 
Current fave quote: Cause you like musicians and I like people with boobs.

ampos

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.

Alex_R

Thank you for your answers and ideas. Very useful!!  :)