<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Allegro Fonts in 3D space and with a custom frustum</title>
		<link>http://www.allegro.cc/forums/view/610628</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 16 Jul 2012 15:11:14 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I have been using Allegro to complement my direct use of OpenGL.</p><p>I think that the OpenGL frustum is set to the window size in Allegro by default (ie. 800x600 for an 800x600 pixeled window). My setup is not like that, even for 2D games.</p><p>My previous experience with OpenGL and fonts is to use the display lists which render 2D sprites and then shift the modelview matrix a bit (glTranslatef) to the right after each glyph to render the next glyph. This allowed me to render to other framebuffers and it also allowed me to use the matrix transformation functions (glTranslatef, glScalef, etc.) to position the text along with the 3D objects and 2D sprites.</p><p>Also, when loading a font, the projection matrix is altered upon the first use for caching. This can be fixed by resetting the projection matrix afterwards but this may be a bit of a problem if I intend to load fonts on the go.</p><p>However, even after this, the font is enormous when rendered. I think that its rendering function assumes that the frustum is going to be the original size (800x600 or so) rather than what it really is. Using glScalef doesn&#39;t change it.</p><p>I would like to know how other people use the allegro_font library in their programs when they do not use the typical Allegro rendering functionality. I don&#39;t really want to load fonts myself via libfreetype if Allegro can do it for me.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Archon)</author>
		<pubDate>Sun, 15 Jul 2012 11:34: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/610628/960162#target">Archon</a> said:</div><div class="quote"><p>I think that the OpenGL frustum is set to the window size in Allegro by default (ie. 800x600 for an 800x600 pixeled window). My setup is not like that, even for 2D games.</p></div></div><p>

It&#39;s only a default, you can change it to whatever you like.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Also, when loading a font, the projection matrix is altered upon the first use for caching.</p></div></div><p>

This could be a bug.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>However, even after this, the font is enormous when rendered. I think that its rendering function assumes that the frustum is going to be the original size (800x600 or so) rather than what it really is.</p></div></div><p>

No. The font simply has the size it was loaded with. So if you load a 20-pixel font it will have a size of 20 units. If your whole screen is only 1 unit wide it is huge now. Simply scale it before drawing.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Using glScalef doesn&#39;t change it.</p></div></div><p>

The OpenGL matrix is ignored by Allegro - you have to use transformations.</p><p>The transformations use the opposite order of OpenGL unfortunately so will be quite confusing for someone used to OpenGL. Basically something like this:
</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>   <a href="http://www.allegro.cc/manual/ALLEGRO_TRANSFORM"><span class="a">ALLEGRO_TRANSFORM</span></a> backup<span class="k2">;</span>
<span class="number">  2</span>   <a href="http://www.allegro.cc/manual/ALLEGRO_TRANSFORM"><span class="a">ALLEGRO_TRANSFORM</span></a> transform<span class="k2">;</span>
<span class="number">  3</span>
<span class="number">  4</span>   <span class="c">// In the beginning:</span>
<span class="number">  5</span>   <a href="http://www.allegro.cc/manual/al_identity_transform"><span class="a">al_identity_transform</span></a><span class="k2">(</span><span class="k3">&amp;</span>transform<span class="k2">)</span><span class="k2">;</span>
<span class="number">  6</span>   sx <span class="k3">=</span> <span class="n">1</span>.<span class="n">0</span> <span class="k3">/</span> w<span class="k2">;</span>
<span class="number">  7</span>   sy <span class="k3">=</span> <span class="n">1</span>.<span class="n">0</span> <span class="k3">/</span> h<span class="k2">;</span>
<span class="number">  8</span>   <span class="c">// This makes the screen have coordinates from 0/0 to 1/1</span>
<span class="number">  9</span>   <span class="c">// Can also flip coordinates or translate/rotate it</span>
<span class="number"> 10</span>   <span class="c">// In theory a perspective transform should work but I never tried -</span>
<span class="number"> 11</span>   <span class="c">// if it does not work it's another bug.</span>
<span class="number"> 12</span>   <a href="http://www.allegro.cc/manual/al_scale_transform"><span class="a">al_scale_transform</span></a><span class="k2">(</span><span class="k3">&amp;</span>transform, sx, sy<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span>   <a href="http://www.allegro.cc/manual/al_use_transform"><span class="a">al_use_transform</span></a><span class="k2">(</span><span class="k3">&amp;</span>transform<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 14</span>
<span class="number"> 15</span>   <span class="c">// In the render function:</span>
<span class="number"> 16</span>   <a href="http://www.allegro.cc/manual/al_draw_line"><span class="a">al_draw_line</span></a><span class="k2">(</span>...<span class="k2">)</span> <span class="c">// uses 0..1 coordinates</span>
<span class="number"> 17</span>
<span class="number"> 18</span>   backup <span class="k3">=</span> <span class="k3">*</span><a href="http://www.allegro.cc/manual/al_get_current_transform"><span class="a">al_get_current_transform</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 19</span>   <a href="http://www.allegro.cc/manual/al_identity_transform"><span class="a">al_identity_transform</span></a><span class="k2">(</span><span class="k3">&amp;</span>transform<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 20</span>   <span class="c">// Move the text to the center of the screen, anticipating the scale</span>
<span class="number"> 21</span>   <a href="http://www.allegro.cc/manual/al_translate_transform"><span class="a">al_translate_transform</span></a><span class="k2">(</span><span class="k3">&amp;</span>transform, <span class="n">0</span>.<span class="n">5</span> <span class="k3">/</span> sx, <span class="n">0</span>.<span class="n">5</span> <span class="k3">/</span> sy<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 22</span>   <span class="c">// Undo the scale so the font is not huge</span>
<span class="number"> 23</span>   <a href="http://www.allegro.cc/manual/al_scale_transform"><span class="a">al_scale_transform</span></a><span class="k2">(</span><span class="k3">&amp;</span>transform, <span class="n">1</span>.<span class="n">0</span> <span class="k3">/</span> sx, <span class="n">1</span>.<span class="n">0</span> <span class="k3">/</span> sy<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 24</span>   <span class="c">// Now apply the global transform</span>
<span class="number"> 25</span>   <a href="http://www.allegro.cc/manual/al_compose_transform"><span class="a">al_compose_transform</span></a><span class="k2">(</span><span class="k3">&amp;</span>transform, <span class="k3">&amp;</span>backup<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 26</span>   <a href="http://www.allegro.cc/manual/al_use_transform"><span class="a">al_use_transform</span></a><span class="k2">(</span><span class="k3">&amp;</span>transform<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 27</span>   <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 class="k2">;</span>
<span class="number"> 28</span>   <a href="http://www.allegro.cc/manual/al_use_transform"><span class="a">al_use_transform</span></a><span class="k2">(</span><span class="k3">&amp;</span>backup<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 29</span>
<span class="number"> 30</span>   <a href="http://www.allegro.cc/manual/al_draw_line"><span class="a">al_draw_line</span></a><span class="k2">(</span>...<span class="k2">)</span> <span class="c">// uses 0..1 coordinates again</span>
</div></div><p>

[EDIT:]</p><p>Actually, with OpenGL ES 1.0 and OpenGL &lt;= 2.0 there also is a projection matrix applied after the modelview matrix by OpenGL. Only the latter is affected by Allegro&#39;s transformations. The projection matrix instead is set to an orthographic projection. So any perspective transform in the modelview matrix will be killed by that projection matrix.</p><p>I think we will want a way to also set the projection matrix. For ES 2.0 and GL 3 and 4 it would just be a second matrix provided to the vertex shader. So basically Allegro would have a &quot;current transform&quot; as well as a &quot;current perspective transform&quot;.</p><p>The latter would just be ignored for software rendering but passed along to shaders as well as fixed-pipeline OpenGL and DirectX (I assume that also can use two matrices in the non-shader case).</p><p>Alternatively, maybe we could make Allegro not alter the perspective matrix at all. Then with non-shader GL/DX you could do your own transformations in that matrix. (With shaders you can do what you want anyway.)</p><p>But, definitely looks to me like some modification to Allegro is required if we want 3D transformations and/or a way for its drawing functions to work together better with direct GL/DX use.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Sun, 15 Jul 2012 18:31:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You know, complaining repeatedly about the same thing for months <i>after</i> the bug report has been submitted (which you don&#39;t reference in your post) is not going to get this fixed any quicker <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Sun, 15 Jul 2012 20:59:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ah, yes, this is a known bug:</p><p><a href="http://sourceforge.net/tracker/index.php?func=detail&amp;aid=3484535&amp;group_id=5665&amp;atid=105665">http://sourceforge.net/tracker/index.php?func=detail&amp;aid=3484535&amp;group_id=5665&amp;atid=105665</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Sun, 15 Jul 2012 22:06:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Archon, could you try this patch (made relative to the git tip). It&#39;s a workabout that doesn&#39;t fix the fundamental issue described in the bug report, but it might fix your specific symptom of it.</p><p>Obviously, you need to use <span class="source-code">al_set_projection_transform</span> to set your custom frustrum projection for this patch to work.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Sun, 15 Jul 2012 22:58: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/610628/960178#target">SiegeLord</a> said:</div><div class="quote"><p>You know, complaining repeatedly about the same thing for months after the bug report has been submitted (which you don&#39;t reference in your post) is not going to get this fixed any quicker <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />.</p></div></div><p>
I haven&#39;t been complaining about it <i>for</i> months... I complained about it months <i>ago</i>. <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>But, definitely looks to me like some modification to Allegro is required if we want 3D transformations and/or a way for its drawing functions to work together better with direct GL/DX use.</p></div></div><p>
What about using allegro_font to paste the glyphs onto an allegro_image or OpenGL texture and extracting the glyph info for each font to compile the display lists?<br />I do not wish to intermingle Allegro drawing routines with OpenGL rendering routines except (as a last resort) at the init stage.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/610628/960189#target">SiegeLord</a> said:</div><div class="quote"><p>Archon, could you try this patch</p></div></div><p>
I&#39;ll have to try this on the weekend and post back on this thread. Thanks.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Archon)</author>
		<pubDate>Mon, 16 Jul 2012 15:11:14 +0000</pubDate>
	</item>
</rss>
