<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>[A5+OpenGL] How to prevent al_draw_text from resetting the viewport?</title>
		<link>http://www.allegro.cc/forums/view/616766</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sun, 26 Feb 2017 06:38:09 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I only need OpenGL.<br />I need to set the viewport before drawing anything.For image, I can use the low level vertex array rendering to bypass any al_draw_bitmap family functions.<br />However, I use al_draw_text to render the text. al_draw_text calls al_draw_bitmap underlying, and al_draw_bitmap will &quot;use_transform&quot;, when OpenGL implementation updates the transform, it always reset the viewport, which is I don&#39;t expect. (for details, see function ogl_update_transformation in ogl_draw.c in Allegro source code).</p><p>So, how can I render text without reset the viewport?</p><p>Thanks
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (wqking)</author>
		<pubDate>Sat, 25 Feb 2017 19:28:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Which version are you using?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Sat, 25 Feb 2017 19:39:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The latest 5.2.2 from the download page.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (wqking)</author>
		<pubDate>Sat, 25 Feb 2017 19:53:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I see: <a href="https://github.com/liballeg/allegro5/blob/master/src/opengl/ogl_draw.c#L531">https://github.com/liballeg/allegro5/blob/master/src/opengl/ogl_draw.c#L531</a></p><p>I think that only gets called when you change the target bitmap. al_draw_text has to change the target bitmap when it draws into the texture with the glyph pictures. When it switches back to the original target, it will reset the viewport to 0/0/w/h and not what it was before. You can completely avoid the target bitmap switch by pre-rendering your glyphs. You can try something like this (with a display created and active on the current thread):
</p><div class="source-code snippet"><div class="inner"><pre><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>...<span class="k2">)</span><span class="k2">;</span>
<span class="k1">int</span> ranges<span class="k2">[</span><span class="n">100</span> <span class="k3">*</span> <span class="n">2</span><span class="k2">]</span><span class="k2">;</span>
<span class="k1">int</span> n <span class="k3">=</span> al_get_font_ranges<span class="k2">(</span><a href="http://www.allegro.cc/manual/font"><span class="a">font</span></a>, <span class="n">100</span>, ranges<span class="k2">)</span><span class="k2">;</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> n<span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span> <span class="k2">{</span>
    <span class="k1">for</span> <span class="k2">(</span><span class="k1">int</span> j <span class="k3">=</span> ranges<span class="k2">[</span>i <span class="k3">*</span> <span class="n">2</span> <span class="k3">+</span> <span class="n">0</span><span class="k2">]</span><span class="k2">;</span> j <span class="k3">&lt;</span><span class="k3">=</span> ranges<span class="k2">[</span>i <span class="k3">*</span> <span class="n">2</span> <span class="k3">+</span> <span class="n">1</span><span class="k2">]</span><span class="k2">;</span> j<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span> <span class="k2">{</span>
        <span class="k1">int</span> s <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_utf8_encode"><span class="a">al_utf8_encode</span></a><span class="k2">(</span>text, j<span class="k2">)</span><span class="k2">;</span>
        text<span class="k2">[</span>s<span class="k2">]</span> <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
        <a href="http://www.allegro.cc/manual/al_draw_text"><span class="a">al_draw_text</span></a><span class="k2">(</span>text<span class="k2">)</span><span class="k2">;</span>
    <span class="k2">}</span>
<span class="k2">}</span>
</pre></div></div><p>

Alternatively, a patch to preserve the viewport probably could be applied to Allegro. We do have some functions to support mixing Allegro with OpenGL, and this sounds like something that would make sense.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Sun, 26 Feb 2017 01:14:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Can&#39;t you just reset the viewport to what you expect after the text is drawn? Or is the issue that you expect the text drawing to actually use your viewport setting?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Sun, 26 Feb 2017 01:35:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>@Elias:<br />Seems rendering to a memory texture is a good workaround for now. Though I think Allegro should support customized viewport. I will raise feature request later.<br />BTW, I think the viewport will be reset on each call of al_use_transform, no matter the target changes or not.</p><p>@SiegeLord:<br />I want the text be drawn within the viewport. What I want to implement is a camera system using viewport.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (wqking)</author>
		<pubDate>Sun, 26 Feb 2017 06:38:09 +0000</pubDate>
	</item>
</rss>
