Pro OpenGL ES for iOS

(singke) #1

CHAPTER 6: Will It Blend? (^181)
static const GLfloat squareColorsYMCA[] =
{
1.0, 1.0, 0, 1.0,
0, 1.0, 1.0, 1.0,
0, 0, 0, 1.0,
1.0, 0, 1.0, 1.0,
};
static const GLfloat squareColorsRGBA[] =
{
1.0, 0, 0, 1.0,
0, 1.0, 0, 1.0,
0, 0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0,
};
static GLfloat textureCoords[] =
{
0.0, 0.0,
1.0, 0.0,
0.0, 1.0,
1.0, 1.0
};
static float transY = 0.0;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
[self setClipping];
glClearColor(0.0, 0.0,0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//Set up for using textures.
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,m_Texture0.name);
glTexCoordPointer(2, GL_FLOAT,0,textureCoords);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
//Do square one bouncing up and down.
glTranslatef(0.0, (GLfloat)(sinf(transY)/2.0), -4.0);
glVertexPointer(3, GL_FLOAT, 0, squareVertices);
glEnableClientState(GL_VERTEX_ARRAY);

Free download pdf