Some Texture Loading Questions in DX9

Started by
4 comments, last by lzr 18 years, 8 months ago
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
------------------------My Site: http://lzr.cc
Advertisement
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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

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.
------------------------My Site: http://lzr.cc
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

For the love of god, please tell me that you've just omitted your error checking code for brevity, and you don't really assume that all those functions succeed.
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.
------------------------My Site: http://lzr.cc
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.
------------------------My Site: http://lzr.cc

This topic is closed to new replies.

Advertisement