1

i'd like to make this :

draw object 1 (because I should use glDrawElement or glDrawArray, depth test should be used) draw object 2

blend 1 and 2 (obj 1 + transparent obj2)

Explaining by simple pseudo code,

glEnable(GL_BNELD);

/// draw obj1 ///
glEnable(GL_DEPTH_TEST);
glUniform4f(color1,1.0f);
glDrawElements(...) // draw obj1
glDisable(GL_DEPTH_TEST);

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

/// draw obj2 ///
glEnable(GL_DEPTH_TEST);
glUniform4f(color2,0.5f);
glDrawElements(...) // draw obj2
glDisable(GL_DEPTH_TEST);

glDisable(GL_BLEND);

I heard that those blending and depth test are not used simultaneously, then is there any alternative? (actually the result of above code looks like strange)

Wooni
  • 481
  • 1
  • 3
  • 17
  • Yes you can but you need to know what are you doing (to avoid artifacts) this might help: [OpenGL - How to create Order Independent transparency?](http://stackoverflow.com/a/37783085/2521214) – Spektre Feb 22 '17 at 06:47

1 Answers1

4

Yes, blending and depth testing can be used at the same time. And you'll need it if you want to draw something translucent that's partially occluded by something opaque in the foreground.

What's not possible with the current state of the art of simple depth buffered rendering, is order independent transparency, i.e. blending objects in arbitrary order with the outcome being equivalent to drawing them far to near.

datenwolf
  • 159,371
  • 13
  • 185
  • 298