Pro OpenGL ES for iOS

(singke) #1

CHAPTER 1: Computer Graphics: From Then to Now (^15)
The application delegate has no active code in it, so we can ignore it. The real action
takes place in the viewController via three main sections. The first initializes things using
some of the standard view controller methods we all know and love, the second serves
to render and animate the image, and the third section manages these shader things.
Don’t worry if you don’t get it completely, because this example is merely intended to
give you a general overview of what a basic OpenGL ES program looks like.
Note All of these exercises are available on the Apress site, including additional bonus
exercises that may not be in the book.
You will notice that throughout all of the listings, various parts of the code are marked
with a numbered comment. The numbers correspond to the descriptions following the
listing and that highlight various parts of the code.
Listing 1-1. The initialization of the wizard-generated view controller.
#import "TwoCubesViewController.h"
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
// Uniform index.
Enum //
{
UNIFORM_MODELVIEWPROJECTION_MATRIX,
UNIFORM_NORMAL_MATRIX,
NUM_UNIFORMS
};
GLint uniforms[NUM_UNIFORMS];
// Attribute index.
enum
{
ATTRIB_VERTEX,
ATTRIB_NORMAL,
NUM_ATTRIBUTES
};
GLfloat gCubeVertexData[216] = //
{
// Data layout for each line below is:
// positionX, positionY, positionZ, normalX, normalY, normalZ,
0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,

Free download pdf