Sign in to follow this  

problem loading .dat data

This topic is 4858 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
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


#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
// works
blit((BITMAP*)datafile[building_red].dat, screen, 0, 0, 64, 32, ((BITMAP*)datafile[building_red].dat)->w, ((BITMAP*)datafile[building_red].dat)->h);

// neater
BITMAP* bmp = (BITMAP*)datafile[building_red].dat;
blit(bmp, screen, 0, 0, 64, 32, bmp->w, bmp->h);

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 4858 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this