Textures not found when loading x-file

Started by
5 comments, last by Supernat02 19 years, 8 months ago
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?
Advertisement
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.
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.
I've exported the modells again from 3dsmax and now everythings works fine..

Altough I haven't got a clue why it's working now..

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
Chris ByersMicrosoft DirectX MVP - 2005
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?
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
Chris ByersMicrosoft DirectX MVP - 2005

This topic is closed to new replies.

Advertisement