<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>[A5] shouldn&#39;t al_set_clipping_rectangle use floats?</title>
		<link>http://www.allegro.cc/forums/view/606562</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 02 Mar 2011 19:47:08 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The function al_set_clipping_rectangle uses integers, however the drawing functions take floats as arguments.</p><p>Matthew Leverton <a href="http://www.allegro.cc/forums/thread/606527/905254#target">said</a> in another thread that someone might setup the screen to go from (0,0)-(1,1).</p><p>If someone does that, then what values should be passed to al_set_clipping_rectangle?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Mon, 28 Feb 2011 22:34:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;d imagine the function uses the reciprocal of the bitmap size.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Mon, 28 Feb 2011 22:40:29 +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/606562/905709#target">Arthur Kalliokoski</a> said:</div><div class="quote"><p>I&#39;d imagine the function uses the reciprocal of the bitmap size.</p></div></div><p>

Indeed. With bitmap being whatever is returned by <span class="source-code"><a href="http://www.allegro.cc/manual/al_get_target_bitmap"><span class="a">al_get_target_bitmap</span></a></span>. We only support aligned clipping rectangles, so using the transformations doesn&#39;t make sense (e.g. what if someone use a transformation to rotate by 45 degree).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Mon, 28 Feb 2011 23:34:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>So when one uses clipping, the screen coordinate system must not be transformed to (0,0)-(1,1)?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Tue, 01 Mar 2011 00:10:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Use the <a href="http://www.allegro.cc/manual/5/al_set_clipping_rectangle">prototype</a>, Luke!</p><p>[EDIT]</p><p>Trust them.  Seriously.  If it doesn&#39;t work, <i>then</i> post questions.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Tue, 01 Mar 2011 00:12:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Transformations do not affect the result of <span class="source-code"><a href="http://www.allegro.cc/manual/al_set_clipping_rectangle"><span class="a">al_set_clipping_rectangle</span></a><span class="k2">(</span><span class="k2">)</span></span>. You can use transformations with clipping just remember that you will need to convert your clipping coordinates to &quot;pixel&quot; coordinates to use with <span class="source-code"><a href="http://www.allegro.cc/manual/al_set_clipping_rectangle"><span class="a">al_set_clipping_rectangle</span></a><span class="k2">(</span><span class="k2">)</span></span>.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Todd Cope)</author>
		<pubDate>Tue, 01 Mar 2011 01:09:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>There&#39;s some confusion here.</p><p><span class="source-code"><a href="http://www.allegro.cc/manual/al_set_clipping_rectangle"><span class="a">al_set_clipping_rectangle</span></a><span class="k2">(</span><span class="k2">)</span></span> sets the clipping rectangle of the target bitmap&#39;s pixels.</p><p>&quot;Setting up a screen to go from (0,0)-(1,1)&quot; means that you&#39;ll create a transformation which maps input coordinates (like those you pass to <span class="source-code"><a href="http://www.allegro.cc/manual/al_draw_bitmap"><span class="a">al_draw_bitmap</span></a></span>) ranging from (0,0)-(1,1) to what the target bitmap&#39;s dimensions are (e.g. (0,0)-(800,600)).</p><p>So, to clip coordinates (0,0)-(0.5,0.5) you&#39;d do:</p><p><span class="source-code"><a href="http://www.allegro.cc/manual/al_set_clipping_rectangle"><span class="a">al_set_clipping_rectangle</span></a><span class="k2">(</span><span class="n">0</span>, <span class="n">0</span>, <a href="http://www.allegro.cc/manual/al_get_bitmap_width"><span class="a">al_get_bitmap_width</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_get_target_bitmap"><span class="a">al_get_target_bitmap</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span> <span class="k3">*</span> <span class="n">0</span>.<span class="n">5</span>, <a href="http://www.allegro.cc/manual/al_get_bitmap_height"><span class="a">al_get_bitmap_height</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_get_target_bitmap"><span class="a">al_get_target_bitmap</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span> <span class="k3">*</span> <span class="n">0</span>.<span class="n">5</span><span class="k2">)</span><span class="k2">;</span></span></p><p>In other words, the clipping rectangle is applied only after all the transformations have been applied, not before.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Tue, 01 Mar 2011 01:49:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I was speaking of setting up a transformation on the back buffer such that a blit or primitive operation call to it would transformed. That would obviously affect your GUI&#39;s drawing operations.</p><p>Things like the mouse will always be reported in integer screen x,y positions, etc. Clipping is always done in actual bitmap coordinates as well. So for your usage, I don&#39;t see how supporting such transformations would be practical.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Tue, 01 Mar 2011 02:59:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Eventually, it may be a good idea to support draw_with_alpha routines.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Tue, 01 Mar 2011 03:17:21 +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/606562/905752#target">Mark Oates</a> said:</div><div class="quote"><p>
Eventually, it may be a good idea to support draw_with_alpha routines.
</p></div></div><p>

What would those do?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Tue, 01 Mar 2011 18:07:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok, thank you guys. My gui uses clipping to limit widget output, and since mouse coordinates are integers, I will stick to integer coordinates in my gui. This means that if a game uses my gui and does transformations on the coordinate system, there is going to be a problem, but I don&#39;t see a good solution to this.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Tue, 01 Mar 2011 21:38:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You could use the state API (<span class="source-code"><a href="http://www.allegro.cc/manual/al_store_state"><span class="a">al_store_state</span></a><span class="k2">(</span><span class="k2">)</span>, <a href="http://www.allegro.cc/manual/al_restore_state"><span class="a">al_restore_state</span></a><span class="k2">(</span><span class="k2">)</span></span>) to store the user&#39;s transformation and use the identity transformation when rendering your GUI. This way your GUI will always render correctly and the user&#39;s coordinate system will be restored and ready for them to use when your done.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Todd Cope)</author>
		<pubDate>Wed, 02 Mar 2011 01:21:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Right, but the programmer wouldn&#39;t be able to do something like:
</p><div class="source-code snippet"><div class="inner"><pre>resize_widget<span class="k2">(</span><span class="n">0</span>.<span class="n">5</span>, <span class="n">0</span>.<span class="n">5</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

But to me, that&#39;s not a big deal, because it really doesn&#39;t make much sense if you know what transformations are with respect to Allegro.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Wed, 02 Mar 2011 01:37:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>There&#39;s nothing stopping you from doing
</p><div class="source-code snippet"><div class="inner"><pre>gui_resize_widget_f<span class="k2">(</span>gui<span class="k3">*</span> g , widget<span class="k3">*</span> w , <span class="k1">float</span> w_percent , <span class="k1">float</span> h_percent<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
is there?</p><p>The gui knows its dimensions, and applies the percentage to a secondary resize widget function call.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Wed, 02 Mar 2011 02:38:24 +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/606562/905837#target">Elias</a> said:</div><div class="quote"><p>What would those do</p></div></div><p>I&#39;m thinking of functions that draw anything to a bitmap, but only through an alpha mask (or just a grayscale bitmap.)</p><p>As it is now, the effect can be done with offscreen renders and changing to alpha-only blending modes, but it seems like there would be a more proper low-level way to do it.  OpenLayer had this feature, if I recall correctly.</p><p>It&#39;s a feature I&#39;ll surely advocate for more in the future, when I get around to it. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />  That and primitive drawing with filtering to off-screen bitmaps.  With those two you could then combine them to get the equivalent of a sub-pixel clipping region, or any clipping shape for that matter.</p><p>[edit]I&#39;m thinking of something as simple as
</p><div class="source-code snippet"><div class="inner"><pre>al_set_alpha_mask<span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>b<span class="k2">)</span><span class="k2">;</span>
al_unset_alpha_mask<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
and any subsequent drawing operations would only draw the pixels through that mask.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Wed, 02 Mar 2011 10:17:48 +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/606562/905879#target">Todd Cope</a> said:</div><div class="quote"><p>
You could use the state API (al_store_state(), al_restore_state()) to store the user&#39;s transformation and use the identity transformation when rendering your GUI. This way your GUI will always render correctly and the user&#39;s coordinate system will be restored and ready for them to use when your done.
</p></div></div><p>

Thanks, that&#39;s what I&#39;m gonna do.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606562/905880#target">Matthew Leverton</a> said:</div><div class="quote"><p>
But to me, that&#39;s not a big deal, because it really doesn&#39;t make much sense if you know what transformations are with respect to Allegro.
</p></div></div><p>

I agree.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606562/905891#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>
The gui knows its dimensions, and applies the percentage to a secondary resize widget function call.
</p></div></div><p>

The problem is the sub-pixel clipping, not the widget resizing.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (axilmar)</author>
		<pubDate>Wed, 02 Mar 2011 18:34: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/606562/905940#target">Mark Oates</a> said:</div><div class="quote"><p>
al_set_alpha_mask(ALLEGRO_BITMAP *b);<br />al_unset_alpha_mask();
</p></div></div><p>

Setting it to NULL could naturally do the unset so the extra unset function is probably not necessary.</p><p>And maybe we should call it al_set_stencil_mask to make more clear what it would do. </p><p>Also, I was thinking about something like:
</p><div class="source-code snippet"><div class="inner"><pre>al_set_stencil_target<span class="k2">(</span>display<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

Which would allow drawing directly to the stencil buffer.</p><p>The software renderer likely would not support this at all, or else it just would be an extra if() in the draw_pixel function.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Wed, 02 Mar 2011 19:47:08 +0000</pubDate>
	</item>
</rss>
