In Chapter 2, OpenGL ES 3.0 Essentials, we looked at the culling technique, which is a quick way to improve performance. This technique avoids rendering polygon faces that face backwards; it's not always desirable to clip the back faces (objects that are not completely enclosed are generally rendered with back faces). Sometimes, it makes sense to view these back faces with different colors. This will help the geometry shape to define characteristics that may not be visible with the same color on both sides of the faces (back and front).
In this recipe, we will render a semi-hollow cylinder with different face colors (inside and outside). The first thing we need to do is to turn off the back culling. We can turn off the back culling with (glDisable (GL_CULL_FACE)
).
In order to apply different colors on the front and back faces, we need to recognize them first. The OpenGL ES shading language provides a simple global-level variable called gl_FrontFacing
in the fragment...