2

How can I make the texture of a shape transparent? (E.g. cube or cylinder).

I'm trying now:

glEnable(GL_BLEND);
glEnable(GL_ALPHA_TEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glAlphaFunc(GL_GREATER, 1f);
glColor4f(0.5f, 0.5f, 0.5f, 0.2f);
//Cube code

This doesn’t work quite right, the textures are getting lighter, but I don’t see the objects behind them.

How can I make transparency, which will show what is behind the object?

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Aryesia
  • 152
  • 7
  • 3
    Blending will not automatically get transparency right. You'll need to draw the objects in the right order sorted from back to front to get correct transparency. – derhass Jan 27 '20 at 09:50
  • But remember that for depth-tested non-transparent drawing, front-to-back is the way to go, so don't do back-to-front for everything. – Andrea Jan 28 '20 at 00:11
  • OpenGL transparency is tricky because OpenGL renders things *one at a time* - you tell it to draw some polygons on the screen, then some more polygons. If you draw transparent stuff before the stuff that comes behind it, while using a depth buffer, the depth buffer will make it so *only* the transparent stuff is drawn. If you draw the behind stuff before the transparent stuff, then they're both drawn. – user253751 Jan 28 '20 at 15:27
  • see [OpenGL - How to create Order Independent transparency?](https://stackoverflow.com/a/37783085/2521214) – Spektre Jan 29 '20 at 08:57

0 Answers0