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

Swizzling


Swizzling is a new GL shading language feature that allows you to rearrange components of a vector. For example:

vec4 A (1.0, 2.0, 3.0 , 4.0);

Here, vec4 is represented by the x, y, z, and w component. The result is as follows:

vec4 B = A.xxzz;

Now, B is equivalent to {1.0, 1.0, 2.0, 2.0}

Getting ready

The component access of the vec2/3/4s data type in the shading language can be considered either as vector, color, or texture coordinates or an array:

Form type

Components

Example: vec4(1.1, 2.2, 3.3, 4.4 );

Vector

{x, y, z, w}

float a = v.x;

float b= v.y;

Color

{r, g, b, a}

float a = v.r;

float b= v.g;

Texture coordinates

{s, t, p, q}

float a = v.s;

float b= v.t;

Array

[0, 1, 2, 3]

float a = v[0];

float b= v[1];

How to do it...

Swizzling is a mechanism of accessing a component directly using component names. For example:

There's more...

In preceding cases, swizzling occurs on the right-hand side of assignments. However, swizzling may occur on the left-hand side of assignments as well: