<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Allegro 5 - al_load_bitmap() not working!</title>
		<link>http://www.allegro.cc/forums/view/607748</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 04 Jul 2011 08:02:06 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi guys, </p><p>I have spent the past 5 hours fiddling around searching the web and the wiki to try and solve this problem I am having with al_load_bitmap. </p><p>I have moderate experience with C++ but this is my first time using the allegro library so I dont know a great deal about this but regardless of what I do I cannot get al_load_bitmap() to work.</p><p>At the moment I&#39;m just trying to place bitmaps on the screen and regardless how basic I make the code I can&#39;t get it to work, can anyone spot something i&#39;m doing wrong perhaps?</p><p>Even this basic code won&#39;t work:</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">  1</span><span class="p">#include &lt;stdio.h&gt;</span>
<span class="number">  2</span><span class="p">#include &lt;allegro5/allegro.h&gt;</span>
<span class="number">  3</span><span class="p">#include &lt;allegro5/allegro_image.h&gt;</span>
<span class="number">  4</span> 
<span class="number">  5</span><span class="k1">int</span> main<span class="k2">(</span><span class="k1">int</span> argc, <span class="k1">char</span> <span class="k3">*</span><span class="k3">*</span>argv<span class="k2">)</span>
<span class="number">  6</span><span class="k2">{</span>
<span class="number">  7</span>  <a href="http://www.allegro.cc/manual/al_init"><span class="a">al_init</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  8</span>
<span class="number">  9</span>  <a href="http://www.allegro.cc/manual/al_init_image_addon"><span class="a">al_init_image_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 10</span>
<span class="number"> 11</span>  <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>bmp <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_bitmap"><span class="a">al_load_bitmap</span></a><span class="k2">(</span><span class="s">"LowerFull.bmp"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 12</span>  <span class="k1">if</span><span class="k2">(</span><span class="k3">!</span>bmp<span class="k2">)</span>
<span class="number"> 13</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_345.html" target="_blank">fprintf</a><span class="k2">(</span>stderr,<span class="s">"failed to load bitmap.\n"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 14</span>  
<span class="number"> 15</span>  <span class="k1">while</span><span class="k2">(</span><span class="k1">true</span><span class="k2">)</span><span class="k2">{</span>
<span class="number"> 16</span>    ...
<span class="number"> 17</span>  <span class="k2">}</span>
<span class="number"> 18</span><span class="k2">}</span>
</div></div><p>

Any help would be greatly appreciated, Thanks! <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>Edit: I have also tried using an absolute path and that does not work either.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Callum Gregg)</author>
		<pubDate>Sun, 03 Jul 2011 04:08:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What part doesn&#39;t work?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Sun, 03 Jul 2011 04:23:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I always receive NULL for my bmp variable.</p><p>Edit:</p><p>Aha! I have finally got it to work!<br />I saw another post by you discussing a similar topic where you suggested the following code:</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"> 1</span>ALLEGRO_PATH <span class="k3">*</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_RESOURCES_PATH<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 2</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, <span class="s">"LowerFull.bmp"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 3</span>
<span class="number"> 4</span>bmp <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_bitmap"><span class="a">al_load_bitmap</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, <span class="s">'/'</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
</div></div><p>

I&#39;m assuming then the error was simply in pointing to the file? Yet this seems odd as an absolute address didn&#39;t work either!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Callum Gregg)</author>
		<pubDate>Sun, 03 Jul 2011 04:31:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ve seen that question and solution so many times. Someone just needs to put that in the manual somewhere. ALWAYS USE <span class="source-code"><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_RESOURCES_PATH<span class="k2">)</span><span class="k2">;</span></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (North~)</author>
		<pubDate>Sun, 03 Jul 2011 04:44: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/607748/923427#target">Callum Gregg</a> said:</div><div class="quote"><p> Yet this seems odd as an absolute address didn&#39;t work either!
</p></div></div><p>You probably used back slashes like &quot;c:\foo\bar.png&quot; when it should be &quot;c:/foo/bar.png&quot;.</p><p>Note that you can also do this:
</p><div class="source-code snippet"><div class="inner"><pre>ALLEGRO_PATH <span class="k3">*</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_RESOURCES_PATH<span class="k2">)</span><span class="k2">;</span>
<a href="http://www.delorie.com/djgpp/doc/libc/libc_92.html" target="_blank">chdir</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, <span class="s">'/'</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</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>

bmp <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_bitmap"><span class="a">al_load_bitmap</span></a><span class="k2">(</span><span class="s">"LowerFull.bmp"</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Sun, 03 Jul 2011 07:14:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hmm, I am actually still having issues with this, it works for loading one of my bitmaps but not the others, the code is practically identical I&#39;m not sure where I could be going wrong! </p><p>I can load in LowerFull.bmp but it wont let me load in LowerHalf.bmp, they are both in the same directory so I can&#39;t understand where the problem is. </p><p>If I print out the string it shows the correct directory for both yet the second returns false and if I try to draw it gives me an Access Violation error.</p><p>Any more ideas?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Callum Gregg)</author>
		<pubDate>Sun, 03 Jul 2011 08:41:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>How big are the bitmaps?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Sun, 03 Jul 2011 08:43:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The bitmaps are 100kb and 200kb in size, the larger one has no problem loading, while the bigger one does.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Callum Gregg)</author>
		<pubDate>Sun, 03 Jul 2011 17:20:00 +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/607748/923473#target">Callum Gregg</a> said:</div><div class="quote"><p> The bitmaps are 100kb and 200kb in size.</p></div></div><p>I thought they had to be powers-of-two for dimensions, at least on some older cards.  Those sizes don&#39;t strike me as fitting that criteria.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Sun, 03 Jul 2011 17:22:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ah, perhaps, I have quite a modern graphics card however, but how would I go about optimizing the bitmaps for that then?</p><p>Oh sorry, the exact size is 332kb for LowerFull.bmp and 111kb for LowerHalf.bmp
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Callum Gregg)</author>
		<pubDate>Sun, 03 Jul 2011 17:23:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You&#39;d set the dimensions in the bitmap editor to have the vertical and horizontal sizes to be powers-of-two, preferably 2048 or less. (MSPaint, paint.net or whatever you&#39;re using)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Sun, 03 Jul 2011 17:26:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>EDIT: beaten...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (J-Gamer)</author>
		<pubDate>Sun, 03 Jul 2011 17:27:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Should I also destroy every bmp and path after I have used it? (I know its good practise to free up memory but are there any more implications caused by not deleting a bitmap/path from memory and trying to replace the same variable with another bitmap/path?)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Callum Gregg)</author>
		<pubDate>Sun, 03 Jul 2011 17:48:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I thought Allegro 5 automatically took care of any problems with NPOT (non power of two) textures by making them powers of two if NPOT is not supported.</p><p>Yes, you should destroy bitmaps when you are done with them. You can ignore this, but then you are leaking memory that you may need later.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 04 Jul 2011 02:40:09 +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/607748/923473#target">Callum Gregg</a> said:</div><div class="quote"><p> The bitmaps are 100kb and 200kb in size, the larger one has no problem loading, while the bigger one does.
</p></div></div><p>File size doesn&#39;t really matter, but the dimensions do. The height and width must be no larger than whatever your video card supports. Otherwise, you will have to load it as a memory bitmap (which is very slow).</p><p>They don&#39;t have to be a power of two.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Mon, 04 Jul 2011 06:16:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>OTOH, 2048 x 2048 = 4,194,304 (well over 4000k) even for 8 bit color without header info.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Mon, 04 Jul 2011 06:42:08 +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/607748/923519#target">Matthew Leverton</a> said:</div><div class="quote"><p>They don&#39;t have to be a power of two.</p></div></div><p>Some cards/drivers are moronic though, by advertising NPOT support, but doing it in software.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Mon, 04 Jul 2011 08:02:06 +0000</pubDate>
	</item>
</rss>
