Sign in to follow this  

Textures, SPRITES, etc...

This topic is 4200 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

When I load a textured bitmap, it changes size when I draw it to the backbuffer. I don't understand. Does anyone know anythinga about this? Thanks!

Share this post


Link to post
Share on other sites
If the images dimensions are not powers of two (256x256, 512x512, etc.), then DX will resize it to the next closest power of two. This will cause your image to stretch in one or both dimensions.

Share this post


Link to post
Share on other sites
See D3DXCreateTextureFromFileEx - You can pass a D3DXIMAGE_INFO structure to it to get the actual size of the image, and you can get use IDirect3DTexture9::GetLevelDesc(0) to find out what size D3DX created the texture at. You can use those two values to work out the texture coordinates you should use.

Or, just use power of 2 textures [smile]

Share this post


Link to post
Share on other sites
I will defiently try that. Here is some of the code that might help you understand the problem better.

//set Direct3D presentation parameters
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = (!fullscreen);
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_R5G6B5;
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferWidth = width;
d3dpp.BackBufferHeight= height;
d3dpp.hDeviceWindow = hWnd;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;

....

//creat the new texture by loading a btimap image file
D3DXCreateTextureFromFileEx(
d3ddev, //Direct 3d device object
filename, //bitmap filename
info.Width, //bitmap image width
info.Height, //bitmap image height
1, //mip-map levles (1 for no chain)
D3DPOOL_DEFAULT, //the type of surface (standard)
D3DFMT_UNKNOWN, //surface format (default)
D3DPOOL_DEFAULT, //memory class for the texture
D3DX_DEFAULT, //image filter
D3DX_DEFAULT, //mip filter
transcolor, //color key for transparency
&info, //bitmap file info (from loaded file)
NULL, //color palette
&texture); //destination texture

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Thanks fellas. I changed the dimensions of the bitmap and it totally worked! like you had mentioned, DirectX must have been streteching the bitmap out since it wasn't a power of 2 bitmap!

Share this post


Link to post
Share on other sites

This topic is 4200 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.

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