Jump to content
  • Advertisement
Sign in to follow this  
beebs1

D3D Texture Dimensions

This topic is 3178 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
Advertisement
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)
{
LPDIRECT3DTEXTURE9 tempTexture = NULL;
D3DXIMAGE_INFO imageInfo;

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

/* try find a png file at given path */
LastError = D3DXCreateTextureFromFileEx(d3d.lpD3DDevice,
fullFileName.c_str(),
D3DX_DEFAULT, // width
D3DX_DEFAULT, // height
1, // mip levels
0, // usage
D3DFMT_UNKNOWN, // format
D3DPOOL_MANAGED,
D3DX_FILTER_NONE,
D3DX_FILTER_NONE,
0,
&imageInfo,
NULL,
&tempTexture
);

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

OutputDebugString("created user texture: ");
OutputDebugString(fullFileName.c_str());
OutputDebugString("\n");

*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 GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!