<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Loading image from .dat file</title>
		<link>http://www.allegro.cc/forums/view/602957</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 28 Jan 2010 07:35:40 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>So, I&#39;m pretty much stuck with this for quite a while now</p><p>I&#39;m trying to put all my images in a .dat file but grabber doesn&#39;t work in Vista, so I got dat for linux and put all the images in a .dat file using linux. The only problem is that I can&#39;t get the images to be loaded in the game. It compiles fine, but the images don&#39;t show up on the screen.<br />My code for loading the images is pretty much this:</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><a href="http://www.allegro.cc/manual/DATAFILE" target="_blank"><span class="a">DATAFILE</span></a> <span class="k3">*</span>data<span class="k2">;</span>
<span class="number"> 2</span><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>background<span class="k2">;</span>
<span class="number"> 3</span><a href="http://www.allegro.cc/manual/packfile_password" target="_blank"><span class="a">packfile_password</span></a><span class="k2">(</span><span class="s">"password"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 4</span>data <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_datafile" target="_blank"><span class="a">load_datafile</span></a><span class="k2">(</span><span class="s">"dat1.dat"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 5</span><a href="http://www.allegro.cc/manual/packfile_password" target="_blank"><span class="a">packfile_password</span></a><span class="k2">(</span>NULL<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 6</span>background <span class="k3">=</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><span class="k2">)</span> data<span class="k2">[</span>BACKGROUND_BMP<span class="k2">]</span>.dat
</div></div><p>

Is something wrong with my code?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (moodle)</author>
		<pubDate>Wed, 27 Jan 2010 05:18:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
I&#39;ve a feeling it would help if you showed more code.</p><p>Also, there should be a &#39;;&#39; on the last statement but I guess you cut and pasted a bit inaccurately missing the last character.</p><p>I don&#39;t think anyone can diagnose your problem from the code you posted because it all seems okay.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Wed, 27 Jan 2010 05:33:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What else would you like to see? I&#39;ve attached my main file just in case
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (moodle)</author>
		<pubDate>Wed, 27 Jan 2010 05:51:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
Sorry moodle.</p><p>I can tell by your code that you know more about it all than me. You need someone else to help.</p><p>Just wondered if you&#39;d called allegro_init() before loading the datafile.</p><p>EDIT : something tells me you&#39;re problem is because you made the dat file on linux though.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Wed, 27 Jan 2010 06:12:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This is what I&#39;ve seen some do:</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> init_players<span class="k2">(</span><span class="k1">void</span><span class="k2">)</span>
<span class="number">  2</span><span class="k2">{</span>
<span class="number">  3</span>  <a href="http://www.allegro.cc/manual/DATAFILE" target="_blank"><span class="a">DATAFILE</span></a> <span class="k3">*</span>pb<span class="k2">;</span>
<span class="number">  4</span>  <span class="k1">unsigned</span> <span class="k1">int</span> i, j<span class="k2">;</span>
<span class="number">  5</span>
<span class="number">  6</span>  pb <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_datafile_object" target="_blank"><span class="a">load_datafile_object</span></a><span class="k2">(</span>PCX_DATAFILE, <span class="s">"USCHRS_PCX"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  7</span>
<span class="number">  8</span>  <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span>pb<span class="k2">)</span>
<span class="number">  9</span>  <span class="k2">{</span>
<span class="number"> 10</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"Could not load character graphics!"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 11</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_298.html" target="_blank">exit</a><span class="k2">(</span><span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 12</span>  <span class="k2">}</span>
<span class="number"> 13</span>
<span class="number"> 14</span>  <span class="k1">for</span> <span class="k2">(</span>i <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> i <span class="k3">&lt;</span> MAX_CHARACTERS<span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span>
<span class="number"> 15</span>  <span class="k2">{</span>
<span class="number"> 16</span>    <span class="k1">for</span> <span class="k2">(</span>j <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> j <span class="k3">&lt;</span> MAX_FRAMES_PER_CHAR<span class="k2">;</span> j<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span>
<span class="number"> 17</span>    <span class="k2">{</span>
<span class="number"> 18</span>      <a href="http://www.allegro.cc/manual/blit" target="_blank"><span class="a">blit</span></a><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><span class="k2">)</span> pb-&gt;dat, frames<span class="k2">[</span>i<span class="k2">]</span><span class="k2">[</span>j<span class="k2">]</span>, j <span class="k3">*</span> ENTITY_W, i <span class="k3">*</span> ENTITY_H, <span class="n">0</span>, <span class="n">0</span>, ENTITY_W, ENTITY_H<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 19</span>    <span class="k2">}</span>
<span class="number"> 20</span>  <span class="k2">}</span>
<span class="number"> 21</span>
<span class="number"> 22</span>  <a href="http://www.allegro.cc/manual/unload_datafile_object" target="_blank"><span class="a">unload_datafile_object</span></a><span class="k2">(</span>pb<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 23</span><span class="k2">}</span>
</div></div><p>

It may not be the way your dat file is set up, but it may help. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (OnlineCop)</author>
		<pubDate>Wed, 27 Jan 2010 07:56:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>@OnlineCop<br />Since I&#39;m using global compression, the load_datafile_object will be slow, and I&#39;ll only try this after I think there&#39;s no more chance of figuring this out.</p><p>I mean, my problem doesn&#39;t seem to be with loading the file. I&#39;ve added an if statement to print something if I wasn&#39;t able to load it, and it didn&#39;t print anything. So I have no idea of wtf is going on..
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (moodle)</author>
		<pubDate>Wed, 27 Jan 2010 08:47:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I was more referring to line 18...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (OnlineCop)</author>
		<pubDate>Wed, 27 Jan 2010 08:55:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
What do you get if you check background after this line :-</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>background <span class="k3">=</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><span class="k2">)</span> data<span class="k2">[</span>BACKGROUND_BMP<span class="k2">]</span>.dat<span class="k2">;</span><span class="c">//load_bitmap("background.bmp", NULL);</span>
</pre></div></div><p>

eg </p><div class="source-code snippet"><div class="inner"><pre>
<span class="k1">if</span><span class="k2">(</span>background <span class="k3">=</span><span class="k3">=</span> NULL<span class="k2">)</span>
<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">"background is NULL.\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="k3">-</span><span class="n">1</span><span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Wed, 27 Jan 2010 08:58:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I dunno; you only sent main.cpp, and we need
</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 "common.h"</span>
<span class="number"> 2</span><span class="p">#include "includes.h"</span>
<span class="number"> 3</span><span class="p">#include "gamebasics.h"</span>
<span class="number"> 4</span><span class="p">#include "dat.h"</span>
</div></div><p>
<img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (OnlineCop)</author>
		<pubDate>Wed, 27 Jan 2010 09:00:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>@William<br />I&#39;ve tried doing this....and the game runs just the same, without printing or exiting..</p><p>@OnlineCop<br />I can send the other files, but I don&#39;t think they&#39;re important..They have the classes I wrote(and there are quite a few <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />) and dat.h is the header created when I used dat on linux. I&#39;ve attached it, and if you want I could attach my classes later.</p><p>EDIT: Ok, nevermind it...I guess the problem was when I created the .dat file in linux. Thanks anyways
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (moodle)</author>
		<pubDate>Wed, 27 Jan 2010 09:11:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
What about if you try :-</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/blit" target="_blank"><span class="a">blit</span></a><span class="k2">(</span>background, <a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span>, background-&gt;w, background-&gt;h<span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/readkey" target="_blank"><span class="a">readkey</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

...right after you load it.</p><p>Again I&#39;m probably underestimating your abilities but I wondered if there might be some other error in your code which would mean the bitmap&#39;s getting drawn somewhere off-screen.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Wed, 27 Jan 2010 09:27:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>@William<br />Nah, I&#39;ve managed to make the image appear properly</p><p>Now, since my images will be loaded by many different classes in different files, I was trying to put my DATAFILE as a global variable, but my compiler is complaining(probably about the packfile_password()- not 100% sure about this.</p><p>I declared my DATAFILE as an extern variable on my gamebasics.h file, and I&#39;m doing this in the .cpp:</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><a href="http://www.allegro.cc/manual/packfile_password" target="_blank"><span class="a">packfile_password</span></a><span class="k2">(</span><span class="s">"password"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 2</span><a href="http://www.allegro.cc/manual/DATAFILE" target="_blank"><span class="a">DATAFILE</span></a><span class="k3">*</span> data <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_datafile" target="_blank"><span class="a">load_datafile</span></a><span class="k2">(</span><span class="s">"data.dat"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 3</span><a href="http://www.allegro.cc/manual/packfile_password" target="_blank"><span class="a">packfile_password</span></a><span class="k2">(</span>NULL<span class="k2">)</span><span class="k2">;</span>
</div></div><p>

And the error I get is: error: <br />expected constructor, destructor, or type conversion before &#39;(&#39; token</p><p>This error pops up on the 2 lines where I&#39;m using packfile_password..Any clues?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (moodle)</author>
		<pubDate>Wed, 27 Jan 2010 09:49:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you want <span class="source-code"><a href="http://www.allegro.cc/manual/DATAFILE" target="_blank"><span class="a">DATAFILE</span></a><span class="k3">*</span> data</span> to be global, shouldn&#39;t this work fine?</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/DATAFILE" target="_blank"><span class="a">DATAFILE</span></a><span class="k3">*</span> data <span class="k3">=</span> NULL<span class="k2">;</span>

...

<span class="k1">void</span> that_function<span class="k2">(</span><span class="k1">void</span><span class="k2">)</span>
<span class="k2">{</span>
  ...
  <a href="http://www.allegro.cc/manual/packfile_password" target="_blank"><span class="a">packfile_password</span></a><span class="k2">(</span><span class="s">"password"</span><span class="k2">)</span><span class="k2">;</span>
  data <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_datafile" target="_blank"><span class="a">load_datafile</span></a><span class="k2">(</span><span class="s">"data.dat"</span><span class="k2">)</span><span class="k2">;</span>
<div class="highlight">  <a href="http://www.allegro.cc/manual/packfile_password" target="_blank"><span class="a">packfile_password</span></a><span class="k2">(</span><span class="s">""</span><span class="k2">)</span><span class="k2">;</span> </div>

  ...
<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (OnlineCop)</author>
		<pubDate>Wed, 27 Jan 2010 10:18:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes, it should <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /><br />But it isn&#39;t <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" /></p><p>Some of the images appear just fine, and others are completely screwed up. And now the game stops working all of a sudden..<br />I think I&#39;ll go to bed now, and try to fix this tomorrow
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (moodle)</author>
		<pubDate>Wed, 27 Jan 2010 10:38:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If the grabber won&#39;t work you can use the dat.exe command line tool to add files to a dat file.</p><p>Also, i ran into the same problem.  Is this a C program or C++ program?  I just wrote a game in C and put all my images into a dat file and ran into the same thing.  To fix it i had to load all the images for all the sprites before i setup the sprite data like x, y, etc.  This is assuming the BITMAP images for the sprites are separate from the other sprite data.  It isn&#39;t as organized but its the only thing i found to fix it.  If you are using C like i did, i used malloc to create the sprites, my only guess is somehow calling this before loading an image was somehow messing it up.  So by loading all the images first and then using malloc to create the sprites fixed it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (cwl157)</author>
		<pubDate>Thu, 28 Jan 2010 03:39:25 +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/602957/848793#target">moodle</a> said:</div><div class="quote"><p>I&#39;m trying to put all my images in a .dat file but grabber doesn&#39;t work in Vista</p></div></div><p>

Grabber runs just fine with Vista.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (LennyLen)</author>
		<pubDate>Thu, 28 Jan 2010 07:35:40 +0000</pubDate>
	</item>
</rss>
