0

My particles are not glowing. I searched on the internet that its been done with

glBlendFunc(GL_SRC_ALPHA, GL_ONE);

This piece of code changes my particles, but it is not glowing. Can anybody see what is wrong in my code? Here are the relevant codes:

void init (void) {
    glEnable (GL_LIGHTING); //enable the lighting
    glEnable (GL_LIGHT0); //enable LIGHT0, our Diffuse Light
    glEnable (GL_LIGHT1); //enable LIGHT1, our Ambient Light
    glEnable(GL_BLEND);
 //   glEnable(GL_DEPTH);

  //  glEnable(GL_COLOR_MATERIAL);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE);

}

void update()
{
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glRotatef(g_orientation, 0.0, 1.0, 0.0); // rotate in y axis
    glTranslatef(-g_posX, -g_posY, -g_posZ);

    glClear(GL_COLOR_BUFFER_BIT);
    glClear(GL_DEPTH_BUFFER_BIT);

    GLfloat DiffuseLight[] = {dlr, dlg, dlb}; //set DiffuseLight[] to the specified values
    GLfloat AmbientLight[] = {alr, alg, alb}; //set AmbientLight[] to the specified values
    glLightfv (GL_LIGHT0, GL_DIFFUSE, DiffuseLight); //change the light accordingly
    glLightfv (GL_LIGHT1, GL_AMBIENT, AmbientLight); //change the light accordingly
    GLfloat LightPosition[] = {lx, ly, lz, lw}; //set the LightPosition to the specified values
    glLightfv (GL_LIGHT0, GL_POSITION, LightPosition); //change the light accordingly
    glColorMaterial(GL_FRONT,GL_DIFFUSE);
    drawRockets();
    if(explosion == true){
        drawParticles();
    }
    drawMolen();
    glutSwapBuffers();
    if(rotate==1)
        angle++;
}

//commonly used material values
GLfloat no_mat[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat default_ambient[] = {0.2, 0.2, 0.2, 1.0};
GLfloat mat_ambient[] = { 0.7, 0.7, 0.7, 1.0 };
GLfloat mat_ambient_color[] = { 0.8, 0.8, 0.2, 1.0 };
GLfloat mat_diffuse[] = { 0.1, 0.5, 0.8, 1.0 };
GLfloat default_diffuse[] = {0.8, 0.8, 0.8, 1.0};
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat no_shininess[] = { 0.0 };
GLfloat low_shininess[] = { 5.0 };
GLfloat high_shininess[] = { 100.0 };
GLfloat mat_emission[] = {0.3, 0.5, 0.9, 0.0};
GLfloat mat_emission1[] = {0.0, 1.0, 0.2, 1.0};
GLfloat mat_emission2[] = {0.0, 0.0, 1.0, 0.0};
GLfloat mat_emission3[] = {1.0, 1.0, 0.0, 0.0};

Here is another example how I want my glutsolidspheres to be: Ball of Light (Light, Material?) glutsolidsphere

Community
  • 1
  • 1
M.Tlan
  • 33
  • 7
  • I don't know what a "glowing particle" is, but you probably want `GL_ONE, GL_ONE` for additive blending. Also don't call `glClear (...)` twice, just `OR` the bits together (e.g. `glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)`) – Andon M. Coleman Dec 07 '14 at 14:41
  • I supposed to glow like fireworks – M.Tlan Dec 07 '14 at 14:53
  • Blending only has an effect if the color is partially transparent, i.e. the alpha component of the color is less than 1.0. It looks like all your materials are completely opaque. – Reto Koradi Dec 07 '14 at 15:57
  • @RetoKoradi: You mean alpha blending. You can still use a blend function when drawing opaque geometry as long as the src / dst factors are constant or based on color. Which is why I think `GL_ONE, GL_ONE` would probably do what the OP wants - it just adds the incoming color to the existing color (though it will oversaturate very quickly). – Andon M. Coleman Dec 07 '14 at 19:22
  • @AndonM.Coleman Right, I guess you can still add up the colors. But the `GL_SRC_ALPHA` that the OP was trying to use doesn't really make much sense if alpha is always 1.0. Actually, that would end up being the same as `GL_ONE, GL_ONE`, wouldn't it? – Reto Koradi Dec 07 '14 at 19:54
  • @RetoKoradi: Yeah, I think you're right. The source alpha component would be a constant **1.0**. So I don't really know what is meant by glowing in this situation if that blend function doesn't take care of the problem. Maybe bloom? – Andon M. Coleman Dec 07 '14 at 20:47
  • Well I want it to be like this: https://www.youtube.com/watch?v=bYttMMXZw38 But my particles(glutsolidspheres) are just ugly. It doesnt look like glowing fireworks particles. This is what I meant to say. – M.Tlan Dec 07 '14 at 21:12

0 Answers0