Using files for fonts in BlitzPlus/Blitz3D
BlitzPlus Forums/BlitzPlus Programming/Using files for fonts in BlitzPlus/Blitz3D
| ||
I was wondering if this was possible |
| ||
If you are referring to bitmap fonts, it is possible and there are tons of submitted codes in the forum and archives: http://www.blitzbasic.com/codearcs/codearcs.php?code=698 otherwise please do elaborate.. |
| ||
Here's some Blitz3D code I use for generating a bitmap image file.Graphics 800, 600, 0, 2 font = LoadFont( "Arial", 16, True ) SetFont font ; Find widest char. w = 0 For n = 0 To 9 w1 = StringWidth( n ) If w1 > w Then w = w1 : n1 = n Next h = FontHeight() img = CreateImage( w, h * 10 ) SetBuffer ImageBuffer( img ) Color 255, 255, 255 ClsColor 0, 0, 0 Cls For n = 0 To 9 Text w / 2, n * h, n, True Next SaveImage img, "arial num text.bmp" End Once you have your image you can then load it in as an animated image and use it to display the individual characters as frames in the animated image. You can leave the image as a BMP (bitmap) or use a tool like Irfanview ( http://www.irfanview.com/ ) to convert it to PNG, etc. Global G_hud_arial_numbers Const C_HUD_ARIAL_NUM_WIDTH = 7 Const C_HUD_ARIAL_NUM_HEIGHT = 16 G_hud_arial_numbers = LoadAnimImage( "media\hud-images\arial num text.png", C_HUD_ARIAL_NUM_WIDTH, C_HUD_ARIAL_NUM_HEIGHT, 0, 10 ) You can then draw the image frame with the character you want to draw wherever you want it on the screen. Note that for 2D graphics drawn over 3D you need to do the DrawImage operation between the RenderWorld and Flip commands. RenderWorld DrawImage G_hud_arial_numbers, x, y, framenum Flip If you want to use a custom font when generating the font image files then you'll need to install the font (you can grab fonts from sites such as http://www.dafont.com/ , http://www.fontsquirrel.com/ , etc ) and then load it with LoadFont while specifying it's internal name (not the filename). Loading fonts can be a bit funky. You can find more info about that at: http://www.blitzbasic.com/b3ddocs/command.php?name=LoadFont&ref=2d_cat |
| ||
I was just wondering if a ttf or something similar could be implemented by file without installing to the fonts folder. I actually did manage to do this anyway with LoadFont. |
| ||
I think I have tried this before and it is possible. |
| ||
It is possible to use ttf and fon fonts that aren't installed. HOWEVER * The font file itself must be RENAMED to match the Font Name displayed. FOr example "Arial Narrow" which has a file name of "ArialN.TTF" or such, should be renamed to "Arial Narrow.ttf"*** *The fonts must be placed within the same directory as the executable. (I actually need to check this, since I believe providing a valid, full path should be sufficient) Somewhere I made a short example code where you can test that fonts are loaded and working correctly.... (Will update with link soon...) ***Just an example, please don't actually rename the Arial Narrow font, since this is a core Windows file and should be within %WINDIR%\Fonts\ folder and left well alone!!! I just used it as an example of a ttf font |
| ||
It is possible to use ttf and fon fonts that aren't installed. HOWEVER * The font file itself must be RENAMED to match the Font Name displayed. FOr example "Arial Narrow" which has a file name of "ArialN.TTF" or such, should be renamed to "Arial Narrow.ttf"*** *The fonts must be placed within the same directory as the executable. (I actually need to check this, since I believe providing a valid, full path should be sufficient) Somewhere I made a short example code where you can test that fonts are loaded and working correctly.... _______________ http://www.blitzbasic.com/codearcs/codearcs.php?code=3061 _______________ ***Just an example, please don't actually rename the Arial Narrow font, since this is a core Windows file and should be within %WINDIR%\Fonts\ folder and left well alone!!! I just used it as an example of a ttf font |