Sign in to follow this  
GuestUnit

Can't load a sprite

Recommended Posts

I was following a tutorial about an introduction to sprites, but something is bothering me. Does it matter where the location of the image file is? Because it appears to be so. If that's true, where should I be putting the file? To just see if the cpp compiled, I copied the example cpp and made my own L"example.png" but when it ran the sprite image wouldn't appear and I had to shut down the computer because of alt+tabbing out of DirectX.

Share this post


Link to post
Share on other sites
My IDE would have me place the image in the project file. Some might have you place it in a resources folder, I don't know. Depending on which IDE you're using, you might want to look into this.

How does DX handle failed loads?: OpenGL, for example, will load an image, but if the load fails, nothing will happen. My program will continue on its happy way, never caring. You should try to write code for if the image doesn't load, and if you can't keep the game running, you should exit (with some way of telling yourself what the problem was). But I know there was a problem because the texture comes back as zero.

Share this post


Link to post
Share on other sites
File loading commands usually assume that you give it a path to the file, relative to some current working directory. That's usually the same directory that the program is executing from, but it could be different depending on your operating system or compile settings. You need to figure out the full relative path to your resources from that default directory.

Give us your language and compiler and we can help you more.

Share this post


Link to post
Share on other sites
By default its the same directory the cpp and h files are are(The project directory).

You can change it by:
Project -> Properties
Configuration Properties -> Debugging
Change the "WorkingDirectory" field to the path where you "game dir" is
eg: "D:\cpp\games\space game\game dir"

Share this post


Link to post
Share on other sites
If your image is in the working directory (as the last poster mentioned), you can just call the image name: "image.tga". If it's in a subdirectory, as my images are, you'll have to include that: "textures/image.tga".

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