Jump to content
  • Advertisement
Sign in to follow this  
Kiristu

[Solved] ID3DXSprite, scaling and transparency

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

Hi, I'm using the ID3DXSprite interface to render 2D graphics. It works fine as it is, so I wanted to add a new effect: resizing the sprites using D3DXMatrixScaling and setTransform ... According to all documentation I found, it should work quite easily. But it doesn't, if I decrease the size X and Y from 1.0 to 0.6, my sprites become transparent, and are not visible anymore for 0.5 and less ... Another thing, if I set X scale = 0.5 (or less) and Y scale at, say, 1.0, then it works fine. So my code is something like:

D3DXMATRIX transMat;
D3DXMATRIX scaleMat;

dxSprite->SetTransform(D3DXMatrixTranslation(&transMat, x, y, 0));

D3DXMatrixMultiply(&transMat, D3DXMatrixScaling(&scaleMat, xScale, yScale, 0), &transMat);

...

dxSprite->SetTransform(&transMat);

dxSprite->Draw(
((LPDIRECT3DTEXTURE9)gtexture),
&r,
¢er,
&D3DXVECTOR3(x, y, 0),
0xFFFFFFFF);

...




Any idea ??? Thanks, K. [Edited by - Kiristu on June 30, 2007 3:32:52 PM]

Share this post


Link to post
Share on other sites
Advertisement
Hi there, this may be the thing you need is this

D3DXMatrixTransformation2D(
D3DXMATRIX *pOut,
CONST D3DXVECTOR2 *pScalingCenter,
FLOAT ScalingRotation,
CONST D3DXVECTOR2 *pScaling,
CONST D3DXVECTOR2 *pRotationCenter,
FLOAT Rotation,
CONST D3DXVECTOR2 *pTranslation

I'm still using the older Sprite at the moment.

Share this post


Link to post
Share on other sites
Hi,

Even if my code is getting shorter and easier to read, there is still the same issue with color.

My code is now something like:


D3DXVECTOR2 scaling(size_h, size_v);
D3DXVECTOR2 spriteCentre(width/2, height/2);
D3DXVECTOR2 trans(x, y);
D3DXMATRIX mat;

D3DXMatrixTransformation2D(&transMat,NULL,0.0,&scaling,&spriteCentre,angle,&trans);
dxSprite->SetTransform(&transMat);
RECT r;
HRESULT hres;
r.left = xTexture;
r.right = xTexture + width;
r.top = yTexture;
r.bottom = yTexture + height;

hres = Globals::dxSprite->Draw(
((LPDIRECT3DTEXTURE9)gtextures),
&r,
NULL,
NULL,
0xFFFFFFFF);

dxSprite->SetTransform(D3DXMatrixIdentity(&identMat));





As soon as the parameters are less than 1.0, the sprite is getting transparent, and it is nearly invisible at 0.5 (again, it won't be transparent if size_h or size_v is >= 1.0 !)

My sprite begin is:
dxSprite->Begin(D3DXSPRITE_ALPHABLEND | D3DXSPRITE_SORT_TEXTURE);

Could this have any impact ??


Please help !

K.

[Edited by - Kiristu on June 27, 2007 2:20:42 PM]

Share this post


Link to post
Share on other sites
I think my problmen *may* come fro, the texture format I've choosen (I'm not so at ease with all the parameters).

I store all my animation steps in a texture that I create with:


HRESULT res = D3DXCreateTexture(
lpDirect3DDevice9,
squareSize,
squareSize,
0,
0,
D3DFMT_A8R8G8B8,
D3DPOOL_MANAGED,
&pTexture);




I copy/paste the pictures using the D3DXLoadSurfaceFromFile function, in something like:


result = gtexture->GetSurfaceLevel(0, &pTexSurface);

D3DXLoadSurfaceFromFile(pTexSurface,
NULL,
&r,
img1.c_str(),
NULL,
D3DX_FILTER_NONE,
colorKey,
NULL);

result = pTexSurface->Release();





Am I right ?

Could this cause a problem while resizing the sprite where the texture is applied ??

Thanks,
K.

Share this post


Link to post
Share on other sites
I finally found the "problem".

When I create my tecture using the following parameters:



HRESULT res = D3DXCreateTexture(
Globals::lpDirect3DDevice9,
Globals::squareSize,
Globals::squareSize,
0,
0,
D3DFMT_A8R8G8B8,
D3DPOOL_MANAGED,
&pTexture);




It does make the sprite transparent while resizing to smaller.

It is because of the mipmap parameter, I don't really understand why (I will have to when I will do 3D ... later ...), but if I put 1 instead of 0, the problem disappears.



HRESULT res = D3DXCreateTexture(
Globals::lpDirect3DDevice9,
Globals::squareSize,
Globals::squareSize,
1,
0,
D3DFMT_A8R8G8B8,
D3DPOOL_MANAGED,
&pTexture);





Hope this can help someone else one day ...

K.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!