Texture render troubles

Recommended Posts

TheMac    100
I'm trying to render a texture at the same size as the file, but it's being rendered about twice the size. Does anyone know how I can control the size of the textures I'm rendering?

Share on other sites
jollyjeffers    1570
Please give us a chance - we need more details [smile]

• Native DirectX / Managed DirectX
• Direct3D 9 / Direct3D 8

• What dimensions are the file (let me guess, not 2N, right?)?

• Is the texture, once loaded, revealing the correct or incorrect dimensions?

• What method are you using to load in the file? You can specify various flags to force D3DX to not scale your image

• What method are you using to render it? D3DX Sprites? Custom Sprites? Regular 3D texture mapping?

Get back to me with a bit more context and I'll see what I can come up with [wink]

Jack

Share on other sites
TheMac    100
Sorry about that, I wasn't for sure what kind of information would be needed.

This is unmanaged using DX9.

The dimensions are 104x37, so not not n^2.

I'm not sure how to see what the texture is when it's loaded. I think I can check the height and width properties, but whenever I try and access them, or modify them, the compiler tells me that there not members of the texture.

This is the code I'm using to load the image:
if(!SUCCEEDED(D3DXCreateTextureFromFile(m_Device, sPath, &m_Texture)))		return false;if(!SUCCEEDED(D3DXCreateSprite(m_Device, &m_Sprite)))	return false;

This is the code I'm using to render it:
// Rendering the controlslist<CONTROL*>::iterator i = Ctl_list.begin();for(; i != Ctl_list.end(); i++){	CONTROL* ctl = *i;	RECT rc;	if(ctl->Texture_primary && ctl->Sprite)	{		ctl->Sprite->Begin(0);		ctl->Sprite->SetTransform(NULL);		if(ctl->Rect.bottom <= 0 || ctl->Rect.right <= 0)		{			rc.top = ctl->Rect.top;			rc.bottom = (long)ctl->lHeigth;                        rc.left = ctl->Rect.left;			rc.right = (long)ctl->lWidth;		}		else		{			rc = ctl->Rect;		}		ctl->Sprite->Draw(ctl->Texture_primary, &rc, NULL, NULL, 0xFFFFFFFF);		ctl->Sprite->End();	}}

And I'm not sure what a custom sprite is, so I guess I'm using a DX sprite.

Thanks a bunch,
Shane

[Edited by - Muhammad Haggag on November 23, 2005 10:22:27 AM]

Share on other sites
Markup tags use square brackets, not angle brackets. Check GDNet Forums FAQ.

Share on other sites
jollyjeffers    1570
Quote:
 Original post by TheMacSorry about that, I wasn't for sure what kind of information would be needed.

S'Ok [smile] More is usually better than less.

Quote:
 Original post by TheMacThe dimensions are 104x37, so not not n^2.

Under normal D3DX operation that would be loaded as a 128x64 texture (the next biggest 2n dimensions).

Your call to D3DXCreateTextureFromFile() is almost certainly just a convenient alias to D3DXCreateTextureFromFileEx() - which has a lot more detail. In particular it states, for height/width:

Quote:
 If this value is zero or D3DX_DEFAULT, the dimensions are taken from the file and rounded up to a power of two.

I would guess that, for lack of any other suitable default, this is what your D3DXCreateTextureFromFile() call is doing.

If you want to maintain the sizes stored in the file then you need to use D3DXCreateTextureFromFileEx() directly and pass in D3DX_FROM_FILE or D3DX_DEFAULT_NONPOW2:
Quote:
 If D3DX_FROM_FILE, the size will be taken exactly as it is in the file, and the call will fail if this violates device capabilities.
Quote:
 If the device supports non-power of 2 textures and D3DX_DEFAULT_NONPOW2 is sepcified, the size will not be rounded.

Quote:
 Original post by TheMacI'm not sure how to see what the texture is when it's loaded. I think I can check the height and width properties, but whenever I try and access them, or modify them, the compiler tells me that there not members of the texture.

You have to #define D3D_DEBUG_INFO and use m_Width and m_Height iirc. That's obviously for debug only and shouldn't be used in production builds.

The correct way of accessing dimensions is by acquiring a D3DXIMAGE_INFO struct. You can do this directly from the D3DXCreateTextureFromFileEx() call, or before-loading with a D3DXGetImageInfoFromFile() call. If you do it post-loading then D3DX is no longer involved, and you have to retrieve a D3DSURFACE_DESC struct via IDirect3DTexture9::GetLevelDesc() call.

hth
Jack

Random Aside: I might actually bookmark/archive this reply for future reference

Share on other sites
TheMac    100
Thank you very much, you have been a BIG help. And yes I will have to bookmark this.

Thanks,
Shane