Sign in to follow this  
chadsxe

How do you get the width and height from a LPDIRECT3DTEXTURE9

Recommended Posts

I need to figure out how to get the width and height from a loaded How do you get the width and height from a LPDIRECT3DTEXTURE9. I am not sure how to do this. Any suggestion would be great help. Regards Chad

Share this post


Link to post
Share on other sites
To get the size on disk, pass an Info structure to D3DXCreateTextureFromFileEx. In memory the texture may be resized to a power of 2 size. The value returned here is what the image really was, on disk.

To get the size created
D3DSURFACE_DESC desc;
pTex->GetLevelDesc(0, &desc);

Share this post


Link to post
Share on other sites
Awesome....Works perfect

For completiton sakes can someone shed some insight on what is ment by "level". For example we pass 0 above, when would we ever pass 1 or >?

Regards

Chad

Share this post


Link to post
Share on other sites
It's the mipmap level. If you load a 256x256 texture, unless you say otherwise, D3DX will also create a 128x128, 64x64, ..., 1x1 surface. This improves how textures in the distance look. Without mips, you'll get a shimmering effect. Level 0 is the top level, full sized. Each level below is half the size of the one above.

Share this post


Link to post
Share on other sites
Quote:
Original post by Namethatnobodyelsetook
Level 0 is the top level, full sized. Each level below is half the size of the one above.


Each level below is 1/4 the size of the one above

For example:

128 * 128 = 16384
64 * 64 = 4096

4096 / 16384 = 1/4

Share this post


Link to post
Share on other sites
Quote:
Original post by Namethatnobodyelsetook
In memory the texture may be resized to a power of 2 size.


How do you get the size of the texture in memory if it's been resized?

Share this post


Link to post
Share on other sites
GetLevelDesc will tell you the size of the texture in memory. D3DXCreateTextureFrom* will resize a texture at load time if specified, but I don't know if the width and height returned from the function is the width/height of the texture before or after resize.

Share this post


Link to post
Share on other sites
Quote:
Original post by Headkaze
Quote:
Original post by Namethatnobodyelsetook
In memory the texture may be resized to a power of 2 size.


How do you get the size of the texture in memory if it's been resized?


D3DXCreateTextureFromFileEx's optional info structure is filled with size, and format, of the texture on disk. GetLevelDesc will return the size, and format, of the texture created in D3D.

You can tell D3DX to not make a larger texture, if the device doesn't require it, by specifying a size of "D3DX_DEFAULT_NONPOW2".

You can tell D3DX that if it makes a larger texture, to just fill in the upper right part of the texture, rather than stretching it, by setting the filter (not the mipfilter) to D3DX_FILTER_NONE. In this case you'll want to pass an info structure to D3DX. That will be filled with the original texture size. Then you would use GetLevelDesc to find the created texture size. Finally you would use both sets of information to calculate your UV texture coordinates (instead of 1.0f, you would use loadinfo.width/desc.width, loadinfo.height/desc.height)

example:
A texture is a 60x100 grey scale (L8) on disk. This will be in the info structure from D3DX regardless of how it's loaded into D3D. What comes out of GetLevelDesc depends on your card, and what options you chose.

If your card supports L8, it will be loaded as L8. If not, it's often loaded as A8R8G8B8. This format will be in GetLevelDesc.

If your card requires square textures, GetLevelDesc will return a width and height of 128 (next biggest pow2 size).

If your card doesn't need square textures, GetLevelDesc will return a 64x128 texture.

If you ask for "D3DX_DEFAULT_NONPOW2", you'll either get a 60x100 texture if the card doesn't require pow2 sizes, a 64x128 texture if it does require pow2 sizes, or 128x128 if square is needed. Most cards can use non-pow2 textures in a limited fashion (no mips, wrapping, etc... See Nonpow2conditional in the caps). That fact makes this flag dangerous, as you can easily load textures that can't be used for general cases, only things like fonts, huds, title screens, etc.

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