Sign in to follow this  

Textures not found when loading x-file

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

I've changed my directory structure of my project. All the header/cpp and x-files with textures where dumped in one directory so I added a directory source with dirs for my cpp and header files. I also created a directory media with a dir XFiles in it. The problem is that after changing my code to use the new paths I get the error that the textures for my XFile can't be found but the x-file itself can be found. My mesh constructor calls an init function where i use the code from Tutorial 6.. everything worked perfect before I changed the directorys
// Old code:
CubeMesh = new CMesh("Cube.x");
// New code:
CubeMesh = new CMesh(".\\Media\\XFiles\\Cube.x");

Any idea what could be the problem?

Share this post


Link to post
Share on other sites
I would suggest you debug print the file location when you load the texture, then check that with the actual location. There may be a problem there. But that does seem kind of strange.

If you've got the right file name + location, I can't help you.

Share this post


Link to post
Share on other sites
Have you created a sub-folder for textures and a sub-folder for X files? The X files and associated textures will most likely need to be in the same directory.

If you have text based X files open them up in Wordpad and look at the material templates. Part of the material template is a path to the texture file. Make sure that path points to the texture file relative to where the X file is.

Also, you do not need the ".\\" at the start of your paths.

Share this post


Link to post
Share on other sites
One thing you can do is export the x files as text instead of binary, then check how the texture filenames are being stored by the exporter. It would be good to know this information if you plan on re-distributing. If it stores them as "c:\my documents\projects\test\textures" for instance, that's BAD. It should be a relative path to your x file.

Chris

Share this post


Link to post
Share on other sites
I've checked the paths and in the working version the complete path is mentioned:

D:\\Programming\\MyPrograms\\RazorEngine\\Media\\XFiles\\Icecube.jpg

If I change this to "Icecube.jpg" I get the error that the texture can't be found.

The strange thin is that if I open my Xfile with the Meshviewer from the SDK the cube shows up with the correct texture.

If I change "Icecube.jpg" to "Media\\XFiles\\Icecube.jpg" the textures are loaded correctly.

So what should I do? Change all the paths in my xfiles before distributing it to other users?

Share this post


Link to post
Share on other sites
You would want to probably store the installation directory in a key in the registry when the player installs the game. Then, load this registry key in your game, say it's "C:\Program Files\Games Inc\Game of the Year". Then, set the current windows directory to this directory before calling the Load function for the texture. Then if the texture's filename is "textures\tex1.bmp", it will be appended to the current directory (or so is usually the case).

Functions you'll need:
SetCurrentDirectory("String");
See Registry Sample in the MSDN Library.

Chris

Share this post


Link to post
Share on other sites

This topic is 4867 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.

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