<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>I can&#39;t make this 8-bit font work</title>
		<link>http://www.allegro.cc/forums/view/590946</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 17 Apr 2007 21:01:35 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hello. I&#39;m coding this little Pong game, and I designed this 8-bit font to give it a retro style:<br /><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/4/4/44982cd76182f7586fa474e3284a2e5a.jpg" alt="psypong6x8_8bpp.jpg" width="113" height="127" /></p><p>In my program, I import the font using <tt>load_bitmap()</tt>. I know I can use <tt><b>load_font()</b></tt>, but let me explain why I need the bitmap:</p><p>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: <tt>FONT <b>*fonts[4]</b>;</tt></p><p>The program takes the original .bmp, then resizes it to 2, 4 and 8 times, and finally uses <tt>grab_font_from_bitmap()</tt> to fill the fonts array with the resized fonts. Here&#39;s the function, it works very well:</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><a href="http://www.allegro.cc/manual/FONT" target="_blank"><span class="a">FONT</span></a> <span class="k3">*</span>grab_font_from_bitmap_scaled<span class="k2">(</span><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>origin, BYTE scale<span class="k2">)</span><span class="k2">{</span></td></tr><tr><td class="number">2</td><td>  BYTE i, j<span class="k2">;</span></td></tr><tr><td class="number">3</td><td>  <span class="k1">unsigned</span> <span class="k1">int</span> char_w, char_h<span class="k2">;</span></td></tr><tr><td class="number">4</td><td>  <a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>tmp<span class="k2">;</span></td></tr><tr><td class="number">5</td><td>  <a href="http://www.allegro.cc/manual/FONT" target="_blank"><span class="a">FONT</span></a> <span class="k3">*</span>ret<span class="k2">;</span></td></tr><tr><td class="number">6</td><td>&#160;</td></tr><tr><td class="number">7</td><td>  <span class="c">/* An ASCII 8-bit font file has 14 rows and 16 columns */</span></td></tr><tr><td class="number">8</td><td>  char_w <span class="k3">=</span> <span class="k2">(</span>origin-&gt;w-1<span class="k2">)</span> <span class="k3">/</span> <span class="n">16</span><span class="k2">;</span></td></tr><tr><td class="number">9</td><td>  char_h <span class="k3">=</span> <span class="k2">(</span>origin-&gt;h-1<span class="k2">)</span> <span class="k3">/</span> <span class="n">14</span><span class="k2">;</span></td></tr><tr><td class="number">10</td><td>&#160;</td></tr><tr><td class="number">11</td><td>  <span class="c">/* We create an 8-bit bitmap */</span></td></tr><tr><td class="number">12</td><td>  tmp <span class="k3">=</span> <a href="http://www.allegro.cc/manual/create_bitmap_ex" target="_blank"><span class="a">create_bitmap_ex</span></a><span class="k2">(</span><span class="n">8</span>, <span class="n">16</span> <span class="k3">*</span> char_w <span class="k3">*</span> escala <span class="k3">+</span> <span class="n">1</span>, <span class="n">14</span> <span class="k3">*</span> char_h <span class="k3">*</span> escala <span class="k3">+</span> <span class="n">1</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">13</td><td>  <a href="http://www.allegro.cc/manual/clear_to_color" target="_blank"><span class="a">clear_to_color</span></a><span class="k2">(</span>tmp, <a href="http://www.allegro.cc/manual/makecol8" target="_blank"><span class="a">makecol8</span></a><span class="k2">(</span><span class="n">255</span>, <span class="n">255</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">14</td><td>&#160;</td></tr><tr><td class="number">15</td><td>  <span class="k1">for</span><span class="k2">(</span>i<span class="k3">=</span><span class="n">0</span><span class="k2">;</span> i<span class="k3">&lt;</span><span class="n">16</span><span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span><span class="k2">{</span></td></tr><tr><td class="number">16</td><td>    <span class="k1">for</span><span class="k2">(</span>j<span class="k3">=</span><span class="n">0</span><span class="k2">;</span> j<span class="k3">&lt;</span><span class="n">14</span><span class="k2">;</span> j<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span><span class="k2">{</span></td></tr><tr><td class="number">17</td><td>      <a href="http://www.allegro.cc/manual/stretch_blit" target="_blank"><span class="a">stretch_blit</span></a><span class="k2">(</span>origin, tmp,</td></tr><tr><td class="number">18</td><td>                   <span class="n">1</span><span class="k3">+</span>i<span class="k3">*</span>char_w, <span class="n">1</span><span class="k3">+</span>j<span class="k3">*</span>char_h,</td></tr><tr><td class="number">19</td><td>                   char_w, char_h,</td></tr><tr><td class="number">20</td><td>                   <span class="n">1</span><span class="k3">+</span>i<span class="k3">*</span>char_w<span class="k3">*</span>scale-i, <span class="n">1</span><span class="k3">+</span>j<span class="k3">*</span>char_h<span class="k3">*</span>scale-j,</td></tr><tr><td class="number">21</td><td>                   char_w<span class="k3">*</span>scale, char_h<span class="k3">*</span>scale<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">22</td><td>    <span class="k2">}</span></td></tr><tr><td class="number">23</td><td>  <span class="k2">}</span></td></tr><tr><td class="number">24</td><td>&#160;</td></tr><tr><td class="number">25</td><td>  ret <span class="k3">=</span> <a href="http://www.allegro.cc/manual/grab_font_from_bitmap" target="_blank"><span class="a">grab_font_from_bitmap</span></a><span class="k2">(</span>tmp<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">26</td><td>  <span class="k1">return</span> ret<span class="k2">;</span></td></tr><tr><td class="number">27</td><td><span class="k2">}</span></td></tr></tbody></table></div></div><p>

The only problem is that I want to have them as <u>mono fonts</u> (to be able to change the text color in textprintf), but the resulting fonts <b>always</b> turn out to be truecolor, no matter how hard I try to make them 8-bit and mono. <img src="http://www.allegro.cc/forums/smileys/cry.gif" alt=":&#39;(" /> Even if I apply <tt><b>grab_font_from_bitmap()</b></tt> on the original bitmap (without the resizing), I still get a truecolor font.</p><p>What am I doing wrong? Thank you for your help.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Julio Sepia)</author>
		<pubDate>Tue, 10 Apr 2007 22:07:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>IIRC, your input bitmap needs to be 8-bit and contain exactly 3 colors in order to be monospace. You should use <tt>set_color_conversion(COLORCONV_NONE)</tt> to load the bitmap and keep it in 8-bit mode, then grab it. (Alternatively, <tt>set_color_depth(8)</tt>, grab the fonts, then set the proper color depth).</p><p>Of course, your create_bitmap_ex probably makes it work. In that case, make sure the font has exactly 3 colors, I suppose.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CGamesPlay)</author>
		<pubDate>Wed, 11 Apr 2007 00:20:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>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.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Milan Mimica)</author>
		<pubDate>Wed, 11 Apr 2007 00:36:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m pretty sure it has three colors, I had Irfanview count them. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><p>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.</p><p>I tried using your suggestion of set_color_conversion() on loading, and set_color_depth() on resizing, but nothing changed, sorry. <img src="http://www.allegro.cc/forums/smileys/sad.gif" alt=":(" /> There must be something wrong with my resizing.</p><p>I don&#39;t use any palette routines anywhere. Could that be the problem? I don&#39;t know how to work with palettes.</p><p>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. <img src="http://www.allegro.cc/forums/smileys/cry.gif" alt=":&#39;(" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Julio Sepia)</author>
		<pubDate>Wed, 11 Apr 2007 00:55:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Note that stretch_blit() cannot handle different color depths.</p><p>Can&#39;t you just rescale the whole bitmap font instead of glyph per glyph?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Milan Mimica)</author>
		<pubDate>Wed, 11 Apr 2007 03:30:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you for the suggestion, it does work fine if I just resize the bitmap itself. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> I was resizing it glyph by glyph because I thought there was supposed to be exactly 1 pixel between each row of characters, but I was obviously wrong.</p><p>As for the stretch_blit, you can see I&#39;m already using 8-bit color both for the source and tmp bitmaps (thanks to create_bitmap_ex). Anyway, I&#39;ll try making a separate program to convert my .pcx to a suitable .bmp mono font, let&#39;s hope it works.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Julio Sepia)</author>
		<pubDate>Wed, 11 Apr 2007 20:49:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you want a function similar to textout() that can zoom the text, check out <a href="http://allegro.cc/forums/thread/590903/664826#target">this snippet of code</a>.</p><p>AE.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Andrei Ellman)</author>
		<pubDate>Thu, 12 Apr 2007 17:58:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you, it&#39;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.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Julio Sepia)</author>
		<pubDate>Thu, 12 Apr 2007 22:21:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>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).</p><p>AE.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Andrei Ellman)</author>
		<pubDate>Sun, 15 Apr 2007 22:27:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yep, that&#39;s exactly what I do for the score. However, since I can&#39;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&#39;t be practical to apply the same functions to recolor and/or resize text in the help screen or the GUI. <img src="http://www.allegro.cc/forums/smileys/sad.gif" alt=":(" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Julio Sepia)</author>
		<pubDate>Tue, 17 Apr 2007 21:01:35 +0000</pubDate>
	</item>
</rss>
