Skip to main content
gamedev.net
🔒 Locked

Texture discussion

Started by L1st3r 1 reply 150+ views
Original Post
L1st3r
L1st3r
I am a newbie when it comes to direct X programming. It actually took me 2 days with a book in front of me to get a texture to properly display itself on the screen. For some reason, unless the texture''s bmp file I was loading it from was a power of 2, the texture would look all garbled up. I was under the assumption that only the actual texture object needed to be a power of 2, not the picture file. Exactly why is this?
IndirectX
IndirectX
D3DX might convert the textures for you, but if you're using 0,0-1,1 texture coordinates then you'll end up referencing entire (expanded) texture, only part of which was filled with meaningful data.

[edited by - IndirectX on June 19, 2002 7:59:10 PM]
---visit #directxdev on afternet <- not just for directx, despite the name
TooTer
TooTer
If you use D3DXCreateTextureFromFileEx you can pass in a D3DXIMAGE_INFO structure that will describe your image including information like the actual width and height of the image. Then you need to get the description of the actual texture that has been created (pTexture->GetLevelDesc(0, &desc)), this will give you the actual width and height of the texture (this will be the part that is in powers of two).

Now that you have this information (and assuming that image.width != texture.width) then to show only you image on the texture you can calculate it as:

  
FLOAT fTexelWidth = 1.0f/desc.width;
FLOAT fTexelHeight = 1.0f/desc.height;

topLeftUV = (0.0f, 0.0f);
bottomRightUV = ( image.Width * fTexelWidth, image.Height * fTexelKeight);


Note: I may be missing that 0.5 offset somewhere in here as well, all of this is off the top of my head.

Cheers,

Scott

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.