<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Slowness when drawing fonts</title>
		<link>http://www.allegro.cc/forums/view/607522</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 15 Jun 2011 06:03:27 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi guys, I&#39;m noticing an incredible slowness when drawing fonts.</p><p>I&#39;m initializing a font on a second thread to avoid having to initialize it when the object is created, since it&#39;s slow and I can notice my game getting stuck a little bit. But, after initialize it when I draw it for <i>first time</i>, I still noticing my game getting stuck, even if I just draw one letter. Once the text has been drawn for first time, the slowness disappear... I just wanted to know if this is normal, or there is a problem.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Sat, 04 Jun 2011 20:16:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>When using TrueType fonts, glyphs are cached when they are drawn for the first time. You should expect this initial slowness as a result.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Todd Cope)</author>
		<pubDate>Sun, 05 Jun 2011 21:50:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hmm, why are they not cached when the font is loaded?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Sun, 05 Jun 2011 22:15:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Probably because caching thousands of unicode characters is not feasible. I think there should be an <span class="source-code">al_cache_font_glyph_ranges<span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_FONT"><span class="a">ALLEGRO_FONT</span></a> <span class="k3">*</span> fp, <span class="k1">int</span> ranges_n, <span class="k1">int</span> ranges<span class="k2">[</span><span class="k2">]</span><span class="k2">)</span></span> function. If you know what characters you are going to be using, this would be quite useful.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Todd Cope)</author>
		<pubDate>Sun, 05 Jun 2011 22:29:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ah, so it just caches those characters you&#39;re using when you first draw them.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Sun, 05 Jun 2011 22:37:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes I think they should be a way to &quot;prepare&quot; the font within the loading process? doesn&#39;t matter how long it takes, I don&#39;t thin would take too much time anyway... I would prefer that than this...<br /> <br />I did this little example to see if there is something wrong with my game. But the problem still there.</p><p><a href="http://www.allegro.cc/files/attachment/604220">example.zip</a>	</p><p>if you want the .exe download <a href="http://www.allegro.cc/files/attachment/604221">this</a>	</p><p>Once I draw the font for first time the velocity increase. Here I loaded the same font 5 times, so you can check it more than just once before closing the application. And I&#39;m playing a beep continuously so you can hear the interruption when the font is drawn.</p><p>I also put an <span class="source-code"><span class="k1">if</span></span> to draw 10 bitmaps at the same time, to prove that drawing fonts for first time is ridiculously slow.</p><p>Key A, S, D, F and G draw text. Key B draw 10 bitmaps.</p><p>I didn&#39;t destroy the objects, anyway it&#39;s just an example... </p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">   1</span><span class="p">#include &lt;stdio.h&gt;</span>
<span class="number">   2</span><span class="p">#include &lt;list&gt;</span>
<span class="number">   3</span>
<span class="number">   4</span><span class="p">#define ALLEGRO_STATICLINK</span>
<span class="number">   5</span><span class="p">#include "allegro5/allegro.h"</span>
<span class="number">   6</span><span class="p">#include "allegro5/allegro_font.h"</span>
<span class="number">   7</span><span class="p">#include "allegro5/allegro_ttf.h"</span>
<span class="number">   8</span><span class="p">#include "allegro5/allegro_image.h"</span>
<span class="number">   9</span><span class="p">#include &lt;allegro5/allegro_audio.h&gt;</span>
<span class="number">  10</span><span class="p">#include &lt;allegro5/allegro_acodec.h&gt;</span>
<span class="number">  11</span>
<span class="number">  12</span><span class="k1">class</span> SPOT <span class="k2">{</span>
<span class="number">  13</span>
<span class="number">  14</span>   private:
<span class="number">  15</span>
<span class="number">  16</span>      <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a>  <span class="k3">*</span>bmp<span class="k2">;</span>
<span class="number">  17</span>      <span class="k1">float</span> posi_X, posi_Y, vel<span class="k2">;</span>
<span class="number">  18</span>
<span class="number">  19</span>   public:
<span class="number">  20</span>
<span class="number">  21</span>      SPOT<span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>T_bmp, <span class="k1">float</span> T_y, <span class="k1">float</span> T_vel<span class="k2">)</span> <span class="k2">:</span>
<span class="number">  22</span>      bmp    <span class="k2">(</span>T_bmp<span class="k2">)</span>,
<span class="number">  23</span>      posi_X <span class="k2">(</span><span class="k3">-</span><span class="n">100</span><span class="k2">)</span>,
<span class="number">  24</span>      posi_Y <span class="k2">(</span>T_y<span class="k2">)</span>,
<span class="number">  25</span>      vel    <span class="k2">(</span>T_vel<span class="k2">)</span><span class="k2">{</span><span class="k2">}</span>
<span class="number">  26</span>
<span class="number">  27</span>   ~SPOT<span class="k2">(</span><span class="k2">)</span><span class="k2">{</span>
<span class="number">  28</span>
<span class="number">  29</span>      <a href="http://www.allegro.cc/manual/al_destroy_bitmap"><span class="a">al_destroy_bitmap</span></a><span class="k2">(</span>bmp<span class="k2">)</span><span class="k2">;</span>
<span class="number">  30</span>
<span class="number">  31</span>   <span class="k2">}</span>
<span class="number">  32</span>
<span class="number">  33</span>   <span class="k1">void</span> move<span class="k2">(</span><span class="k2">)</span><span class="k2">{</span>
<span class="number">  34</span>
<span class="number">  35</span>      <a href="http://www.allegro.cc/manual/al_draw_bitmap"><span class="a">al_draw_bitmap</span></a><span class="k2">(</span>bmp, posi_X, posi_Y, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  36</span>
<span class="number">  37</span>      posi_X <span class="k3">+</span><span class="k3">=</span> vel<span class="k2">;</span>
<span class="number">  38</span>
<span class="number">  39</span>      <span class="k1">if</span><span class="k2">(</span>posi_X&gt;640<span class="k2">)</span> posi_X<span class="k3">=</span><span class="k3">-</span><span class="n">100</span><span class="k2">;</span>
<span class="number">  40</span>
<span class="number">  41</span>   <span class="k2">}</span>
<span class="number">  42</span>
<span class="number">  43</span><span class="k2">}</span><span class="k2">;</span>
<span class="number">  44</span>
<span class="number">  45</span><span class="k1">int</span> main<span class="k2">(</span><span class="k2">)</span>
<span class="number">  46</span><span class="k2">{</span>
<span class="number">  47</span>    <span class="k1">if</span><span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/al_init"><span class="a">al_init</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span>
<span class="number">  48</span>    <span class="k2">{</span>
<span class="number">  49</span>        <a href="http://www.delorie.com/djgpp/doc/libc/libc_345.html" target="_blank">fprintf</a><span class="k2">(</span>stderr, <span class="s">"Failed to initialize Allegro.\n"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  50</span>        <span class="k1">return</span> <span class="k3">-</span><span class="n">1</span><span class="k2">;</span>
<span class="number">  51</span>    <span class="k2">}</span>
<span class="number">  52</span>
<span class="number">  53</span>    <a href="http://www.allegro.cc/manual/al_init_font_addon"><span class="a">al_init_font_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  54</span>    <a href="http://www.allegro.cc/manual/al_init_ttf_addon"><span class="a">al_init_ttf_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  55</span>    <a href="http://www.allegro.cc/manual/al_init_image_addon"><span class="a">al_init_image_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  56</span>    <a href="http://www.allegro.cc/manual/al_install_audio"><span class="a">al_install_audio</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  57</span>    <a href="http://www.allegro.cc/manual/al_init_acodec_addon"><span class="a">al_init_acodec_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  58</span>    <a href="http://www.allegro.cc/manual/al_reserve_samples"><span class="a">al_reserve_samples</span></a><span class="k2">(</span><span class="n">1</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  59</span>    <a href="http://www.allegro.cc/manual/al_install_keyboard"><span class="a">al_install_keyboard</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  60</span>
<span class="number">  61</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_DISPLAY"><span class="a">ALLEGRO_DISPLAY</span></a> <span class="k3">*</span>display <span class="k3">=</span> NULL<span class="k2">;</span>
<span class="number">  62</span>    display <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_display"><span class="a">al_create_display</span></a><span class="k2">(</span><span class="n">640</span>,<span class="n">480</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  63</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a>  <span class="k3">*</span>Obj_Bmp <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_bitmap"><span class="a">al_load_bitmap</span></a><span class="k2">(</span><span class="s">"spot.png"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  64</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a>  <span class="k3">*</span>Obj_Bmp2<span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_bitmap"><span class="a">al_load_bitmap</span></a><span class="k2">(</span><span class="s">"spot.png"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  65</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_FONT"><span class="a">ALLEGRO_FONT</span></a>    <span class="k3">*</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a>    <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_ttf_font"><span class="a">al_load_ttf_font</span></a><span class="k2">(</span><span class="s">"consola.ttf"</span>,<span class="n">72</span>,<span class="n">0</span> <span class="k2">)</span><span class="k2">;</span>
<span class="number">  66</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_FONT"><span class="a">ALLEGRO_FONT</span></a>    <span class="k3">*</span>font2    <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_ttf_font"><span class="a">al_load_ttf_font</span></a><span class="k2">(</span><span class="s">"consola.ttf"</span>,<span class="n">72</span>,<span class="n">0</span> <span class="k2">)</span><span class="k2">;</span>
<span class="number">  67</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_FONT"><span class="a">ALLEGRO_FONT</span></a>    <span class="k3">*</span>font3    <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_ttf_font"><span class="a">al_load_ttf_font</span></a><span class="k2">(</span><span class="s">"consola.ttf"</span>,<span class="n">72</span>,<span class="n">0</span> <span class="k2">)</span><span class="k2">;</span>
<span class="number">  68</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_FONT"><span class="a">ALLEGRO_FONT</span></a>    <span class="k3">*</span>font4    <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_ttf_font"><span class="a">al_load_ttf_font</span></a><span class="k2">(</span><span class="s">"consola.ttf"</span>,<span class="n">72</span>,<span class="n">0</span> <span class="k2">)</span><span class="k2">;</span>
<span class="number">  69</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_FONT"><span class="a">ALLEGRO_FONT</span></a>    <span class="k3">*</span>font5    <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_ttf_font"><span class="a">al_load_ttf_font</span></a><span class="k2">(</span><span class="s">"consola.ttf"</span>,<span class="n">72</span>,<span class="n">0</span> <span class="k2">)</span><span class="k2">;</span>
<span class="number">  70</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_KEYBOARD_STATE"><span class="a">ALLEGRO_KEYBOARD_STATE</span></a> keyboard<span class="k2">;</span>
<span class="number">  71</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_SAMPLE"><span class="a">ALLEGRO_SAMPLE</span></a> <span class="k3">*</span>beep <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_sample"><span class="a">al_load_sample</span></a><span class="k2">(</span><span class="s">"beep.ogg"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  72</span>
<span class="number">  73</span>    <span class="c">//Obj_Bmp = al_load_bitmap("spot.png");</span>
<span class="number">  74</span>
<span class="number">  75</span>
<span class="number">  76</span>    std::list<span class="k3">&lt;</span>SPOT<span class="k3">*</span><span class="k3">&gt;</span> Spo_List<span class="k2">;</span>
<span class="number">  77</span>
<span class="number">  78</span>    <span class="k1">for</span><span class="k2">(</span><span class="k1">int</span> a<span class="k3">=</span><span class="n">0</span><span class="k2">;</span> a<span class="k3">&lt;</span><span class="n">10</span><span class="k2">;</span> a<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span>
<span class="number">  79</span>       Spo_List.push_back<span class="k2">(</span><span class="k1">new</span> SPOT<span class="k2">(</span>Obj_Bmp, <a href="http://www.delorie.com/djgpp/doc/libc/libc_637.html" target="_blank">rand</a><span class="k2">(</span><span class="k2">)</span>%<span class="n">480</span>, <a href="http://www.delorie.com/djgpp/doc/libc/libc_637.html" target="_blank">rand</a><span class="k2">(</span><span class="k2">)</span>%<span class="n">10</span><span class="k3">+</span><span class="n">1</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  80</span>
<span class="number">  81</span>    <span class="k1">while</span><span class="k2">(</span><span class="n">1</span><span class="k2">)</span><span class="k2">{</span>
<span class="number">  82</span>       <a href="http://www.allegro.cc/manual/al_get_keyboard_state"><span class="a">al_get_keyboard_state</span></a><span class="k2">(</span><span class="k3">&amp;</span>keyboard<span class="k2">)</span><span class="k2">;</span>
<span class="number">  83</span>
<span class="number">  84</span>       <a href="http://www.allegro.cc/manual/al_clear_to_color"><span class="a">al_clear_to_color</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span><span class="n">50</span>,<span class="n">10</span>,<span class="n">70</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  85</span>
<span class="number">  86</span>       <span class="k1">if</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_key_down"><span class="a">al_key_down</span></a><span class="k2">(</span><span class="k3">&amp;</span>keyboard, ALLEGRO_KEY_A<span class="k2">)</span><span class="k2">)</span>
<span class="number">  87</span>       <a href="http://www.allegro.cc/manual/al_draw_text"><span class="a">al_draw_text</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a>, <a href="http://www.allegro.cc/manual/al_map_rgba"><span class="a">al_map_rgba</span></a><span class="k2">(</span><span class="n">255</span>,<span class="n">255</span>,<span class="n">255</span>,<span class="n">255</span><span class="k2">)</span>,  <span class="n">640</span><span class="k3">/</span><span class="n">2</span>, <span class="k2">(</span><span class="n">480</span><span class="k3">/</span><span class="n">4</span><span class="k2">)</span>,ALLEGRO_ALIGN_CENTRE, <span class="s">"Slow Font : (!"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  88</span>
<span class="number">  89</span>       <span class="k1">else</span> <span class="k1">if</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_key_down"><span class="a">al_key_down</span></a><span class="k2">(</span><span class="k3">&amp;</span>keyboard, ALLEGRO_KEY_S<span class="k2">)</span><span class="k2">)</span>
<span class="number">  90</span>       <a href="http://www.allegro.cc/manual/al_draw_text"><span class="a">al_draw_text</span></a><span class="k2">(</span>font2, <a href="http://www.allegro.cc/manual/al_map_rgba"><span class="a">al_map_rgba</span></a><span class="k2">(</span><span class="n">255</span>,<span class="n">255</span>,<span class="n">255</span>,<span class="n">255</span><span class="k2">)</span>, <span class="n">640</span><span class="k3">/</span><span class="n">2</span>,  <span class="n">50</span><span class="k3">+</span><span class="k2">(</span><span class="n">480</span><span class="k3">/</span><span class="n">4</span><span class="k2">)</span>,ALLEGRO_ALIGN_CENTRE, <span class="s">"Slow Font : (!"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  91</span>
<span class="number">  92</span>       <span class="k1">else</span> <span class="k1">if</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_key_down"><span class="a">al_key_down</span></a><span class="k2">(</span><span class="k3">&amp;</span>keyboard, ALLEGRO_KEY_D<span class="k2">)</span><span class="k2">)</span>
<span class="number">  93</span>       <a href="http://www.allegro.cc/manual/al_draw_text"><span class="a">al_draw_text</span></a><span class="k2">(</span>font3, <a href="http://www.allegro.cc/manual/al_map_rgba"><span class="a">al_map_rgba</span></a><span class="k2">(</span><span class="n">255</span>,<span class="n">255</span>,<span class="n">255</span>,<span class="n">255</span><span class="k2">)</span>, <span class="n">640</span><span class="k3">/</span><span class="n">2</span>, <span class="n">100</span><span class="k3">+</span><span class="k2">(</span><span class="n">480</span><span class="k3">/</span><span class="n">4</span><span class="k2">)</span>,ALLEGRO_ALIGN_CENTRE, <span class="s">"Slow Font : (!"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  94</span>
<span class="number">  95</span>       <span class="k1">else</span> <span class="k1">if</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_key_down"><span class="a">al_key_down</span></a><span class="k2">(</span><span class="k3">&amp;</span>keyboard, ALLEGRO_KEY_F<span class="k2">)</span><span class="k2">)</span>
<span class="number">  96</span>       <a href="http://www.allegro.cc/manual/al_draw_text"><span class="a">al_draw_text</span></a><span class="k2">(</span>font4, <a href="http://www.allegro.cc/manual/al_map_rgba"><span class="a">al_map_rgba</span></a><span class="k2">(</span><span class="n">255</span>,<span class="n">255</span>,<span class="n">255</span>,<span class="n">255</span><span class="k2">)</span>, <span class="n">640</span><span class="k3">/</span><span class="n">2</span>, <span class="n">150</span><span class="k3">+</span><span class="k2">(</span><span class="n">480</span><span class="k3">/</span><span class="n">4</span><span class="k2">)</span>,ALLEGRO_ALIGN_CENTRE, <span class="s">"Slow Font : (!"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  97</span>
<span class="number">  98</span>       <span class="k1">else</span> <span class="k1">if</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_key_down"><span class="a">al_key_down</span></a><span class="k2">(</span><span class="k3">&amp;</span>keyboard, ALLEGRO_KEY_G<span class="k2">)</span><span class="k2">)</span>
<span class="number">  99</span>       <a href="http://www.allegro.cc/manual/al_draw_text"><span class="a">al_draw_text</span></a><span class="k2">(</span>font5, <a href="http://www.allegro.cc/manual/al_map_rgba"><span class="a">al_map_rgba</span></a><span class="k2">(</span><span class="n">255</span>,<span class="n">255</span>,<span class="n">255</span>,<span class="n">255</span><span class="k2">)</span>, <span class="n">640</span><span class="k3">/</span><span class="n">2</span>, <span class="n">200</span><span class="k3">+</span><span class="k2">(</span><span class="n">480</span><span class="k3">/</span><span class="n">4</span><span class="k2">)</span>,ALLEGRO_ALIGN_CENTRE, <span class="s">"Slow Font : (!"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 100</span>
<span class="number"> 101</span>       <span class="k1">else</span> <span class="k1">if</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_key_down"><span class="a">al_key_down</span></a><span class="k2">(</span><span class="k3">&amp;</span>keyboard, ALLEGRO_KEY_B<span class="k2">)</span><span class="k2">)</span>
<span class="number"> 102</span>       <span class="k1">for</span><span class="k2">(</span><span class="k1">int</span> a<span class="k3">=</span><span class="n">0</span><span class="k2">;</span> a<span class="k3">&lt;</span><span class="n">10</span><span class="k2">;</span>a<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span>
<span class="number"> 103</span>       <a href="http://www.allegro.cc/manual/al_draw_bitmap"><span class="a">al_draw_bitmap</span></a><span class="k2">(</span>Obj_Bmp2, <span class="n">200</span><span class="k3">+</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_637.html" target="_blank">rand</a><span class="k2">(</span><span class="k2">)</span>%<span class="n">40</span>, <span class="n">200</span><span class="k3">+</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_637.html" target="_blank">rand</a><span class="k2">(</span><span class="k2">)</span>%<span class="n">40</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span> <span class="c">// This Bitmap haven't being drawn previusly.</span>
<span class="number"> 104</span>
<span class="number"> 105</span>       <span class="k1">else</span> <span class="k1">if</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_key_down"><span class="a">al_key_down</span></a><span class="k2">(</span><span class="k3">&amp;</span>keyboard, ALLEGRO_KEY_ESCAPE<span class="k2">)</span><span class="k2">)</span>
<span class="number"> 106</span>       <span class="k1">break</span><span class="k2">;</span>
<span class="number"> 107</span>
<span class="number"> 108</span>       <span class="k1">for</span><span class="k2">(</span>std::list<span class="k3">&lt;</span>SPOT<span class="k3">*</span><span class="k3">&gt;</span><span class="k2">:</span><span class="k2">:</span>iterator it <span class="k3">=</span> Spo_List.begin<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> it <span class="k3">!</span><span class="k3">=</span> Spo_List.end<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> it<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span>
<span class="number"> 109</span>          <span class="k2">(</span><span class="k3">*</span>it<span class="k2">)</span><span class="k3">-</span><span class="k3">&gt;</span>move<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 110</span>
<span class="number"> 111</span>       <a href="http://www.allegro.cc/manual/al_flip_display"><span class="a">al_flip_display</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 112</span>
<span class="number"> 113</span>       <a href="http://www.allegro.cc/manual/al_rest"><span class="a">al_rest</span></a><span class="k2">(</span><span class="n">0</span>.<span class="n">05</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 114</span>       <a href="http://www.allegro.cc/manual/al_play_sample"><span class="a">al_play_sample</span></a><span class="k2">(</span>beep, <span class="n">1</span>.<span class="n">0</span>, <span class="n">0</span>.<span class="n">0</span>, <span class="n">1</span>.<span class="n">0</span>, ALLEGRO_PLAYMODE_ONCE, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 115</span>
<span class="number"> 116</span>
<span class="number"> 117</span>    <span class="k2">}</span>
<span class="number"> 118</span>    <a href="http://www.allegro.cc/manual/al_destroy_display"><span class="a">al_destroy_display</span></a><span class="k2">(</span>display<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 119</span>    <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 120</span><span class="k2">}</span>
</div></div><p>

<b>Edit:</b>
</p><h1> </h1><p>
This is from the FreeType documentation</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>

The  FreeType engine  doesn&#39;t cache  anything, be  it  outlines or<br />  bitmaps.  Hence, a program that  renders text by calling the glyph<br />  loader on each letter is slow.</p><p>  Because  caching  cannot  be  performed  in  both  an  <u>easy</u>  and<br />  <u>portable</u>  way it  is left  to the  application.   Moreover, some<br />  graphics systems  already provide some  sort of caching,  and it&#39;s<br />  better to take advantage of it rather than re-implementing it.</p><p>  The  hows  and when  of  caching  are  explained in  the  &quot;glyphs&quot;<br />  documentation file.  The &quot;bitmaps&quot; doc  file is also a good source<br />  of information if you intend to render individual glyph bitmaps.</p></div></div><p>

So Allegro is calling the loader each time it renders a letter? which is that loader? I&#39;m going to need to learn the freeType caching sub-system to cache my letters? <img src="http://www.allegro.cc/forums/smileys/cry.gif" alt=":&#39;(" />  .And if I do so, can I apply the changes in my games or I&#39;m going to have to hack Allegro?.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Mon, 06 Jun 2011 06:31:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920204#target">AMCerasoli</a> said:</div><div class="quote"><p>So Allegro is calling the loader each time it renders a letter?</p></div></div><p>
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920191#target">Todd Cope</a> said:</div><div class="quote"><p>When using TrueType fonts, glyphs are cached when they are drawn for the first time.</p></div></div><p>
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920196#target">Mark Oates</a> said:</div><div class="quote"><p>Ah, so it just caches those characters you&#39;re using when you first draw them.</p></div></div><p>
 <br /> <br /> <br /> <br />You could just draw each letter you&#39;re going to use once before starting, you know. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (gnolam)</author>
		<pubDate>Mon, 06 Jun 2011 07:18:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920204#target">AMCerasoli</a> said:</div><div class="quote"><p>So Allegro is calling the loader each time it renders a letter?</p></div></div><p>No. As was stated, the first time you draw a letter, it is cached by allegro into a texture reserved for that font. Drawing the text initially is slow, because drawing text is slow.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> I&#39;m going to need to learn the freeType caching sub-system to cache my letters?</p></div></div><p>As was stated in that text you quoted, no. FreeType does NO cacheing of its own. It is up to the api you&#39;re using to provide cacheing. Which allegro does. Which is why its not (horribly) slow after you draw some characters. You could just draw some text using the entire alphabet on loading, and then all the characters you use will be cached.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Mon, 06 Jun 2011 07:20:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Even faster would be caching whole words or the whole text, when possible.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Mon, 06 Jun 2011 15:05:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920243#target">gnolam</a> said:</div><div class="quote"><p>You could just draw each letter you&#39;re going to use once before starting, you know. </p></div></div><p>

I think I can&#39;t do something like this in my game, would be the same, but even if I could this sounds very archaic to me.</p><p>I&#39;m loading the font in another thread, I tried to draw the font on the second thread outside the boundaries of the game but the program crashed, I know why.</p><p>But even if I draw the text as you said, that would stuck the game the same, just that isn&#39;t going to show anything... I don&#39;t want to load and &quot;draw each letter&quot; at the start of the game, and then send the <span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_FONT"><span class="a">ALLEGRO_FONT</span></a></span> pointer to all my objects and stuff.</p><p>I want different objects loading different font and draw them without problem.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920244#target">Thomas Fjellstrom</a> said:</div><div class="quote"><p>No. As was stated, the first time you draw a letter, it is cached by allegro into a texture reserved for that font. Drawing the text initially is slow, because drawing text is slow.</p></div></div><p>

Drawing text isn&#39;t slow, caching them it&#39;s. So we should create a function to cache some letter before drawing them.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>As was stated in that text you quoted, no. FreeType does NO cacheing of its own. It is up to the api you&#39;re using to provide cacheing.</p></div></div><p>

For that reason (FreeType does NO cacheing of its own) I was saying if <b>I</b> was going to need to make the caching process, if FreeType were able to make the cache of some letters, I bet there would exist a function like Todd Cope mentioned.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Which allegro does. Which is why its not (horribly) slow after you draw some characters. You could just draw some text using the entire alphabet on loading, and then all the characters you use will be cached.
</p></div></div><p>

Yes but it&#39;s doing it wrong. Exaggerating it&#39;s like loading the bitmap before you want to draw it. After drawing it for first time it&#39;s very fast. And again drawing the entire alphabet besides being very archaic, isn&#39;t an option that I could take, because when I load the font my game is already running, and there are images in motion, and you can see the &quot;cache and drawing&quot; process that allegro make the first time when you draw the font, and see all the animations getting stuck, it takes less time to download a small file from a server than drawing text for the first time.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920277#target">Elias</a> said:</div><div class="quote"><p>Even faster would be caching whole words or the whole text, when possible.</p></div></div><p> And this is the straw that broke the camel&#39;s back.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Mon, 06 Jun 2011 16:53:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920281#target">AMCerasoli</a> said:</div><div class="quote"><p>But even if I draw the text as you said, that would stuck the game the same, just that isn&#39;t going to show anything...</p></div></div><p>
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Drawing text isn&#39;t slow, caching them it&#39;s.</p></div></div><p>
&gt;_&lt;<br />At this point, you should re-read the thread from the beginning, and then think hard about the implications of what everyone has been saying. Because you&#39;re being <i>mind-bogglingly</i> obtuse here.
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Yes but it&#39;s doing it wrong. Exaggerating it&#39;s like loading the bitmap before you want to draw it.</p></div></div><p>
... like I said.<br />But maybe you&#39;re onto something. Let&#39;s skip that slow loading part and just start drawing our graphics without loading them first!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (gnolam)</author>
		<pubDate>Mon, 06 Jun 2011 17:21:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I don&#39;t understand... <img src="http://www.allegro.cc/forums/smileys/cry.gif" alt=":&#39;(" /></p><p>How should I solve this?? drawing some text using the entire alphabet on loading? that implies using <span class="source-code"><a href="http://www.allegro.cc/manual/al_draw_text"><span class="a">al_draw_text</span></a><span class="k2">(</span><span class="k2">)</span></span> after loading right? or there is another way?</p><p>I really would prefer the function that Todd Cope mentioned...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Mon, 06 Jun 2011 17:52:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The function that Todd Cope mentioned would be a convenience, nothing else. Loading and rendering a glyph from the font takes time. Whether you precache x glyphs or cache x glyphs on the fly, the total time to cache x glyphs is the same.</p><p>Your problem is loading a heavy resource at runtime and expecting no impact on performance.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (gnolam)</author>
		<pubDate>Mon, 06 Jun 2011 18:02:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920281#target">AMCerasoli</a> said:</div><div class="quote"><p>And this is the straw that broke the camel&#39;s back.</p></div></div><p>

It&#39;s how it always worked in SDL_ttf. The function to draw text simply returns an SDL_Surface (same as ALLEGRO_BITMAP) which you then have to draw separately. And for many things it makes the most sense - for example if you display a page of text which does not change it may be like 100 times faster drawing the text to a bitmap once then just drawing that bitmap 60 times a second than drawing 1000ds of single glyphs in the page 60 times a second. Caching whole words or lines would be in-between those two.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Mon, 06 Jun 2011 18:23:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Wait, I&#39;m loading the font in another thread, using <span class="source-code"><a href="http://www.allegro.cc/manual/al_load_font"><span class="a">al_load_font</span></a><span class="k2">(</span><span class="k2">)</span></span> right?</p><p>Then when I want to draw the font, Allegro takes the characters that I want to draw and render them on runtime. </p><p>From where Allegro takes the characters ? I have no idea, I have being reading about faces and stuff like that about the FreeType library,  what I know is when I want to draw my text allegro is doing two things, when in fact should just do one thing, draw the text.</p><p>So far I think there are 3 process with fonts.</p><ol><li><p>Loading the font from a File - slow</p></li><li><p>Caching the font that I want to draw - slow</p></li><li><p>Draw the font - fast</p></li></ol><p>

We&#39;re doing 3 processes with only two functions. If process Nº1 and Nº2 were done at the same time when calling <span class="source-code"><a href="http://www.allegro.cc/manual/al_load_font"><span class="a">al_load_font</span></a></span> there wouldn&#39;t be any problem. But that is not possible, because:</p><div class="quote_container"><div class="title"><a href="http://www.fifi.org/doc/freetype2-demos/cache.html">www.fifi.org</a> said:</div><div class="quote"><p>
Each face contains hundreds, if not thousands of distinct glyph images. Since typical text only uses a fraction of a face&#39;s glyphs, loading all glyphs at once is nearly never a good idea. Instead, it&#39;s better to only retrieve and store the ones we need more often.
</p></div></div><p>

I don&#39;t know if that has something to do whit the topic, but I think so.</p><p>So as you said &quot;Whether you precache x glyphs or cache x glyphs on the fly, the total time to cache x glyphs is the same.&quot; The different with precache x glyphs from cache x glyphs on the fly is that I can do it on another thread, whitout interrupting the game. </p><p>Basically precache x glyphs would be separated form the drawing process so you can process that step on another thread. </p><p>The suggestion that people is giving my now is: &quot;draw first the text and then is going to be fast&quot;, that&#39;s ok, but I cannot draw text on a second thread, and my game isn&#39;t based on &quot;Loading&quot; screens. Everything is happening on runtime, so if something haven&#39;t been loaded simply isn&#39;t shown.</p><p>The bad thing with fonts, is that even if you have loaded the font from a file isn&#39;t completely &quot;prepared&quot; as normal bitmaps, sounds etc... The only way would be placing a loading screen, load bitmas and other things, load the font, draw some letters and the move on. But my current implementation doesn&#39;t allow me to do that.</p><p><b>Edit:</b> Reading Elias&#39;s post
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Mon, 06 Jun 2011 18:53:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You can&#39;t load a font in another thread. If you manage to not have it crash then that likely explains the slowness at least. You have to load it from the same thread where you call al_create_display.</p><p>(There is now a way in 5.1 svn to load the font in another thread though.)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Mon, 06 Jun 2011 18:56:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m loading the font in another thread without any problem... I wish that was the reason for this slowness when drawing fonts, but in the example above I&#39;m not creating another thread and the problem is exactly the same (slow as hell). I&#39;m going to try to learn a little bit about FreeType, to see if I can find a workaround for this problem, I haven&#39;t seen the Allegro code not even once, so this is going to be really difficult to me.</p><p>No wait, I&#39;m going to check out first the SDL and SFML libraries, try to run some  font examples, if I see that is the same than Allegro, then there shouldn&#39;t be any solution... That is easier.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Mon, 06 Jun 2011 19:11:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>How much FPS does ex_ttf report? And how slow exactly is font drawing in your example and how do you measure it?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Mon, 06 Jun 2011 20:40:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920295#target">AMCerasoli</a> said:</div><div class="quote"><p>I&#39;m loading the font in another thread without any problem...</p></div></div><p>Except it&#39;s likely creating the font&#39;s cache as a Memory bitmap instead of a display bitmap, which will make it slower than necessary.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Mon, 06 Jun 2011 21:40:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Elias, why don&#39;t you mention the al_convert_bitmap and stuff you just made since your example uses it for exactly this purpose (converting fonts that were made in memory).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kazzmir)</author>
		<pubDate>Mon, 06 Jun 2011 21:50:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>How long do we have to wait before we release 5.2 <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" />.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Tue, 07 Jun 2011 01:49:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920332#target">Trent Gamblin</a> said:</div><div class="quote"><p> How long do we have to wait before we release 5.2 .
</p></div></div><p>Eight years.</p><p>Things that don&#39;t break backward compatibility can be candidates for 5.0 features. Just because something is in 5.1 doesn&#39;t mean it won&#39;t make it into the next 5.0 release.</p><p>Generally any incremental improvements (such as converting memory bitmaps to video bitmaps) end up in the next 5.0 release.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Tue, 07 Jun 2011 01:53:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok I have already prove (to myself) that SFML it&#39;s faster than Allegro when drawing fonts, I decided to start with SFML because Elias said that SDL does the same than Allegro. I&#39;m still working on the example to prove it, because here are many &quot;nonbelievers&quot; about what I&#39;m saying... </p><p>However I found a very similar function about what Todd Coped was talking about: </p><div class="source-code snippet"><div class="inner"><pre>
<span class="k1">bool</span> sf::Font::LoadFromFile     <span class="k2">(</span>std::size_t    SizeInBytes,
                                 <span class="k1">unsigned</span> <span class="k1">int</span>   CharSize <span class="k3">=</span> <span class="n">30</span>,
                                 <span class="k1">const</span> Unicode::Text <span class="k3">&amp;</span>Charset <span class="k3">=</span> ourDefaultCharset   
                                <span class="k2">)</span>
</pre></div></div><p>

Example: <span class="source-code">MyFont.LoadFromFile<span class="k2">(</span><span class="s">"arial.ttf"</span>, <span class="n">50</span>, L<span class="s">"abcdefghij"</span><span class="k2">)</span></span>
</p><pre>

Parameters:

Filename 	: Font file to load
CharSize 	: Size of characters in bitmap - the bigger, the higher quality (30 by default)
Charset 	: Characters set to generate (by default, contains the ISO-8859-1 printable characters)

</pre><p>
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>

Passing your own character set may be needed if you want to use non-ASCII characters; in this case, just pass the list of characters that you&#39;re going to use as a wide string. Unicode is of course supported, so you could as well use chinese or arabic characters. By default, the character set is defined as the extended ASCII range 31-255, (0-30 are non-printable characters) which will be enough for a default usage. </p></div></div><p>

Maybe this has nothing to do, but I think it does. Seems like SFML pre-cache the extended ASCII range of letters by default when loading the font. I&#39;ll keep reading...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Tue, 07 Jun 2011 15:34:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920335#target">Matthew Leverton</a> said:</div><div class="quote"><p>Generally any incremental improvements (such as converting memory bitmaps to video bitmaps) end up in the next 5.0 release.</p></div></div><p>

So we can put things like the shaders addon into a 5.0 release? I somehow assumed we don&#39;t want any new functions in there. But thinking about it, there isn&#39;t much reason for that. As long as a game doesn&#39;t access internals, they could just replace the allegro5.dll with the newer one without re-compiling and it would keep working even if there are now additional functions.</p><p>[edit:]<br />AMCerasoli: did you see my two questions above?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Tue, 07 Jun 2011 15:48:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I have to agree with AMCerasoli, that there should be a mechanism during or after font loading that allows you to precache a range of glyphs. At least the ascii range needs to be cached for most all applications that use text.</p><p>It would be a sad day if you guys made AMCerasoli convert to SDL. <img src="http://www.allegro.cc/forums/smileys/cry.gif" alt=":&#39;(" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Tue, 07 Jun 2011 16:00:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I don&#39;t think I fully understand the problem.<br />The first time a glyph is used, it&#39;s cached for future use. That means that the first time you draw text, it&#39;s slower. On subsequent redraws, it should be (much) faster because the text is precached. Am I understanding this right? If so, I don&#39;t really understand why that&#39;s an issue. I mean, pre-caching wouldn&#39;t eally be faster, you&#39;d just have to wait somewhere else for the cache to be built.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920292#target">Elias</a> said:</div><div class="quote"><p>Caching whole words or lines would be in-between those two.</p></div></div><p>
Perhaps Allegro could keep track of the most recently drawn 100 (say) strings (or words) in a cache in addition to caching glyphs?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Tue, 07 Jun 2011 17:24:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920400#target">Edgar Reynaldo</a> said:</div><div class="quote"><p> have to agree with AMCerasoli, that there should be a mechanism during or after font loading that allows you to precache a range of glyphs.</p></div></div><p>

<span class="source-code"><a href="http://www.allegro.cc/manual/al_get_text_width"><span class="a">al_get_text_width</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a>, <span class="s">"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"</span><span class="k2">)</span><span class="k2">;</span></span></p><p>^ We already have it.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920406#target">Evert</a> said:</div><div class="quote"><p>Perhaps Allegro could keep track of the most recently drawn 100 (say) strings (or words) in a cache in addition to caching glyphs?</p></div></div><p>

Yes, but would have to test my assumption about it first. I wonder how e.g. Firefox or Chrome draw all their text - but I&#39;d think they also use per-glyph caching. At least in Firefox text is 100% identical to Allegro 5... i.e. when I use the same font with the same size then all glyphs are at the exact same pixel positions (each separate glyph position rounded to a whole integer pixel position just like in A5).</p><p>What might be the real problem is how long one al_draw_bitmap() call takes. A specialized text drawer which uses al_hold_bitmap_drawing or even al_draw_prim is a lot faster (using the very same texture cache).</p><p>Also, the ttf addon isn&#39;t very clever about texture management right now. We should probably at least have an al_optimize_ttf_cache(ALLEGRO_FONT *) function which tries to combine all cached-so-far glyphs into a single texture.</p><p>In any case, I still have no idea how slow or fast font drawing is... if only the caching is a problem then my code snippet above fully solves the issue <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Tue, 07 Jun 2011 19:51:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920406#target">Evert</a> said:</div><div class="quote"><p>The first time a glyph is used, it&#39;s cached for future use. That means that the first time you draw text, it&#39;s slower. On subsequent redraws, it should be (much) faster because the text is precached. Am I understanding this right?</p></div></div><p>

More or less. Isn&#39;t that I completely understand the process, but as you have said &quot;The first time a glyph is used, it&#39;s cached for future use&quot; this is done by Allegro and not by FreeType, basically is a bad implementation when drawing fonts, because caching the glyphs immediately before draw them makes the program take the glyphs from a truetype font  file,&quot;prepare&quot; them from a bunch of vectors depending on the size, all this on runtime. </p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>I don&#39;t really understand why that&#39;s an issue. I mean, pre-caching wouldn&#39;t really be faster, you&#39;d just have to wait somewhere else for the cache to be built.</p></div></div><p>

We&#39;re talking about pre-caching because Allegro isn&#39;t caching the glyphs before they are drawn at runtime. But actually we should be talking about caching the glyphs, just that, everyone knows that this should be done before we draw the text to the screen, and not at runtime.</p><p>Separating the caching from the drawing, has 2 very important advantages:</p><ol><li><p>It lets you create multi-thread applications, where you can load the font on a different thread and in which you cannot actually draw anything so you can&#39;t cache the glyphs. Therefore you rely on the main thread, which should be the UI thread, so when you draw the font you would be caching them too, stopping the animations or other stuffs (My case)</p></li><li><p>You don&#39;t need to draw the alphabet outside of the screen to cache the fonts in a loading phase</p></li></ol><p>


</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
<b>glyph caching</b><br />Each time you request a glyph image from a font, FT2 does it by parsing the relevant portion of the font file/stream and interpreting it according to its font format. This can be very slow for certain formats, including scalable ones like TrueType or Type 1.</p><p>Any decent text-rendering sub-system must thus be capable of caching glyph data in order to reach appropriate rendering speed</p><p>Note that we provide a beta caching sub-system with FreeType 2 since version 2.0.1. Even though you&#39;re free to write your own to suit your needs.
</p></div></div><p>

So I think the best solution is that one adopted by SFML where they have the  extended ASCII range already cached on loading, and if you want you can select another fonts if you want. something like <span class="source-code"><a href="http://www.allegro.cc/manual/al_load_font"><span class="a">al_load_font</span></a><span class="k2">(</span><span class="k1">char</span> <span class="k1">const</span> <span class="k3">*</span>filename, <span class="k1">int</span> size, <span class="k1">char</span> <span class="k1">const</span><span class="k3">*</span>charset, <span class="k1">int</span> flags<span class="k2">)</span></span>. That function should be caching the extended ASCII range of character, because it&#39;s illogical to be writing <span class="source-code"><span class="s">"abcdefg..."</span></span> each time we load a font, or we could create another function to do the cache of estrange characters. Even the Spanish alphabet fits very well in the extended ASCII range, so would be a good idia having a separated function... It&#39;s the same though.</p><p><b>Edit:</b> Again... reading Elias post... Just because my English isn&#39;t that well...</p><p><b>Edit2:</b> That function actually cache those letters?... that might be something. I&#39;ll try it. <img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=":D" /></p><p><b>Edit3:</b> <br />Aww... That it&#39;s worse <img src="http://www.allegro.cc/forums/smileys/sad.gif" alt=":(" /> . That reduce my FPS not only when I draw the font for first time... But also still slow for the rest of the game...</p><p>Maybe because I&#39;m doing it on another thread:</p><div class="source-code snippet"><div class="inner"><pre>
     <a href="http://www.allegro.cc/manual/al_lock_mutex"><span class="a">al_lock_mutex</span></a><span class="k2">(</span>p_dato-&gt;mutex<span class="k2">)</span><span class="k2">;</span>
     p_dato-&gt;font <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_font"><span class="a">al_load_font</span></a><span class="k2">(</span><span class="s">"font/consola.ttf"</span>,<span class="n">17</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
     <a href="http://www.allegro.cc/manual/al_get_text_width"><span class="a">al_get_text_width</span></a><span class="k2">(</span>p_dato-&gt;font, <span class="s">"abcdefghijklmnopqrstuvw..."</span><span class="k2">)</span><span class="k2">;</span>
     <a href="http://www.allegro.cc/manual/al_unlock_mutex"><span class="a">al_unlock_mutex</span></a><span class="k2">(</span>p_dato-&gt;mutex<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

I&#39;m in checkmate... <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Tue, 07 Jun 2011 20:04:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920420#target">AMCerasoli</a> said:</div><div class="quote"><p>It lets you create multi-thread applications, where you can load the font on a different thread and in which you cannot actually draw anything so you can&#39;t cache the glyphs.</p></div></div><p>
Not it does not because it is exactly as you say, <b>if you load the font on a different thread you can&#39;t cache the glyphs</b>, this is because the other thread does not have the proper context to create a video bitmap. (To effectively cache the font you draw the glyphs into a video bitmap and further use of those glyphs comes from that video bitmap.)<br />The best you can do from another thread is cache the font into a memory bitmap (not a video bitmap), which will give much worse performance when using that font. (video bitmaps can make use hardware accelerated drawing, memory bitmaps cannot)</p><p>Note that everything I just wrote I learned solely by reading this thread, as I didn&#39;t know about these things beforehand and it has all been explained to you in this thread numerous times.</p><p><b>EDIT:</b>
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Maybe because I&#39;m doing it on another thread:</p></div></div><p>
Maybe because the glyphs are being cached to a memory bitmap? Because they are cached in a thread that can only create memory bitmaps?</p><p>Try caching the font from the &quot;main&quot; thread.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Slartibartfast)</author>
		<pubDate>Tue, 07 Jun 2011 20:32:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920420#target">AMCerasoli</a> said:</div><div class="quote"><p>&quot;The first time a glyph is used, it&#39;s cached for future use&quot; this is done by Allegro and not by FreeType, basically is a bad implementation when drawing fonts, because caching the glyphs immediately before draw them makes the program take the glyphs from a truetype font  file,&quot;prepare&quot; them from a bunch of vectors depending on the size, all this on runtime. </p></div></div><p>
I still don&#39;t understand.<br />This work has to be done at least once, either when the font is loaded (but you can&#39;t do it for all glyphs in the font, there&#39;s potentially far too many of those) or on-demand when it turns out that those characters are actually needed.<br />The question is, do you do more work up front (at the risk of doing work that you don&#39;t need to do), or do you do work when it turns out that you have to? In general, especially when it comes to data processing, you&#39;re better off doing the latter.<br />Yes, it means that the first time you request the data (want to draw the glyph), it&#39;s slower because you first have to do extra work. But that overhead should be gone the next time you use the data, right? So what&#39;s the problem?</p><p>Is it <i>really</i> a problem if you get a small slow-down the first time you use a bit of data as long as it&#39;s gone when you re-use the data afterwards? Your runtime performance is not going to be determined by how fast things are the first time you draw them, but by how fast things are when you redraw them every frame.</p><p>EDIT
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920423#target">Slartibartfast</a> said:</div><div class="quote"><p>the other thread does not have the proper context to create a video bitmap.</p></div></div><p>
Quoted for emphasis.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Tue, 07 Jun 2011 20:39:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920416#target">Elias</a> said:</div><div class="quote"><p> At least in Firefox text is 100% identical to Allegro 5... i.e. when I use the same font with the same size then all glyphs are at the exact same pixel positions (each separate glyph position rounded to a whole integer pixel position just like in A5).</p></div></div><p>

Yes the same in PhotoShop, it&#39;s very precise.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920423#target">Slartibartfast</a> said:</div><div class="quote"><p>Not it does not because it is exactly as you say, if you load the font on a different thread you can&#39;t cache the glyphs,</p></div></div><p>

Have you run my example? even on a multi core computer I can notice the application getting stuck, there, <b>I&#39;m not using Multi-thread SO THAT ISN&#39;T THE REASON</b>.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Note that everything I just wrote I learned solely by reading this thread, as I didn&#39;t know about these things beforehand and it has all been explained to you in this thread numerous times.</p></div></div><p>

Nice!, I&#39;m proud of you</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Try caching the font from the &quot;main&quot; thread.</p></div></div><p>

That is what I did in my example, check it.<br /><b>Edit:</b>
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920424#target">Evert</a> said:</div><div class="quote"><p>This work has to be done at least once, either when the font is loaded (but you can&#39;t do it for all glyphs in the font, there&#39;s potentially far too many of those)</p></div></div><p>

You can&#39;t do it for all Unicode character, TTF files not even has so many charter inside anyway. But you could do it for your alphabet.</p><p>What you&#39;re suggesting is that if for some reason I want to show text on my game in two idioms at the same time it&#39;s more logic to block out the entire UI while the process is caching the glyphs for first time when drawing, than doing that previously, even better in another thread?</p><p>You know what?, fine, there is no problem, everything is ok, I&#39;ll take this into account the next time I&#39;m on a project, or the next time I find a bug or whatever.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Tue, 07 Jun 2011 20:41:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920425#target">AMCerasoli</a> said:</div><div class="quote"><p>
That is what I did in my example, check it.
</p></div></div><p>
Actually, it isn&#39;t. The relevant glyphs are cached when first used, not when loaded.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Have you run my example?</p></div></div><p>
Yes. It runs blindingly fast. There is a tiny, insignificant slowdown when first writing with the font, and that insignificant slowdown disappears if I manually cache the font. (In this case by replicating the call to al_draw_text before entering the main loop)</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Have you run my example?</p></div></div><p>
Did you read your own message that I was responding to? Allow me to quote it for you:
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920420#target">AMCerasoli</a> said:</div><div class="quote"><p>Separating the caching from the drawing, has 2 very important advantages:<br />1) It lets you create multi-thread applications, where you can load the font on a different thread and in which you cannot actually draw anything so you can&#39;t cache the glyphs. Therefore you rely on the main thread, which should be the UI thread, so when you draw the font you would be caching them too, stopping the animations or other stuffs (My case)</p></div></div><p>
You claimed that separating caching from drawing will allow you to load the font from a different thread, and I explained to you that either way you cannot load the font from a different thread.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Slartibartfast)</author>
		<pubDate>Tue, 07 Jun 2011 20:58:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>AMCerasoli, if you use a smaller font does it work? Maybe Allegro is creating a memory bitmap cache. (I don&#39;t know how it works...) Your example works fine for me.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920399#target">Elias</a> said:</div><div class="quote"><p> So we can put things like the shaders addon into a 5.0 release? 
</p></div></div><p>Theoretically, yes. While it may seem more proper to put big new features into a 5.2 branch, it (in my opinion) isn&#39;t worth it because maintaining two major releases is a pain in the butt. People will expect the older 5.0 branch to be continued to be maintained (bug fixed), which is just a hassle when it comes to providing binaries.</p><p>I would leave 5.2 alone until we come up with things that either completely break backward compatibility or are major changes to the core or how things are done. I don&#39;t know what would fit in that latter category.</p><p>Peter W&#39;s opinion would be more useful than mine.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Tue, 07 Jun 2011 21:52:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920435#target">Matthew Leverton</a> said:</div><div class="quote"><p>People will expect the older 5.0 branch to be continued to be maintained (bug fixed), which is just a hassle when it comes to providing binaries</p></div></div><p>I&#39;m not sure why, it was never done for 3.x or 4.x. As soon as a new .x release is made, the last one is abandoned afaik.</p><p>I&#39;m pretty sure 3.x was abandoned entirely when 4.x was released. So maintaining 4.x and 5.x right now is a bit of an aberration.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Tue, 07 Jun 2011 22:16:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Indeed, when 5.2 gets out 5.0 is deprecated. Just like you had to upgrade from 4.0 to 4.2 if you still wanted to benefit from bug fixes. There also was no more 4.2.x releases after 4.4.0 got released (I think at least, didn&#39;t follow 4.x development so closely).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Tue, 07 Jun 2011 22:26:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If 5.0 is abandoned the instant 5.2 comes out, then switching to 5.2 for any reason other than breaking backward compatibility is purely psychological. And since we aren&#39;t in a war with SDL (etc) to see who has the largest version number, then I&#39;d stick with 5.0 as long as we aren&#39;t breaking things.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Tue, 07 Jun 2011 23:03:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920435#target">Matthew Leverton</a> said:</div><div class="quote"><p>AMCerasoli, if you use a smaller font does it work? Maybe Allegro is creating a memory bitmap cache. (I don&#39;t know how it works...) Your example works fine for me.</p></div></div><p>

My font is already very small (17):</p><p><span class="remote-thumbnail"><span class="json">{"name":"604230","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/9\/59e3b6697ce14975f343cf8476a526f7.png","w":805,"h":633,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/9\/59e3b6697ce14975f343cf8476a526f7"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/5/9/59e3b6697ce14975f343cf8476a526f7-240.jpg" alt="604230" width="240" height="188" /></span></p><p>Maybe you have a 360 teraflops computer, but I have tasted the game on different computers and the fastest one still being slow, I&#39;m doing a simple game I can&#39;t demand too much in the minimum requirements.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920416#target">Elias</a> said:</div><div class="quote"><p>In any case, I still have no idea how slow or fast font drawing is... if only the caching is a problem then my code snippet above fully solves the issue</p></div></div><p>

ehh... No it doesn&#39;t... I have test it using my example and the text still slow when it&#39;s drawn for first time.</p><p>I have modified the ex_ttf file to show you the problem, if you want I can send you the file, but I think the problem is very clear right now.</p><p><div class="media-player youtube"><div style="margin: 1em 2em; background: url(/images/movie.png); width: 180px; height: 100px; text-align: center;"><a href="http://www.allegro.cc//www.youtube.com/watch?v=H-xeWhHuCt0" target="_blank"><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/object/0/6/066283ff2af94c0b8d0ee6456c630b8e.jpg" border="0" alt="video" title="Click to play video" /></a></div></div>	</p><p>You can see the lot of FPS that are drooped the first time the text is loaded and that is just a small amount of text with an small size. I&#39;m not a nit-picky guy, guys, but it&#39;s drooping my game frames very noticeable... I hope in future version of Allegro the glyph are cached on loading like SFML does.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Wed, 08 Jun 2011 00:10:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920447#target">AMCerasoli</a> said:</div><div class="quote"><p>ehh... No it doesn&#39;t... I have test it using my example and the text still slow when it&#39;s drawn for first time.</p></div></div><p>

Are you sure that you:</p><p>- Included <b>all</b> glyphs in the cache?<br />- Do <b>not</b> do the caching from another thread/without a display?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Wed, 08 Jun 2011 01:13:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920425#target">AMCerasoli</a> said:</div><div class="quote"><p>What you&#39;re suggesting is that if for some reason I want to show text on my game in two idioms at the same time</p></div></div><p>
&quot;two idioms at the same time&quot;???</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>it&#39;s more logic to block out the entire UI while the process is caching the glyphs for first time when drawing, than doing that previously, even better in another thread?</p></div></div><p>
No, I&#39;m saying that if that&#39;s the issue that&#39;s being discussed, <i>I</i> don&#39;t really see why that&#39;s a problem. And the reason I was asking is because it wasn&#39;t entirely clear to me what the issue was/is.<br />And why bring up &quot;another thread&quot; if you find it necessary to reply to someone else in bold face that <b>you&#39;re not using multiple threads</b>?</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>You know what?, fine, there is no problem, everything is ok, I&#39;ll take this into account the next time I&#39;m on a project, or the next time I find a bug or whatever.</p></div></div><p>
Count to ten first next time you feel the urge to post.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920447#target">AMCerasoli</a> said:</div><div class="quote"><p>You can see the lot of FPS that are drooped the first time the text is loaded and that is just a small amount of text with an small size.</p></div></div><p>
You&#39;re aware of course that your monitor is only able to display ~60fps, right?<br />Anyway, are you serious? You get a momentary blip going from ~580fps to ~520fps the first time the text is drawn. Is that really a big deal and what you call a &quot;massive slowdown&quot;?<br />I&#39;m not saying there <i>can&#39;t</i> be an issue or things can&#39;t be improved, but if this is quantitatively what we&#39;re talking about, I really don&#39;t see where you&#39;re coming from. Sorry.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Wed, 08 Jun 2011 01:15:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920452#target">Evert</a> said:</div><div class="quote"><p>&quot;two idioms at the same time&quot;???</p></div></div><p>

Yes Evert, two idioms at the same time... Draw two languages at the same time... You looks like a compiler...</p><p>To do something like that, I would have to 1) load a .ttf which has the letters for the two different idioms (Ex: German, Italian), or load two different .tff one for German and another for Italian... Anyway my point was that the more letter you want to draw the slower the process is going to be. Without a cache function if for some reason you want to do something like this:</p><p>Hello Evert<br />مرحبا ايفرت<br />прывітанне Эвэрт<br />喜埃弗特<br />היי Evert</p><p>Your game UI is going to get block for three weeks with the current implementation, at least with a cache function I could put a &quot;Loading...&quot; on the window and don&#39;t block the UI, while I&#39;m processing the cache process on another thread, yes I know, &quot;I cannot&quot; load fonts on another thread. I&#39;m going to reimplement my game structure to adjust to this conditions, I didn&#39;t know that loading things on another thread would be loaded as memory bitmaps, because I guess it&#39;s the same with normal bitmaps. For that reason a <b>al_convert_bitmap</b> function would be good. But I think I can fix the necessity to load the font on another thread with some changes, I can&#39;t fix the Super Extra Disproportionate time that it take to draw them for first time, though.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>No, I&#39;m saying that if that&#39;s the issue that&#39;s being discussed, I don&#39;t really see why that&#39;s a problem. And the reason I was asking is because it wasn&#39;t entirely clear to me what the issue was/is.</p></div></div><p>

Sorry... I didn&#39;t get that way... I use to simply say: &quot;ohhh ok&quot;.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>And why bring up &quot;another thread&quot; if you find it necessary to reply to someone else in bold face that you&#39;re not using multiple threads?</p></div></div><p>

I&#39;m bringing up &quot;another thread&quot; because I want to make sure developers know what I&#39;m doing in case I&#39;m doing something wrong, which I&#39;m actually doing (loading fonts in another thread) supposedly should fail, but it doesn&#39;t (so far).</p><p>If that &quot;someone&quot; had read the entire thread he would know that I&#39;m using multi-thread but the example (which is presenting the same problem) isn&#39;t.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>You&#39;re aware of course that your monitor is only able to display ~60fps, right?</p></div></div><p> <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" /></p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Anyway, are you serious? You get a momentary blip going from ~580fps to ~520fps the first time the text is drawn. Is that really a big deal and what you call a &quot;massive slowdown&quot;?<br />I&#39;m not saying there can&#39;t be an issue or things can&#39;t be improved, but if this is quantitatively what we&#39;re talking about, I really don&#39;t see where you&#39;re coming from. Sorry.</p></div></div><p>

I&#39;m not a conformist, if I see that my application is getting stuck for 0.00001 seconds I want to know why, if isn&#39;t my fault, I want to know what is doing the library, and if I found there is a problem with the library, I will report it. But I just want to clarify that the stuck time isn&#39;t 0.00001 seconds it&#39;s much more, and this is an issue.</p><p><b>Edit:</b>
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920451#target">Elias</a> said:</div><div class="quote"><p>
- Included all glyphs in the cache?<br />- Do not do the caching from another thread/without a display</p></div></div><p>
Yes and yes.</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">   1</span><span class="p">#include &lt;stdio.h&gt;</span>
<span class="number">   2</span><span class="p">#include &lt;list&gt;</span>
<span class="number">   3</span>
<span class="number">   4</span><span class="p">#define ALLEGRO_STATICLINK</span>
<span class="number">   5</span><span class="p">#include "allegro5/allegro.h"</span>
<span class="number">   6</span><span class="p">#include "allegro5/allegro_font.h"</span>
<span class="number">   7</span><span class="p">#include "allegro5/allegro_ttf.h"</span>
<span class="number">   8</span><span class="p">#include "allegro5/allegro_image.h"</span>
<span class="number">   9</span><span class="p">#include &lt;allegro5/allegro_audio.h&gt;</span>
<span class="number">  10</span><span class="p">#include &lt;allegro5/allegro_acodec.h&gt;</span>
<span class="number">  11</span>
<span class="number">  12</span><span class="k1">class</span> SPOT <span class="k2">{</span>
<span class="number">  13</span>
<span class="number">  14</span>   private:
<span class="number">  15</span>
<span class="number">  16</span>      <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a>  <span class="k3">*</span>bmp<span class="k2">;</span>
<span class="number">  17</span>      <span class="k1">float</span> posi_X, posi_Y, vel<span class="k2">;</span>
<span class="number">  18</span>
<span class="number">  19</span>   public:
<span class="number">  20</span>
<span class="number">  21</span>      SPOT<span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>T_bmp, <span class="k1">float</span> T_y, <span class="k1">float</span> T_vel<span class="k2">)</span> <span class="k2">:</span>
<span class="number">  22</span>      bmp    <span class="k2">(</span>T_bmp<span class="k2">)</span>,
<span class="number">  23</span>      posi_X <span class="k2">(</span><span class="k3">-</span><span class="n">100</span><span class="k2">)</span>,
<span class="number">  24</span>      posi_Y <span class="k2">(</span>T_y<span class="k2">)</span>,
<span class="number">  25</span>      vel    <span class="k2">(</span>T_vel<span class="k2">)</span><span class="k2">{</span><span class="k2">}</span>
<span class="number">  26</span>
<span class="number">  27</span>   ~SPOT<span class="k2">(</span><span class="k2">)</span><span class="k2">{</span>
<span class="number">  28</span>
<span class="number">  29</span>      <a href="http://www.allegro.cc/manual/al_destroy_bitmap"><span class="a">al_destroy_bitmap</span></a><span class="k2">(</span>bmp<span class="k2">)</span><span class="k2">;</span>
<span class="number">  30</span>
<span class="number">  31</span>   <span class="k2">}</span>
<span class="number">  32</span>
<span class="number">  33</span>   <span class="k1">void</span> move<span class="k2">(</span><span class="k2">)</span><span class="k2">{</span>
<span class="number">  34</span>
<span class="number">  35</span>      <a href="http://www.allegro.cc/manual/al_draw_bitmap"><span class="a">al_draw_bitmap</span></a><span class="k2">(</span>bmp, posi_X, posi_Y, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  36</span>
<span class="number">  37</span>      posi_X <span class="k3">+</span><span class="k3">=</span> vel<span class="k2">;</span>
<span class="number">  38</span>
<span class="number">  39</span>      <span class="k1">if</span><span class="k2">(</span>posi_X&gt;640<span class="k2">)</span> posi_X<span class="k3">=</span><span class="k3">-</span><span class="n">100</span><span class="k2">;</span>
<span class="number">  40</span>
<span class="number">  41</span>   <span class="k2">}</span>
<span class="number">  42</span>
<span class="number">  43</span><span class="k2">}</span><span class="k2">;</span>
<span class="number">  44</span>
<span class="number">  45</span><span class="k1">int</span> main<span class="k2">(</span><span class="k2">)</span>
<span class="number">  46</span><span class="k2">{</span>
<span class="number">  47</span>    <span class="k1">if</span><span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/al_init"><span class="a">al_init</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span>
<span class="number">  48</span>    <span class="k2">{</span>
<span class="number">  49</span>        <a href="http://www.delorie.com/djgpp/doc/libc/libc_345.html" target="_blank">fprintf</a><span class="k2">(</span>stderr, <span class="s">"Failed to initialize Allegro.\n"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  50</span>        <span class="k1">return</span> <span class="k3">-</span><span class="n">1</span><span class="k2">;</span>
<span class="number">  51</span>    <span class="k2">}</span>
<span class="number">  52</span>
<span class="number">  53</span>    <a href="http://www.allegro.cc/manual/al_init_font_addon"><span class="a">al_init_font_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  54</span>    <a href="http://www.allegro.cc/manual/al_init_ttf_addon"><span class="a">al_init_ttf_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  55</span>    <a href="http://www.allegro.cc/manual/al_init_image_addon"><span class="a">al_init_image_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  56</span>    <a href="http://www.allegro.cc/manual/al_install_audio"><span class="a">al_install_audio</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  57</span>    <a href="http://www.allegro.cc/manual/al_init_acodec_addon"><span class="a">al_init_acodec_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  58</span>    <a href="http://www.allegro.cc/manual/al_reserve_samples"><span class="a">al_reserve_samples</span></a><span class="k2">(</span><span class="n">1</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  59</span>    <a href="http://www.allegro.cc/manual/al_install_keyboard"><span class="a">al_install_keyboard</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  60</span>
<span class="number">  61</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_DISPLAY"><span class="a">ALLEGRO_DISPLAY</span></a> <span class="k3">*</span>display <span class="k3">=</span> NULL<span class="k2">;</span>
<span class="number">  62</span>    display <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_display"><span class="a">al_create_display</span></a><span class="k2">(</span><span class="n">640</span>,<span class="n">480</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  63</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a>  <span class="k3">*</span>Obj_Bmp <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_bitmap"><span class="a">al_load_bitmap</span></a><span class="k2">(</span><span class="s">"spot.png"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  64</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a>  <span class="k3">*</span>Obj_Bmp2<span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_bitmap"><span class="a">al_load_bitmap</span></a><span class="k2">(</span><span class="s">"spot.png"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  65</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_FONT"><span class="a">ALLEGRO_FONT</span></a>    <span class="k3">*</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a>    <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_ttf_font"><span class="a">al_load_ttf_font</span></a><span class="k2">(</span><span class="s">"consola.ttf"</span>,<span class="n">72</span>,<span class="n">0</span> <span class="k2">)</span><span class="k2">;</span>
<span class="number">  66</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_FONT"><span class="a">ALLEGRO_FONT</span></a>    <span class="k3">*</span>font2    <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_ttf_font"><span class="a">al_load_ttf_font</span></a><span class="k2">(</span><span class="s">"consola.ttf"</span>,<span class="n">72</span>,<span class="n">0</span> <span class="k2">)</span><span class="k2">;</span>
<span class="number">  67</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_FONT"><span class="a">ALLEGRO_FONT</span></a>    <span class="k3">*</span>font3    <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_ttf_font"><span class="a">al_load_ttf_font</span></a><span class="k2">(</span><span class="s">"consola.ttf"</span>,<span class="n">72</span>,<span class="n">0</span> <span class="k2">)</span><span class="k2">;</span>
<span class="number">  68</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_FONT"><span class="a">ALLEGRO_FONT</span></a>    <span class="k3">*</span>font4    <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_ttf_font"><span class="a">al_load_ttf_font</span></a><span class="k2">(</span><span class="s">"consola.ttf"</span>,<span class="n">72</span>,<span class="n">0</span> <span class="k2">)</span><span class="k2">;</span>
<span class="number">  69</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_FONT"><span class="a">ALLEGRO_FONT</span></a>    <span class="k3">*</span>font5    <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_ttf_font"><span class="a">al_load_ttf_font</span></a><span class="k2">(</span><span class="s">"consola.ttf"</span>,<span class="n">72</span>,<span class="n">0</span> <span class="k2">)</span><span class="k2">;</span>
<span class="number">  70</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_KEYBOARD_STATE"><span class="a">ALLEGRO_KEYBOARD_STATE</span></a> keyboard<span class="k2">;</span>
<span class="number">  71</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_SAMPLE"><span class="a">ALLEGRO_SAMPLE</span></a> <span class="k3">*</span>beep <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_sample"><span class="a">al_load_sample</span></a><span class="k2">(</span><span class="s">"beep.ogg"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  72</span>
<span class="number">  73</span>    <span class="c">//Obj_Bmp = al_load_bitmap("spot.png");</span>
<span class="number">  74</span>
<span class="number">  75</span>
<span class="number">  76</span>    std::list<span class="k3">&lt;</span>SPOT<span class="k3">*</span><span class="k3">&gt;</span> Spo_List<span class="k2">;</span>
<span class="number">  77</span>
<span class="number">  78</span>    <span class="k1">for</span><span class="k2">(</span><span class="k1">int</span> a<span class="k3">=</span><span class="n">0</span><span class="k2">;</span> a<span class="k3">&lt;</span><span class="n">10</span><span class="k2">;</span> a<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span>
<span class="number">  79</span>       Spo_List.push_back<span class="k2">(</span><span class="k1">new</span> SPOT<span class="k2">(</span>Obj_Bmp, <a href="http://www.delorie.com/djgpp/doc/libc/libc_637.html" target="_blank">rand</a><span class="k2">(</span><span class="k2">)</span>%<span class="n">480</span>, <a href="http://www.delorie.com/djgpp/doc/libc/libc_637.html" target="_blank">rand</a><span class="k2">(</span><span class="k2">)</span>%<span class="n">10</span><span class="k3">+</span><span class="n">1</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  80</span>
<span class="number">  81</span>    <a href="http://www.allegro.cc/manual/al_get_text_width"><span class="a">al_get_text_width</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a>, <span class="s">"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  82</span>    <a href="http://www.allegro.cc/manual/al_get_text_width"><span class="a">al_get_text_width</span></a><span class="k2">(</span>font2, <span class="s">"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  83</span>    <a href="http://www.allegro.cc/manual/al_get_text_width"><span class="a">al_get_text_width</span></a><span class="k2">(</span>font3, <span class="s">"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  84</span>    <a href="http://www.allegro.cc/manual/al_get_text_width"><span class="a">al_get_text_width</span></a><span class="k2">(</span>font4, <span class="s">"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  85</span>    <a href="http://www.allegro.cc/manual/al_get_text_width"><span class="a">al_get_text_width</span></a><span class="k2">(</span>font5, <span class="s">"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  86</span>
<span class="number">  87</span>    <span class="k1">while</span><span class="k2">(</span><span class="n">1</span><span class="k2">)</span><span class="k2">{</span>
<span class="number">  88</span>       <a href="http://www.allegro.cc/manual/al_get_keyboard_state"><span class="a">al_get_keyboard_state</span></a><span class="k2">(</span><span class="k3">&amp;</span>keyboard<span class="k2">)</span><span class="k2">;</span>
<span class="number">  89</span>
<span class="number">  90</span>       <a href="http://www.allegro.cc/manual/al_clear_to_color"><span class="a">al_clear_to_color</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span><span class="n">50</span>,<span class="n">10</span>,<span class="n">70</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  91</span>
<span class="number">  92</span>       <span class="k1">if</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_key_down"><span class="a">al_key_down</span></a><span class="k2">(</span><span class="k3">&amp;</span>keyboard, ALLEGRO_KEY_A<span class="k2">)</span><span class="k2">)</span>
<span class="number">  93</span>       <a href="http://www.allegro.cc/manual/al_draw_text"><span class="a">al_draw_text</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a>, <a href="http://www.allegro.cc/manual/al_map_rgba"><span class="a">al_map_rgba</span></a><span class="k2">(</span><span class="n">255</span>,<span class="n">255</span>,<span class="n">255</span>,<span class="n">255</span><span class="k2">)</span>,  <span class="n">640</span><span class="k3">/</span><span class="n">2</span>, <span class="k2">(</span><span class="n">480</span><span class="k3">/</span><span class="n">4</span><span class="k2">)</span>,ALLEGRO_ALIGN_CENTRE, <span class="s">"Slow Font : (!"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  94</span>
<span class="number">  95</span>       <span class="k1">else</span> <span class="k1">if</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_key_down"><span class="a">al_key_down</span></a><span class="k2">(</span><span class="k3">&amp;</span>keyboard, ALLEGRO_KEY_S<span class="k2">)</span><span class="k2">)</span>
<span class="number">  96</span>       <a href="http://www.allegro.cc/manual/al_draw_text"><span class="a">al_draw_text</span></a><span class="k2">(</span>font2, <a href="http://www.allegro.cc/manual/al_map_rgba"><span class="a">al_map_rgba</span></a><span class="k2">(</span><span class="n">255</span>,<span class="n">255</span>,<span class="n">255</span>,<span class="n">255</span><span class="k2">)</span>, <span class="n">640</span><span class="k3">/</span><span class="n">2</span>,  <span class="n">50</span><span class="k3">+</span><span class="k2">(</span><span class="n">480</span><span class="k3">/</span><span class="n">4</span><span class="k2">)</span>,ALLEGRO_ALIGN_CENTRE, <span class="s">"Slow Font : (!"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  97</span>
<span class="number">  98</span>       <span class="k1">else</span> <span class="k1">if</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_key_down"><span class="a">al_key_down</span></a><span class="k2">(</span><span class="k3">&amp;</span>keyboard, ALLEGRO_KEY_D<span class="k2">)</span><span class="k2">)</span>
<span class="number">  99</span>       <a href="http://www.allegro.cc/manual/al_draw_text"><span class="a">al_draw_text</span></a><span class="k2">(</span>font3, <a href="http://www.allegro.cc/manual/al_map_rgba"><span class="a">al_map_rgba</span></a><span class="k2">(</span><span class="n">255</span>,<span class="n">255</span>,<span class="n">255</span>,<span class="n">255</span><span class="k2">)</span>, <span class="n">640</span><span class="k3">/</span><span class="n">2</span>, <span class="n">100</span><span class="k3">+</span><span class="k2">(</span><span class="n">480</span><span class="k3">/</span><span class="n">4</span><span class="k2">)</span>,ALLEGRO_ALIGN_CENTRE, <span class="s">"Slow Font : (!"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 100</span>
<span class="number"> 101</span>       <span class="k1">else</span> <span class="k1">if</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_key_down"><span class="a">al_key_down</span></a><span class="k2">(</span><span class="k3">&amp;</span>keyboard, ALLEGRO_KEY_F<span class="k2">)</span><span class="k2">)</span>
<span class="number"> 102</span>       <a href="http://www.allegro.cc/manual/al_draw_text"><span class="a">al_draw_text</span></a><span class="k2">(</span>font4, <a href="http://www.allegro.cc/manual/al_map_rgba"><span class="a">al_map_rgba</span></a><span class="k2">(</span><span class="n">255</span>,<span class="n">255</span>,<span class="n">255</span>,<span class="n">255</span><span class="k2">)</span>, <span class="n">640</span><span class="k3">/</span><span class="n">2</span>, <span class="n">150</span><span class="k3">+</span><span class="k2">(</span><span class="n">480</span><span class="k3">/</span><span class="n">4</span><span class="k2">)</span>,ALLEGRO_ALIGN_CENTRE, <span class="s">"Slow Font : (!"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 103</span>
<span class="number"> 104</span>       <span class="k1">else</span> <span class="k1">if</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_key_down"><span class="a">al_key_down</span></a><span class="k2">(</span><span class="k3">&amp;</span>keyboard, ALLEGRO_KEY_G<span class="k2">)</span><span class="k2">)</span>
<span class="number"> 105</span>       <a href="http://www.allegro.cc/manual/al_draw_text"><span class="a">al_draw_text</span></a><span class="k2">(</span>font5, <a href="http://www.allegro.cc/manual/al_map_rgba"><span class="a">al_map_rgba</span></a><span class="k2">(</span><span class="n">255</span>,<span class="n">255</span>,<span class="n">255</span>,<span class="n">255</span><span class="k2">)</span>, <span class="n">640</span><span class="k3">/</span><span class="n">2</span>, <span class="n">200</span><span class="k3">+</span><span class="k2">(</span><span class="n">480</span><span class="k3">/</span><span class="n">4</span><span class="k2">)</span>,ALLEGRO_ALIGN_CENTRE, <span class="s">"Slow Font : (!"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 106</span>
<span class="number"> 107</span>       <span class="k1">else</span> <span class="k1">if</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_key_down"><span class="a">al_key_down</span></a><span class="k2">(</span><span class="k3">&amp;</span>keyboard, ALLEGRO_KEY_B<span class="k2">)</span><span class="k2">)</span>
<span class="number"> 108</span>       <span class="k1">for</span><span class="k2">(</span><span class="k1">int</span> a<span class="k3">=</span><span class="n">0</span><span class="k2">;</span> a<span class="k3">&lt;</span><span class="n">10</span><span class="k2">;</span>a<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span>
<span class="number"> 109</span>       <a href="http://www.allegro.cc/manual/al_draw_bitmap"><span class="a">al_draw_bitmap</span></a><span class="k2">(</span>Obj_Bmp2, <span class="n">200</span><span class="k3">+</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_637.html" target="_blank">rand</a><span class="k2">(</span><span class="k2">)</span>%<span class="n">40</span>, <span class="n">200</span><span class="k3">+</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_637.html" target="_blank">rand</a><span class="k2">(</span><span class="k2">)</span>%<span class="n">40</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span> <span class="c">// This Bitmap haven't being drawn previusly.</span>
<span class="number"> 110</span>
<span class="number"> 111</span>       <span class="k1">else</span> <span class="k1">if</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_key_down"><span class="a">al_key_down</span></a><span class="k2">(</span><span class="k3">&amp;</span>keyboard, ALLEGRO_KEY_ESCAPE<span class="k2">)</span><span class="k2">)</span>
<span class="number"> 112</span>       <span class="k1">break</span><span class="k2">;</span>
<span class="number"> 113</span>
<span class="number"> 114</span>       <span class="k1">for</span><span class="k2">(</span>std::list<span class="k3">&lt;</span>SPOT<span class="k3">*</span><span class="k3">&gt;</span><span class="k2">:</span><span class="k2">:</span>iterator it <span class="k3">=</span> Spo_List.begin<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> it <span class="k3">!</span><span class="k3">=</span> Spo_List.end<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> it<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span>
<span class="number"> 115</span>          <span class="k2">(</span><span class="k3">*</span>it<span class="k2">)</span><span class="k3">-</span><span class="k3">&gt;</span>move<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 116</span>
<span class="number"> 117</span>       <a href="http://www.allegro.cc/manual/al_flip_display"><span class="a">al_flip_display</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 118</span>
<span class="number"> 119</span>       <a href="http://www.allegro.cc/manual/al_rest"><span class="a">al_rest</span></a><span class="k2">(</span><span class="n">0</span>.<span class="n">01</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 120</span>       <span class="c">//Beep(500,20);</span>
<span class="number"> 121</span>       <a href="http://www.allegro.cc/manual/al_play_sample"><span class="a">al_play_sample</span></a><span class="k2">(</span>beep, <span class="n">1</span>.<span class="n">0</span>, <span class="n">0</span>.<span class="n">0</span>, <span class="n">1</span>.<span class="n">0</span>, ALLEGRO_PLAYMODE_ONCE, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 122</span>
<span class="number"> 123</span>
<span class="number"> 124</span>    <span class="k2">}</span>
<span class="number"> 125</span>    <a href="http://www.allegro.cc/manual/al_destroy_display"><span class="a">al_destroy_display</span></a><span class="k2">(</span>display<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 126</span>    <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 127</span><span class="k2">}</span>
</div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Wed, 08 Jun 2011 02:14:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920447#target">AMCerasoli</a> said:</div><div class="quote"><p>
I hope in future version of Allegro the glyph are cached on loading like SFML does.
</p></div></div><p>

That&#39;s not going to happen. The fonts (2 of them) I&#39;m using for my current game have over 30,000 characters each. If you need glyphs cached just draw them like a bunch of people have said. Caching glyphs is slow, there&#39;s no way around it, but dropping to 520 FPS is not even an issue.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Wed, 08 Jun 2011 02:46:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920467#target">AMCerasoli</a> said:</div><div class="quote"><p>Yes Evert, two idioms at the same time... Draw two languages at the same time... You looks like a compiler...</p></div></div><p>
Look, I appreciate that your English is not very good and that we&#39;re all going to make an effort to understand what you mean, but &quot;two idioms at the same time&quot; just doesn&#39;t make sense as a sentence. It <i>certainly</i> doesn&#39;t mean &quot;display two languages that require vastly different character sets&quot;.<br />If it&#39;s not clear what you mean, it&#39;s up to <i>you</i> to make the effort of being more clear.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>For that reason a al_convert_bitmap function would be good.</p></div></div><p>
I think Elias committed that to SVN the other day, have a look.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p><img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" /></p></div></div><p>
What?<br />It doesn&#39;t, and if you lock to the update frequency of the screen (what used to be called &quot;wait for vsync&quot;, not sure what the best phrase to use these days is) and/or only draw to the screen when you&#39;ve actually changed something so you need to redraw, you&#39;re never going to get a bogus &quot;500 fps&quot;.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>if I see that my application is getting stuck for 0.00001 seconds I want to know why,</p></div></div><p>
Hyperbole can sometimes be very effective, but if you push it too far it just becomes ridiculous.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>if isn&#39;t my fault, I want to know what is doing the library, and if I found there is a problem with the library, I will report it.</p></div></div><p>
Well, you know what it&#39;s doing and why the delay is there. It&#39;s not a &quot;problem&quot; in the sense that the behaviour is by design.<br />I&#39;m not saying it&#39;s not nice to have a way to pre-cache data you already know you&#39;re going to need, but based on the numbers you&#39;ve posted, I don&#39;t see there&#39;s a major problem with the current implementation.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>But I just want to clarify that the stuck time isn&#39;t 0.00001 seconds it&#39;s much more, and this is an issue.</p></div></div><p>
The drop in framerate corresponds to a processing time of 0.2ms. You want to display a &quot;loading...&quot; message for that?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Wed, 08 Jun 2011 03:09:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>hahaha It&#39;s funny how all this reminds me when I was in the school... Now I could say something like:</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920476#target">Evert</a> said:</div><div class="quote"><p>Look, I appreciate that your English is not very good and that we&#39;re all going to make an effort to understand what you mean, but &quot;two idioms at the same time&quot; just doesn&#39;t make sense as a sentence. It certainly doesn&#39;t mean &quot;display two languages that require vastly different character sets&quot;.<br />If it&#39;s not clear what you mean, it&#39;s up to you to make the effort of being more clear.</p></div></div><p>

a word to the wise is sufficient...</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>What?<br />It doesn&#39;t, and if you lock to the update frequency of the screen (what used to be called &quot;wait for vsync&quot;, not sure what the best phrase to use these days is) and/or only draw to the screen when you&#39;ve actually changed something so you need to redraw, you&#39;re never going to get a bogus &quot;500 fps&quot;.</p></div></div><p>

I know man, that&#39;s just an example, my current game is running at 30FPS logic and drawing, for that reason I can see it.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Hyperbole can sometimes be very effective, but if you push it too far it just becomes ridiculous.</p></div></div><p> It&#39;s just an example</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Well, you know what it&#39;s doing and why the delay is there. It&#39;s not a &quot;problem&quot; in the sense that the behaviour is by design.</p></div></div><p> Of course it is!</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>I&#39;m not saying it&#39;s not nice to have a way to pre-cache data you already know you&#39;re going to need, but based on the numbers you&#39;ve posted, I don&#39;t see there&#39;s a major problem with the current implementation.</p></div></div><p> The numbers that I&#39;m posting are from an example!, I said &quot;I have modified the ex_ttf file to show you the problem&quot;, if the FPS drooped were worse in that simple example, then there would have a really <u>bad</u> <u>bad</u> implementation.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>The drop in framerate corresponds to a processing time of 0.2ms. You want to display a &quot;loading...&quot; message for that?</p></div></div><p> That was just an example... I want to cry...</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920471#target">Trent Gamblin</a> said:</div><div class="quote"><p>That&#39;s not going to happen. The fonts (2 of them) I&#39;m using for my current game have over 30,000 characters each. If you need glyphs cached just draw them like a bunch of people have said. Caching glyphs is slow, there&#39;s no way around it, but dropping to 520 FPS is not even an issue.</p></div></div><p> Allegro would only cache the  extended ANSCII range, and there would be another function for people which uses other glyphs... the 520 FPS was an example...  I think I&#39;m going to commit suicide.</p><p>But doesn&#39;t matter, if is not going to happen, isn&#39;t going to happen, it&#39;s fine, now depend on my which decision to take. Thanks to all.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AMCerasoli)</author>
		<pubDate>Wed, 08 Jun 2011 03:38:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Why cache the extended ascii range? You have no idea what glyphs the user is going to use until they draw them. That&#39;s why you draw the glyphs you need yourself, they&#39;ll be cached, and you move on.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Wed, 08 Jun 2011 04:17:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>AMCerasoli can you be specific about the kind of slowdowns you are seeing? Exactly how much time does it take to render the font the first time? I took your original example and added some timing measurements to it. I see this:
</p><div class="source-code snippet"><div class="inner"><pre><span class="n">14</span>.<span class="n">090000</span> milliseconds
<span class="n">0</span>.<span class="n">169000</span> milliseconds
<span class="n">0</span>.<span class="n">159000</span> milliseconds
<span class="n">0</span>.<span class="n">160000</span> milliseconds
<span class="n">0</span>.<span class="n">163000</span> milliseconds
<span class="n">0</span>.<span class="n">179000</span> milliseconds
</pre></div></div><p>
So caching takes 2 orders of magnitude longer than drawing but still 14ms is insanely small. Are you seeing something on the order of seconds?</p><p>Attached is your main.cpp but with calls to gettimeofday (I only measured pressing the A key).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kazzmir)</author>
		<pubDate>Wed, 08 Jun 2011 04:18:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920480#target">AMCerasoli</a> said:</div><div class="quote"><p>I know man, that&#39;s just an example, my current game is running at 30FPS logic and drawing, for that reason I can see it.</p></div></div><p>
The problem is, you start out by saying &quot;text is drawn slowly the first time round&quot;, which is true. There&#39;s a reason for why that is the case, and the reason is that the first time a character is used, Allegro caches the glyphs <i>so that things are faster the next time they&#39;re used</i>.<br />You then proceed to say that there&#39;s a horrible drop in FPS when text is drawn for the first time, and show an example that... doesn&#39;t show a horrible drop in FPS at all.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>It&#39;s just an example</p></div></div><p>
Yes. A bad one, because your hyperbole was very over the top.<br />This is exactly the problem: you talk about horrible slow downs, weeks of rendering time, wanting to find out why your game takes 0.00001 seconds longer to do something and yet the only actual data you present don&#39;t show <i>any</i> indication of a problem that even remotely justifies that level of hyperbole.</p><p><i>Please try to be more clear</i> about how big of a problem we&#39;re dealing with here.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Allegro would only cache the  extended ANSCII range, and there would be another function for people which uses other glyphs...</p></div></div><p>
First of all, there&#39;s no such thing as &quot;extended ASCII range&quot;, Allegro uses UTF-8 encoding. Allegro <i>could</i> precache the full standard Latin alphabet, but if I only intend to use the fint to display a score, that&#39;s wasting a LOT of cache for no gain (and if we&#39;re talking about slowdowns, that&#39;ll slow down font loading for no gain as well). That&#39;s what I meant earlier: don&#39;t do work now that you don&#39;t know you need to do later.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>the 520 FPS was an example...</p></div></div><p>
Again, a <i>bad</i> example because it doesn&#39;t actually support your claim that there&#39;s a massive problem. Just quote numbers from your game.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>But doesn&#39;t matter, if is not going to happen, isn&#39;t going to happen, it&#39;s fine, now depend on my which decision to take. Thanks to all.</p></div></div><p>
What isn&#39;t going to happen is us spending a lot of time trying to avoid a drop from 580 to 520 FPS. However, a drop from 30 to (say) 5 FPS is a very different story.<br />So once again, <i>please try to be more clear and precise</i>.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Wed, 08 Jun 2011 06:31:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920416#target">Elias</a> said:</div><div class="quote"><p>
</p><div class="quote_container"><div class="title">Edgar said:</div><div class="quote"><p>
 have to agree with AMCerasoli, that there should be a mechanism during or after font loading that allows you to precache a range of glyphs.
</p></div></div><p>
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/al_get_text_width"><span class="a">al_get_text_width</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a>, <span class="s">"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
^ We already have it.
</p></div></div><p>

The manual says absolutely nothing about al_get_text_width caching glyphs. Are we supposed to be psychic?</p><p>I wrote up some test code. Pass the path to the font you want to test on the command line. It caches all the printable regular ascii characters and measures the time it takes to load, cache, and display them :
</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">   1</span>
<span class="number">   2</span><span class="p">#include &lt;cstdio&gt;</span>
<span class="number">   3</span>
<span class="number">   4</span><span class="p">#include "allegro5/allegro.h"</span>
<span class="number">   5</span><span class="p">#include "allegro5/allegro_font.h"</span>
<span class="number">   6</span><span class="p">#include "allegro5/allegro_ttf.h"</span>
<span class="number">   7</span>
<span class="number">   8</span>
<span class="number">   9</span><span class="k1">class</span> AllegroSetup <span class="k2">{</span>
<span class="number">  10</span><span class="k1">private</span> <span class="k2">:</span>
<span class="number">  11</span>   <a href="http://www.allegro.cc/manual/ALLEGRO_DISPLAY"><span class="a">ALLEGRO_DISPLAY</span></a><span class="k3">*</span> display<span class="k2">;</span>
<span class="number">  12</span>   <a href="http://www.allegro.cc/manual/ALLEGRO_TIMER"><span class="a">ALLEGRO_TIMER</span></a><span class="k3">*</span> timer<span class="k2">;</span>
<span class="number">  13</span>   <a href="http://www.allegro.cc/manual/ALLEGRO_EVENT_QUEUE"><span class="a">ALLEGRO_EVENT_QUEUE</span></a><span class="k3">*</span> event_queue<span class="k2">;</span>
<span class="number">  14</span>   <span class="k1">bool</span> ready<span class="k2">;</span>
<span class="number">  15</span><span class="k1">public</span> <span class="k2">:</span>
<span class="number">  16</span>   AllegroSetup<span class="k2">(</span><span class="k1">int</span> w , <span class="k1">int</span> h , <span class="k1">double</span> tick_time<span class="k2">)</span> <span class="k2">:</span>
<span class="number">  17</span>      display<span class="k2">(</span><span class="n">0</span><span class="k2">)</span>,
<span class="number">  18</span>      timer<span class="k2">(</span><span class="n">0</span><span class="k2">)</span>,
<span class="number">  19</span>      event_queue<span class="k2">(</span><span class="n">0</span><span class="k2">)</span>,
<span class="number">  20</span>      ready<span class="k2">(</span><span class="k1">false</span><span class="k2">)</span>
<span class="number">  21</span>   <span class="k2">{</span>
<span class="number">  22</span>      <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/al_init"><span class="a">al_init</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"Failed to initialize Allegro.\n"</span><span class="k2">)</span><span class="k2">;</span><span class="k1">return</span><span class="k2">;</span><span class="k2">}</span>
<span class="number">  23</span>      <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span><span class="k2">(</span>display <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_display"><span class="a">al_create_display</span></a><span class="k2">(</span>w,h<span class="k2">)</span><span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number">  24</span>         <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"Failed to create %i X %i display.\n"</span> , w , h<span class="k2">)</span><span class="k2">;</span>
<span class="number">  25</span>         <span class="k1">return</span><span class="k2">;</span>
<span class="number">  26</span>      <span class="k2">}</span>
<span class="number">  27</span>      <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span><span class="k2">(</span>timer <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_timer"><span class="a">al_create_timer</span></a><span class="k2">(</span>tick_time<span class="k2">)</span><span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number">  28</span>         <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"Failed to create %lg paced timer.\n"</span> , tick_time<span class="k2">)</span><span class="k2">;</span>
<span class="number">  29</span>         <span class="k1">return</span><span class="k2">;</span>
<span class="number">  30</span>      <span class="k2">}</span>
<span class="number">  31</span>      <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/al_install_keyboard"><span class="a">al_install_keyboard</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number">  32</span>         <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"Failed to initialize keyboard.\n"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  33</span>         <span class="k1">return</span><span class="k2">;</span>
<span class="number">  34</span>      <span class="k2">}</span>
<span class="number">  35</span>      <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/al_install_mouse"><span class="a">al_install_mouse</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number">  36</span>         <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"Failed to install mouse.\n"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  37</span>         <span class="k1">return</span><span class="k2">;</span>
<span class="number">  38</span>      <span class="k2">}</span>
<span class="number">  39</span>      <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span><span class="k2">(</span>event_queue <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_event_queue"><span class="a">al_create_event_queue</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number">  40</span>         <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"Failed to create event queue.\n"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  41</span>         <span class="k1">return</span><span class="k2">;</span>
<span class="number">  42</span>      <span class="k2">}</span>
<span class="number">  43</span>      <a href="http://www.allegro.cc/manual/al_register_event_source"><span class="a">al_register_event_source</span></a><span class="k2">(</span>event_queue , <a href="http://www.allegro.cc/manual/al_get_keyboard_event_source"><span class="a">al_get_keyboard_event_source</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  44</span>      <a href="http://www.allegro.cc/manual/al_register_event_source"><span class="a">al_register_event_source</span></a><span class="k2">(</span>event_queue , <a href="http://www.allegro.cc/manual/al_get_display_event_source"><span class="a">al_get_display_event_source</span></a><span class="k2">(</span>display<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  45</span>      <a href="http://www.allegro.cc/manual/al_register_event_source"><span class="a">al_register_event_source</span></a><span class="k2">(</span>event_queue , <a href="http://www.allegro.cc/manual/al_get_mouse_event_source"><span class="a">al_get_mouse_event_source</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  46</span>      <a href="http://www.allegro.cc/manual/al_register_event_source"><span class="a">al_register_event_source</span></a><span class="k2">(</span>event_queue , <a href="http://www.allegro.cc/manual/al_get_timer_event_source"><span class="a">al_get_timer_event_source</span></a><span class="k2">(</span>timer<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  47</span>      ready <span class="k3">=</span> <span class="k1">true</span><span class="k2">;</span>
<span class="number">  48</span>   <span class="k2">}</span>
<span class="number">  49</span>
<span class="number">  50</span>   ~AllegroSetup<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number">  51</span>      <span class="k1">if</span> <span class="k2">(</span>event_queue<span class="k2">)</span> <span class="k2">{</span><a href="http://www.allegro.cc/manual/al_destroy_event_queue"><span class="a">al_destroy_event_queue</span></a><span class="k2">(</span>event_queue<span class="k2">)</span><span class="k2">;</span><span class="k2">}</span>
<span class="number">  52</span>      <span class="k1">if</span> <span class="k2">(</span>display<span class="k2">)</span> <span class="k2">{</span><a href="http://www.allegro.cc/manual/al_destroy_display"><span class="a">al_destroy_display</span></a><span class="k2">(</span>display<span class="k2">)</span><span class="k2">;</span><span class="k2">}</span>
<span class="number">  53</span>   <span class="k2">}</span>
<span class="number">  54</span>
<span class="number">  55</span>   <span class="k1">bool</span> Ready<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span><span class="k1">return</span> ready<span class="k2">;</span><span class="k2">}</span>
<span class="number">  56</span>
<span class="number">  57</span>   <span class="k1">inline</span> <span class="k1">operator</span> <a href="http://www.allegro.cc/manual/ALLEGRO_DISPLAY"><span class="a">ALLEGRO_DISPLAY</span></a><span class="k3">*</span> <span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span><span class="k1">return</span> display<span class="k2">;</span><span class="k2">}</span>
<span class="number">  58</span>   <span class="k1">inline</span> <span class="k1">operator</span> <a href="http://www.allegro.cc/manual/ALLEGRO_EVENT_QUEUE"><span class="a">ALLEGRO_EVENT_QUEUE</span></a><span class="k3">*</span> <span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span><span class="k1">return</span> event_queue<span class="k2">;</span><span class="k2">}</span>
<span class="number">  59</span>   <span class="k1">inline</span> <span class="k1">operator</span> <a href="http://www.allegro.cc/manual/ALLEGRO_TIMER"><span class="a">ALLEGRO_TIMER</span></a><span class="k3">*</span> <span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span><span class="k1">return</span> timer<span class="k2">;</span><span class="k2">}</span>
<span class="number">  60</span><span class="k2">}</span><span class="k2">;</span>
<span class="number">  61</span>
<span class="number">  62</span>
<span class="number">  63</span><span class="k1">int</span> <a href="http://www.allegro.cc/manual/readkey"><span class="a">readkey</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_EVENT_QUEUE"><span class="a">ALLEGRO_EVENT_QUEUE</span></a><span class="k3">*</span> eq<span class="k2">)</span> <span class="k2">{</span>
<span class="number">  64</span>   <span class="k1">while</span> <span class="k2">(</span><span class="n">1</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number">  65</span>      <a href="http://www.allegro.cc/manual/ALLEGRO_EVENT"><span class="a">ALLEGRO_EVENT</span></a> ev<span class="k2">;</span>
<span class="number">  66</span>      <a href="http://www.allegro.cc/manual/al_wait_for_event"><span class="a">al_wait_for_event</span></a><span class="k2">(</span>eq , <span class="k3">&amp;</span>ev<span class="k2">)</span><span class="k2">;</span>
<span class="number">  67</span>      <span class="k1">if</span> <span class="k2">(</span>ev.type <span class="k3">=</span><span class="k3">=</span> ALLEGRO_EVENT_KEY_CHAR<span class="k2">)</span> <span class="k2">{</span>
<span class="number">  68</span>         <span class="k1">return</span> ev.keyboard.keycode<span class="k2">;</span>
<span class="number">  69</span>      <span class="k2">}</span>
<span class="number">  70</span>   <span class="k2">}</span>
<span class="number">  71</span>   <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span>
<span class="number">  72</span><span class="k2">}</span>
<span class="number">  73</span>
<span class="number">  74</span>
<span class="number">  75</span>
<span class="number">  76</span><span class="k1">int</span> main<span class="k2">(</span><span class="k1">int</span> argc , <span class="k1">char</span><span class="k3">*</span><span class="k3">*</span> argv<span class="k2">)</span> <span class="k2">{</span>
<span class="number">  77</span>   
<span class="number">  78</span>   <span class="k1">const</span> <span class="k1">char</span><span class="k3">*</span> font_name <span class="k3">=</span> <span class="s">"verdana.ttf"</span><span class="k2">;</span>
<span class="number">  79</span>   
<span class="number">  80</span>   <span class="k1">if</span> <span class="k2">(</span>argc <span class="k3">&gt;</span> <span class="n">1</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number">  81</span>      font_name <span class="k3">=</span> argv<span class="k2">[</span><span class="n">1</span><span class="k2">]</span><span class="k2">;</span>
<span class="number">  82</span>   <span class="k2">}</span>
<span class="number">  83</span>   
<span class="number">  84</span>   
<span class="number">  85</span>   AllegroSetup allegro<span class="k2">(</span><span class="n">800</span>,<span class="n">600</span>,<span class="n">1</span>.<span class="n">0</span><span class="k3">/</span><span class="n">60</span>.<span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  86</span>   <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span>allegro.Ready<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span><span class="k1">return</span> <span class="n">1</span><span class="k2">;</span><span class="k2">}</span>
<span class="number">  87</span>   
<span class="number">  88</span>   <a href="http://www.allegro.cc/manual/al_init_font_addon"><span class="a">al_init_font_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  89</span>   <a href="http://www.allegro.cc/manual/al_init_ttf_addon"><span class="a">al_init_ttf_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  90</span>   
<span class="number">  91</span>   <span class="k1">double</span> start <span class="k3">=</span> <span class="n">0</span>.<span class="n">0</span><span class="k2">;</span>
<span class="number">  92</span>   <span class="k1">double</span> stop <span class="k3">=</span> <span class="n">0</span>.<span class="n">0</span><span class="k2">;</span>
<span class="number">  93</span>   <span class="k1">double</span> load_time <span class="k3">=</span> <span class="n">0</span>.<span class="n">0</span><span class="k2">;</span>
<span class="number">  94</span>   <span class="k1">double</span> cache_time <span class="k3">=</span> <span class="n">0</span>.<span class="n">0</span><span class="k2">;</span>
<span class="number">  95</span>   <span class="k1">double</span> display_time <span class="k3">=</span> <span class="n">0</span>.<span class="n">0</span><span class="k2">;</span>
<span class="number">  96</span>   
<span class="number">  97</span>   <span class="k1">double</span> total_load_time <span class="k3">=</span> <span class="n">0</span>.<span class="n">0</span><span class="k2">;</span>
<span class="number">  98</span>   <span class="k1">double</span> total_cache_time <span class="k3">=</span> <span class="n">0</span>.<span class="n">0</span><span class="k2">;</span>
<span class="number">  99</span>   <span class="k1">double</span> total_display_time <span class="k3">=</span> <span class="n">0</span>.<span class="n">0</span><span class="k2">;</span>
<span class="number"> 100</span>   
<span class="number"> 101</span>   <span class="k1">int</span> count <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 102</span>   
<span class="number"> 103</span>   <span class="k1">const</span> <span class="k1">int</span> NUM <span class="k3">=</span> <span class="n">13</span><span class="k2">;</span>
<span class="number"> 104</span>   <span class="k1">const</span> <span class="k1">char</span><span class="k3">*</span> strs<span class="k2">[</span>NUM<span class="k2">]</span> <span class="k3">=</span> <span class="k2">{</span>
<span class="number"> 105</span>      <span class="s">"abcde"</span>,
<span class="number"> 106</span>      <span class="s">"fghij"</span>,
<span class="number"> 107</span>      <span class="s">"klmno"</span>,
<span class="number"> 108</span>      <span class="s">"pqrst"</span>,
<span class="number"> 109</span>      <span class="s">"uvwxyz"</span>,
<span class="number"> 110</span>      <span class="s">"01234"</span>,
<span class="number"> 111</span>      <span class="s">"56789"</span>,
<span class="number"> 112</span>      <span class="s">"!@#$%"</span>,
<span class="number"> 113</span>      <span class="s">"^&amp;*()"</span>,
<span class="number"> 114</span>      <span class="s">"-=_+"</span>,
<span class="number"> 115</span>      <span class="s">"[]{}\\|"</span>,
<span class="number"> 116</span>      <span class="s">",.&lt;&gt;/?"</span>,
<span class="number"> 117</span>      <span class="s">";:'\""</span>
<span class="number"> 118</span>   <span class="k2">}</span><span class="k2">;</span>
<span class="number"> 119</span>   
<span class="number"> 120</span>   <span class="k1">bool</span> quit <span class="k3">=</span> <span class="k1">false</span><span class="k2">;</span>
<span class="number"> 121</span>   
<span class="number"> 122</span>   <span class="k1">while</span> <span class="k2">(</span><span class="k3">!</span>quit<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 123</span>      <a href="http://www.allegro.cc/manual/ALLEGRO_EVENT"><span class="a">ALLEGRO_EVENT</span></a> ev<span class="k2">;</span>
<span class="number"> 124</span>      <span class="k1">while</span> <span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/al_is_event_queue_empty"><span class="a">al_is_event_queue_empty</span></a><span class="k2">(</span>allegro<span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 125</span>         <a href="http://www.allegro.cc/manual/al_wait_for_event"><span class="a">al_wait_for_event</span></a><span class="k2">(</span>allegro , <span class="k3">&amp;</span>ev<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 126</span>         <span class="k1">if</span> <span class="k2">(</span>ev.type <span class="k3">=</span><span class="k3">=</span> ALLEGRO_EVENT_DISPLAY_CLOSE<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 127</span>            quit <span class="k3">=</span> <span class="k1">true</span><span class="k2">;</span>
<span class="number"> 128</span>            <span class="k1">break</span><span class="k2">;</span>
<span class="number"> 129</span>         <span class="k2">}</span>
<span class="number"> 130</span>         <span class="k1">else</span> <span class="k1">if</span> <span class="k2">(</span>ev.type <span class="k3">=</span><span class="k3">=</span> ALLEGRO_EVENT_KEY_DOWN<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 131</span>            <span class="k1">if</span> <span class="k2">(</span>ev.keyboard.keycode <span class="k3">=</span><span class="k3">=</span> ALLEGRO_KEY_ESCAPE<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 132</span>               quit <span class="k3">=</span> <span class="k1">true</span><span class="k2">;</span>
<span class="number"> 133</span>               <span class="k1">break</span><span class="k2">;</span>
<span class="number"> 134</span>            <span class="k2">}</span>
<span class="number"> 135</span>         <span class="k2">}</span>
<span class="number"> 136</span>      <span class="k2">}</span>
<span class="number"> 137</span>      <span class="k1">if</span> <span class="k2">(</span>quit<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 138</span>         <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span>count<span class="k2">)</span> <span class="k2">{</span>count <span class="k3">=</span> <span class="n">1</span><span class="k2">;</span><span class="k2">}</span>
<span class="number"> 139</span>         <span class="k1">break</span><span class="k2">;</span>
<span class="number"> 140</span>      <span class="k2">}</span>
<span class="number"> 141</span>      
<span class="number"> 142</span>      <span class="c">// measure loading time</span>
<span class="number"> 143</span>      start <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_time"><span class="a">al_get_time</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 144</span>      <a href="http://www.allegro.cc/manual/ALLEGRO_FONT"><span class="a">ALLEGRO_FONT</span></a><span class="k3">*</span> <a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a> <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_ttf_font"><span class="a">al_load_ttf_font</span></a><span class="k2">(</span>font_name , <span class="k3">-</span><span class="n">20</span> , <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 145</span>      stop <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_time"><span class="a">al_get_time</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 146</span>      load_time <span class="k3">=</span> stop <span class="k3">-</span> start<span class="k2">;</span>
<span class="number"> 147</span>      total_load_time <span class="k3">+</span><span class="k3">=</span> load_time<span class="k2">;</span>
<span class="number"> 148</span>      <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a><span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 149</span>         <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"Font file %s failed to load!\n"</span> , font_name<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 150</span>         <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span>count<span class="k2">)</span> <span class="k2">{</span>count <span class="k3">=</span> <span class="n">1</span><span class="k2">;</span><span class="k2">}</span>
<span class="number"> 151</span>         <span class="k1">break</span><span class="k2">;</span>
<span class="number"> 152</span>      <span class="k2">}</span>
<span class="number"> 153</span>      
<span class="number"> 154</span>      <a href="http://www.allegro.cc/manual/al_clear_to_color"><span class="a">al_clear_to_color</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span><span class="n">0</span>,<span class="n">0</span>,<span class="n">0</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 155</span>      
<span class="number"> 156</span>      <span class="c">// measure caching time</span>
<span class="number"> 157</span>      start <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_time"><span class="a">al_get_time</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 158</span>      <span class="k1">for</span> <span class="k2">(</span><span class="k1">int</span> i <span class="k3">=</span> <span class="n">0</span> <span class="k2">;</span> i <span class="k3">&lt;</span> NUM <span class="k2">;</span> <span class="k3">+</span><span class="k3">+</span>i<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 159</span>         <span class="k1">int</span> x <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_text_width"><span class="a">al_get_text_width</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a> , strs<span class="k2">[</span>i<span class="k2">]</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 160</span>      <span class="k2">}</span>
<span class="number"> 161</span>      stop <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_time"><span class="a">al_get_time</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 162</span>      cache_time <span class="k3">=</span> stop <span class="k3">-</span> start<span class="k2">;</span>
<span class="number"> 163</span>      total_cache_time <span class="k3">+</span><span class="k3">=</span> cache_time<span class="k2">;</span>
<span class="number"> 164</span>      
<span class="number"> 165</span>      <a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> white <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span><span class="n">255</span>,<span class="n">255</span>,<span class="n">255</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 166</span>      <span class="c">// measure drawing time</span>
<span class="number"> 167</span>      start <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_time"><span class="a">al_get_time</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 168</span>      <span class="k1">for</span> <span class="k2">(</span><span class="k1">int</span> i <span class="k3">=</span> <span class="n">0</span> <span class="k2">;</span> i <span class="k3">&lt;</span> NUM <span class="k2">;</span> <span class="k3">+</span><span class="k3">+</span>i<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 169</span><span class="c">//void al_draw_text(const ALLEGRO_FONT *font , ALLEGRO_COLOR color, float x , float y , int flags , char const *text)</span>
<span class="number"> 170</span>         <a href="http://www.allegro.cc/manual/al_draw_text"><span class="a">al_draw_text</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a> , white , <span class="n">10</span> , <span class="n">10</span> <span class="k3">+</span> <span class="n">30</span><span class="k3">*</span>i , <span class="n">0</span> , strs<span class="k2">[</span>i<span class="k2">]</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 171</span>      <span class="k2">}</span>
<span class="number"> 172</span>      stop <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_time"><span class="a">al_get_time</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 173</span>      display_time <span class="k3">=</span> stop <span class="k3">-</span> start<span class="k2">;</span>
<span class="number"> 174</span>      total_display_time <span class="k3">+</span><span class="k3">=</span> display_time<span class="k2">;</span>
<span class="number"> 175</span>      
<span class="number"> 176</span>      <span class="k3">+</span><span class="k3">+</span>count<span class="k2">;</span>
<span class="number"> 177</span><span class="c">//void al_draw_textf(const ALLEGRO_FONT *font, ALLEGRO_COLOR color , float x , float y , int flags , const char *format, ...)</span>
<span class="number"> 178</span>      <a href="http://www.allegro.cc/manual/al_draw_textf"><span class="a">al_draw_textf</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a> , white , <span class="n">410</span> , <span class="n">10</span> , <span class="n">0</span> , <span class="s">"Average load time  = %0.3f ms"</span> , <span class="n">1000</span>.<span class="n">0f</span><span class="k3">*</span><span class="k2">(</span><span class="k2">(</span><span class="k1">float</span><span class="k2">)</span>total_load_time <span class="k3">/</span> <span class="k2">(</span><span class="k1">float</span><span class="k2">)</span>count<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 179</span>      <a href="http://www.allegro.cc/manual/al_draw_textf"><span class="a">al_draw_textf</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a> , white , <span class="n">410</span> , <span class="n">40</span> , <span class="n">0</span> , <span class="s">"Average cache time = %0.3f ms"</span> , <span class="n">1000</span>.<span class="n">0f</span><span class="k3">*</span><span class="k2">(</span><span class="k2">(</span><span class="k1">float</span><span class="k2">)</span>total_cache_time <span class="k3">/</span> <span class="k2">(</span><span class="k1">float</span><span class="k2">)</span>count<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 180</span>      <a href="http://www.allegro.cc/manual/al_draw_textf"><span class="a">al_draw_textf</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a> , white , <span class="n">410</span> , <span class="n">70</span> , <span class="n">0</span> , <span class="s">"Average draw time  = %0.3f ms"</span> , <span class="n">1000</span>.<span class="n">0f</span><span class="k3">*</span><span class="k2">(</span><span class="k2">(</span><span class="k1">float</span><span class="k2">)</span>total_display_time <span class="k3">/</span> <span class="k2">(</span><span class="k1">float</span><span class="k2">)</span>count<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 181</span>      <a href="http://www.allegro.cc/manual/al_draw_textf"><span class="a">al_draw_textf</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a> , white , <span class="n">410</span> , <span class="n">100</span> , <span class="n">0</span> , <span class="s">"Test count = %i tests"</span> , count<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 182</span>      
<span class="number"> 183</span>      <a href="http://www.allegro.cc/manual/al_flip_display"><span class="a">al_flip_display</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 184</span>      
<span class="number"> 185</span>      <a href="http://www.allegro.cc/manual/al_destroy_font"><span class="a">al_destroy_font</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 186</span>   <span class="k2">}</span>
<span class="number"> 187</span>
<span class="number"> 188</span>   <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"Average load time     = %0.3lf ms\n"</span> , <span class="n">1000</span>.<span class="n">0</span><span class="k3">*</span><span class="k2">(</span>total_load_time <span class="k3">/</span> <span class="k2">(</span><span class="k1">double</span><span class="k2">)</span>count<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 189</span>   <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"Average cache time    = %0.3lf ms\n"</span> , <span class="n">1000</span>.<span class="n">0</span><span class="k3">*</span><span class="k2">(</span>total_cache_time <span class="k3">/</span> <span class="k2">(</span><span class="k1">double</span><span class="k2">)</span>count<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 190</span>   <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"Average display time  = %0.3lf ms\n"</span> , <span class="n">1000</span>.<span class="n">0</span><span class="k3">*</span><span class="k2">(</span>total_display_time <span class="k3">/</span> <span class="k2">(</span><span class="k1">double</span><span class="k2">)</span>count<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 191</span>   <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"Test count = %i\n"</span> , count<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 192</span>   
<span class="number"> 193</span>   <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 194</span><span class="k2">}</span>
</div></div><p>

I ran it for about 10 minutes and here are my results :
</p><pre>
c:\ctwoplus\progcode\allegro5\test&gt;A5Bouncer.exe
Average load time     = 0.980 ms
Average cache time    = 305.909 ms
Average display time  = 0.368 ms
Test count = 2130

c:\ctwoplus\progcode\allegro5\test&gt;
</pre><p>

So there is definitely a noticeable delay when caching the glyphs - just over 3/10ths of a second.</p><p>I still think there should be an explicit function in Allegro 5 that will do this for you, and al_get_text_width is cumbersome to use when you have different languages and varied characters in use. It could be as simple as :
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> al_cache_glyph_range<span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_FONT"><span class="a">ALLEGRO_FONT</span></a><span class="k3">*</span> <a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a> , <span class="k1">int</span> start , <span class="k1">int</span> number<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

Imagine the case where users wish to display Kanji - they will almost always be caching new glyphs, and there will be noticeable slowdowns during their program every time they draw new text.</p><p>PS. Why does verdana.ttf look like <span class="cuss"><span><span class="cuss"><span>shit</span></span></span></span> (some characters are noticeably lighter or darker than others) ?<br /><span class="remote-thumbnail"><span class="json">{"name":"604233","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/1\/a1a1d12e510134d770d50f9f39bc9134.png","w":812,"h":632,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/1\/a1a1d12e510134d770d50f9f39bc9134"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/a/1/a1a1d12e510134d770d50f9f39bc9134-240.jpg" alt="604233" width="240" height="186" /></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Wed, 08 Jun 2011 06:35:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920503#target">Edgar Reynaldo</a> said:</div><div class="quote"><p> PS. Why does verdana.ttf look like  (some characters are noticeably lighter or darker than others) ?</p></div></div><p>It seems to me that the anti aliasing isn&#39;t allowing any pixels in the thinnest parts to be drawn full white.  I&#39;ve tried forcing pixels to be all white past a certain threshold, but then they have the jaggies, looking even worse.  If you want a small font to look good, choose a font that cooperates.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Wed, 08 Jun 2011 06:39:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920503#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>The manual says absolutely nothing about al_get_text_width caching glyphs. Are we supposed to be psychic?</p></div></div><p>No, but it has to render the characters to be able to measure the length a given string will be when drawn. I was kinda surprised at that too the first time I heard about it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 08 Jun 2011 06:41:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920505#target">Arthur Kalliokoski</a> said:</div><div class="quote"><p>
It seems to me that the anti aliasing isn&#39;t allowing any pixels in the thinnest parts to be drawn full white. I&#39;ve tried forcing pixels to be all white past a certain threshold, but then they have the jaggies, looking even worse. If you want a small font to look good, choose a font that cooperates.
</p></div></div><p>
You&#39;re right, it was just a <span class="cuss"><span><span class="cuss"><span><span class="cuss"><span>shit</span></span></span></span>ty</span></span> font. I tried using AMCerasoli&#39;s consola.ttf font, and it looks a 1000 times better with the same dimensions.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920506#target">Thomas Fjellstrom</a> said:</div><div class="quote"><p>
No, but it has to render the characters to be able to measure the length a given string will be when drawn. I was kinda surprised at that too the first time I heard about it.
</p></div></div><p>
That doesn&#39;t make much sense - what do you do, test pixel colors? Can&#39;t you calculate the width given the information in the font? Why does it have to be drawn first?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Wed, 08 Jun 2011 06:54:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920507#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>Why does it have to be drawn first?</p></div></div><p>I don&#39;t know. But I assume it has to do with how non fixed width fonts will render a specific sentence. A sentence&#39;s length depends on the order of the characters. Sometimes a row here or there is skipped.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 08 Jun 2011 07:02:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>@Arthur<br />I got verdana.ttf to look good by using the flag ALLEGRO_TTF_MONOCHROME when loading the font. It disables anti-aliasing for the font. It also made consola.ttf look chunky and ugly though, so it doesn&#39;t work for every font.</p><p>@Thomas<br />It still seems like it should just be a sum of widths and offsets based on a lookup. Without knowing the guts of Allegro 5 and FreeType though, I couldn&#39;t say if it could be done.</p><p>I expanded my test to include a second measurement of al_get_text_width for the same strings, and it took just as long as the first time! That has got to be the slowest function I&#39;ve seen in a while. 13 5 character strings takes 0.3 seconds to measure the width of? I guess that precludes me from making any text editors with Allegro 5 then. </p><p>Why doesn&#39;t al_get_text_width take advantage of the fact that the glyphs it is using are already cached?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Wed, 08 Jun 2011 07:38:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920435#target">Matthew Leverton</a> said:</div><div class="quote"><p>
Theoretically, yes. While it may seem more proper to put big new features into a 5.2 branch, it (in my opinion) isn&#39;t worth it because maintaining two major releases is a pain in the butt. People will expect the older 5.0 branch to be continued to be maintained (bug fixed), which is just a hassle when it comes to providing binaries.</p><p>I would leave 5.2 alone until we come up with things that either completely break backward compatibility or are major changes to the core or how things are done. I don&#39;t know what would fit in that latter category.</p><p>Peter W&#39;s opinion would be more useful than mine.
</p></div></div><p>

I&#39;ve had problems with my internet connection the last few days, so I haven&#39;t been following closely.</p><p>My plan was to stick with the Allegro 4 model, of which there are two. In 4.0.x we maintained forward <b>and</b> backwards compatibility, meaning no new symbols would be added in a stable branch. In 4.2.x, we dropped the forwards compatibility requirement. Following that model, we could add new symbols within the 5.0.x branch. I haven&#39;t done that so far, even for small additions.</p><p>Our development model doesn&#39;t really allow backporting of big changes. All sorts of stuff gets dumped together into the unstable branch then refined over time. It&#39;s not easy to untangle the final state of a single feature for inclusion into the stable branch. The alternative is to stabilise all the new features together at once, then declare the unstable branch &#39;stable&#39;. Since we already call the unstable branch &#39;5.1&#39;, it would be a bit confusing to release it as &#39;5.0.4&#39;... but possible.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Wed, 08 Jun 2011 11:11:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Whether something is called 5.0.X or 5.2.0 doesn&#39;t matter to me as long as we aren&#39;t trying to maintain 5.0 for very long after 5.2 is released. Obviously programs that dynamically link against 5.0 would cease getting free upgrades, but I don&#39;t particularly care about that...</p><p>Would you include new addons in 5.0? Seems like those shouldn&#39;t require any changes to the core Allegro that would be hard to backport.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Wed, 08 Jun 2011 11:27:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920467#target">AMCerasoli</a> said:</div><div class="quote"><p>If that &quot;someone&quot; had read the entire thread he would know that I&#39;m using multi-thread but the example (which is presenting the same problem) isn&#39;t.</p></div></div><p>
Someone has read the entire thread before trying to help you.<br />Someone has also seen it explained to you over and over again that:<br />1) You must load fonts from the &quot;main&quot; thread. (technically you have to load them from the thread that creates the display if I understand correctly)<br />2) If certain glyphs in the font are uncached, they will be cached when they are first drawn (because there&#39;s no better way to automatically choose what to cache) but<br />3) You can cause the glyphs to be cached yourself (for example by writing &quot;abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456780-=&quot; once before that actual game logic is started), which means that there will be no delays during the game when first writing something.<br />This is it. This is how things are.</p><p>You however keep repeating that allegro should cache some glyphs for you when first loading the font, and again it has been explained to you that it will only move the &quot;horrible delay&quot; from when you (the programmer) choose to draw/cache the font (for example, by doing (3) from before) to the loading function.<br />You can even implement the function you want to have by yourself!<br />Something like: (not guaranteed to work, just an example)
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/ALLEGRO_FONT"><span class="a">ALLEGRO_FONT</span></a> <span class="k3">*</span>AMCerasoli_load_and_cache<span class="k2">(</span><span class="k1">const</span> <span class="k1">char</span> <span class="k3">*</span>filename, <span class="k1">int</span> size, <span class="k1">int</span> flags<span class="k2">)</span>
<span class="k2">{</span>
 <a href="http://www.allegro.cc/manual/ALLEGRO_FONT"><span class="a">ALLEGRO_FONT</span></a> <span class="k3">*</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a> <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_font"><span class="a">al_load_font</span></a><span class="k2">(</span>filename, size, flags<span class="k2">)</span><span class="k2">;</span>
 <a href="http://www.allegro.cc/manual/al_get_text_width"><span class="a">al_get_text_width</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a>, <span class="s">"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"</span><span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
<a href="http://www.allegro.cc/manual/ALLEGRO_FONT"><span class="a">ALLEGRO_FONT</span></a> <span class="k3">*</span>AMCerasoli_load_and_cache<span class="k2">(</span><span class="k1">const</span> <span class="k1">char</span> <span class="k3">*</span>filename, <span class="k1">int</span> size, <span class="k1">int</span> flags<span class="k2">)</span>
<span class="k2">{</span>
 <a href="http://www.allegro.cc/manual/ALLEGRO_FONT"><span class="a">ALLEGRO_FONT</span></a> <span class="k3">*</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a> <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_font"><span class="a">al_load_font</span></a><span class="k2">(</span>filename, size, flags<span class="k2">)</span><span class="k2">;</span>
 <a href="http://www.allegro.cc/manual/al_get_text_width"><span class="a">al_get_text_width</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a>, <span class="s">"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"</span><span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>

</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920480#target">AMCerasoli</a> said:</div><div class="quote"><p>my current game is running at 30FPS logic and drawing, for that reason I can see it.</p></div></div><p>
I probably shouldn&#39;t ask, but how is your game timed to 30FPS? You didn&#39;t by chance time it like the example by simply calling al_rest() after each loop, right?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Slartibartfast)</author>
		<pubDate>Wed, 08 Jun 2011 12:41:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920503#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>The manual says absolutely nothing about al_get_text_width caching glyphs. Are we supposed to be psychic?</p></div></div><p>

No, the manual and/or code should be improved. That&#39;s why threads like this are good (if anyone will care to submit a patch) <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>PS. Why does verdana.ttf look like  (some characters are noticeably lighter or darker than others) ?</p></div></div><p>

Try setting your web browser to use verdana.ttf (with the same size). Does it look different there? If not then the problem is with the font. Otherwise if it looks better than Allegro there, try using another program using freetype (for me that&#39;s firefox on linux, which has pixel-by-pixel 100% identical rgb values to Allegro here). If there is a difference then the ttf addon does something wrong and we should try to fix it.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920509#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>I expanded my test to include a second measurement of al_get_text_width for the same strings, and it took just as long as the first time!</p></div></div><p>

Hm, maybe al_get_text_width doesn&#39;t cache after all, let me check the code...</p><p>[edit:]</p><p>I can&#39;t try any examples from here, but at least it does look like it uses the cache (<span class="source-code"><span class="k1">if</span> <span class="k2">(</span>glyph-&gt;bitmap<span class="k2">)</span></span>): <a href="http://allefant.com/gtags/S/1921.html#L178">http://allefant.com/gtags/S/1921.html#L178</a></p><p>Is your example updated to do that second measurement? kazzmir&#39;s timing results suggest that caching is being used (and improves time a lot). But AMCerasoli also saw no improvement after the al_get_text_width() line it seems... does allegro.log say anything suspicious? There may very well be some bug in the glyph caching code (I remember reports here where the first cached glyph was never drawn for example but could never find a cause.)</p><p>Maybe you and AMCerasoli are both using DirectX but everyone else is using OpenGL? And then the bug would be somewhere in the DirectX code, maybe it fails locking very small bitmap regions very often or something.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Wed, 08 Jun 2011 15:29:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Linux make worst possible use of FreeType, so this is bad example. The cause of odd looking Vertana is probably in A5 TTF addon code. I didn&#39;t looked at the it yet.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Michał Cichoń)</author>
		<pubDate>Wed, 08 Jun 2011 16:50:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920559#target">Michał Cichoń</a> said:</div><div class="quote"><p>Linux make worst possible use of FreeType</p></div></div><p> Got some reference for that?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Wed, 08 Jun 2011 17:50:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think <a href="http://www.antigrain.com/research/font_rasterization/index.html#FONT_RASTERIZATION">this</a> describe the issue.<br />Mostly I agree with opinion in this article.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Michał Cichoń)</author>
		<pubDate>Wed, 08 Jun 2011 18:08:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Interesting, but at least in my Linux (Ubuntu, but manually changed the gnome font settings until it looked good) Freetype just seems to be perfectly tuned then. Coincidentally, text there looks almost like in Windows (and on my Mac indeed all text looks worse than both of those) <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Wed, 08 Jun 2011 18:41:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>FreeType require at least basic knowledge about typography how it apply to raster grids. People responsible for creating font rendering in our new engine are very creative on field of missuses.<br />I had to agree Linux (Gnome actually) has improved on field of text rendering.<br />Ok, maybe we should leave this as a digression. Because how exactly &quot;good looking&quot; text is defined depends from who is looking.<br />Please go back to performance problems <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Michał Cichoń)</author>
		<pubDate>Wed, 08 Jun 2011 19:15:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Edgar Reynaldo: I modified your example to do the cache timing twice and this is what it looks here:<br /><span class="remote-thumbnail"><span class="json">{"name":"604237","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/2\/52dd016bca4c51b20edcb30f3e06ce72.png","w":810,"h":629,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/2\/52dd016bca4c51b20edcb30f3e06ce72"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/5/2/52dd016bca4c51b20edcb30f3e06ce72-240.jpg" alt="604237" width="240" height="186" /></span></p><p>So yes, caching is slow. But at least it does seem to work and al_get_text_width() is fast once the glyphs are cached.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Wed, 08 Jun 2011 22:25:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The glyph caching in the TTF addon should probably be optimised by caching more than one glyph at a time, thereby removing redundant lock/unlocks. (I didn&#39;t check it though).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Thu, 09 Jun 2011 05:41:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>There was a bug - I was adding the wrong variable to the second cache&#39;s total time.</p><p>After I fixed it, the second cache time was almost negligible. I also compared DIRECT3D to OPENGL and OPENGL_3_0 drivers :</p><p>Direct3D :
</p><pre>
c:\ctwoplus\progcode\allegro5\test&gt;A5Bouncer.exe
Average load time     = 1.278 ms
Average cache time    = 310.100 ms
Average cache2 time   = 0.021 ms
Average display time  = 0.202 ms
Test count = 100

</pre><p>

OpenGL :
</p><pre>
c:\ctwoplus\progcode\allegro5\test&gt;A5Bouncer.exe
Average load time     = 0.639 ms
Average cache time    = 41.820 ms
Average cache2 time   = 0.014 ms
Average display time  = 0.295 ms
Test count = 500

</pre><p>

OpenGL 3.0 :<br />Couldn&#39;t test, failed to create a display with this option on my laptop.</p><p>OpenGL is a little more than 7.5 times as fast as Direct3D when creating the initial cache of glyphs, but slightly slower to draw and faster to load.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 09 Jun 2011 05:42:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I just ran the test of my computer.<br />Average load time     = 0.34 ms<br />Average cache time    = 25 ms<br />Average cache2 time   = 0.016 ms<br />Average display time  = 0.065 ms</p><p>But... The main reason I&#39;m posting is that the first time I ran it the average cache time was more like 300ms. It dropped dramatically the second time without me having changed anything. I can only guess that the drop was a result of some kind of Windows 7 automatic optimization.</p><p>(I assume it&#39;s using Direct3D.)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Karadoc ~~)</author>
		<pubDate>Thu, 09 Jun 2011 08:19:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920692#target">Karadoc ~~</a> said:</div><div class="quote"><p> the drop was a result of some kind of Windows 7 automatic optimization.</p></div></div><p>I&#39;d guess verdana.ttf was already in file buffers.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Thu, 09 Jun 2011 08:43:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920688#target">Peter Wang</a> said:</div><div class="quote"><p>The glyph caching in the TTF addon should probably be optimised by caching more than one glyph at a time, thereby removing redundant lock/unlocks. (I didn&#39;t check it though).
</p></div></div><p>

Yes, if someone makes a patch for an extra al_cache_glyph_rage function as Edgar proposed it could do that. However I&#39;m not sure it really would be faster. At least with OpenGL locking a bitmap region only locks that region (i.e. GPU transfer is limited to the locked area). Multiple calls therefore only save the lock commands themselves. Since the al_get_text_width(&quot;abc...&quot;) approach does not do any other OpenGL calls between the lock/unlock calls it might have little to no effect. The driver even might optimize it into a single lock already. But only trying it out would tell of course.</p><p>About the DirectX case, not sure why it&#39;s so slow. I don&#39;t understand how locking works there at all - if someone likes to read up on MSDN I&#39;m sure we could make it as fast as OpenGL. If it&#39;s that every lock/unlock call has to download/upload the whole bitmap from/to the GPU then reducing the times the bitmap is locked will have a big impact there of course.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Thu, 09 Jun 2011 16:45:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I was thinking we&#39;d just cache the new glyphs as a first pass over the string in the render() method, then draw them in a second pass. That way you can minimise the number of times you lock the cache bitmap.  I had a quick try at this, but it&#39;s not a completely trivial change.</p><p>I think it would make a big difference. On the benchmark you posted, I can reduce the average cache time from 19.5 ms to ~13 ms just by reducing the cache bitmap size from 256x256 to 128x128. If I switch to using memory bitmaps, the cache time drops to 0.9 ms (obviously drawing time goes up).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Thu, 09 Jun 2011 18:44:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hm, I guess something with locking doesn&#39;t work the way I thought then.</p><p>Or maybe your numbers can be explained by the fact that we do an unconditional texture upload of the complete texture whenever a bitmap is first created. This is of course stupid. Whenever a 256x256 cache is created al_create_bitmap allocates 256x256 pixels worth of uninitialized memory and uploads them to a texture just to clear that texture immediately afterwards. Instead we should leave the texture un-initialized in the first place (pass NULL to glTexImage2D). (This will also speed up al_load_bitmap.)</p><p>Also, looking at the ttf code we do some stupid things during cache creation, for example:
</p><div class="source-code snippet"><div class="inner"><pre> <span class="n">297</span>                      <span class="k1">unsigned</span> <span class="k1">char</span> c <span class="k3">=</span> <span class="k3">*</span>ptr<span class="k2">;</span>
 <span class="n">298</span>                      <span class="k1">float</span> cf <span class="k3">=</span> c <span class="k3">/</span> <span class="n">255</span>.<span class="n">0f</span><span class="k2">;</span>
 <span class="n">299</span>                      <span class="k3">*</span>dptr<span class="k3">+</span><span class="k3">+</span> <span class="k3">=</span> <span class="n">255</span> <span class="k3">*</span> cf<span class="k2">;</span>
 <span class="n">300</span>                      <span class="k3">*</span>dptr<span class="k3">+</span><span class="k3">+</span> <span class="k3">=</span> <span class="n">255</span> <span class="k3">*</span> cf<span class="k2">;</span>
 <span class="n">301</span>                      <span class="k3">*</span>dptr<span class="k3">+</span><span class="k3">+</span> <span class="k3">=</span> <span class="n">255</span> <span class="k3">*</span> cf<span class="k2">;</span>
 <span class="n">302</span>                      <span class="k3">*</span>dptr<span class="k3">+</span><span class="k3">+</span> <span class="k3">=</span> c<span class="k2">;</span>
</pre></div></div><p>
That&#39;s a useless divide, three useless multiplies and 4 useless float/char conversions for each pixel. Probably negligible performance-wise but still hurts my eyes <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /></p><p>[edit:]</p><p>I changed both of those things, but neither made a difference.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Thu, 09 Jun 2011 19:11:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/920728#target">Elias</a> said:</div><div class="quote"><p>Probably negligible performance-wise but still hurts my eyes <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />[edit:]I changed both of those things, but neither made a difference.</p></div></div><p>
The compiler may be clever enough to figure out that it should eliminate both the divide and the multiply. Maybe. Maybe not.<br />I wouldn&#39;t expect a massive performance boost either way, but yes, that sight of that code makes you want to slam you head against your desk (or it would, were I not on the sofa with a fever).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Fri, 10 Jun 2011 01:22:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok, according to valgrind --tool=cachegrind 75% of all time is spent in <span class="source-code">glTexSubImage2d<span class="k3">&lt;</span><span class="k3">-</span>ogl_unlock_region<span class="k3">&lt;</span><span class="k3">-</span>al_unlock_region<span class="k3">&lt;</span><span class="k3">-</span>al_unlock_bitmap-&gt;cache_glyph<span class="k3">&lt;</span><span class="k3">-</span>render_glyph<span class="k3">&lt;</span><span class="k3">-</span><a href="http://www.allegro.cc/manual/text_length"><span class="a">text_length</span></a><span class="k3">&lt;</span><span class="k3">-</span><a href="http://www.allegro.cc/manual/al_get_text_width"><span class="a">al_get_text_width</span></a></span>.</p><p>(92% of all time is spent in al_get_text_width - FT_Load_Glyph only takes up about 8%)</p><p>So yes, caching multiple glyphs at a time and thus reducing the calls to glTexSubImage2D seems to be the way to optimize this <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>Also interesting, half of the time spent in glTexSubImage2D is actually shown inside of memcpy - so it seems the first thing my OpenGL driver does is copy the passed memory somewhere else. Could also have to do with valgrind, everything runs very slow under it so its profiling results can be quite inaccurate.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Fri, 10 Jun 2011 01:53:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok, I&#39;m working on it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Fri, 10 Jun 2011 18:52:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yeah, one of the things you want to do with many OpenGL Drivers is cut down on the number of OpenGL calls as much as possible. Many of them do a lot of setup and tear down for one call, and it can add up.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 10 Jun 2011 19:22:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>In 5.1 now:</p><p><span class="remote-thumbnail"><span class="json">{"name":"604282","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/d\/ed92c4fa8cd621687df68979d49d84f8.png","w":800,"h":600,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/d\/ed92c4fa8cd621687df68979d49d84f8"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/e/d/ed92c4fa8cd621687df68979d49d84f8-240.jpg" alt="604282" width="240" height="180" /></span></p><p>The bottleneck now is clearing new bitmaps(!). This is only a hack to avoid artefacts when OpenGL samples the pixels around the actual glyph. If I comment that out:</p><p><span class="remote-thumbnail"><span class="json">{"name":"604283","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/7\/d753057ed86b6505a3c8db333762ae22.png","w":800,"h":600,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/7\/d753057ed86b6505a3c8db333762ae22"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/d/7/d753057ed86b6505a3c8db333762ae22-240.jpg" alt="604283" width="240" height="180" /></span></p><p>(I don&#39;t understand the other timing differences.)<br />The clearing is avoidable, but is too tedious for me to do.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Sat, 11 Jun 2011 12:08:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>WOW! <img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" /></p><p>Any chance you can do the same thing for the Direct3D drivers?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sat, 11 Jun 2011 12:25:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>D3D should have benefited from the same change. Post your results for that?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Sat, 11 Jun 2011 12:41:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Downloading 5.1 from SVN...</p><p>I won&#39;t be able to test for a while - it&#39;s taking me longer to get setup than I thought.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sat, 11 Jun 2011 12:50:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><pre class="terminal scroll">matthew@mercury:~/tmp$ ./font50
Average load time     = 0.476 ms
Average cache time    = 8.766 ms
Average display time  = 0.440 ms
Test count = 1012

matthew@mercury:~/tmp$ ./font51
Average load time     = 0.316 ms
Average cache time    = 4.946 ms
Average display time  = 0.586 ms
Test count = 1013</pre><p>

Looks like cache time has dropped but display time has increased (OpenGL). This is 5.0 compared to 5.1 SVN.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Sat, 11 Jun 2011 23:52:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ah, that&#39;s not good. I modified the benchmark to better represent what a real program does, but the slowdown is still there (0.060 ms/call to 0.066 ms/call on my machine).  The problem seems to be simply making the second pass over the string.</p><p>Since drawing speed is a lot more important than caching speed, I guess I&#39;ll have to back out that part of my changes.</p><p>EDIT: but we can still do it when the caching is done as part of computing text dimensions. Done in SVN.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Sun, 12 Jun 2011 17:37:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The latest SVN was even slower with the original test (~0.586 to ~0.644).</p><p>But with your test program, SVN is the same speed as 5.0.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Sun, 12 Jun 2011 23:08:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Try turning off cpu throttling. I wouldn&#39;t put too much stock in the original test anyway, at least the drawing part. It does too little of it and is likely impacted by all the other things going on.</p><p>ex_ttf should be more representative of real programs. On my machine it went from ~4800 FPS to ~5500 FPS (cpu throttling disabled). Most of that should be attributed to the improvements to al_get_text_dimensions.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Mon, 13 Jun 2011 05:12:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Manually maxing the CPU frequency didn&#39;t change things.</p><p>ex_ttf is slightly (&lt;2%) faster in SVN than 5.0. (Integrated Intel GMA950.)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Mon, 13 Jun 2011 05:44:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Can you also test r14782 instead of 5.0? That&#39;s what I have been comparing.  The 5.1 seems to have regressed slightly due to other changes.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Mon, 13 Jun 2011 06:05:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The latest is about 7% faster than 14782 on ex_ttf.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Mon, 13 Jun 2011 06:24:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>r14533 is the culprit.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Make al_compose_transform do a full 3d multiply. Add some possibly necessary (for 3d) bits to al_ortho_transform
</p></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Mon, 13 Jun 2011 06:53:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Okay, finally got all of A5 built from SVN.</p><p>I compared the results from 5.0.2 earlier to SVN r14784 (after your initial fix) and to SVN r14796 (latest) and these are the times I came up with :</p><pre>
All times in milliseconds
-------------------------------------------------------------
                |   load   |  cache   |  cache2  | display  |
-------------------------------------------------------------
OpenGL          |          |          |          |          |
----------------|----------|----------|----------|----------|
5.0.2           |    0.639 |   41.820 |    0.014 |    0.295 |
5.1SVN r14784   |    0.643 |   15.076 |    0.030 |    0.336 |
5.1SVN r14796   |    0.619 |   13.344 |    0.017 |    0.437 |
-------------------------------------------------------------
Direct3D        |          |          |          |          |
----------------|----------|----------|----------|----------|
5.0.2           |    1.278 |  310.100 |    0.021 |    0.202 |
5.1SVN r14784   |    0.680 |   86.996 |    0.034 |    0.197 |
5.1SVN r14796   |    0.653 |   32.468 |    0.020 |    0.199 |
-------------------------------------------------------------
</pre><p>

Direct3D is looking really nice now, and the caching time is comparable with OpenGL. The cache times for the latest svns for OpenGL have definitely improved too.</p><p>The only thing that might have gotten worse is display times for the latest svn version for OpenGL.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Tue, 14 Jun 2011 11:18:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks for testing. But I don&#39;t know what to think. Can you post results for ex_ttf?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Tue, 14 Jun 2011 16:22:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/921151#target">Peter Wang</a> said:</div><div class="quote"><p>r14533 is the culprit.</p></div></div><p>

That should have affected OpenGL and D3D equally <span class="ref"><sup>[<a href="#">1</a>]</sup></span> Wonder what else (specific to OpenGL) made drawing slower.
</p><div class="ref-block"><h2>References</h2><ol><li><a href="http://svn.tomasu.org/index.cgi/allegro/revision/?rev=14533">http://svn.tomasu.org/index.cgi/allegro/revision/?rev=14533</a></li></ol></div></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Tue, 14 Jun 2011 16:42:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What&#39;s the errorbar on those numbers?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Tue, 14 Jun 2011 16:45:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/921333#target">Evert</a> said:</div><div class="quote"><p>
What&#39;s the errorbar on those numbers?
</p></div></div><p>
You mean the statistical variance? I have no idea. I ran the program until the numbers had pretty much stabilized. For OpenGL, it ran fast enough that it had made between 500 and 1000 tests. For Direct3D with 5.0.2 it probably only took 100 tests (which took about 30 seconds for it). The later Direct3D versions are probably comparable to the number of tests for OpenGL.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607522/921330#target">Peter Wang</a> said:</div><div class="quote"><p>
Thanks for testing. But I don&#39;t know what to think. Can you post results for ex_ttf?
</p></div></div><p>

Here you go :
</p><pre>
                   |        FPS
-------------------------------
5.0.2              |  1000-1150
5.1 SVN r14784     |   900-1000
5.1 SVN r14796     |   975-1175
--------------------------
</pre><p>
I did my best to give the most common ranges for the program. It would probably give better results if the fps was averaged.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Wed, 15 Jun 2011 06:03:27 +0000</pubDate>
	</item>
</rss>
