NoOne2007

Hello guys and girls.

I'm having a problem with the Direct3D function "D3DXCreateTextureFromResource". First I want to say, I'm new to DirectX and also to C++. I'm using the newest DirectX SDK, DirectX 9 on Windows XP and my IDE is Microsoft Visual Studio.

I'm using this little piece of code to load a texture:

HRESULT hr = D3DXCreateTextureFromResource(device, NULL, MAKEINTRESOURCE(IDR_IMAGES1), &texture);
if (FAILED(hr))
MessageBox(NULL, DXGetErrorString(hr), L
"Error", MB_OK | MB_ICONEXCLAMATION);

When IDR_IMAGES1 is a bitmap, then it works just fine, then I don't get an error. But when it's a a PNG graphic, then I always get the error 'D3DXERR_INVALIDDATA'.

I'm adding the pictures, by going to the Resource View of MSVS, right clicking and choosing "Add Resource", there I'm clicking on Import, selecting my PNG file and clicking Open. Then I have to enter a Resource Type where I usually enter "Images".

Another thing is, when I try adding a JPG file the way like I wrote up there, MSVS shows me the error: "Filename is not a valid img file.". Well, Filename is of course the filename, and the squares aren't filled in.

Can someone help me with my problem

No One



Re: Game Technologies: DirectX 101 Problems with creating a PNG texture from a resourcefile

Anonymous

Sorry I dont have an answer but I am having the same problem trying to load JPG resouce textures so I doubt its just a typo you have made. If I find a solution I'll post it

Good luck.





Re: Game Technologies: DirectX 101 Problems with creating a PNG texture from a resourcefile

Anonymous

After a little looking around I'm starting to think that anything but a bmp is a special case. There is some code on the page below that isn't loading the image in DirectX but I suspect that it could be modified to work using directX. (It maybe that the resouce is of a binary type so it needs to be handled differently.) Not sure when I will get a chance to try this out though.

http://www.codeproject.com/bitmap/load_jpeg__gif_resource.asp