Sign in to follow this  
lzr

Some Texture Loading Questions in DX9

Recommended Posts

I am converting my 2d DirectDraw game into a 2d Direct3d game (for the rotation, effects, and alpha blending) and I have two questions involving texture loading. By the way, write now I'm using D3DXCreateTextureFromFileEx to load the textures. Anywho, my first question is, how would I load a texture from a resource? And my second question is, well, I need more than one sentence. In my game, currently, I put my package my images along with the data in the files they correspond to. For instance, my tileset file contains, not only tile information, but all the tile imagery as well. Is there anyway to tell DirectX (without writing my own image loading routine 'cause I want to use PNG format) to load from the inside of a file. I don't know if I'm wording this correctly, but I hope you get the point. Thanks, Leeran

Share this post


Link to post
Share on other sites
Quote:
Original post by lzr
Anywho, my first question is, how would I load a texture from a resource?

by "resource" I presume you mean the resource file you can bundle in with a standard windows executable?

If so, the following two functions are likely to be what you want: D3DXCreateTextureFromResource( ) and D3DXCreateTextureFromResourceEx( )

Quote:
Original post by lzr
Is there anyway to tell DirectX (without writing my own image loading routine 'cause I want to use PNG format) to load from the inside of a file.

Sort-of. If you can load in your entire file to memory as a byte-array I assume you also know the byte-offset where your PNG data begins (and how long it is)...

Have a look at either of these two: D3DXCreateTextureFromFileInMemory( ) and D3DXCreateTextureFromFileInMemoryEx( )

hth
Jack

Share this post


Link to post
Share on other sites
Thanks for the speedy reply. I just have a couple follow up questions (sorry). Firstly, what do I send in the HMODULE parameter of D3DXCreateTextureFromResource? And, just to clear stuff up, in the D3DXCreateTextureFromFileInMemory( ), do I load the entire picture into memory and send it? Just wanted to make sure.

Share this post


Link to post
Share on other sites
Quote:
Original post by lzr
Thanks for the speedy reply. I just have a couple follow up questions (sorry). Firstly, what do I send in the HMODULE parameter of D3DXCreateTextureFromResource?


Hi lzr,
Unless you are using external DLLs which contains your resource, then pass NULL as the HMODULE parameter to indicate the resource is in your main EXE file.

HTH,
Cambo_frog

Share this post


Link to post
Share on other sites
I've been trying for like forever to get D3DXCreateTextureFromResource/D3DXCreateTextureFromResourceEx to work, but they just don't.

Here is how I include the resource:

Ball RT_RCDATA "ball.png"

And here is how I load the texture.

D3DXCreateTextureFromResource(Device, NULL, "Ball", &Ball);

And while I'm here, I'd also like to know: How do you load a texture from a different spot in the file. For instance, say I have one 256x256 picture and I just want to load a 64x64 picture located at (64, 128), how would I do that?

Thanks,
Leeran

P.S. Sorry for bringing up such an old file.

Share this post


Link to post
Share on other sites
I've been trying for like forever to get D3DXCreateTextureFromResource/D3DXCreateTextureFromResourceEx to work, but they just don't.

Here is how I include the resource:

Ball RT_RCDATA "ball.png"

And here is how I load the texture.

D3DXCreateTextureFromResource(Device, NULL, "Ball", &Ball);

And while I'm here, I'd also like to know: How do you load a texture from a different spot in the file. For instance, say I have one 256x256 picture and I just want to load a 64x64 picture located at (64, 128), how would I do that?

Thanks,
Leeran

P.S. Sorry for bringing up such an old file.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this