Using D3DXMatrixTransformation2D in DX9

Started by
9 comments, last by Supernat02 19 years, 7 months ago
Yes, in short you can just change to XYZ. haha. I take it you didn't have much luck using D3DXSprite before. Here's a quick overview:

ID3DXSprite *pSprite;LPD3DTEXTURE9 *pTexture;// I don't have all the functions in front of me, so I'm going to code to the best of my ability, but you should get the idea.D3DXCreateSprite(pDevice, &pSprite);void Render(void){  D3DXMATRIX mTransform;  D3DXMatrixTranslation(&mTransform, 1.0f, 2.0f, 0.0f); // Move X,Y,Z to 1,2,0.  pSprite->Begin(D3DXSPRITE_SORT_TEXTURE); // Sort the textures  pSprite->SetTransform(&mTransform);  pSprite->Draw(pTexture, NULL, NULL, NULL, D3DCOLOR_XRGB(255,255,255));  pSprite->End();}


Some notes:
D3DXSPRITE_SORT_TEXTURE means that the sprite will sort the textures that have been put into the Draw call. What happens is the Sprite interface is more than just a SINGLE sprite. It's a Sprite container. You can tell it to draw Some texture at Some position on the screen multiple times between the Begin and End calls. If figures out which ones use the same texture and sorts them so that it doesn't have to call "SetTexture(...)" for every call to Draw. When you call the End function, that's when the rendering actually takes place. In other words, that's when the data actually gets batched up and sent to the video card.

The three NULLS are source rect, Center, and Position. You don't want to set those to NULL all the time. You probably want to set Center to be the center of the screen (width/2, height/2, 0); and the Position to be in the top/left corner of the sprite from the center of the screen.

The color is the "tint" of the texture. Making it red will make the texture red for instance.

SetRenderState is ignored by the ID3DXSprite. You have to specify D3DXSPRITE_DONOTMODIFY_RENDERSTATE in the Begin function to prevent it from overwriting your render states. That may be a bit advanced for now, just keep it in mind.

Good luck,
Chris
Chris ByersMicrosoft DirectX MVP - 2005

This topic is closed to new replies.

Advertisement