<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>al_clone_bitmap() of backbuffer gives bad results with OGL</title>
		<link>http://www.allegro.cc/forums/view/615516</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sun, 05 Jul 2015 10:32:57 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I have a screenshot feature in my minisphere game engine, so that when you press F12, it takes a screenshot and saves it in the user&#39;s home directory.  When I was using DX for rendering, this worked fine.  Now that I&#39;m using OpenGL, however, it doesn&#39;t work so well.  Here&#39;s the code for screenshots in minisphere:</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"> 406</span>snapshot <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_clone_bitmap"><span class="a">al_clone_bitmap</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_get_backbuffer"><span class="a">al_get_backbuffer</span></a><span class="k2">(</span>g_display<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 407</span>path <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_standard_path"><span class="a">al_get_standard_path</span></a><span class="k2">(</span>ALLEGRO_USER_DOCUMENTS_PATH<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 408</span><a href="http://www.allegro.cc/manual/al_append_path_component"><span class="a">al_append_path_component</span></a><span class="k2">(</span>path, <span class="s">"Sphere Files"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 409</span><a href="http://www.allegro.cc/manual/al_append_path_component"><span class="a">al_append_path_component</span></a><span class="k2">(</span>path, <span class="s">"Screenshots"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 410</span><a href="http://www.allegro.cc/manual/al_make_directory"><span class="a">al_make_directory</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_path_cstr"><span class="a">al_path_cstr</span></a><span class="k2">(</span>path, ALLEGRO_NATIVE_PATH_SEP<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 411</span><span class="k1">do</span> <span class="k2">{</span>
<span class="number"> 412</span>  <a href="http://www.delorie.com/djgpp/doc/libc/libc_737.html" target="_blank">sprintf</a><span class="k2">(</span>filename, <span class="s">"SS_%s.png"</span>, rng_name<span class="k2">(</span><span class="n">10</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 413</span>  <a href="http://www.allegro.cc/manual/al_set_path_filename"><span class="a">al_set_path_filename</span></a><span class="k2">(</span>path, filename<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 414</span>  pathstr <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_path_cstr"><span class="a">al_path_cstr</span></a><span class="k2">(</span>path, ALLEGRO_NATIVE_PATH_SEP<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 415</span><span class="k2">}</span> <span class="k1">while</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/al_filename_exists"><span class="a">al_filename_exists</span></a><span class="k2">(</span>pathstr<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 416</span><a href="http://www.allegro.cc/manual/al_save_bitmap"><span class="a">al_save_bitmap</span></a><span class="k2">(</span>pathstr, snapshot<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 417</span><a href="http://www.allegro.cc/manual/al_destroy_bitmap"><span class="a">al_destroy_bitmap</span></a><span class="k2">(</span>snapshot<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 418</span><a href="http://www.allegro.cc/manual/al_destroy_path"><span class="a">al_destroy_path</span></a><span class="k2">(</span>path<span class="k2">)</span><span class="k2">;</span>
</div></div><p>

Here are the screenshots side-by-side, one taken using the above code, and the other using PrintScreen and then pasted into MS Paint:<br /><span class="remote-thumbnail"><span class="json">{"name":"actual.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/e\/1ebd62af7149d8dc5919d444f146eaca.png","w":640,"h":480,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/e\/1ebd62af7149d8dc5919d444f146eaca"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/1/e/1ebd62af7149d8dc5919d444f146eaca-240.jpg" alt="actual.png" width="240" height="180" /></span><span class="remote-thumbnail"><span class="json">{"name":"expected.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/8\/f89f7a92448bb4c87a217ba7ad169172.png","w":656,"h":519,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/8\/f89f7a92448bb4c87a217ba7ad169172"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/f/8/f89f7a92448bb4c87a217ba7ad169172-240.jpg" alt="expected.png" width="240" height="189" /></span></p><p>Make sure to enlarge them because the thumbnails are identical for some reason. <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /></p><p>What it looks like is that <span class="source-code"><a href="http://www.allegro.cc/manual/al_clone_bitmap"><span class="a">al_clone_bitmap</span></a><span class="k2">(</span><span class="k2">)</span></span> is preserving the backbuffer alpha channel even though it&#39;s ignored for actual rendering.  That&#39;s just a guess though.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Pascoe)</author>
		<pubDate>Thu, 02 Jul 2015 20:46:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If the back buffer has an alpha channel, I think it should be preserved. What you should do is create a new bitmap with the display size then al_draw_bitmap the back buffer into that bitmap.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Thu, 02 Jul 2015 21:47:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The alpha channel has no effect on rendering, though, so for all intents and purposes it doesn&#39;t exist. And since the backbuffer serves no other purpose than to stage for rendering, it&#39;s not intuitive that if I grab its contents I get a different image than what is visible to the user.</p><p>Even so, creating a new bitmap won&#39;t help me, will it?  I&#39;ll still end up copying the alpha channel over to the new image.  Unless there&#39;s a way to create bitmap with no alpha channel.  I never remember seeing such an option.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Pascoe)</author>
		<pubDate>Thu, 02 Jul 2015 21:54:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you draw the bitmap the alpha channel is blended, so you just have to use a blend mode where the output is not affected. You also can create a bitmap without alpha, and also a back buffer without alpha.</p><p>I don&#39;t know why opengl uses a back buffer with alpha by default - that probably should be changed.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Thu, 02 Jul 2015 21:58:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Okay, interesting thing I found, I think I discovered a bug.</p><p>Grabbing the backbuffer like this didn&#39;t fix it:
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/al_store_state"><span class="a">al_store_state</span></a><span class="k2">(</span><span class="k3">&amp;</span>old_state, ALLEGRO_STATE_NEW_BITMAP_PARAMETERS<span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_set_new_bitmap_format"><span class="a">al_set_new_bitmap_format</span></a><span class="k2">(</span>ALLEGRO_PIXEL_FORMAT_ANY_NO_ALPHA<span class="k2">)</span><span class="k2">;</span>
snapshot <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_clone_bitmap"><span class="a">al_clone_bitmap</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_get_backbuffer"><span class="a">al_get_backbuffer</span></a><span class="k2">(</span>g_display<span class="k2">)</span><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="k3">&amp;</span>old_state<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

However, this worked:
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/al_set_new_bitmap_format"><span class="a">al_set_new_bitmap_format</span></a><span class="k2">(</span>ALLEGRO_PIXEL_FORMAT_RGB_888<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

So it looks like <span class="source-code">ALLEGRO_PIXEL_FORMAT_ANY_NO_ALPHA</span> is not being honored?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Pascoe)</author>
		<pubDate>Thu, 02 Jul 2015 23:10:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Can you check what the format of the bitmap created by ALLEGRO_PIXEL_FORMAT_ANY_NO_ALPHA is?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Sun, 05 Jul 2015 08:44:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><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/al_set_new_bitmap_format"><span class="a">al_set_new_bitmap_format</span></a><span class="k2">(</span>ALLEGRO_PIXEL_FORMAT_ANY_NO_ALPHA<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 2</span><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span> snapshot <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_clone_bitmap"><span class="a">al_clone_bitmap</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_get_backbuffer"><span class="a">al_get_backbuffer</span></a><span class="k2">(</span>g_display<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 3</span><span class="k1">int</span> pf <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_bitmap_format"><span class="a">al_get_bitmap_format</span></a><span class="k2">(</span>snapshot<span class="k2">)</span><span class="k2">;</span>
</div></div><p>

pf == 9 (ALLEGRO_PIXEL_FORMAT_ARGB_8888)</p><p>For RGB_888, I got back 12, i.e. exactly what I requested.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Pascoe)</author>
		<pubDate>Sun, 05 Jul 2015 09:10:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Looks like in multiple locations in Allegro&#39;s code NO_ALPHA actually means, &quot;don&#39;t care if it has alpha or not&quot;. Sounds like changing this will require a bit of testing.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Sun, 05 Jul 2015 09:36:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>So basically it&#39;s just an alias for PIXEL_FORMAT_ANY.  Seems... redundant.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Pascoe)</author>
		<pubDate>Sun, 05 Jul 2015 09:39:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It&#39;s subtly different. Either way, even if it did select the right format (XRGB_8888), it still wouldn&#39;t quite work, as XRGB means don&#39;t care whether X is alpha or not <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />. The real format you want in this situation is ALLEGRO_PIXEL_FORMAT_ANY_24_NO_ALPHA, which should resolve to ALLEGRO_PIXEL_FORMAT_RGB_888. I&#39;ll probably fix the NO_ALPHA not picking XRGB, but this caveat will continue to remain.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Sun, 05 Jul 2015 10:21:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Just for the record, the documentation says this:</p><div class="source-code snippet"><div class="inner"><pre>ALLEGRO_PIXEL_FORMAT_ANY_NO_ALPHA <span class="k3">-</span> Let the driver choose a format without alpha.
</pre></div></div><p>

I&#39;m fine with it if Allegro itself treats the flag differently, but the documentation should probably be updated in that case. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Pascoe)</author>
		<pubDate>Sun, 05 Jul 2015 10:32:57 +0000</pubDate>
	</item>
</rss>
