OpenGL Alpha Channel Problem
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.
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.
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.
- Welcome to the forums

- 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

- 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

- 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
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| OpenGL ES 2.0, 2D Alpha Transparency Artifacts | Macmenace | 3 | 6,220 |
Mar 28, 2010 11:18 PM Last Post: AnotherJake |
|
| Simple OpenGL ES problem | soulstorm | 3 | 3,400 |
May 14, 2009 03:53 PM Last Post: AnotherJake |
|
| Opengl picking problem (zip file) | papillon68 | 1 | 3,796 |
Mar 1, 2009 08:49 PM Last Post: chronus |
|
| Opengl alpha premultiplication issue | Najdorf | 5 | 4,375 |
Nov 13, 2008 09:49 AM Last Post: Najdorf |
|
| Problem with SOIL in OpenGL | RingoEST | 12 | 8,122 |
Aug 12, 2008 09:30 PM Last Post: RingoEST |
|

