<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>A5 basic load .png example code</title>
		<link>http://www.allegro.cc/forums/view/615391</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 18 May 2015 10:14:37 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I am trying to load a .png file (from hard drive) which will represent my paddle in a pong game.  All methods I try result in a &quot;segmentation fault (core dumped)&quot; output in terminal and the allegro display crashes.</p><p>I will provide my code so you guys can see my latest incorrect way to display a  bitmap to an allegro display <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /> .</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="k1">void</span> Open_window<span class="k2">(</span><span class="k2">)</span><span class="k2">{</span>
<span class="number">  2</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">  3</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">  4</span>
<span class="number">  5</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_DISPLAY"><span class="a">ALLEGRO_DISPLAY</span></a> <span class="k3">*</span>display<span class="k2">;</span>
<span class="number">  6</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>paddle<span class="k2">;</span>
<span class="number">  7</span>    
<span class="number">  8</span>    display <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_display"><span class="a">al_create_display</span></a><span class="k2">(</span><span class="n">640</span>, <span class="n">480</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  9</span>    
<span class="number"> 10</span>    paddle <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">"/home/sean/Desktop/Pong/Paddle.png"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 11</span>
<span class="number"> 12</span>    <a href="http://www.allegro.cc/manual/al_draw_bitmap"><span class="a">al_draw_bitmap</span></a><span class="k2">(</span>paddle, <span class="n">50</span>.<span class="n">0</span>, <span class="n">50</span>.<span class="n">0</span> , <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span>
<span class="number"> 14</span>    <a href="http://www.allegro.cc/manual/al_set_window_title"><span class="a">al_set_window_title</span></a><span class="k2">(</span>display, <span class="s">"PONG MEGA-SUPER-BETA"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 15</span>
<span class="number"> 16</span>    <span class="c">//al_clear_to_color(al_map_rgb(220,0,0)); </span>
<span class="number"> 17</span>
<span class="number"> 18</span>    <a href="http://www.allegro.cc/manual/al_flip_display"><span class="a">al_flip_display</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 19</span>
<span class="number"> 20</span>    <a href="http://www.allegro.cc/manual/al_rest"><span class="a">al_rest</span></a><span class="k2">(</span><span class="n">3</span>.<span class="n">0</span><span class="k2">)</span><span class="k2">;</span> 
<span class="number"> 21</span>
<span class="number"> 22</span>    <a href="http://www.allegro.cc/manual/al_destroy_display"><span class="a">al_destroy_display</span></a><span class="k2">(</span>display<span class="k2">)</span><span class="k2">;</span> <span class="c">/**closes window */</span>
<span class="number"> 23</span>    
<span class="number"> 24</span>    <span class="k1">return</span><span class="k2">;</span>
<span class="number"> 25</span><span class="k2">}</span>
</div></div><p>

Question: What is the correct sequence to simply display a .png file in an ALLEGRO_DISPLAY?  I am talking bare bones, just to give a model so I can see where I am going wrong.</p><p>Thanks in advance.<br />Sean</p><p>Ubuntu 14.04<br />C::B 13.12<br />Allegro 5
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (seanfcarney)</author>
		<pubDate>Sun, 17 May 2015 22:16:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m not seeing anything obviously wrong in the code posted. Did you try getting the return code of each function and/or stepping through the code/using print functions to find out where exactly the application is crashing?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (RPG Hacker)</author>
		<pubDate>Sun, 17 May 2015 22:47:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes. You need to check your return values and/or run it through a debugger. That way you can see where it is stopping.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 18 May 2015 00:51:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>After you load paddle, put in a condition to see if paddle loaded ok...something like:</p><div class="source-code snippet"><div class="inner"><pre><span class="c">//load paddle first</span>
<span class="k1">if</span><span class="k2">(</span>paddle <span class="k3">=</span><span class="k3">=</span> NULL<span class="k2">)</span><span class="k2">{</span>
  <span class="c">//paddle didn't load!! show msg and exit!</span>
<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Dizzy Egg)</author>
		<pubDate>Mon, 18 May 2015 00:57:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I have not.  //&#39;ed out the al_draw_bitmap line and this avoided my segmentation fault.  </p><p>I guess ill use debugger tonight.  I&#39;ll verify the path is correct. Cannot think of much else I could have screwed up.  Obviously I did though <img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" /> .</p><p>Thanks for the help. </p><p>Will let you know what I find.</p><p>Sean</p><p>======<br />EDIT<br />======<br />My .png file is not loading properly.  I now have to find out why.</p><p>USED THE FOLLOWINg:</p><p> </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>   paddle <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">"/sean/Desktop/Pong/Paddle.png"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  2</span>
<span class="number">  3</span>    t
<span class="number">  4</span><span class="k1">if</span><span class="k2">(</span>paddle <span class="k3">=</span><span class="k3">=</span> NULL<span class="k2">)</span><span class="k2">{</span>
<span class="number">  5</span>  <span class="k1">int</span> x<span class="k2">;</span>
<span class="number">  6</span>  cout<span class="k3">&lt;</span><span class="k3">&lt;</span><span class="s">"ERROR"</span><span class="k2">;</span>
<span class="number">  7</span>    cin&gt;&gt;x<span class="k2">;</span>
<span class="number">  8</span>  <span class="k1">return</span><span class="k2">;</span>
<span class="number">  9</span><span class="k2">}</span>
</div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (seanfcarney)</author>
		<pubDate>Mon, 18 May 2015 01:01:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><span class="source-code"><a href="http://www.allegro.cc/manual/al_filename_exists"><span class="a">al_filename_exists</span></a></span> could be useful to you.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (LennyLen)</author>
		<pubDate>Mon, 18 May 2015 01:11:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>yeah it&#39;s not finding your .png because the executable doesn&#39;t run from the place you&#39;d expect...if you want more help just say the word! But look up &quot;get executable filename&quot; and stuff like that.....
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Dizzy Egg)</author>
		<pubDate>Mon, 18 May 2015 02:38:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hmm I am confused.  </p><p>Wouldn&#39;t supplying the full path to a .png eliminate the need to have the image in some kind of local directory?  I was actually trying to avoid the scenario I seemed to make for myself.</p><p>I&#39;ve been sifting through the Allegro5 online manual with no further incite past I need to use al_filenamame_exists(path/paddle.png) to determine if I get the path correct. </p><p>I used cout&lt;&lt;ALLEGRO_EXENAME_PATH; and the returned value in the console was &quot;6&quot;.  Now I&#39;m just not sure what I need to do with this info.</p><p>Any clues would be helpful.</p><p>=======<br />EDIT:<br />=======</p><p>You all may now open hand slap me.  I found the solution to my problem.  Paddle.png was an incorrect file name.  paddle.png was the correct file name.  I now have &quot;/home/sea/Desktop/paddle.png&quot; as the path.</p><p>My 20x100 pixel white paddle is not proudly displayed with a black background.</p><p>Thanks for all the help again.</p><p>Sean
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (seanfcarney)</author>
		<pubDate>Mon, 18 May 2015 03:10:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Good to hear you solved your problem.<br />As for the problem you mentioned in your last post (even though it isn&#39;t important anymore)</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/615391/1013345#target">seanfcarney</a> said:</div><div class="quote"><p> I used cout&lt;&lt;ALLEGRO_EXENAME_PATH; and the returned value in the console was &quot;6&quot;. Now I&#39;m just not sure what I need to do with this info.</p></div></div><p>ALLEGRO_EXENAME_PATH is just a define, as far as I know. It is a constant that is meant to be passed to a certain function to get the ALLEGRO_PATH object containing the actual path. This object can then be used to generate a C string containing the path.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (RPG Hacker)</author>
		<pubDate>Mon, 18 May 2015 03:37:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>For now using an absolute path is OK, but if you want to later distribute the game, this won&#39;t work. Allegro can help you with <a href="https://www.allegro.cc/manual/5/al_get_standard_path">https://www.allegro.cc/manual/5/al_get_standard_path</a>, but probably you have to decide on some  standard path like in /usr/share/pong or such  where the resources (image files) of your game should be put and load them from there.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (beoran)</author>
		<pubDate>Mon, 18 May 2015 10:14:37 +0000</pubDate>
	</item>
</rss>
