Advertisement

Weird problem with my new particle engine class

Started by February 14, 2002 05:01 PM
15 comments, last by BeyondDeath 23 years ago
Im just working on a new particle engine class (its not that great still) but the alpha channel seems to be broken when i specify my color. I do somthing like: glColor4f(1,1,1,plife); and plife is between 0 and 1. 0 being pretty close to it being deat and 1 being alive. but that doesnt have any effect on the color. its full on till it is deleted. Any ideas? I can post the drawing code if you want.
That would be useful, yes.



-------- E y e .Scream Software --------
----------------------------------------
                                  /-\
    http://www.eyescream.cjb.net | * |
                                  \-/
----------------------------------------
Advertisement
  void CPEngine::draw(){	glPushMatrix();	glTranslatef(0,0,-50);	tex.bind();	CParticle *a = h;	glEnable(GL_BLEND);						glBlendFunc(GL_SRC_ALPHA,GL_ONE);				particles = 0;	glDisable(GL_DEPTH_TEST);	while(a != NULL)	{		particles++;		glColor4f(1,1,1,a->life/life);		glBegin(GL_TRIANGLE_STRIP);			glTexCoord2d(0,1); glVertex3f(a->l.x,a->l.y+1,a->l.z);			glTexCoord2d(1,1); glVertex3f(a->l.x+1,a->l.y+1,a->l.z);			glTexCoord2d(0,0); glVertex3f(a->l.x,a->l.y,a->l.z);			glTexCoord2d(1,0); glVertex3f(a->l.x+1,a->l.y,a->l.z);		glEnd();		a=a->next;	}	glPopMatrix();	glDisable(GL_BLEND);							// Enable Blending	glEnable(GL_DEPTH_TEST);}  
disable lighting + enable modulate

http://uk.geocities.com/sloppyturds/gotterdammerung.html
Translation :
glDisable(GL_LIGHTING);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
Its still not working. I have removed the lighting code completely from the project. Used that modulate thing, disabled color material. Still acting funny. If you want to see any other code, particle creation etc just ask.

Thanks for the help
Advertisement
this is probably not very helpful, but be sure to check where exactly the problem is...

so, call
glColor4f(1.0f,1.0f,1.0f,0.2f);
and look if the particles are transparent then...

I am suspecting that your variabes "a->life" and "life" are integers... and therefore "a->life/life" is an integer division, which will result in an integer... (so, if you expect something between 0 and 1, it will always be rounded to 0!).

nik

Edited by - LeMatsch on February 15, 2002 11:13:31 AM

Edited by - LeMatsch on February 15, 2002 11:14:20 AM
I hope that your particles are located "randomly".
If all your particles have the same coordinates, then this effect is normal.
Gotta check''em m8.
you chould probably change

glBlendFunc(GL_SRC_ALPHA,GL_ONE);

to

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

*and*

glColor4f(1,1,1,a->life/life);

to

glColor4f(1,1,1,((float)a->life/(float)life));



Hope that works.
Waramp.Before you insult a man, walk a mile in his shoes.That way, when you do insult him, you'll be a mile away, and you'll have his shoes.
Well I tried the 0.2 for alpha nad it doesnt seem to have any effect. Also, the blending function just makes the black part of the particle visible.

Im having a heck of a time testing the program now (my geforce 2''s fan just died so im using an old pci voodoo banshee) so its giving me 0.5fps and it aint pretty.

the generation code is:
  	if(flag == UPDATE || flag == UPDATE_AND_CREATE)	{		CParticle *a=h;		while(a != NULL)		{			a->l.x += a->v.x * deltaT;			a->l.y += a->v.y * deltaT;			a->l.z += a->v.z * deltaT;			a->life -= a->drate * deltaT;			a = a->next;		}		a = h;		CParticle *temp;		while(a != NULL)		{				if(a->life < -life)			{/*				b->next = a->next;				b=a->next;				delete a;*/				if(a == h) 				{					temp=h;					h=h->next;					delete temp;					particles--;					a=h;				}				else 				{					temp=Prev(a);					temp->next=a->next;					delete a;					a= temp;					particles--;				}			}			else				a = a->next;		}	}	if(flag == CREATE || flag == UPDATE_AND_CREATE)	{		if(!stoped)		{			CParticle *a = h;			if(a == NULL && c>= 1 && max >= 1)			{				c--;				a = new CParticle;				a->next = NULL;				a->c = cdef;				a->l = emitloc;				float random_pitch = float(rand()/float(32767/180));				float random_yaw = float(rand()/float(32767/180));				a->v.x = (cosf(random_pitch)) * vel.x;				a->v.y = (sinf(random_pitch)*cosf(random_yaw))* vel.y;				a->v.z = (sinf(random_pitch)*sinf(random_yaw))* vel.z;				a->life = life;				a->drate = randfloat(0,1);				h = a;				particles++;			}			if(a!=NULL)			{				while(a->next != NULL)					a = a->next;				for(int x = 0; x<(c);x++)				{					if(particles < max)					{						particles++;						a->next = new CParticle;						a = a->next;						a->next = NULL;						a->c = cdef;						a->l = emitloc;						a->life = life;						float random_pitch = float(rand()/float(32767/180));						float random_yaw = float(rand()/float(32767/180));						a->v.x = (cosf(random_pitch)) * vel.x;						a->v.y = (sinf(random_pitch)*cosf(random_yaw))* vel.y;						a->v.z = (sinf(random_pitch)*sinf(random_yaw))* vel.z;						a->drate = randfloat(0,1);					}					else						break;				}			}		}	}  


yes the life variables are floats:
  class CParticle{public:	CVec3d l,v; //LOCATION,OLD LOCATION, VELOCITY	CVec3d c; // Color	CVec3d r;	float life;	float drate; //death rate	CParticle *next; //NEXT PARTICLE};class CPEngine{private:		CParticle *h; //Head particle	bool attractemit;	bool attractparticles;	bool stoped;	CVec3d emitloc; //Emitter location	CVec3d emitspread; // Spread of the emission	CVec3d vel;	CVec3d cdef; //Default color (start)	CVec3d cdest; //Destination color	CVec3d grav;	CTexture tex;	float life;  


Thanx again

This topic is closed to new replies.

Advertisement