Jump to content
  • Advertisement
Sign in to follow this  
m4rcel

Question about scaling a sprite using ID3DXSprite

This topic is 3620 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 hello... May I ask you guys here about ID3DXSprite scaling? What I'm trying to do is to scale a .png sprite to display it in smaller size. I already load the image into a texture using D3DXCreateTextureFromFileEx(pd3dDevice, L"media\\alphabeth-white.png", 0, 0, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_FILTER_NONE, D3DCOLOR_ARGB( 255, 0, 0, 0 ), NULL, NULL, &g_mcAlphabet_norm); And then on the rendering routine, i used this functions : D3DXMatrixScaling( &matTransform, 0.7f, 0.7f, 1.0f ); g_TMSprite->SetTransform( &matTransform ); g_TMSprite->Draw(g_mcAlphabet_norm,&rect_letter,NULL,&vPos_Clue,D3DCOLOR_ARGB(255, 0, 255, 0)); And the result of that was kinda strange, I can see the sprite is displayed with smaller size, but behind that sprite there was also displayed something like random small pieces of my sprite at random places also. It was hard to explain, maybe you guys can see at the picture below I attached. error display sprite I don't know why this happened, at first I thought it was the alpha channel of my image. Then I try to use SetRenderState change the alpha channel behaviour but that did not work. Also, this problem only happened if I scale the image below 0.8f. Above that, it's okay, there is no image breaking problem. Could any of you guys know a way to solve this problem, or any of you had similar problem? Any help would be appreciated. Thanksss...

Share this post


Link to post
Share on other sites
Advertisement
Perhaps I'm misunderstanding your intent, but why not change the size of the sprite's rectangle instead?

Share this post


Link to post
Share on other sites
Hmmm... but I thought a rectangle is used when you want to display only a certain portion of the whole sprite, but not for scaling?

Share this post


Link to post
Share on other sites
You're correct, I misunderstood your intent.

You might try D3DXMATRIXTransformation2D for the matrix instead.

Share this post


Link to post
Share on other sites
Thanks for the suggestion, Buckeye.

I have tried using D3DXMATRIXTransformation2D like this :

D3DXVECTOR2 scaling(0.7f,0.7f);
D3DXMatrixTransformation2D(&matTransform, NULL, 0.0f, &scaling, NULL, 0.0f, NULL);
g_TMSprite->SetTransform( &matTransform );

The result is the same, the image breaking behind the image already displayed.

This is really confusing.
Currently my solution is to scale the image using photoshop, and just use the already scaled down image, rather than scaled it on my code.
But this means that I would lose the flexibility to change the image properties from my code.

Share this post


Link to post
Share on other sites
Quote:
D3DXMatrixScaling( &matTransform, 0.7f, 0.7f, 1.0f );
g_TMSprite->SetTransform( &matTransform ); g_TMSprite->Draw(g_mcAlphabet_norm,&rect_letter,NULL,&vPos_Clue,D3DCOLOR_ARGB(255, 0, 255, 0));

I assumed you were summarizing your code above, so just checking:

Do you call sprite->Begin(..flags..) before the Draw and sprite->End() after?

EDIT: Also, as I remember, the SetTransform call has to be between the Begin and End calls.

Also, a quick look at an SDK example uses 3D matrix transforms for scaling (with z=1.0f) so you're initial scaling matrix is probably okay. Sorry about that.

[Edited by - Buckeye on July 16, 2008 11:23:55 PM]

Share this post


Link to post
Share on other sites
Sorry for the late reply, I had a long weekend vacation since friday :)

Yes, I have put sprite->Begin() and sprite->End() to enclose my sprite->Draw(). Otherwise, I think that my sprite wouldn't display at all.

My sprite->Begin() is like this :

g_TMSprite->Begin(D3DXSPRITE_ALPHABLEND);

Then after drawing all sprites :

g_TMSprite->End();

I guess since I'm stuck in this problem, I better move on to other task at hand first, because there's still a lot of other things to do in this project.

Thanks anyway.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!