<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>loading bitmaps with allegro</title>
		<link>http://www.allegro.cc/forums/view/587322</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 01 Sep 2006 23:22:28 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hello!<br />I&#39;d written a programm to show a bitmap on the screen. After compiling there where no errors or warnings. But each time I start the exe-file there comes an error-message. The bitmap is in the same directory like the .cpp and the .exe and I can&#39;t find the error in the programm, I hope you can help me.</p><p>#include &lt;allegro.h&gt;</p><p>int set_graphic_mode()<br />{<br />	set_color_depth(32);<br />	if (set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 1024, 768, 0, 0) &gt;= 0)<br />	{<br />		return 1;<br />	}<br />	set_color_depth(24);<br />	if (set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 1024, 768, 0, 0) &gt;= 0)<br />	{<br />		return 1;<br />	}<br />	set_color_depth(32);<br />	if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 1024, 768, 0, 0) &gt;= 0)<br />	{<br />		return 1;<br />	}<br />	return 0;<br />}</p><p>int main(int argc, char **argv)<br />{<br />	allegro_init();<br />	install_keyboard();</p><p>	if (!set_graphic_mode())<br />	{<br />		allegro_message(&quot;Unable to set graphic mode!&quot;);<br />		exit(0);<br />	}</p><p>	BITMAP *bild = load_bitmap(&quot;ffx-2.bmp&quot;, NULL);</p><p>	acquire_screen();<br />	clear(screen);<br />	blit(bild, screen, 0, 0, (SCREEN_W - bild-&gt;w)/2, (SCREEN_H - bild-&gt;h)/2, bild-&gt;w, bild-&gt;h);<br />	release_screen();</p><p>	while (!keypressed());<br />}<br />END_OF_MAIN();
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (blackwind87)</author>
		<pubDate>Wed, 30 Aug 2006 15:48:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>1) Edit your post to use <a href="http://www.allegro.cc/mockup.html">code tags</a>.</p><p>2) </p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
But each time I start the exe-file there comes an error-message.
</p></div></div><p>
What message? Always include all the relevant information when asking for help.</p><p>3) </p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
BITMAP *bild = load_bitmap(&quot;ffx-2.bmp&quot;, NULL);
</p></div></div><p>
You <b>need</b> error checking. 
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>bild <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><span class="s">"ffx-2.bmp"</span>, NULL<span class="k2">)</span><span class="k2">;</span>
<span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span>bild<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">"Couldn't find ffx-2.bmp!\n"</span><span class="k2">)</span><span class="k2">;</span>
    <a href="http://www.delorie.com/djgpp/doc/libc/libc_298.html" target="_blank">exit</a><span class="k2">(</span><span class="n">1</span><span class="k2">)</span><span class="k2">;</span>
   <span class="k2">}</span>
</pre></div></div><p>

4) </p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
The bitmap is in the same directory like the .cpp and the .exe and I can&#39;t find the error in the programm, I hope you can help me.
</p></div></div><p>
And are you running the program through the commandline or through an IDE of some kind? IDEs are notorious for using weird working directories. This will, however, be caught by 3) above.</p><p>5) Main should return 0.</p><p>6) Minor points:<br />a) </p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
END_OF_MAIN();
</p></div></div><p>
Remove the semicolon (counter-intuitive, I know, but it&#39;s how the macro is constructed).</p><p>b) acquire_screen() and release_screen() aren&#39;t necessary. Here, they just clutter up the code (and if you put anything not graphics related in between them, Bad Things<sup>TM</sup> happen to your program).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (gnolam)</author>
		<pubDate>Wed, 30 Aug 2006 15:54:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You should check the return value of load_bitmap().</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
The bitmap is in the same directory like the .cpp and the .exe
</p></div></div><p>
That&#39;s probably irrelevant. The file needs to be in the current working directory when the program is run.<br />To find the directory where the binary is stored, use get_executable_name().
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Wed, 30 Aug 2006 15:55:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What is the error message?</p><p>Also, why on earth have you written your set_graphic_mode function the way you have? END_OF_MAIN() also does not have a semicolon at the end of it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (LennyLen)</author>
		<pubDate>Wed, 30 Aug 2006 15:56:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This program was an example in a book i buied and I thought it should work...<br />Thanks for your help, I will see if I can solve the problem now!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (blackwind87)</author>
		<pubDate>Wed, 30 Aug 2006 16:16:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Which book?... [cue spooky music]
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (LennyLen)</author>
		<pubDate>Wed, 30 Aug 2006 16:23:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It&#39;s a german book about programming with allegro but it is from the year 2003. I don&#39;t know the actual titel...<br />I have fixed some things like described above, but now there comes the message that ffx-2.bmp couldn&#39;t be found. The bitmap is in the same directory and the name is correct and so I don&#39;t understand, why it can&#39;t be found!?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (blackwind87)</author>
		<pubDate>Wed, 30 Aug 2006 16:28:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
It&#39;s a german book about programming with allegro but it is from the year 2003.
</p></div></div><p>

Oh, I was expecting it to be another book notorious for bad coding practices. But hmmm, a German book on Allegro - Spellcaster&#39;s? (This question is directed at established a.cc members, not you blackwind.)</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
The bitmap is in the same directory and the name is correct and so I don&#39;t understand, why it can&#39;t be found!?
</p></div></div><p>

Well, as gnolam has already mentioned, some IDEs create their own working directories, so if you&#39;re attempting to run the program from the IDE, it may be looking in the working directory.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (LennyLen)</author>
		<pubDate>Wed, 30 Aug 2006 16:43:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
why on earth have you written your set_graphic_mode function the way you have?
</p></div></div><p>
What&#39;s wrong with it?<br />It&#39;s good practice to try different graphics modes if one doesn&#39;t work, and putting the code in a function makes it clear and readable. That code is fine.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
[cue spooky music]
</p></div></div><p>
Nah, the programming style is different. Besides, people who use GPAIO2E #include &lt;conio.h&gt; for no good reason.
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
It&#39;s a german book about programming with allegro
</p></div></div><p>
Ah, that would be spelly&#39;s book.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
buied
</p></div></div><p>
bought. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
but now there comes the message that ffx-2.bmp couldn&#39;t be found. The bitmap is in the same directory and the name is correct and so I don&#39;t understand, why it can&#39;t be found!?
</p></div></div><p>
Because it needs to be in the <b>active working directory</b> when the program is run,which is not nescessarily the same as the directory that contains the executable.<br />Try (almost a direct copy&amp;paste from the manual)
</p><div class="source-code snippet"><div class="inner"><pre>   <span class="k1">char</span> name<span class="k2">[</span><span class="n">200</span><span class="k2">]</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>bild<span class="k2">;</span>

   <a href="http://www.allegro.cc/manual/get_executable_name" target="_blank"><span class="a">get_executable_name</span></a><span class="k2">(</span>name, <span class="k1">sizeof</span><span class="k2">(</span>name<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
   <a href="http://www.allegro.cc/manual/replace_filename" target="_blank"><span class="a">replace_filename</span></a><span class="k2">(</span>name, name, <span class="s">"ffx-2.bmp"</span>, <span class="k1">sizeof</span><span class="k2">(</span>name<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
   bild <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>name, NULL<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Wed, 30 Aug 2006 16:46:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
It&#39;s a german book about programming with allegro but it is from the year 2003. I don&#39;t know the actual titel...
</p></div></div><p>
Spielenprogrammen mit Allegro (Lennart Steinke), isn&#39;t it? At least, that is the only one anyone at this forum will be familiar with <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I have fixed some things like described above, but now there comes the message that ffx-2.bmp couldn&#39;t be found. The bitmap is in the same directory and the name is correct and so I don&#39;t understand, why it can&#39;t be found!?
</p></div></div><p>What is the compiler you are using? As said, you have to actually run the program from the same directory as the image file is in. That means that if you double-click on the program icon, make sure the image is also in that Explorer window. Also, double-click on the image and make sure it loads properly.</p><p>[append]
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
What&#39;s wrong with it?<br />It&#39;s good practice to try different graphics modes if one doesn&#39;t work, and putting the code in a function makes it clear and readable. That code is fine.
</p></div></div><p>His code sets 3 different graphics modes, and 2 of them are the same mode <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CGamesPlay)</author>
		<pubDate>Wed, 30 Aug 2006 16:46:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
What&#39;s wrong with it?
</p></div></div><p>

Actually, nothing, I just REALLY didn&#39;t read it properly and somehow missed all the &quot;return 1&quot;&#39;s (my excuse is that I&#39;ve been awake for about 70 hours now and the lack of formatting was making my eyes bleed). It appeared he was setting the graphics mode to three different settings back-to-back.</p><p>[edit]
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
His code sets 3 different graphics modes, and 2 of them are the same mode
</p></div></div><p>

Look again.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (LennyLen)</author>
		<pubDate>Wed, 30 Aug 2006 16:55:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Okay, now there is the first message again:</p><p>An unhandled win32 exception occured in prog4.exe[2988]. Just-In-Time debugging this exception failed with the following error: No installed debugger has Just-In-Time debugging enabled. In Visual Studio, Just-In-Time debugging can be enabled from Tools/Options/Debugging/Just-In-Time.</p><p>But I doesn&#39;t have Visual Studio:o
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (blackwind87)</author>
		<pubDate>Wed, 30 Aug 2006 17:32:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ve got the same problem tonight.</p><p>I&#39;m using Dev-C++ and I&#39;m trying to load a bitmap and display it (shouldn&#39;t be too hard), but the program can&#39;t load it. Like Blackwind it&#39;s in the same dir as the .exe. Other programs have managed to load bitmaps like this (from the same dir as the .exe). But it&#39;s not working this time..???
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Fri, 01 Sep 2006 03:25:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
it&#39;s in the same dir as the .exe
</p></div></div><p>
Once again, <i>it doesn&#39;t matter if it&#39;s in the same directory as the binary, it needs to be in the working directory</i>. Check that it is and if it is, post the program and the image.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Fri, 01 Sep 2006 13:13:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>actually i&#39;ve found where the error is. i had the file name wrong in the code.<br />sorry for being stupid <img src="http://www.allegro.cc/forums/smileys/embarassed.gif" alt=":-[" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Fri, 01 Sep 2006 23:22:28 +0000</pubDate>
	</item>
</rss>
