texture transparency with point sprites

I am making a particle system with point sprites. I am using a basic texture (a white circle with a blackbackground) as the sprite textures. I cant seem to get the particles to have alpha blending without the black part of the texture showing up. I  want that part to be transparent. What setting do I have to use?
MdFoolAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MdFoolAuthor Commented:
Btw, I tried this and it didnt workl...

glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
0
davebytesCommented:
To use SRC_ALPHA, your texture needs to be ARGB with an alpha channel that knocks out the texture.

Depending on the effect desired, you could use an additive blend as well (gives 'glowy' sprites).

-d
0
guitaristxCommented:
Set the black portion of your texture to have an alpha value of zero.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

OwariCommented:
you still need to set your (vertex / polygon / whatever) color with glColor4f(r,g,b,a) for its transparency

glenable(3042);
glblendfunc(...., ....);

glbegin(7);
  glcolor4f(1,1,1,0.2);
  glvertex3f(x,y,z)
  glcolor4f(1,1,1,1);
  3x glVertex3f(_,_,_);
glend;

something like that
hope helpful
0
CBuecheCommented:
Are you drawing your particles after the background?  In order for alpha blending to work properly the transparent objects must be drawn in depth order, back-to-front, relative to each other and the other, non-transparent objects/primitives in the scene (including the background texture, if there is one).
0
MdFoolAuthor Commented:
Im trying to do a particle sytem, having them in depth order would destroy my framerate. Is there another way?
0
guitaristxCommented:
Using OpenGL shouldn't require you to draw them in depth order.  Since your 3d texture is going to be rectangle-shaped, you need to make sure that the portion that's not the round, visible part is transparent, rather than black.  You may have to re-arrange some of your texture code.
0
CBuecheCommented:
After a little bit of digging, I came across what appears to be a good backgrounder on building a particle system.  It's written for DirectX, but the concepts should hold:

http://www.geocities.com/foetsch/particles/particles.htm

Notable points:
- Depth writing should be turned off.  That will also remove the need for the depth sort I mentioned previously.  In OpenGL, you can turn off writing to the depth buffer with glDepthMask(false).
- The specific effect you wish to achieve will determine the parameters of glBlendFunc().
0
davebytesCommented:
particle systems CAN be depth sorted pretty easily.  It's just a sort like any other, and so long as the data doesn't change hugely per frame, there are sort algorithms which will be more linear, less of a hit.

What you do with the depth buffer (write, test), what order you draw it in, what blending mode you use, how you create the textures, all depends on what the particular particle effect is you are trying to achieve.  The last few systems I've built have had something like 4-6 different 'styles' at a high level, and based on the style specific blending mode, transparency use (or not), etc... they implemented different approaches.

Note that especially in the case where you have other transparency in the scene possibly overlapping/interacting with particles, you need to plan for and try out what the rendering approach will be.  We had to turn off z-write on certain transparent objects so that particles WOULDN'T be affected by them... all depends on the objects and the different types of particles.

-d
0
MdFoolAuthor Commented:
Let me give you my current situation and maybe you can help point me in the right direction. I am making a simple particle system to represent some smoke and a fire. I am using opengl and point sprites. For the fire, I can get it to work pretty nice using a generic circular texture and this blend func     BlendFunc(GL_SRC_ALPHA,GL_ONE);            

But for smoke I want the exact opposite to occur. I want the particles to be grey and where they congregate I want it to be darker.  I tried changing the color values but no matter what extreme (0 or 1 for RGB values), the particles always turn white. What would be the best blending function to use? And is there anything else I would need to specifically define?

0
CBuecheCommented:
Try lighting the smoke particles using a light with negative component values.
0
shirsoftCommented:
i am really at a loss why people post such crappy soln... alpha blending CANNOT solve this. The problem is at ur texture creation
The soln goes like this (iam pretty sure ur original image doesnpt have a alpha channel)

Read the texture info from the file into a buffer(lets says texData) .
Create a temporary buffer(called tempBuff) of size (texData)*4/3

For each pixel in texData, copy its rgb data to tempBuff and for the alpha value make it zero if r==0&&g==0&&b==0

Now while calling glTexImage2d or glBuild2dMipmaps , use GL_RGBA, instead of GL_RGB or GL_BGR(or whatever u used earlier)
and this will work

0
davebytesCommented:
As I already mentioned that the textures need alpha, and shirsoft felt the need to 're-touch' a 6-week stale question, I'll hit it again.

Your textures need to have an alpha channel.  Do NOT create the alpha channel on the fly -- create it ahead of time in a graphics program, almost all of the major ones support an alpha channel.  By working the alpha channel in the graphics app, you eliminate 'halo' issues where you want the alpha to fade off at edges, and otherwise exercise complete control over the resulting alpha.  This also saves you load-time headaches of data conversion, etc.  Which, if you're looking to make games, you almost never want to do postprocessing on stuff at load time -- it should be on-disk, ready-to-go, as much as possible.

Save the file as something like a PNG (my favorite, as there's TONS of good open source for reading them), and when you read in your textures, note whether the texture has flagged in the header what format the data is (24-bit RGB, 32-bit ARGB, DXT, etc.).  Read the data right into memory, and you should be able to submit as-is.

Again, there are also ADDITIVE blend techniques where you CAN use non-alpha textures, with black being knocked out.  GL_SRC, GL_DEST -- otherwise known as 1+1 blending.

-d
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
shirsoftCommented:
hey dave, don't take it personally... i just came back to this place bcoz i had absolutely no work for a few days
0
davebytesCommented:
HEH.  Didn't take it personally in the slightest!  that was more of a 'HELLOOOOO' to MdFool to come back and respond... ;)

-d
0
davebytesCommented:
I explained both solutions, and issues, with particle systems.  And also corrected him on the issue of speed hits of depth sorting (which is near-required for many effects).
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Game Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.