Book Image

OpenGL ES 3.0 Cookbook

By : Parminder Singh
Book Image

OpenGL ES 3.0 Cookbook

By: Parminder Singh

Overview of this book

<p>"Write once, use anywhere" is truly the power behind OpenGL ES and has made it an embedded industry standard. The library provides cutting-edge, easy-to-use features to build a wide range of applications in the gaming, simulation, augmented-reality, image-processing, and geospatial domains.</p> <p>The book starts by providing you with all the necessary OpenGL ES 3.0 setup guidelines on iOS and Android platforms. You'll go on to master the fundamentals of modern 3D graphics, such as drawing APIs, transformations, buffer objects, the model-view-project analogy, and much more. The book goes on to deal with advanced topics and offers a wide range of recipes on the light shading, real-time rendering techniques with static and procedure textures to create stunning visualizations and runtime effects.</p>
Table of Contents (21 chapters)
OpenGL ES 3.0 Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Implementing two-side shading


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...