Drawing a solid sphere with transparency in openGL

10,418

You need to explicitely setup alpha blending . Another example.

glEnable (GL_BLEND);

glBlendFunc (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

Share:
10,418
Etan
Author by

Etan

SOreadytohelp

Updated on June 04, 2022

Comments

  • Etan
    Etan almost 2 years

    I want to draw a glutSolidSphere with some transparency, but it doesn't seem to work.

    glColor4f(1, 0, 0, 0); // should be completely invisible
    glPushMatrix();
    glTranslatef(position.x, position.y, position.z);
    glutSolidSphere(3, 5, 5);
    glPopMatrix();
    

    In my main function, I initialize with the following display mode:

    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA | GLUT_ALPHA);
    

    What am I missing here?

  • Etan
    Etan over 13 years
    This works now if multiple objects overlap. However, if there is a fully transparent object with nothing behind, it renders the object instead of the background color
  • Etan
    Etan over 13 years
    void renderScene(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  • Etan
    Etan over 13 years
    scriptreactor.com/transparency.png <-- the red spheres should be completely transparent.
  • Etan
    Etan over 13 years
    okay, had used another blending function accidently. works now. thanks