Sign in to follow this  

Odd sized textures

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

First off, I want to say I'm going through somebody elses code so I may be missing something. I'm using DX8 and I'm trying to load up a texture that is 640x480. Its the background image for the game. Here is the code to finally create the texture on the card:
IDirect3DTexture8 *ptexture = NULL;
	HRESULT hr = D3DXCreateTextureFromFileInMemoryEx(
		GlobalD3DVars::lpD3DDevice,
		data, size,
	  	// Opertunity to control sizes here.
		D3DX_DEFAULT,
		D3DX_DEFAULT,
		use_mipmapping ? 0 : 1, 
		0, 
		use_format,
		D3DPOOL_MANAGED, 
		filter,
	 	D3DX_DEFAULT,
		0, 
		&source_desc, 
		NULL, &ptexture);
If I use the D3DX_DEFAULT option for texture size when the background is rendered its all stretched. Now if I change those to 1024x512 is seems to render properly. Is there some way to get DX to automatically scale the texture to a power of two? Or do I need to do it manually and not use the default setting?

Share this post


Link to post
Share on other sites
The safest way is to let D3DX let it do its thing.

After the loading of the texture you can retrieve the true size of the texture in the cards memory (GetLevelDesc). Use this information to adjust the texture coordinates accordingly.

If you don't want to modify the texture coordinates you provide D3DX with a power of 2 sized texture. Just make some safety checking if you happen on a card which doesn't support these sizes.

Share this post


Link to post
Share on other sites
Quote:
Original post by Endurion
If you don't want to modify the texture coordinates you provide D3DX with a power of 2 sized texture. Just make some safety checking if you happen on a card which doesn't support these sizes.


Probably what I'll have to do. But would it be evil to get the width/height and then figure out an appropriate power of two size and use that instead of the default?

Share this post


Link to post
Share on other sites
Various solutions here.

Make the texture pow2. In this case set the filter and size to D3DX_DEFAULT and D3DX will make and stretch the texture to a pow2 size. This introduces filtering error. When drawn, draw to original size. This introduces more filtering error.

Make texture pow2 take 2. In this case set the filter to D3DX_FILTER_NONE and size as D3DX_DEFAULT. D3DX will now make a pow2 texture but only fill in the space needed. Pull the original size from source_desc. Use GetLevelDesc to find the size created. Use texcoords from (0,0) to (orig.wid/tex.wid, orig.hei/tex.hei). This will have no filtering artifacts, will work on all cards, but will waste a bit of memory.

Make the texture non-pow2. In this case set the size of D3DX_DEFAULT_NONPOW2. A few cards support pure non-pow2 textures, but most support non-pow2 conditional (and have since the DX7 or earlier days). Ensure you use the limitations (no mips, clamp, etc.) when rendering. If on XBox your texture coordinates will also be affected... read the XDK for details (It's simple, but it's still NDA.). This will have no filtering artifacts. This may not work on ancient hardware. There may be performance penalties associated with using this texture, but if it's a title screen or something, it doesn't really matter.

Share this post


Link to post
Share on other sites
I went the evil way and scaled the texture created on the card to the first highest power of two larger then the image. Only doing this on interface screens and there are never a lot on screen at one time so the wasted space isn't that big of an issue.

Share this post


Link to post
Share on other sites

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