OpenGL Alpha Channel Problem

Nibbie
Posts: 1
Joined: 2013.01
Post: #1
Hi. Great website you guys got here.

I'm making a particle engine and the idea is that as the particle's life decreases the alpha value also decreases creating a fade effect.

Code:
```void UpdateRain(void) {     for (int i = 0; i < MAX_PARTICLES; i++)     {         int iRandX = ((rand()%500) - 250);         float dRandX = float(iRandX)/9;         int iRandZ = (rand()%500) - 250;         float dRandZ = (float)iRandZ/9;         int iRandLife = rand()%100;         float dRandLife = (float)iRandLife/100;         int iRandDeath = (rand()%10);         float dRandDeath = (float)iRandDeath/1000;         // Draw the particles using our RGB values         glColor4f(Rain[i].r,Rain[i].g,Rain[i].b,Rain[i].life);         Rain[i].xPos += Rain[i].xDir; //move on the x axis by x speed         Rain[i].yPos += Rain[i].yDir; //move on the y axis by y speed         Rain[i].zPos += Rain[i].zDir; //move on the z axis by z speed         Rain[i].life -= Rain[i].death; //reduce life by value of death         if (Rain[i].life < Rain[i].death)         {             Rain[i].xPos = dRandX;             Rain[i].yPos = 20;             Rain[i].zPos = dRandZ;             Rain[i].xDir = 0.01f;             Rain[i].yDir = -0.5f;             Rain[i].zDir = 0;             Rain[i].r = 0.90f;             Rain[i].g = 0.90f;             Rain[i].b = 1.0f;             Rain[i].life = dRandLife;             Rain[i].death = 0.01f;             Rain[i].speed = (float)(rand()%360);             Rain[i].angle = 160;         }             } } void DrawRain(void) {              for (int i = 0; i < MAX_PARTICLES; i++)     {              glPushMatrix();         glTranslatef (Rain[i].xPos, Rain[i].yPos, Rain[i].zPos);            glDisable (GL_DEPTH_TEST);         glEnable (GL_BLEND);                  glBlendFunc (GL_DST_COLOR, GL_ZERO);         glBindTexture (GL_TEXTURE_2D, myTexture[0]);         //glvertex3f determines particle size         glBegin (GL_QUADS);         glTexCoord2d (0, 0); //bottom left         glVertex3f (.05f, 0, 0.05f);         glTexCoord2d (1, 0); //bottom right         glVertex3f (.1f, 0, .1f);         glTexCoord2d (1, 1); //top right         glVertex3f (0.05f, .55f, 0.05f);         glTexCoord2d (0, 1); //top left         glVertex3f (0.05f, .5f, 0.05f);         glEnd();         glBlendFunc (GL_ONE, GL_ONE);         glBindTexture (GL_TEXTURE_2D, myTexture[1]);              glBegin (GL_QUADS);         glTexCoord2d (0, 0); //bottom left         glVertex3f (.05f, 0, 0.05f);         glTexCoord2d (1, 0); //bottom right         glVertex3f (.1f, 0, .1f);         glTexCoord2d (1, 1); //top right         glVertex3f (0.05f, .55f, 0.05f);         glTexCoord2d (0, 1); //top left         glVertex3f (0.05f, .5f, 0.05f);         glEnd();                glEnable(GL_DEPTH_TEST);         glPopMatrix();     } }```

I'm not quite sure whats causing the problem here so I'd appreciate the help. I'd also like to point out that changing the alpha value in the glcolor4f function seems to have no affect on the particles.

Thanks.
Moderator
Posts: 713
Joined: 2002.04
Post: #2

1. Welcome to the forums
2. Your code would be a lot easier to read – and thus you'd be more likely to receive an answer to your question – if you used the code tag/indentation
3. You'd be more likely to receive an answer to your question if you posted a question/described the problem you're encountering, and didn't just post code
4. I've taken a glance at your code and I'd guess that the explanation for why your call to glColor4f() is not affecting the opacity of your particles is because your call to glColor4f() is in UpdateRain() and not DrawRain() where it most likely belongs...

Mark Bishop
--
Student and freelance OS X & iOS developer