Bonjour a tous,
Jai un probleme de texture lorsque jessaie de creer une explosion pour un jeu video. jutilise une image qui represente une etincelle avec une fond noir. Pour simuler lexplosion je cree donc deux panneaux auquels j'applique ma texture puis jutilise une array pour modifier tout ca en modifiant la taille et le alpha prametre pour la transparence. le probleme c'est que je ne sais pas comment me debarasser du fond noir!! jaimerai juste avoir lintincelle qui apparait car j'ai une autre texture de fond qui cree un decor.
merci pour votre aide, jai ma demo en debut de semaine !!!!
voici le code pour la texture.
class explosion
{
private:
struct Explosion
{
float x;
float y;
float z;
float _Alpha;
float _Scale;
};
GLuint dlist,texture[1];
Explosion ExplosionArray[20];
public:
//////////////
void explosion :: initExplosion(GLvoid) // jinitialise mon explosion ds le init()
{
float df=100.0;
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glShadeModel(GL_SMOOTH);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glMaterialfv(GL_FRONT,GL_SPECULAR,spec_);
glMaterialfv(GL_FRONT,GL_SHININESS,&df);
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0,GL_POSITION,posl_);
glLightfv(GL_LIGHT0,GL_AMBIENT,amb2_);
glEnable(GL_LIGHT0);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT,amb_);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glEnable(GL_TEXTURE_2D);
LoadGLTexture(); //load ma texture
//4 panneaux
glNewList(dlist=glGenLists(1), GL_COMPILE);
glBegin(GL_QUADS);
glRotatef(-45,0,1,0);
glNormal3f(0,0,1);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-5,-4,0);
glTexCoord2f(0.0f, 1.0f); glVertex3f(5,-4,0);
glTexCoord2f(1.0f, 1.0f); glVertex3f(5,4,0);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-5,4,0);
glNormal3f(0,0,-1);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-5,4,0);
glTexCoord2f(0.0f, 1.0f); glVertex3f(5,4,0);
glTexCoord2f(1.0f, 1.0f); glVertex3f(5,-4,0);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-5,-4,0);
glNormal3f(1,0,0);
glTexCoord2f(0.0f, 0.0f); glVertex3f(0,-4,5);
glTexCoord2f(0.0f, 1.0f); glVertex3f(0,-4,-5);
glTexCoord2f(1.0f, 1.0f); glVertex3f(0,4,-5);
glTexCoord2f(1.0f, 0.0f); glVertex3f(0,4,5);
glNormal3f(-1,0,0);
glTexCoord2f(0.0f, 0.0f); glVertex3f(0,4,5);
glTexCoord2f(0.0f, 1.0f); glVertex3f(0,4,-5);
glTexCoord2f(1.0f, 1.0f); glVertex3f(0,-4,-5);
glTexCoord2f(1.0f, 0.0f); glVertex3f(0,-4,5);
glEnd();
glEndList(); // list que jappelle lors dune explosion
}
void explosion :: smallExplosionAt(double x_, double y_, double z_) //creer une explosion aux coordonees x_, y_, z_
{
for(int j=0;j<20;j++)
{
if (ExplosionArray[j]._Alpha<=0)
{
ExplosionArray[j]._Alpha=0.5;
ExplosionArray[j].x=x_;
ExplosionArray[j].y=y_;
ExplosionArray[j].z=z_;
ExplosionArray[j]._Scale=1;
break;
}
}
}
void explosion ::checkExplosion(void) dans le displayCallBackProc
{
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glDepthMask(GL_FALSE);
glBindTexture(GL_TEXTURE_2D, texture[0]);
for(int i=0; i<20; i++)
{
if(ExplosionArray[i]._Alpha>0) // verifie si il ya une explosion
{
glPushMatrix();
ExplosionArray[i]._Alpha-=0.01f; //modifie les paraametres pour donner // une impression de mouvement
ExplosionArray[i]._Scale+=0.03f;
glColor4f(1,1,0,ExplosionArray[i]._Alpha);
glScalef(ExplosionArray[i]._Scale,ExplosionArray[i]._Scale,ExplosionArray[i]._Scale);
glTranslatef(((float)ExplosionArray[i].x)/ExplosionArray[i]._Scale, (float)ExplosionArray[i].y/ExplosionArray[i]._Scale, (float)ExplosionArray[i].z/ExplosionArray[i]._Scale);
glColor4f(1.35, 0.78, 0.3,0.4);
glCallList(dlist); // apelle la list
glPopMatrix();
}
}
glDepthMask(GL_TRUE);
glDisable(GL_BLEND);
// glDisable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
}