<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Developing in Windows, Need a Linux port</title>
		<link>http://www.allegro.cc/forums/view/613104</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 14 Aug 2013 13:37:04 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>So I recently finished a game and I use Windows but most of the people on this forum use Linux so I would like to know how easy is it to port it to linux? I could create a virtual linux machine easy enough but I don&#39;t know how to use anything in linux. Is it as easy as learning the gcc commands to compile the exact same project or would I need to rewrite some parts of the code/edit resources?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AmnesiA)</author>
		<pubDate>Mon, 12 Aug 2013 06:15:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I don&#39;t think <i>most</i> of the people here use linux, but there is a fairly significant fraction that at least sometimes <span class="ref"><sup>[<a href="#">1</a>]</sup></span> use linux.</p><p>As for the porting, what api? Did you use any platform specific code? If its pure Allegro, then the port should be easy.
</p><div class="ref-block"><h2>References</h2><ol><li>In my case, I use it nearly 100% of the time, but others only use it for certain things.</li></ol></div></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Mon, 12 Aug 2013 06:18:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It&#39;s all allegro, I don&#39;t <i>think</i> I used any platform specific code, but I&#39;m pretty newb. If it&#39;s possible for anyone to download the source code (<a href="http://www.filedropper.com/194zsource">http://www.filedropper.com/194zsource</a>) and just check if it compiles alright I&#39;d really appreciate it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AmnesiA)</author>
		<pubDate>Mon, 12 Aug 2013 08:09:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I compiled the sources, I only had to make 2 small change to get the to compile under Linux. First was the use of <span class="source-code"><span class="p">#include &lt;windows.h&gt;</span></span> that I just removed, second was a `for ( auto &amp;c :` that I turned into a `for ( auto c :`. </p><p>I did have some problems with the display of transparency of the sprites, but I found they were fixed if I added an <span class="source-code"><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_rgba"><span class="a">al_map_rgba</span></a><span class="k2">(</span><span class="n">0</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> on every sprite bitmap before drawing the sprite into them. I&#39;m surprised this even worked before on Windows. Allegro doesn&#39;t zero out a new bitmap for you, you have to do that yourself. </p><p>I attached the dynamically built binary for 64 bits Linux, which will only work if someone has all the same shared libraries I do, and a build script. Hope this helps somewhat, but feel free to ask more.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (beoran)</author>
		<pubDate>Mon, 12 Aug 2013 10:42:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hmmm, interesting, thank you so much! I wish I knew more about Linux or programming in general that I&#39;d be able to figure out why the transparency doensn&#39;t work. Thank you for taking the time to do that!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AmnesiA)</author>
		<pubDate>Mon, 12 Aug 2013 10:45:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What were the problems you had beoran? No transparency, or something else? Could you clarify? I&#39;ve seen some PNGs that display correctly with the Windows/OSX native loaders but transparency is sometimes not transparent or only parts of it is with libpng.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Mon, 12 Aug 2013 10:49:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I edited my post, the problem was due to the sprite bitmaps not being zeroed out with a fill. It&#39;s not due to Allegro, I think.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (beoran)</author>
		<pubDate>Mon, 12 Aug 2013 10:58:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>So you call al_clear_to_color( al_map_rgba(0,0,0,0)) on each sprite after setting the target to the new sprite but before calling al_convert_mask_to_alpha? That&#39;s to clear out the new bitmap and prevent any left over data from being drawn to it correct?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AmnesiA)</author>
		<pubDate>Tue, 13 Aug 2013 00:14:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I didn&#39;t look at the source, but from beoran&#39;s description I&#39;m betting you have something like:</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>b <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_bitmap"><span class="a">al_create_bitmap</span></a><span class="k2">(</span>w, h<span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_set_target_bitmap"><span class="a">al_set_target_bitmap</span></a><span class="k2">(</span>b<span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_draw_bitmap_region"><span class="a">al_draw_bitmap_region</span></a><span class="k2">(</span>b2, sx, sy, sw, sh, dx, dy, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_convert_mask_to_alpha"><span class="a">al_convert_mask_to_alpha</span></a><span class="k2">(</span>b, color<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

After you call al_create_bitmap() the bitmap you created has undefined contents. Which means it might be all zeroes, or it might be random garbage (or it might even be a picture of your gf <img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" />). So you have to call al_clear_to_color after al_set_target_bitmap. An alternative way to do it (though in this case it just makes it more complicated I think) is to use a blender like this:</p><div class="source-code snippet"><div class="inner"><pre>...
<a href="http://www.allegro.cc/manual/al_set_target_bitmap"><span class="a">al_set_target_bitmap</span></a><span class="k2">(</span>b<span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/ALLEGRO_STATE"><span class="a">ALLEGRO_STATE</span></a> state<span class="k2">;</span>
<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>state, ALLEGRO_STATE_BLENDER<span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_set_blender"><span class="a">al_set_blender</span></a><span class="k2">(</span>ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO<span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_draw_bitmap"><span class="a">al_draw_bitmap</span></a><span class="k2">(</span>b2, ...<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>state<span class="k2">)</span><span class="k2">;</span>
...
</pre></div></div><p>

The &quot;ONE, ZERO&quot; blender doesn&#39;t skip alpha pixels: it&#39;ll copy them directly into the target instead of &quot;drawing&quot; them... in effect it&#39;ll be the same as clearing.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Tue, 13 Aug 2013 00:51:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That&#39;s exactly what I was wondering, thank you! Gonna fix that right now
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (AmnesiA)</author>
		<pubDate>Tue, 13 Aug 2013 02:26:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ve seen what Beoran described, though I didn&#39;t know it was platform specific. Makes sense that an initialized part of the video buffer would have stuff on it - but the effect, a glitchy, inverted copy of my desktop, was pretty cool to look at. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>In general though it&#39;s always good practice to assign any block of data before you use it. You don&#39;t do <span class="source-code"><span class="k1">int</span> i<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">"%i"</span>, i<span class="k2">)</span><span class="k2">;</span></span> for a reason, after all, and when you copy a transparent image to a bitmap with an alpha-aware blending mode (the default), you are implicitly copying what was there before during the blend operation, even if the existing data is junk.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Winfield)</author>
		<pubDate>Tue, 13 Aug 2013 03:38:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Exactly, Trent, that&#39;s what I ment. Sorry for the pun. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>Winfield, exactly. C does almost nothing behind our backs, so if we don&#39;t initialize a local variable or a newly allocated memory block, then it&#39;s contents <i>may</i> be garbage. They <i>may</i> even zeroed out, by mere accident. We can&#39;t rely on it. It&#39;s up to us to make sure every variable and memory area gets correctly initialized.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (beoran)</author>
		<pubDate>Tue, 13 Aug 2013 15:13:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>(Emphasis mine:)
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/613104/988690#target">beoran</a> said:</div><div class="quote"><p>so if we don&#39;t initialize a <b>local</b> variable</p></div></div><p>

This. This was what had me pulling out my hair for days, when I was but a youngling, which was three weeks ago. Because <span class="source-code"><span class="k1">int</span> i<span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">;</span></span> works <b>just fine</b> in the global scope. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>I really like C, and I&#39;m sure there are architectural reasons for that &quot;gotcha&quot;, but jeez. That&#39;s the kind of stuff we make fun of PHP over!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Winfield)</author>
		<pubDate>Tue, 13 Aug 2013 21:24:49 +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/613104/988698#target">Winfield</a> said:</div><div class="quote"><p>That&#39;s the kind of stuff we make fun of PHP over!</p></div></div><p>No, that is not the kind of stuff we make fun of php over <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><p>also, imo, always initialize your variables, unless you&#39;re doing tricksy things.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 14 Aug 2013 10:31:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The reason local variables aren&#39;t automatically initialized to 0 in C is performance. Normally the first thing you do with local variables is store some calculated result in it, so letting the compiler put a 0 or such in there is a waste of time. And this matters a lot for functions that get called in tight loops.</p><p>Global variables do get initialized automatically to 0 because the compiler has to allocate space for those at compile time anyway, and initializing those global variables only happens once at start up of the program, so the performance overhead is far smaller. </p><p>In most cases, if you wonder why something is so in C, it&#39;s normally either due to legacy code compatibility or performance reasons.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (beoran)</author>
		<pubDate>Wed, 14 Aug 2013 13:37:04 +0000</pubDate>
	</item>
</rss>
