Sign in to follow this  
Followers 0
SherrelE

Allegro bitmap loading issue

2 posts in this topic

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

0

Share this post


Link to post
Share on other sites

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.

1

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
0

Share this post


Link to post
Share on other sites

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  
Followers 0