Skip to main content
GameDev.net gamedev.net
🔒 Locked

problem loading .dat data

Started by raptorstrike Aug 27, 2004 at 9:20 AM 18 replies 2.3k views
Original Post
raptorstrike
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)
____"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
raevin
raevin
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*.
raptorstrike
raptorstrike
yeah i guesss your right but thats not the problem
____"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
catlettc
catlettc
Where are you declaring data?
-ChadC
GameCreator
GameCreator
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.
raptorstrike
raptorstrike
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*'
____"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
23yrold3yrold
23yrold3yrold
If you're casting properly, that shouldn't happen.

draw_sprite(screen, (BITMAP *)data[THE_IMAGE].dat, x, y);
Jesus saves ... the rest of you take 2d4 fire damage.
raptorstrike
raptorstrike
#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)
____"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
Auron
Auron
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 pointerblit(datafile[building_red].dat, screen, 0, 0, 64, 32, 64, 64);// This will workblit((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
raptorstrike
raptorstrike
yeah it worked i should have know i forgot that when you use a .dat file all the pointers are void and you need to declare them thanks
____"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
raptorstrike
raptorstrike
ok now it runs but my bit map comes out as a red square like thing do i need to change the grahics or lower the bit on the map
____"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
raptorstrike
raptorstrike
never mind what i was seeing was just a fraction of the building i just need to scale it down
____"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
23yrold3yrold
23yrold3yrold
// worksblit((BITMAP*)datafile[building_red].dat, screen, 0, 0, 64, 32, ((BITMAP*)datafile[building_red].dat)->w, ((BITMAP*)datafile[building_red].dat)->h);// neaterBITMAP* bmp = (BITMAP*)datafile[building_red].dat;blit(bmp, screen, 0, 0, 64, 32, bmp->w, bmp->h);
Jesus saves ... the rest of you take 2d4 fire damage.
raptorstrike
raptorstrike
um is there anyway to scale your bitmaps or am i just going to have to draw it smaller??
____"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
23yrold3yrold
23yrold3yrold
stretch_blit()

Or you can just use smaller bitmaps.
Jesus saves ... the rest of you take 2d4 fire damage.
raptorstrike
raptorstrike
one final question what function do you use to set what the invisible color is or if you could just tell me where i can find a dictonary of all the allegro functions and peramaters that would work too thanks
____"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
23yrold3yrold
23yrold3yrold
The "invisible color" is always 0 for 8-bit (the first palette entry) and pink (RGB(255, 0, 255)) for truecolor modes. You can't change it, though that might change in later versions of Allegro.

The "dictionary" is otherwise known as the API docs and comes with Allegro in several forms. HTML, TXT, you name it. Check the docs folder.
Jesus saves ... the rest of you take 2d4 fire damage.
raptorstrike
raptorstrike
so dose it support 24 bit? and what do you mean 0 for 8 bit (black?)
____"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
23yrold3yrold
23yrold3yrold
By "truecolor", I mean 16bpp, 24bpp, and 32bpp. All three use pink as the transparent color. As for 8 bit, it's always color 0, which means the first color in the palette (palette[0]). It might be (and usually is) black, but doesn't have to be.
Jesus saves ... the rest of you take 2d4 fire damage.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.