Jump to content
  • Advertisement
Sign in to follow this  
SherrelE

Allegro bitmap loading issue

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

Greetings, all.

I've looked all over the place for a solution to this honestly sort of embarrassing problem. I have this code here:

   // Load BITMAP
    BITMAP *sprPlayer = load_bitmap("./data/spr/digbug.bmp", NULL);
    BITMAP *sprDirt = load_bitmap("./data/spr/ground_ph.bmp", NULL);
    BITMAP *sprGrass = load_bitmap("./data/spr/grass_ph.bmp", NULL);

and I've tried configuring the directory in every which way I know to get it to read the BMP's in the "spr" folder in the "data" folder next to the EXE. Last time I tried this I used an absolute directory (c:/users/whoever/etc) and obviously that won't work on others' computers. I checked the BMP's and they seem to be fine. Any tips?

Using Allegro 4 and Code::Blocks, by the way

Share this post


Link to post
Share on other sites
Advertisement

Relative paths are relative to the current working directory, which does not necessarily have to be where the executable is located. Since you mention that you use an IDE, check what the current working directory is when you execute your executable from the IDE if that is what you're doing.

 

For example, Visual Studio usually sets the working directory to the project directory, but the executable is located somewhere else. Here's my directory setup for my projects:

  • Project directory: c:\path\to\project
  • Executable directory c:\path\to\project\bin\x64\Release
  • Data directory: c:\path\to\project\data

 

Thus, my Visual Studio executes the command "c:\path\to\project\bin\x64\Release\program.exe" with the working directory "c:\path\to\project", and my program thus accesses files in the data directory with "data\file.bmp" because that is the relative path to the bitmap from the working directory.

 

If I instead open the file explorer and double click on the executable, the working directory is the executable directory itself, and thus "data\file.bmp" will not found anymore. In that case I would have to use "..\..\..\data\file.bmp" to take three steps up to leave the "bin\x64\Release" substructure.

Share this post


Link to post
Share on other sites

There's a part of the project properties named Execution Working Directory in build targets, which is set just to "."

and changing that to the directory where I actually put the EXE does nothing, either.

I'll keep tinkering though, I see where you're coming from.

 

EDIT: Scratch that!! It worked! Thanks so much.

Edited by Arale

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!