Advertisement

Help with glColor4f

Started by November 17, 2002 12:33 AM
4 comments, last by XeroGaMeR 22 years, 3 months ago
Ok I''m a newbie programer so bear with me. Well I reorganized the particle engine from tutorial 19 to be a class and do the drawing from a class method. I made two little particle fountains, but the second fountain''s particles don''t fade. Here''s my particle drawing routine: void particle::DrawParticle() { glColor4f(r,g,b,life); //Use the particles RGB values and its life value for transparency glBegin(GL_TRIANGLE_STRIP); //Begin drawing the particle glTexCoord2d(1,1); glVertex3f(x+0.5f+xOffset,y+0.5f+yOffset,z+zoom); //Top Right glTexCoord2d(0,1); glVertex3f(x-0.5f+xOffset,y+0.5f+yOffset,z+zoom); //Top Left glTexCoord2d(1,0); glVertex3f(x+0.5f+xOffset,y-0.5f+yOffset,z+zoom); //Bottom Right glTexCoord2d(0,0); glVertex3f(x-0.5f+xOffset,y-0.5f+yOffset,z+zoom); //Bottom Left glEnd(); x += xs/(2000); //Move the particle''s x position y += ys/(2000); //Move the particle''s y position z += zs/(2000); //Move the particle''s z position xs+=xg; //Alter x speed according to gravity ys+=yg; //Alter y speed according to gravity zs+=zg; //Alter z speed according to gravity life-=fade; //Lower life by the value of fade } The particle''s life force gets subtracted by fade because they eventually dissapear, but with full brightness. I tried only having one particle on each fountain to see if they are getting their life variables messed up but they aren''t interfering with each other. I think its something about glColor4f() that I don''t know about but then again I''m a newbie. Any help would be appreciated. --Insert smart and witty signature here--
--Insert smart and witty signature here--
what blend function are you using?
Advertisement
glBlendFunc(GL_SRC_ALPHA,GL_ONE); // Type Of Blending To Perform

--Insert smart and witty signature here--
--Insert smart and witty signature here--
What value does fade have? Both fade and life are floating point values, right?
try this:

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);


The reason is simple:
new = (dst * alpha) + (src * ( 1 - alpha))

Just another thing: With glColor4f, you alpha must be between 0.0 and 1.0...

Filami, hope I help you!!!

[edited by - filami on November 18, 2002 1:53:18 PM]
Techno Grooves
Filami, I''m using a texture for the particles. With that blend function the first fountain still fades and the second doesn''t fade, also the black background in the picture isn''t transparent so it looks blocky.

lowlevel both values are floating point and the values are always under 1 here''s my life and fade code.

life = 1.0f; //Give particle full life
fade = float(rand()%100)/1000.0f+0.003f; //Give a random fade value
--Insert smart and witty signature here--

This topic is closed to new replies.

Advertisement