Lesson 6 and beyond

Started by
6 comments, last by Aardvajk 17 years, 8 months ago
Hello All: I am using Visual Studio.net to go through the tutorials. I am trying to add an image of a bitmap. Where do I put the image to display it? I know right now you put it in: if (TextureImage[0]=LoadBMP("Data/Crate.bmp")) How do I put the image in that location? Please help!
Advertisement
ok, when testing it via visual studio make a folder in the projects folder (where the source is) called data and in that folder put crate.bmp

when running the exe, the data folder needs to be in the same folder as the exe.
www.stickskate.com -> check it out, some gnarly stick skating movies
Paths are relative to the current directory which in this case would be your project directory.

With Visual C++, this is the same directory that your .cpp and .h files are put in. For example, if I create a project in C:\Projects called MyApp, Visual C++ will create the director C:\Projects\MyApp, inside of which is another directory called MyApp into which .cpp and .h files will go by default. This would be the current directory when you run your project from the IDE.

With your example above, your image needs to be in yet another folder called Data in this folder. To use my example, the full path to the image would be C:\Projects\MyApp\MyApp\Data\Crate.bmp.

The easiest way to confirm this is to add this code to your application temporarily:

#include <fstream>

// and then near the start of your entry point function:

ofstream os("my_temp_file.txt");

If you run your app then exit, you can have a look at your project directory structure and see where my_temp_file.txt has been created. This is the current directory for this application.

You can now delete the file and the code that created it, create a directory called Data at the same location and put Crate.bmp in the Data directory and the code you have posted should work.

Current directories can be a bit of a pain in practise in more complex applications though since they can be changed unexpectedly while your app is running, for example by an open file dialog or by your app being run from a command prompt. It is better to use a complete path from the drive root where you can. You may find it easier to create a folder called Graphics at C:\ and keep your resources in there.

if (TextureImage[0]=LoadBMP("C:\\Graphics\\Crate.bmp"))

HTH Paul

[EDIT] As crazy_andy has just reminded me with the post when I was typing this, when you run the exe directly, the Data folder would need to be in the same directory as the exe. This is another good reason to store your resources outside the project structure while developing and reference by a complete path since otherwise you can only run the project through the IDE.
Where do I get the images that they use in the tutorials? i.e. - crate.bmp
download the source, they are all in there
www.stickskate.com -> check it out, some gnarly stick skating movies
NeHe OpenGL tutorials reference a Data\Crate.bmp if memory serves. You can download the VS source for those examples including the image here if you want.
Use forward slash as the path separator in C++, even if that's not what your OS uses.
Fair comment. Will do.

This topic is closed to new replies.

Advertisement