Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » load_bitmap trouble

Credits go to CGamesPlay, Evert, and Kitty Cat for helping out!
This thread is locked; no one can reply to it. rss feed Print
 1   2 
load_bitmap trouble
Raf Vermeulen
Member #7,166
April 2006

I started a new project today, prototyping an addition to a game engine I already have. I pretty much took over all initialization code and the basic objects from the existing code (which works fine), but stripped the unnecessary parts out (like animation code, as I don't plan on animations on the prototype for now)

The dumb thing is, that it doesn't want to load the tileset...
All source code's in the attached zipfile, along with the tileset. The problem lays in either

Tile::Tile() : /* deze methode is sneller dan wanneer ze in de constructor staan */
size(32),
type(0) {
  if(!m_tile) load_tileset("Gfx/Tile.bmp"); 
  if (!m_tile) cout << "Spritesheet not loaded\n";     
}

(file classes.cpp)
or in

void Tile::load_tileset(const char *tileset) {
  Tile::m_tile = load_bitmap(tileset, NULL);
}

as the output always gives: "Spritesheet not loaded".

m_tile is a static, protected bitmap in Tile, btw.

piccolo
Member #3,163
January 2003
avatar

i think you posted the wrong version of the code. in this version there are a lot of return errors and it wont compile.

wow
-------------------------------
i am who you are not am i

Raf Vermeulen
Member #7,166
April 2006

I only got one version. What're the errors it gives there? Might have something to do with the problem.

The IDE I use, is Dev-C++ v.4.9.9.2, with the standard compiler coming with it and with the Allegro linker parameter.

piccolo
Member #3,163
January 2003
avatar

1#1
2//what you have
3int initiaze() {
4 allegro_init();
5 install_keyboard();
6 install_timer();
7
8 LOCK_VARIABLE(counter);
9 LOCK_FUNCTION(timer_handler);
10 install_int_ex(timer_handler,BPS_TO_TIMER(15)); /* Draai op 15 hz */
11 
12 /* Install handler when user presses X at the topright corner */
13 LOCK_VARIABLE(exit_application);
14 LOCK_FUNCTION(exit_button);
15 set_close_button_callback(exit_button);
16 
17 set_color_depth(16);
18 if(set_gfx_mode( GFX_AUTODETECT_WINDOWED, SCR_WIDTH, SCR_HEIGHT, 0, 0)) exit(1);
19 buffer = create_bitmap(WIDTH*32, HEIGHT*32);
20 Tile::load_tileset("Gfx/Tile.bmp");
21}
22
23#2
24 
25virtual int get_index() {};
26 
27 
28 
29 
30 
31//what i put
32#1
33int initiaze() {
34 allegro_init();
35 install_keyboard();
36 install_timer();
37
38 LOCK_VARIABLE(counter);
39 LOCK_FUNCTION(timer_handler);
40 install_int_ex(timer_handler,BPS_TO_TIMER(15)); /* Draai op 15 hz */
41 
42 /* Install handler when user presses X at the topright corner */
43 LOCK_VARIABLE(exit_application);
44 LOCK_FUNCTION(exit_button);
45// set_close_button_callback(exit_button);
46 
47 set_color_depth(16);
48 if(set_gfx_mode( GFX_AUTODETECT_WINDOWED, SCR_WIDTH, SCR_HEIGHT, 0, 0)) exit(1);
49 buffer = create_bitmap(WIDTH*32, HEIGHT*32);
50 Tile::load_tileset("Gfx/Tile.bmp");
51 return 0;
52}
53 
54#2
55virtual int get_index() {return 0};

there are more tell me when you get the code to the state where you said you had the problem then ill down load the code.
you can change file by editing your attachments

wow
-------------------------------
i am who you are not am i

Raf Vermeulen
Member #7,166
April 2006

Got some trouble with placing the virtual int get_index() part. It keeps saying "virtual outside class declaration"

piccolo
Member #3,163
January 2003
avatar

i c so you did not have a problem with any loading of any map:-X ill take a look at the current code then.

wow
-------------------------------
i am who you are not am i

Raf Vermeulen
Member #7,166
April 2006

The problem's with loading the spritesheet;) If I reinstate the draw-function, the program crashes as it doesn't load the bitmap.

piccolo
Member #3,163
January 2003
avatar

well i tried i wont be able to do it to night there is just to many things to change and fix.

take a look at this site this is where I and a lot of other people learned about tile maps.

http://agdn.netfirms.com/main/
http://agdn.netfirms.com/main/html/tut_1.htm
http://agdn.netfirms.com/main/html/tut_2.htm
http://agdn.netfirms.com/main/html/tut_3.htm

word of advice compile more so your error don't build up like they have.

this site has a 7 lesson plan that you should follow about making tile maps and editors.

wow
-------------------------------
i am who you are not am i

Raf Vermeulen
Member #7,166
April 2006

Ok, thanks. I'll read up on it.

piccolo
Member #3,163
January 2003
avatar

feel free to message me about any one of the tutorials be cause i have completed them all.;D

wow
-------------------------------
i am who you are not am i

Raf Vermeulen
Member #7,166
April 2006

Hmmm, I went through all the tutorials, but they didn't tell me how to fix the spritesheet loading. It was an interesting read, though.

piccolo
Member #3,163
January 2003
avatar

they use sprite sheets in those tutorials.

wow
-------------------------------
i am who you are not am i

Raf Vermeulen
Member #7,166
April 2006

Yeah, but so do I in my other code, and it all works, both in that other code and in that tutorial, but I do the same thing in this code, but it doesn't work here =S

piccolo
Member #3,163
January 2003
avatar

in your code you have a lot of basic errors stacked on top of each other.

wow
-------------------------------
i am who you are not am i

Raf Vermeulen
Member #7,166
April 2006

Hmmm... same thing for the other code (the one from that thread from yesterday), or'm I missing something? That one worked. This one compiles (here, at least), but doesn't work in runtime, so there must be a difference somewhere which I can't spot.

What errors's it give there when compiling?

piccolo
Member #3,163
January 2003
avatar

in your code you have a lot of basic errors stacked on top of each other.

wow
-------------------------------
i am who you are not am i

Raf Vermeulen
Member #7,166
April 2006

How'm I supposed to fix these errors if my compiler doesn't give any and if you don't tell me what they are when you notice them????

CGamesPlay
Member #2,559
July 2002
avatar

How do you run the program? Most likely the problem is that you are in a different directory that you think you are.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Raf Vermeulen
Member #7,166
April 2006

I've tried running it from Dev-C++ right after compiling, from inside the directory, and from inside the other code's directory (which uses the same subfolder and spritesheet's filename), and it all does the same.

CGamesPlay
Member #2,559
July 2002
avatar

Try putting this code in the load_tileset function:

if(!file_exists(tileset))
    cerr << "Spritesheet does not exist at location " << tileset << "!" << endl;
else if((m_tile = load_bitmap(tileset, NULL)) == NULL)
    cerr << "Spritesheet exists, but failed to load!" << endl;

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Raf Vermeulen
Member #7,166
April 2006

Ok, file_exists didn't quite work (didn't want to compile, and if I added 0, NULL, it gave runtime crashes), so I did it like this:

     FILE * file;
     file = fopen(tileset,"r");
     if (!file) cout << "Error with opening of file\n";
     else cout << "Could open file\n";
     fclose(file);
      
     if( (Tile::m_tile = load_bitmap(tileset, NULL)) == NULL)
         cout << "PROBLEM!\n";

The output of this is:
Could open file
PROBLEM!

So it can reach the file, but something's wrong with the load_bitmap part. Not much that can be done wrong with that, though =S

CGamesPlay
Member #2,559
July 2002
avatar

So, what are your color conversion settings? (Do you call set_color_conversion?) What is your color depth? If you compile using the debug version of Allegro, do you get an assertion failure?

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Raf Vermeulen
Member #7,166
April 2006

I don't know how to compile with the debug version. Color depth's set to 16. Set_color_conversion's not called. The graphical mode's set like this:

    set_color_depth(16);
    if(set_gfx_mode( GFX_AUTODETECT_WINDOWED, SCR_WIDTH, SCR_HEIGHT, 0, 0)) exit(1);
    buffer = create_bitmap(WIDTH*32, HEIGHT*32);

That's the same as in the other code, where it does load the tileset.

I also tried loading the tileset from the other code, and that gives the same problem.

Kauhiz
Member #4,798
July 2004

Quote:

I also tried loading the tileset from the other code, and that gives the same problem.

Hmm, I wonder where the problem could be, then...

---
It's Ridge Racer! RIIIIIDGE RAAAAACER!

CGamesPlay
Member #2,559
July 2002
avatar

You should write a simple test case to load the bitmap and blit it to the screen in as few lines as possible. Don't put the bitmap in a subdirectory or anything, just load and blit. I want to see if this is a problem with Allegro.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

 1   2 


Go to: