Jump to content
  • Advertisement
Sign in to follow this  
raptorstrike

problem loading .dat data

This topic is 5041 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok in allegro im trying to use this function void drawAll() { blit( ( BITMAP* )data[ building ].dat, buffer, 0, 0, 0, 0, SCREEN_W, SCREEN_H ); acquire_screen(); blit( buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H ); release_screen(); } if my understanding of this function is right the filename[ spacific file ].datatype but my compiler says that data is undefined do i need to inclose this statement in () if i put it in "" i get a critical error error: `data' undeclared (first use this function)

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by raptorstrike
ok in allegro im trying to use this function
void drawAll()
{
blit( ( BITMAP* )data[ building ].dat, buffer,
0, 0, 0, 0, SCREEN_W, SCREEN_H );
acquire_screen();
blit( buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H );
release_screen();
}


if my understanding of this function is right the
filename[ spacific file ].datatype
but my compiler says that data is undefined do i need to inclose this statement in () if i put it in "" i get a critical error

error: `data' undeclared (first use this function)

Well, for one, isn't it not safe to do "data[ building ].dat"?? *the spaces are what I'm refering to*.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Why would that be unsafe? It's just whitespace, the compiler will trim.

Share this post


Link to post
Share on other sites
Well, here's the source for the datafile example...


/*
* Example program for the Allegro library, by Shawn Hargreaves.
*
* This program demonstrates how to access the contents of an
* Allegro datafile (created by the grabber utility).
*/



#include "allegro.h"


/* the grabber produces this header, which contains defines for the names
* of all the objects in the datafile (BIG_FONT, SILLY_BITMAP, etc).
*/

#include "example.h"



int main(int argc, char *argv[])
{
DATAFILE *datafile;
char buf[256];

allegro_init();
install_keyboard();
if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) {
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);
return 1;
}

/* we still don't have a palette => Don't let Allegro twist colors */
set_color_conversion(COLORCONV_NONE);

/* load the datafile into memory */
replace_filename(buf, argv[0], "example.dat", sizeof(buf));
datafile = load_datafile(buf);
if (!datafile) {
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
allegro_message("Error loading %s!\n", buf);
return 1;
}

/* select the palette which was loaded from the datafile */
set_palette(datafile[THE_PALETTE].dat);

/* aha, set a palette and let Allegro convert colors when blitting */
set_color_conversion(COLORCONV_TOTAL);

/* display the bitmap from the datafile */
textout(screen, font, "This is the bitmap:", 32, 16, makecol(255, 255, 255));
blit(datafile[SILLY_BITMAP].dat, screen, 0, 0, 64, 32, 64, 64);

/* and use the font from the datafile */
textout(screen, datafile[BIG_FONT].dat, "And this is a big font!", 32, 128,
makecol(0, 255, 0));

readkey();

/* unload the datafile when we are finished with it */
unload_datafile(datafile);

return 0;
}

END_OF_MAIN();






As you can see you first need to declare your datafile:
DATAFILE *data;
(in your case it's data instead of datafile)

It seems to me that you didn't do that globally (meaning declared outside of the main function).

The next step after that is to load the actual file into the variable. That's done with
data = load_datafile("yourfilename.dat");
where you replace yourfilename.dat with whatever your filename is. Do this before you call that drawAll() function.

Share this post


Link to post
Share on other sites
well i think i got that problem fixed but there is one error left that says there is an invalid convertion from BITMAP* to void

error: invalid conversion from `void*' to `BITMAP*'

Share this post


Link to post
Share on other sites


#include "main.h"
#include "allegro.h"

int main(int argc, char *argv[])
{
DATAFILE *datafile;
char buf[256];

allegro_init();
install_keyboard();
if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) {
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);
return 1;
}

/* we still don't have a palette => Don't let Allegro twist colors */
set_color_conversion(COLORCONV_NONE);

/* load the datafile into memory */
replace_filename(buf, argv[0], "datafile.dat", sizeof(buf));
datafile = load_datafile(buf);
if (!datafile) {
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
allegro_message("Error loading %s!\n", buf);
return 1;
}

/* select the palette which was loaded from the datafile */
// set_palette(datafile[THE_PALETTE].dat);

/* aha, set a palette and let Allegro convert colors when blitting */
set_color_conversion(COLORCONV_TOTAL);

/* display the bitmap from the datafile */
textout(screen, font, "This is the bitmap:", 32, 16, makecol(255, 255, 255));
blit(datafile[building_red].dat, screen, 0, 0, 64, 32, 64, 64);

/* and use the font from the datafile */
// textout(screen, datafile[BIG_FONT].dat, "And this is a big font!", 32, 128,
// makecol(0, 255, 0));

readkey();

/* unload the datafile when we are finished with it */
unload_datafile(datafile);

return 0;
}

END_OF_MAIN();




heres the file thats having the problems i think it SHOULD compile fine but its not (is this a problem with dev-cpp im useing 4.9.9.0)

Share this post


Link to post
Share on other sites
Just as 23 said, you've got to cast the data object to a BITMAP*, like this:

// This doesn't work because you haven't cast the pointer
blit(datafile[building_red].dat, screen, 0, 0, 64, 32, 64, 64);

// This will work
blit((BITMAP *)datafile[building_red].dat, screen, 0, 0, 64, 32, 64, 64);


If you already did that, then tell us your error message. Your code looks fine otherwise...

-Auron

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!