Jump to content
  • Advertisement
Sign in to follow this  
ols

D3DXCreateTextureFromFileEx invalid method call

This topic is 5006 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 really hope someone can help, as a bit lost! Trying to load a texture from a file, but my loading method says that there is an invalid method call (in my D3DXCreateTextureFromFileEx call). I have looked everywhere I can think of for an answer, but cant see it. Maybe it is something REALLY easy which I am just not seeing, but thought I would post just in case anyone has any ideas. Code for the loading method is below. Any help is greatly appreciated. Cheers, Ols (I was storing the result of the call in an int so I could assess which error was being produced; I have removed the switch statement assessing this int as it is superflous!) IDirect3DTexture9* CGameApp::LoadTexture(char* fileName) { IDirect3DTexture9* d3dTexture; D3DXIMAGE_INFO SrcInfo; D3DCOLOR colourKey = 0xFFFF00FF; int create = D3DXCreateTextureFromFileEx(_pD3DDevice, fileName, 0, 0, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_DEFAULT, colourKey, &SrcInfo, NULL, &d3dTexture); return d3dTexture; }

Share this post


Link to post
Share on other sites
Advertisement
Yeah, I know how it is, D3DERR_INVALIDCALL is really annoyingly vague. I'll throw out a few guesses, in case they might help.

First thought was that maybe the file name is incorrect. If you're giving it a relative path, maybe the current directory has changed, and it therefore can't find the file. Try giving it an absolute path, or try opening the file with a std::istream object and checking is_open(), to make sure the filename is correct.

Second, I tend to use D3DX_FILTER_NONE for MipFilter when I only have one mip level. I have no idea if using D3DX_DEFAULT would cause a problem in this case.

Third, see if D3DFMT_X8R8G8B8 (no alpha) works. Maybe the card doesn't like D3DFMT_A8R8G8B8 for some reason.

Try using D3DPOOL_DEFAULT, just for fun. I don't know why. Maybe DirectX doesn't want to be responsible for your image. It's too immature.

Make sure your device pointer isn't NULL, of course.

Maybe your image is a palettized image, and it's complaining that you didn't provide a palette.

Maybe your image is too large, and since you specify 0, 0 for the width and height, it has to use the image's actual size, but can't.

Okay, those are all the guesses I can think of at the moment, some probably better and more reasonable than others. Good luck tracking the problem down. (And no one better complain about me saying "good luck"!)

Share this post


Link to post
Share on other sites
If that doesn't solve your problem, here's a quote from the SDK:

Use D3DXCheckTextureRequirements to determine if your device can support the texture given the current state.

This function supports the following file formats: .bmp, .dds, .dib, .hdr, .jpg, .pfm, .png, .ppm, and .tga. See D3DXIMAGE_FILEFORMAT.

Mipmapped textures automatically have each level filled with the loaded texture. When loading images into mipmapped textures, some devices are unable to go to a 1x1 image and this function will fail. If this happens, then the images need to be loaded manually.

For the best performance when using D3DXCreateTextureFromFileEx:

Doing image scaling and format conversion at load time can be slow. Store images in the format and resolution they will be used. If the target hardware requires power of 2 dimensions, then create and store images using power of 2 dimensions.
For mipmap image creation at load time, filter using D3DX_FILTER_BOX. A box filter is much faster than other filter types such as D3DX_FILTER_TRIANGLE.
Consider using DDS files. Since DDS files can be used to represent any Microsoft DirectX 9.0 texture format, they are very easy for D3DX to read. Also, they can store mipmaps, so any mipmap-generation algorithms can be used to author the images.

Share this post


Link to post
Share on other sites
Quote:
Yeah, I know how it is, D3DERR_INVALIDCALL is really annoyingly vague.


Quote:
Original post by DrunkenHyena
Have you tried linking to the debug version of D3DX?


The bulk of debug output comes from errors that return as D3DERR_INVALIDCALL. This is because there are literally thousands of different reasons why all of the D3D functions could fail - far to many to have a DWORD/HRESULT defined for each one. Instead, the debug runtime throws a detailed debug message to your IDE, then returns the defult D3DERR_INVALIDCALL. D3DERR_INVALIDCALL should be your cue to fire up the debugger and find out exactly what's going on [wink].

Share this post


Link to post
Share on other sites
Thanks all for your replies, but after trying out some of your suggestions it appears my problem is far more diverse and bizarre than I realised! I am completely stuck now and been trying to fix it since yesterday afternoon with no luck. Here is what I can work out so far....

The program I am working on has been built up iteratively, each time the code being moved to a new file within a new project for any updates to be made so that the older programs still work.
This has not been a problem up to this point, but now it appears that the old programs are coming back to haunt me! I have added a couple more methods to my header file CGameApp.h, including the LoadTexture function which I showed above. However, when I add the code for this function to the CGameApp.cpp file, it does not consider it to be part of CGameApp and instead places it within the global scope. Not sure if that makes a lot of sense...
I am using Visual C++ 2005 Express Edition, and the Intellisense (i.e. autocomplete) appears to think that it should be using the old header file as well. When I type CGameApp:: a list of possible choices comes up, but this ignores any new information that I have placed within the header file.

I have tried everything I can think of, including moving the old files and all manner of other things! Cant think of them all at the moment as this is just driving me nuts!!

I know that this is not likely to be the correct forum to now post, but I dont know if i can move the post.

PLEASE HELP!!!!

Share this post


Link to post
Share on other sites
Did you update the library and source directory settings in your IDE? Order is important. Be sure to put the newest code directories at the top of the list, and remove the others of course.

Chris

Share this post


Link to post
Share on other sites
Thanks for all the help thus far; cleared it all out and started again, but this time the texture is being drawn as black i.e. only get a black square. Any ideas? This is killing me!!!!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!