Dark Bit Factory & Gravity
PROGRAMMING => Other languages => Blitz => Topic started by: Pixel_Outlaw on January 18, 2008
-
I know how to load textures in Blitzmax and apply them as images to quads forming on screen text. However how can I load non image based fonts and use them within Opengl? The problem with bitmap fonts is that they have to have a set cell width and this looks terrible with narrow letters such as the letter 'i" and lowercase "l". I've always used bitmap fonts but really it would be nice to have fonts appear as they do with the gldrawtext command.
-
The drawtext command in the Max2d module of Blitzmax uses regular fonts loaded via some code you can find in the following sources. font.bmx, imagefont.bmx, image.bmx. But its might be difficult to figure out what does what since a lot of the code from Blitzmax is spread over several sources and a lot of times types, methods and functions are overwritten in other types which are extended. So it can be quite confusing.
This is why I decided to go with bitmap fonts created from truetype via a tool I made. This tool will then place the characters of the font onto a power2 image and save out either a text or binary list of where each character is on the image and what size is has. I then load this image with my sprite engine and use this one texture and UV coords to create quads with individual characters on them. This works just fine for what I have used it for so far. But since I already did the font-2-bitmap tool a long time ago, it was ofcause not that difficult to get the rest of the work done.
But I am thinking you would like to get the font loaded directly into your program and I unfortunately do not know enough about how truetype font files are put together to know how to handle them other than drawing them onto a buffer and grabbing what is needed.
I have used varied width bitmap fonts lots of times even with BlitzPlus when I was using that for making demos. Its fairly easy to setup, but it needs that little extra work of packing a font onto an image and making the coord sets for each character. The advantage is that you only use one texture for the entire font instead one for each character.
[edit] I just did a search and found this: http://gpwiki.org/index.php/OpenGL:Tutorials:Font_System (http://gpwiki.org/index.php/OpenGL:Tutorials:Font_System) It has a C font class which uses the bitmap creator from AngelCode, and if you check the angelCode page, you will see that it packs the characters onto a bitmap and then writes a list for for characters in either txt,xml or binary. I think that most people who do demo stuff uses a bitmap and some sort of bitmap font code.
-
OK, well I would actually like to use my own bitmap fonts if possible then. I guess the question is how do I account for spacing with large or small characters?
-
Here is an example of a font converted and packed into a bitmap image.
(http://zac-interactive.dk/temp/font.png)
Here is an example of the font data generated by my font tool.
32 ; font height
; data format: ascii code, x, y, width
32,0,0,16
33,16,0,4
34,20,0,8
35,28,0,18
36,46,0,13
37,59,0,21
38,80,0,20
39,100,0,4
40,104,0,8
41,112,0,8
42,120,0,13
43,133,0,17
44,150,0,6
45,156,0,11
46,167,0,4
47,171,0,13
48,184,0,14
49,198,0,10
50,208,0,13
51,221,0,13
52,234,0,14
53,0,32,13
54,13,32,13
55,26,32,12
56,38,32,12
57,50,32,13
58,63,32,4
59,67,32,6
60,73,32,17
61,90,32,17
62,107,32,17
63,124,32,11
64,135,32,26
65,161,32,21
66,182,32,18
67,200,32,19
68,219,32,22
69,0,64,19
70,19,64,18
71,37,64,22
72,59,64,23
73,82,64,10
74,92,64,13
75,105,64,20
76,125,64,18
77,143,64,26
78,169,64,21
79,190,64,20
80,210,64,18
81,228,64,20
82,0,96,21
83,21,96,15
84,36,96,20
85,56,96,22
86,78,96,21
87,99,96,31
88,130,96,22
89,152,96,20
90,172,96,18
91,190,96,13
92,203,96,13
93,216,96,13
94,229,96,13
95,0,128,16
96,16,128,7
97,23,128,13
98,36,128,14
99,50,128,12
100,62,128,14
101,76,128,13
102,89,128,12
103,101,128,16
104,117,128,16
105,133,128,8
106,141,128,9
107,150,128,15
108,165,128,8
109,173,128,24
110,197,128,16
111,213,128,13
112,226,128,14
113,240,128,14
114,0,160,12
115,12,160,10
116,22,160,11
117,33,160,16
118,49,160,15
119,64,160,20
120,84,160,15
121,99,160,16
122,115,160,12
123,127,160,10
124,137,160,4
125,141,160,10
126,151,160,17
127,168,160,16
http://zac-interactive.dk/temp/bitmapfontexample.rar (http://zac-interactive.dk/temp/bitmapfontexample.rar) This is some code I did a while ago, and it shows how you could setup a type and load the image and data. The code also shows you how to draw a string of characters connected with the right widths. It is using the standard max2d commands, with a function that can draw part of an image. So there will be some differences when dealing directly with openGL ofcause. Especially since you probably will be using quads with characters picked on the texture/image using UV coords. Just ask if you hit the wall and cannot get something working. I have it fully working for my sprite engine, and I would be happy to provide code, but I am thinking that you would like to try it out yourself first.
-
check out this thread it might help you out:
http://www.blitzmax.com/Community/posts.php?topic=71132
-
I've got a program that will take any Windows font and spit out a power-of-2 bmp along with the boxes that define each character. From those you could work out the uvs needed in OpenGL. It's what I use in my demos.
Source and EXE attached. The bin file is just 4 32bit values per character, x,y,w,h.
Jim
-
Ok thanks. I'll get back to you if I need help. :goodpost: