OpenGl Blending Problem/Question

Started by
17 comments, last by ByteMe95 23 years, 2 months ago
It does look like you could be using the wrong blend function, giving an additive effect ie the colours being added. You should be using:

glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

This will do:
Source Colour (of the particle ) * Alpha of the particle +
Colour of destination (ie whats already there, your sky ) * ( 1 - alpha of the particle ).

This is the way to get it looking right against the sky, but you may need to change your colour and alpha values of the particles, as they seem to be set up nicely for being rendered additively against a black background.

In theory you should also do a depth sort and render the furthest transparent particles first before the ones in front.

quote:
I tried the GL_ONE , GL_ONE_MINUS_SRC_ALPHA, but that didnt work, the particles weren't transparent anymore for some reason.



Yep, that's right...that blend function does: source colour + destination colour * ( 1 - source alpha ).
so it would be a weirdy additive effect ie particle colour plus a bit from the background.

Game production:
Good, quick, cheap: Choose two.

Edited by - Danack on January 31, 2001 2:20:47 PM
Game production:Good, quick, cheap: Choose two.
Advertisement
for effects like rocket fire
i find
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
doesnt brighten enuf (hell it doesnt brighten at all) thus flames of 20 layers wont look any different to flames of one layer

one one is to bright
one one

one oneminussrcalpha


http://members.xoom.com/myBollux
Hey, thanks for all the replies.

I tried glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); and this is what happened:



I''m sure there are other thinsg I need to change, but I''m not sure what. when I do glcolor4f when drawing the particles I changed Alpha to 1.0-Alpha but that didnt work so I guess it''s completely wrong.

Just so you know, when i draw the particles they are textured and I disable depth testing when drawing them (I thought you had to do that to do blending)

zedzeek, how did you get the slame to draw on that background without mixing in with the sky?



ByteMe95::~ByteMe95()
Cerebrum Software
ByteMe95::~ByteMe95()My S(h)ite
Hey, thanks for all the replies.

I tried glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); and this is what happened:



I''m sure there are other thinsg I need to change, but I''m not sure what. when I do glcolor4f when drawing the particles I changed Alpha to 1.0-Alpha but that didnt work so I guess it''s completely wrong.

Just so you know, when i draw the particles they are textured and I disable depth testing when drawing them (I thought you had to do that to do blending)

zedzeek, how did you get the slame to draw on that background without mixing in with the sky?



ByteMe95::~ByteMe95()
Cerebrum Software
ByteMe95::~ByteMe95()My S(h)ite
your texture needs an alpha channel
RGB contain the image colours and A contains the brightness (dont make it too bright)
disable lighting
enable blending
glColor(1,1,1,0.5) // alter alpha to do a fade out

http://members.xoom.com/myBollux
ive just noticed this thread, as i was gonna post something similar...

i have a font bmp for my HUD, im using just black and white as a mask, and to get different color i modify my color3f()

to make it transparent (ie: no black) i use
glBlendFunc(GL_ONE, GL_ONE); (i have no idea why this works, im thinkging it shouldnt) and only draw that texture/quad once

i also want some of the HUD to be transparent, so i then use glBlendFunc(GL_SRC_ALPHA,GL_ONE); as well.

this works, but like byteme95, it alphablends with the background too much, and red[color3f''d] font on a green background makes it orange. my font doesnt use any alpha channel, but this works, but i want to keep it red on whatever bg its on.

so, i dont want to use alpha blending… so what can i use? <br><br>__________________<br>graham "red" reeves.<br><br><a href="mailto:red@deadpenguin.org">red@deadpenguin.org</a><br><a href="http://www.deadpenguin.org">www.deadpenguin.org</a>
__________________graham "red" reeves.[email=red@deadpenguin.org]red@deadpenguin.org[/email]www.deadpenguin.org
Well, I just figured out how to make an alpha channel in photoshop, but I jsut realized that BMPs dont store that info. Looks like TGA is the right way to go, but I have NO idea how to load tga files as textures, with alpha channels.

All I know is how to load bmp files as is shown in the nehe tuts.

Anyone have any suggestions? Or beter yet some code?

ByteMe95::~ByteMe95()
Cerebrum Software
ByteMe95::~ByteMe95()My S(h)ite
Ok, I have decide to bring this topic back to life since I never really figured out the problem. I have been kinda busy wtih scvhool work over the past few weeks, but now I have time to crack this nagging bug.

SO...
I put in a TGA loader into my code, loaded my texture with an alpha channel, I''m using glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );, and here''s what it looks like now:



that doesntl look right at all, even if I take away the background sky now, here''s what I get:



that doesnt look like what I want it to look like at all
???
any suggestions now??
I really want to get past this, I think thias demo is gonna be pretty cool, hopefully I''ll be able to get it up on nehe

ByteMe95::~ByteMe95()
Cerebrum Software
ByteMe95::~ByteMe95()My S(h)ite
if u want send me the code (inclusive build files,textures etc) + ill take a quick look at it.

http://members.xoom.com/myBollux

This topic is closed to new replies.

Advertisement