[Fixed Gracefully] D3DXCreateTextureFromResource () - How to ?

Started by
4 comments, last by Steven Hansen 18 years, 6 months ago
Hi all!. I have a little problem: How to create a texture from resource which type is not .BMP (such as .DDS, .PNG etc etc...). The DXSDK documentations provides not enough infos to do this correctly. I've tried a number of ways but still not succeeded, I also searched the forum but someone else had posted a similar question and got no answer. Thank you for your helps. V@T [Edit] Once again :/ This seems to be no answer. It will be an unsolvable question. The first time I have to say the DXSDK sucks :( [/Edit] [Edit] Thanks Steve!. The question is now become "Fixed". :) Rate++ ; [/Edit] [Edited by - Skeleton_V@T on November 3, 2005 12:55:44 AM]
--> The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones <--
Advertisement
I don't understand what the problem is.

What have you tried, where have you failed?

heres what the SDK has to say:
Quote:From SDK:
The resource being loaded must be of type RT_BITMAP or RT_RCDATA. Resource type RT_RCDATA is used to load formats other than bitmaps (such as .tga, .jpg, and .dds).

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


Are you making your resource as RT_RCDATA?
Sirob Yes.» - status: Work-O-Rama.
Hi.

My purpose: embed the images into the executable itself for not having to carry dozens of images along with the exe when running program, I think this is quite popular to save the images as resources. I can then load the images by using D3DXCreateTextureFromResource ().

My first attempt: I embeded a bitmap into the exe and the function worked well. The bitmap was stored as RT_RCBITMAP resource type (which appears as 'Bitmap' in the Resource editor).

My second attempt: I embeded a DDS (or PNG, JPG, or some other things), did as above and received an error from the function - D3DERR_INVALIDDATA. The image was stored as "RC_RCDATA" (note that quotes "", the image is display exactly as it is now).

(I have read the SDK dozens times and digged the Internet but couldn't find any answer, maybe sendind an email to Microsoft will serve my purpose)

My third attempt: I renamed the image to *.BIN because the Resource Editor will not accept any RT_RCDATA resource type without a .BIN extension. And I've got a linker error: "error RC2135 : file not found: "Image.BIN". What do you think ? I am totally sure the file is there, even Visual Studio can open it, but can not compile it (what was it doing ???).


A member in the forum has posted this question several times and received nothing.
V@T

[Edit]
Have you ever tried to add a resource as RT_RCDATA resource type using VS.NET ?. I've never succeeded, any time I tried, I got a linker error as mentioned above.
[/Edit]
--> The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones <--
This might not be the best solution, but I know most commercial games provide a package file which contains many resources in one file. You'd then use D3DXCreateTextureFromFileInMemory, which should solve your problems with D3DXCreateTextureFromResource.

As for the resource problem, I don't really know. I've never actually done that. Could there be something to do with VS looking in the wrong directory? I think I saw somewhere it should be in the project directory, though I'm not too sure.

Googling, all I could find were references to having the files in the wrong directory.
Sirob Yes.» - status: Work-O-Rama.
Ahhh, thank you, I gave up. Even this solution is implemented, it wouldn't be a good solution for larger projects though. I am just surprised why people didn't try this as I thought it was quite popular to use CreateTexture () that way.

Nevertheless, thanks for helping me.
V@T

--> sirob.Ratings++ ;
--> The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones <--
Wow - you give up quick! Solution coming up:

inside Resource.h:
#define IDR_TEXTUREID <somenumber>

inside ProjectName.rc (edit this manually for best results):
IDR_TEXTUREID RcData "<relativepath>\\texture.tga"

Load code:
#include "Resource.h"LPDIRECT3DTEXTURE9 texture;HANDLE srcModuleHandle = GetModuleHandle("<yourexe.exe>"); // Or NULL for default.D3DXCreateTextureFromResource(device, srcModuleHandle, MAKEINTRESOURCE(IDR_TEXTUREID), &texture);


I use this VERY frequently - any more problems, PM me or something. Should be straightforward.

This topic is closed to new replies.

Advertisement