Animating Textures in DirectX 9

Started by
29 comments, last by busytree 17 years, 7 months ago
Here's a copy-and-paste of my presentation parameters:

	memset(&m_d3dPresent, 0, sizeof(m_d3dPresent));	m_d3dPresent.BackBufferWidth			= m_nWidth;	m_d3dPresent.BackBufferHeight			= m_nHeight;	m_d3dPresent.BackBufferFormat			= (bWindowed) ? D3DFMT_UNKNOWN : D3DFMT_R5G6B5;	m_d3dPresent.BackBufferCount			= 1;	m_d3dPresent.MultiSampleType			= D3DMULTISAMPLE_NONE;	m_d3dPresent.MultiSampleQuality			= 0;	m_d3dPresent.SwapEffect					= D3DSWAPEFFECT_COPY;	m_d3dPresent.hDeviceWindow				= m_hWnd;	m_d3dPresent.Windowed					= bWindowed;	m_d3dPresent.EnableAutoDepthStencil		= true;	m_d3dPresent.AutoDepthStencilFormat = D3DFMT_D16;	m_d3dPresent.Flags						= D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;	m_d3dPresent.FullScreen_RefreshRateInHz	= D3DPRESENT_RATE_DEFAULT;	m_d3dPresent.PresentationInterval		= (bVSync) ? D3DPRESENT_INTERVAL_DEFAULT : D3DPRESENT_INTERVAL_IMMEDIATE;


If its windowed then I do indeed use D3DFMT_UNKNOWN.

If you do what EasilyConfused said with D3DLoadTextureFromFileEx() you should be good with the colorkey.


Oh yeah! I know that we aren't using sprites but this should fix your problem:

Call D3DXCreateSprite() to create a sprite, then call Begin(D3DXSPRITE_ALPHABLEND) on your sprite after BeginScene(), and end it prior to EndScene(), that may help you out. It fixed my problem that I had with it.


Brandon

Advertisement
Ok I am going to try what you have told me and report my progress back here. :)
That is very interesting. I called the D3DXCreateSprite() and Begin(D3DXSPRITE_ALPHABLEND). Now my sprite has transparent background. Now is there a way to do this without involving D3DXSPRITE? Currently I am struggling with D3DXCreateTextureFromFileEx().

D3DXCreateTextureFromFileEx(pd3dDevice, "BOT.png", D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_FROM_FILE, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0xFF000000, NULL, NULL, &g_pTex );

Is there something horribly wrong what I did?
Quote:Original post by busytree
Animated robot

I have another question Why is my background not square when vertices postion says it so?

*** Source Snippet Removed ***


Because your monitors aspect ratio is not 1:1. More than likely your aspect ratio is 4:3 (1024x768, 1600x1200 etc), 5:4 (1280x1024), or 16:9 (720x540, 1920x1080 ect), which will distort the screen accordingly.
codeXtremeif(you->intelligence < radish->intelligence) you->STFU();
I am tyring to find my other file, where I had the polygon a perfect square, and it showed on the screen as the perfect square. Could it be the setting of a camera?
How come when I render a cube with size 64 on all corners. How come it does not seem to be stretched?
What size is your robot image?
Maybe it's stretching it to be a power of 2?
See default info on the size inputs: D3DXCreateTextureFromFileEx.
It may be something else though - I'm not good enough at this stuff yet to know without testing things in the code (and I'm not on Windows now).
Tadd- WarbleWare
my robot image is 46 X 64 and the wooden texture is 128x128. I think my robot should be 46x46 or 64x64? I want the collision to be very close to the actual picture too. The wooden texture is driving me mad.
On antoher note, you should not change your vertexbuffer to animate the texture but instead use "Texture Matrix Transforms". That should improve speed quite a bit when you have many sprites animated.
Aaack! You need powers of 2 for your textures! 1,2,4,6,8,16,32,64,128,256,512,1024,etc

Your textures need to be in those dimensions or DirectX is going to scale up to the next power 2. e.g. a 256x257 image will turn into a 256x512 image after DirectX gets a hold of it. Modify the UVs of your quad to appropriately display the correct part of the texture.

Brandon

This topic is closed to new replies.

Advertisement