#### Archived

This topic is now archived and is closed to further replies.

# ID3DXSprite : Changing Sprite Colors

This topic is 5166 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi. I have been trying to come up with a way to draw combining the inherent colors of a sprite with another color at run-time. I would''ve figured I could do this by setting the color parameter when using the sprite.draw statement. Unfortunately altering the color parameter only seems to darken my sprite, usually to black or almost completely black. Let''s say I have a green tree with a reddish trunk If I specify the color parameter as dark-ish green it is drawn as a darker green tree, and the trunk is black. If I have a green tree and I specify the color parameter as red then it is drawn completely black, except for the trunk which is dark red. From what I have read on the forums this does not seem to be the normal effect. The way that it is working for me is basically useless. I would like something that could shift the spectrum so I could draw a blueish or redish tree or whatever. I am using the DirectX 9 summer update with vb.net. I have alphablend turned on in the sprite.begin statement. Everything else works fine except for this. Also it won''t let me modify the renderstate outside of the begin statement since I am using the sprite class. I assume this is normal for directx9 sprite. Sorry I can''t supply any source code since the computer with the code doesn''t have internet access right now. Tell me if you need any clarification. Thanks in advance

##### Share on other sites
The color parameter is only for modulation so you cannot change one color into another (meaning like a green into a red). Your best bet is to make some kind of mask for your sprites and then overlay them in the color you want.

EDIT

There is also texture palette, but from what others have said it is not widely supported.

[edited by - Zorbfish on May 28, 2004 7:55:18 PM]

##### Share on other sites
Greyscale images seem to work pretty well on my card. I can''t speak for compatibility, though. I''m pretty sure the D3DXFont does colorizing on greyscale textures.

##### Share on other sites
This may not be exactly what you are trying to accomplish, but here is what I do.

Let''s say I got a sprite of a tree with green leaves and a red trunk (like you said).

Well, if I do a SetColorOverlay(1.0f, 0.0f, 0.0f);

the entire tree would be red...like it was under a bright red light...but it still looks good.

Try this code and see if it helps.

-cb

CSprite_D3DX::SetColorOverlay(float r, float g, float b){	Red = r; Green = g; Blue = b;}//---------------------------------------------------------------------------------//	Draw//---------------------------------------------------------------------------------int CSprite_D3DX::Draw(){	// Build a source RECT which will copy only a small portion of the texture.	// Also, you will notice that NumFramesWide is used for both TOP and LEFT	// This is correct    srcRect.top    = (( CurrentFrame / NumFramesWide ) * FrameHeight);    srcRect.left   = (( CurrentFrame % NumFramesWide ) * FrameWidth);	srcRect.bottom = srcRect.top  + FrameHeight;    srcRect.right  = srcRect.left + FrameWidth;	D3DXVECTOR2 vCenter( 0.0f, 0.0f );	D3DXVECTOR2 vScale( scalex, scaley );	D3DXVECTOR2 vPosition( (float)x, (float)y );	D3DXVECTOR2 vRotationCenter( (float)rotxcenter, (float)rotycenter);	D3DXMATRIX mat;	D3DXMatrixTransformation2D(&mat,&vCenter,NULL,&vScale,&vRotationCenter,rotation,&vPosition);	D3DSprite->SetTransform(&mat);	//Add the sprite to the Sprite buffer (actually gets drawn when the Sprite->End executes)	D3DSprite->Draw( D3DSpriteTexture,					 &srcRect,					 NULL,					 NULL,					 D3DCOLOR_COLORVALUE(Red, Green, Blue, Alpha) );	return true;}

##### Share on other sites
SetColorOverlay seems to be exactly like what I need, unfortunately it doesn''t look like it is directly implemented in the directx9 summer update version of sprite. I searched all over the internet trying to find some info on setcoloroverlay, but as usual I turned up nothing very useful. SetColorOverlay or some equivalent might be there, but I certainly cannot find it.
The only significant methods that stem off of sprite for me are device, begin, end, flush, setworldviewRH, setworldviewLH, and transform.

Specifically what I am trying to do is have a outdoor scene that slightly shifts color as the day goes by. At night it would either render things completely dark, or to some degree a little bluish depending on how full the moon is. Also I will hopefully be using this to change to color of some sprites as seasons change.

Hopefully I will be able to do this without completely dropping the directx9 sprite class, since everything else in my engine works fine.

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
17
5. 5

• 14
• 29
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631773
• Total Posts
3002265
×