• Advertisement
Sign in to follow this  

How to remove the black background of a .tga texture with alpha channel

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

Recently,I'm trying to save the scene during rendering to .tga texture with alpha channel.When I did it,the whole picture seems darker than the way it looks on screen.Then I realise I should remove the background color which is default black.
[attachment=9517:rgb.jpg]
It‘s the same with Particle Illusion Software when it saves the alpha and give a choice whether to remove BG color. Here's my code.
[source lang="cpp"]
if(S_OK == pRenderSurface->LockRect(&rect,NULL,D3DLOCK_NO_DIRTY_UPDATE))
{
DWORD* pColor = (DWORD*)rect.pBits;
for( int y = 0 ; y < height ; y++ )
for(int x = 0 ; x < width ; x++ )
{
D3DXCOLOR color = pColor[y*rect.Pitch/4+x];
if(color.a > 0)
{
color.r /= color.a;
color.g /= color.a;
color.b /= color.a;
}
pColor[y*rect.Pitch/4+x]=color;
}
pRenderSurface->UnlockRect();
}
D3DXSaveSurfaceToFile(texPath1,D3DXIFF_TGA,pRenderSurface,NULL,NULL);
[/source]

Now the problem is,the picture seems too light,and some details lost.I'm confused about the result.Did I do it in a wrong way?[attachment=9516:problem.jpg]

What I want that Illusion Particle does
[attachment=9531:ball3.jpg] Edited by Tunisia hawker

Share this post


Link to post
Share on other sites
Advertisement
Hi,
it seems you lost part of your code during copy-paste. Line number 8 doesn't make sense and certainly wouldn't compile without errors.

Share this post


Link to post
Share on other sites

Hi,
it seems you lost part of your code during copy-paste. Line number 8 doesn't make sense and certainly wouldn't compile without errors.

Thank you for pointing out my mistake.It looks OK during edit state,but some charactor just failed to show up.I guess it's
[source lang="cpp"]color.a < 1[/source] Edited by Tunisia hawker

Share this post


Link to post
Share on other sites
I came to realise maybe I should calculate the origin color each time when the draw call happens and any pixel get modified.Is that right?I just used method above but the color becomes brighter.Color buffer seems to have an explosion.small colorful paricles far away from each other are just alright,they only be written once.While the pixel in the central part are influenced by several particle systems,totally a mess. Edited by Tunisia hawker

Share this post


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

  • Advertisement