SeventhStar
August 7th, 2005, 04:35 AM
Hello,
I'm somewhat new to D3D8...
Someone told me that texture widths and heights must be always a power of two and I believed him.
I just tried with a file that is not a power of two and it worked fine. I'm not using the texture as a texture but as a 2d sprite. Can you tell me if this is some feature of my particular video device or I can safely continue to use textures with wacky sizes as long as I use them as 2d sprites and don't wory about other users using my software
Btw I create them with D3DXCreateTextureFromFileInMemory and draw them with D3DXSprite::Draw.
Thanks for any help!
philkr
August 7th, 2005, 09:15 AM
You can use textures of any size. But when you load them, they will be loaded in a texture format which has width and heights power of two. For example if you have a texture with160x160 it will be loaded as a texture of 256x256. The remaining parts are just empty. Then the texture is stretched to fit the 256 pixels by the D3DXSprite interface when it is drawn. So it look right.
SeventhStar
August 7th, 2005, 10:05 AM
Okay... WHAT stretching?
I have a bitmap file with a size of 95x50. Earlier I used to make it 128x64 adn draw just the part I need, but now I accidently forgot to make a file with the appropriate size and I noticed that it was drawn and loaded ok.
here is my exact code:
D3DXCreateTextureFromFileEx( g_pDevice, "c:\\test.tga", 0, 0,
0, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, D3DX_FILTER_NONE,
D3DX_FILTER_NONE, D3DCOLOR_ARGB(255,0,0,0), NULL, NULL,
&g_pTexture);
....
void RenderScene() {
g_pDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );
g_pDevice->BeginScene();
g_pSprite->Begin();
static float a=0.f;
a+=0.1;
static D3DXVECTOR2 v(200,200);
g_pSprite->Draw(g_pSprite, NULL, NULL, NULL, a, &v, 0xFFFFFFFF);
g_pSprite->End();
g_pDevice->EndScene();
g_pDevice->Present(NULL, NULL, NULL, NULL);
}
It is drawn ok! No stretching!
philkr
August 7th, 2005, 10:28 AM
Maybe it is not stretched in this case, but the parts which remain empty are made transparent.
SeventhStar
August 7th, 2005, 11:29 AM
Ok, you're right
D3DSURFACE_DESC desc;
m_pTexture->GetLevelDesc(0, &desc);
GL_TRACE("width: %d, height %d\n", desc.Width, desc.Height);
this code gave me a 128x64 size although the actual file is smaller... That means that i could have smaller resources but I would still have to pass and save the size of the images... :(
SouthernCodeMonkey
August 7th, 2005, 01:44 PM
You wouldn't want to use textures that aren't powers of 2 in dimension for performance reasons anyway.
Regards.
miteshpandey
August 7th, 2005, 02:45 PM
I think D3DXCreateTextureFromFileEx has a parameter that allows to set a flag if you want to use texture sizes not in the power of two.