<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Load a .png File</title>
		<link>http://www.allegro.cc/forums/view/590117</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sun, 18 Feb 2007 09:19:43 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m trying to load a .png into a game called Labyrinth, the file is called map1.png</p><p>The code I have to load it is:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">char</span> <span class="k3">*</span>filename <span class="k3">=</span> <span class="s">"map1.png"</span><span class="k2">;</span>
    <a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>image<span class="k2">;</span>
    image <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_bitmap" target="_blank"><span class="a">load_bitmap</span></a><span class="k2">(</span>filename, NULL<span class="k2">)</span><span class="k2">;</span>
    <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span>image<span class="k2">)</span><span class="k2">{</span><a href="http://www.allegro.cc/manual/set_gfx_mode" target="_blank"><span class="a">set_gfx_mode</span></a><span class="k2">(</span>GFX_TEXT, <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><a href="http://www.allegro.cc/manual/allegro_message" target="_blank"><span class="a">allegro_message</span></a><span class="k2">(</span><span class="s">"Error loading %s"</span>, filename<span class="k2">)</span><span class="k2">;</span><span class="k1">return</span> <span class="n">1</span><span class="k2">;</span><span class="k2">}</span>
  <span class="k1">for</span><span class="k2">(</span><span class="k1">int</span> y_y <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> y_y <span class="k3">&lt;</span> <span class="n">64</span><span class="k2">;</span> y_y<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> x_x <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> x_x <span class="k3">&lt;</span> <span class="n">48</span><span class="k2">;</span> x_x<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span><span class="k2">{</span>
      <span class="k2">(</span><a href="http://www.allegro.cc/manual/getpixel" target="_blank"><span class="a">getpixel</span></a><span class="k2">(</span>image, x_x, y_y<span class="k2">)</span><span class="k3">=</span><span class="k3">=</span><a href="http://www.allegro.cc/manual/makecol" target="_blank"><span class="a">makecol</span></a><span class="k2">(</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 class="k2">(</span>board<span class="k2">[</span>x_x<span class="k2">]</span><span class="k2">[</span>y_y<span class="k2">]</span> <span class="k3">=</span> <span class="s">'x'</span><span class="k2">)</span><span class="k2">:</span><span class="k2">(</span>board<span class="k2">[</span>x_x<span class="k2">]</span><span class="k2">[</span>y_y<span class="k2">]</span><span class="k2">)</span><span class="k2">;</span>
    <span class="k2">}</span>
  <span class="k2">}</span>
</pre></div></div><p>
The indenting is a little weird because I didn&#39;t want to put in the whole main function.<br />(The getpixel is just to take the picture and load it into a character array)</p><p>Allegro gets initialized all nice, the project works fine without this code. It puts up the error message &quot;Error loading map1.png&quot; which means its not a code problem (or is it?) but instead where I put the file. I&#39;m using Visual C++ 8.0.</p><p>There is the main folder Labyrinth with two folders in it, Labyrinth and release; along with the solution and the intellisense thing. Inside Labyrinth (the second one) is the project itself, the .cpp file and a .h, along with another folder called Release (capitalized unlike the other release folder) Inside the Release folder are some files, a manifest, but not the exe. Inside release (lowercase) is solely the exe.</p><p>Anyone know where I should put the PNG?</p><p>EDIT: I tried running the program with map1.png in every single folder and it still didn&#39;t load properly. <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Skax459)</author>
		<pubDate>Sat, 17 Feb 2007 20:45:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Do you have loadpng setup and working correctly? Allegro can&#39;t load PNG natively, you need the loadpng addon.</p><p>The map1.png file should be in the working directory of the program (usually, the same folder as the exe).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BAF)</author>
		<pubDate>Sat, 17 Feb 2007 20:47:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Allegro doesn&#39;t support PNG out of the box. If you&#39;re not using <a href="http://tjaden.strangesoft.net/loadpng/index.html">loadpng</a> you probably want to. It lets load_bitmap load png images. it also requires you to link to libpng and libz (zlib).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Sat, 17 Feb 2007 20:50:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What does allegro load natively? Just bmp?<br />EDIT: I changed everything to bmp (the code, the picture) and it still won&#39;t load.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Skax459)</author>
		<pubDate>Sat, 17 Feb 2007 20:54:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It does bmp, pcx, tga and I think thats it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Sat, 17 Feb 2007 20:54:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Its all in BMP but it still isnt working. Do you think its a location problem or a code problem?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Skax459)</author>
		<pubDate>Sat, 17 Feb 2007 21:13:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This is really bad coding style. If statements, for crying out loud! Indentation!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Sat, 17 Feb 2007 21:57:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I changed everything to bmp (the code, the picture) and it still won&#39;t load.
</p></div></div><p>
If you need alpha channel TGA is the best option with allegro, otherwise just use PCX, but avoid BMP at any cost!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Paul whoknows)</author>
		<pubDate>Sat, 17 Feb 2007 22:07:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You did <b>convert</b> the image to bitmap and not rename the extension to bmp <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Steve Terry)</author>
		<pubDate>Sun, 18 Feb 2007 09:19:43 +0000</pubDate>
	</item>
</rss>
