Point sprites showing entire square

Started by
8 comments, last by DXnut 17 years, 11 months ago
Hi, I'm using a particle engine, and everything is working perfectly except for one thing: The texture for the point sprites is being rendered as a square. What I want it to do is show the highlighted circle in the texture, and "ignore" the black background. I looked at many tutorials, and somehow they don't have this problem. I tried turning off fog, but that wasn't the problem. Could someone tell me how to stop it from displaying the black part(it is alphablending with the background, so I can see the square edges)?
Advertisement
Alphablending needs to be turned on:
DEVICE->SetRenderState(D3DRS_ALPHABLENDINGENABLE, TRUE);DEVICE->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ALPHA);DEVICE->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);


And your image needs to have an alpha layer in it.
reallycoolme,

It sounds like you've either got alpha blending turned off, there's no alpha channel in your texture, or your texture stages aren't set up quite right. You didnt say whether you're using OpenGL or DirectX, so I'll assume you're using DirectX. Make sure your texture stages are something similar to this:

m_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
m_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);

Which tells the shader to pull the alpha values from the texture's alpha channel. As for the alpha channel on the texture, make sure your texture and back buffer are a format which supports an alpha channel, such as A8R8G8B8 for 32 bit or A1R5G5B5 for 16 bit.

Cheers and good luck!
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints
Thx for the help...I'll try it when I get home. (Im at my parents work right now)
I think the problem is that the texture doesnt have an alpha channel because I did turn on alpha.
Actually you will not use the alpha channel for this, but you need to enable alpha blending for it to work. What you need to do is to tell it to blend the black part of the texture with the background. So, this will only work if your background color (set in the IDirect3DDevice9::Clear() function) is black.

m_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
m_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
m_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);

m_pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
m_pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
--------------------------Most of what I know came from Frank D. Luna's DirectX books
You said that it will only work if the background is black....but my background has mountains (terrain) and fog in it, so I guess it will not work like that.
*more focused*
I made my picture have a transparent background..
perhaps another question should be: which file format should the texture be? .png? .gif doesnt work properly so I've not been using that.
.bmp doesnt have an alpha channel does it?

[Edited by - reallycoolme on April 29, 2006 4:51:36 PM]
I think Targa's (TGA) and PNG's are common image formats that support alpha blending... Try those.
GIF's only allow transparency (no alpha blending).
As for BMP's, I'm not sure of any alpha channel, and I doubt it.
Projects:> Thacmus - CMS (PHP 5, MySQL)Paused:> dgi> MegaMan X Crossfire
I guess this directx question is soprt of turning into a painting question, but I'm saving my image (.png) with alpha, yet whenever i change the alpha, there is NO effect in the particle alpha. I know the particles are alphablending because when they overlap, they become brighter. is there something I have to do to read in alpha from the file?
Seems like they are blending but not alpha blending. Additive blending would make particles brighter, but alpha blending shouldn't.

I'd suggest using alpha testing as an easy solution.
I have used Photoshop to do this. You can start with your current .bmp image.

1) Save it as a .tga file;

2) Use the magic wand to select the black part and then do a select-inverse;

3) Save the selection as a channel to create the alpha channel.

That is an easy way. You can also play with the masking tools to create a feathered edge and make other adjustments.
--------------------------Most of what I know came from Frank D. Luna's DirectX books

This topic is closed to new replies.

Advertisement