Question

I'm developing a 3D game for iOS with openGL ES2. the 3D sprites should be semi-transparent with an alpha channel of about 0.5 to show the background. The problem is that I want the back side of the 3D sprites to be completely not visible. In other words i want to see only the front side of the sprite (just like it would appear with an alpha channel = 1) but with the background visible through it. Is there any blend function or some shader setting to obtain this effect?

Was it helpful?

Solution

Presumably your sprites are textured onto geometry (quads drawn using triangles or triangle strips)? All you need to do is enable face culling:

glEnable(GL_CULL_FACE);

This will prevent drawing the "back" side of any polygon well before it gets to the blending stage of the graphics pipeline -- so you get a performance win in addition to the visual effect your after.

You do need to make sure that your "front" and "back" sides are defined consistently, though. By default, OpenGL considers any polygon whose vertices are in counter-clockwise order to be front-facing (and vice versa). If enabling face culling makes all your sprites disappear, it's because their vertices are in clockwise order. Either reorder your vertices, or tell OpenGL that they're all backwards with glFrontFace(GL_CW).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top