Advertisement Jump to content
Sign in to follow this  
Panos KJ

Convert IDirectXSprite::Draw calls to ID3DXSprite::Draw

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

Hello guys, this is my first post in this forum. So, I am maintaining an old game, written in C++ and using DirectX9b. In order to use shader model 3 I decided to update the source code to Directx9c. The issue I am trying to fix right now is exactly what the title suggests.


To make a long story short, here is the function I am currently using to replace the old functionality:

HRESULT SpriteDrawFix(
	LPD3DXSPRITE pSprite,				// The sprite
	LPDIRECT3DTEXTURE9 pSrcTexture,		// The texture to draw.
	CONST RECT* pSrcRect,				// The src rect 
	CONST D3DXVECTOR2* pScaling,		// Scaling
	CONST D3DXVECTOR2* pRotationCenter,	// The rotation center if rotation is used.
	FLOAT Rotation,						// Rotation in radians.
	CONST D3DXVECTOR2* pTranslation,	// Translation, i.e. moving the object to this place.
	D3DCOLOR Color)						// Color to module the image pixels.
	D3DXVECTOR3 vScale = pScaling != nullptr ? D3DXVECTOR3{ pScaling->x, pScaling->y, 1 } : D3DXVECTOR3{ 1, 1, 1 };
	D3DXVECTOR3 vCenter = pRotationCenter != nullptr ? D3DXVECTOR3{ pRotationCenter->x, pRotationCenter->y, 0 } : D3DXVECTOR3{ 0, 0, 0 };
	D3DXVECTOR3 vTrans = pTranslation != nullptr ? D3DXVECTOR3{ pTranslation->x, pTranslation->y, 0 } : D3DXVECTOR3{ 0, 0, 0 };

	D3DXMATRIXA16 s, r, t, total;

	D3DXMatrixScaling(&s, vScale.x, vScale.y, 1);
	D3DXMatrixRotationZ(&r, Rotation);
	D3DXMatrixTranslation(&t, vTrans.x + vCenter.x * vScale.x, vTrans.y + vCenter.y * vScale.y, 0);

	total = s * r * t;


	HRESULT hr = pSprite->Draw(pSrcTexture, pSrcRect, &vCenter, nullptr, Color);

	return hr;

It works for most cases, however, there seems to be a problem with rotation. This screenshot speaks for itself:




With Directx9b and using the old method, this renders as expected. I would appreciate it if someone knows what causes this bug or how the original method was implemented. Thanks in advance.


PS: I just noticed IDirectXSprite never existed, well, you got the picture anyway.

Edited by Panos KJ

Share this post

Link to post
Share on other sites

Sorry for double posting, I just want to share the solution, which was pretty simple after:

D3DXMatrixTransformation2D(&m, nullptr, 0, pScaling, pRotationCenter, -Rotation, pTranslation);

The thing is, I still don't understand what this function does differently compared to my initial approach.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!