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

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 on other sites
Quote:
 Original post by raptorstrikeok in allegro im trying to use this functionvoid 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 ].datatypebut my compiler says that data is undefined do i need to inclose this statement in () if i put it in "" i get a critical errorerror: 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 on other sites
yeah i guesss your right but thats not the problem

Share on other sites
Why would that be unsafe? It's just whitespace, the compiler will trim.

Share on other sites
Where are you declaring data?

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;

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
where you replace yourfilename.dat with whatever your filename is. Do this before you call that drawAll() function.

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 on other sites
If you're casting properly, that shouldn't happen.

draw_sprite(screen, (BITMAP *)data[THE_IMAGE].dat, x, y);

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 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 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);

-Auron

1. 1
2. 2
Rutin
21
3. 3
4. 4
frob
17
5. 5

• 9
• 12
• 9
• 33
• 13
• Forum Statistics

• Total Topics
632590
• Total Posts
3007246

×