Advertisement Jump to content
Sign in to follow this  

D3D Texture Dimensions

This topic is 3335 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hiya, Does anyone know how I can find the dimensions of an IDirect3DTexture9 object? I'm using D3DX to load textures, but it automatically changes the texture sizes to the nearest power-of-2. This is fine, but I'm not sure how to determine the the dimensions of the original file (without parsing it myself :) Any help would be much appreciated! Cheers

Share this post

Link to post
Share on other sites
Use a D3DXIMAGE_INFO struct, which when passed to the D3Dx function, will provide you with the width and height of the image itself before d3dx changes it.

I think you'll probably have to use the Ex versions of the D3Dx functions as i'm not sure the basic ones can take the D3DXIMAGE_INFO struct.

so eg from some of my own code:

LPDIRECT3DTEXTURE9 CheckAndLoadUserTexture(const char *fileName, int *width, int *height)

std::string fullFileName(fileName);
fullFileName += ".png";

/* try find a png file at given path */
LastError = D3DXCreateTextureFromFileEx(d3d.lpD3DDevice,
D3DX_DEFAULT, // width
D3DX_DEFAULT, // height
1, // mip levels
0, // usage
D3DFMT_UNKNOWN, // format

if (FAILED(LastError))
LogDxError(LastError, __LINE__, __FILE__);
*width = 0;
*height = 0;
return NULL;

OutputDebugString("created user texture: ");

*width = imageInfo.Width;
*height = imageInfo.Height;
return tempTexture;

as you can see at the end i grab the Width and Height from imageInfo

Share this post

Link to post
Share on other sites
1. You can use the Ex version of the function (E.g. D3DXCreateTextureFromFileEx), and use D3DX_DEFAULT_NONPOW2 for the width and height to prevent D3DX from resizing the image.
2. You can use the Ex version of the function and pass in a valid D3DXIMAGE_INFO struct as the 3rd last parameter to have D3DX fill in details about the image file.
3. If you want to know the new size of the texture after it's been resized, you can call IDirect3DTexture9::GetLevelDesc(0), which will give you a D3DSURFACE_DESC which contains (among other things), the width and height of the surface level.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!