# D3DXCreateTextureFromFile failing :(

This topic is 4330 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hey. makn a heightmap here and have run into a bit of a boo boo. Ive spent last 2 hours searching through google and gamedev on a possible solution and have tried fixing it myself. basically my D3DXCreateTextureFromFile is failing. I think primarerly that when i specify the file to be loaded, i am missing like \0 or \n at the end..or something liek that, as the file is in same directory. here is the relevent code, if any1 can point me in the right direction id be very happy. i have these includes:
#include <d3dx9.h>
#include <d3d9.h>
#pragma comment (lib, "d3d9.lib")
#pragma comment (lib, "d3dx9.lib")

bool cHeightMap::loadHeightMapTexture( std::string fileName )
{
HRESULT hr = 0;

hr = ::D3DXCreateTextureFromFile( mDevice, fileName.c_str(), &mTexture );

if( FAILED( hr ) )
{
::MessageBox(0,"ERROR: Texture Not Loaded  successfully. ",fileName.c_str(), MB_ICONERROR  );
return false;
}
return true;
}


in debug mode, this compiles and goes into the FAILED part, displays message and returns false. mDevice is initalized and i have the DirectX window all set up. here how the varibles above are initalized.
fileName = "terrain.raw";
// Texture is as below. //
Direct3DTexture9*      mTexture

the file is in the right place, all spelling is the same. ....just cant figure out what i'm missing.. Ive scoured the web for adive and would be really thankfull if any1 the problem. cheerz.

##### Share on other sites
Have you tried the debug runtimes? usually they elaborate on what the error really was. If you're so sure the filename/location is correct (you considered the possibility of a different working directory?) then it could be a format and/or dimensions issue - there are still hardware requirements imposed by the D3DXCreateTextureFromFileEx() function.

hth
Jack

##### Share on other sites
Yeah ive tripple checked the working directory, as for the format, ive seem the *.raw file being used quite a bit, and i even downloaded a pre-made heightmap and dimensions r set appropitly.
The thing is that it doesnt crash, the function d3dcreate computes then fails and gets caught in my error check with the if statement.
Also back in my main, if this function doesnt return true then i make the program exit, because if i dont have the file, then theres no point in interperating data that doesnt exist.
also i dont think hardware would be an issue here, i have the x850xt, and im sure its cappable of doing this simple task.

thankz for ur post, if i use the debug libs, will i get extra information into the D3DXCreateTextureFromFile function even thou it doesnt crash?

##### Share on other sites
From the documentation on D3DXCreateTextureFromFile:
This function supports the following file formats: .bmp, .dds, .dib, .hdr, .jpg, .pfm, .png, .ppm, and .tga.

If you want raw data in a texture you'll have to either convert it to one of the above formats or load it manually.

##### Share on other sites
Yes, if you change to d3dx9d.lib (D for debug) you should get extra info on why the load failed.