![]() |
|
I can't make this 8-bit font work |
Julio Sepia
Member #8,511
April 2007
|
Hello. I'm coding this little Pong game, and I designed this 8-bit font to give it a retro style: In my program, I import the font using load_bitmap(). I know I can use load_font(), but let me explain why I need the bitmap: The game must be able to run at two different resolutions (320x240, 640x480). For each resolution, I must have three versions of the font: small, medium and big. To that effect, I declared an array of pointers to fonts: FONT *fonts[4]; The program takes the original .bmp, then resizes it to 2, 4 and 8 times, and finally uses grab_font_from_bitmap() to fill the fonts array with the resized fonts. Here's the function, it works very well:
The only problem is that I want to have them as mono fonts (to be able to change the text color in textprintf), but the resulting fonts always turn out to be truecolor, no matter how hard I try to make them 8-bit and mono. What am I doing wrong? Thank you for your help. |
CGamesPlay
Member #2,559
July 2002
![]() |
IIRC, your input bitmap needs to be 8-bit and contain exactly 3 colors in order to be monospace. You should use set_color_conversion(COLORCONV_NONE) to load the bitmap and keep it in 8-bit mode, then grab it. (Alternatively, set_color_depth(8), grab the fonts, then set the proper color depth). Of course, your create_bitmap_ex probably makes it work. In that case, make sure the font has exactly 3 colors, I suppose. -- Ryan Patterson - <http://cgamesplay.com/> |
Milan Mimica
Member #3,877
September 2003
![]() |
The formating of your font bitmap is wrong. Use grabber to open a datafile containing mono font (unifont.dat in examples directory), and export the font as bitmap to see what it should look like. It should use only 2 or 3 colors.
-- |
Julio Sepia
Member #8,511
April 2007
|
I'm pretty sure it has three colors, I had Irfanview count them. I noticed something: everytime I apply the resizing function on the 8bpp bitmap, the program crashes. If I load a 32bpp version of it, it runs fine, but the fonts are considered truecolor (even though the bitmap only uses 3 colors). I get the same result with .pcx and .tga files. If I load a 32bpp image file converted to 8bpp with set_color_conversion(), the resizing function crashes anyway. I tried using your suggestion of set_color_conversion() on loading, and set_color_depth() on resizing, but nothing changed, sorry. I don't use any palette routines anywhere. Could that be the problem? I don't know how to work with palettes. EDIT: Milan is right, I was using the wrong colors. Now I made a BMP with the right colors (white-0 for the space between the characters, black for the background and full blue for the characters), but it still crashes. |
Milan Mimica
Member #3,877
September 2003
![]() |
Note that stretch_blit() cannot handle different color depths. Can't you just rescale the whole bitmap font instead of glyph per glyph?
-- |
Julio Sepia
Member #8,511
April 2007
|
Thank you for the suggestion, it does work fine if I just resize the bitmap itself. As for the stretch_blit, you can see I'm already using 8-bit color both for the source and tmp bitmaps (thanks to create_bitmap_ex). Anyway, I'll try making a separate program to convert my .pcx to a suitable .bmp mono font, let's hope it works. |
Andrei Ellman
Member #3,434
April 2003
|
If you want a function similar to textout() that can zoom the text, check out this snippet of code. AE. -- |
Julio Sepia
Member #8,511
April 2007
|
Thank you, it's the kind of effect I was looking for, but I have the impression that the zooming would be slow to do frame-by-frame, since my game already uses lots of special effects (mainly for interframe blending) despite being a simple Pong clone. |
Andrei Ellman
Member #3,434
April 2003
|
If the special effects or the game-gfx do not cross the score, you only need to update the score onscreen when it changes. If they do, you can always zoom the score to a separate bitmap (that is only updated when the score is updated), and blit the zoomed score to the screen on each render-cycle. Alternatively, if the source-font is sufficiently small, it might be quicker to zoom the score to screen than to blit from a pre-zoomed bitmap (whichever of the two methods is faster depends on several things, but give both a try to see which one is faster). AE. -- |
Julio Sepia
Member #8,511
April 2007
|
Yep, that's exactly what I do for the score. However, since I can't change the color of the text using textprintf, I had to make a function to do it. It works for the score, but it wouldn't be practical to apply the same functions to recolor and/or resize text in the help screen or the GUI. |
|