Pro OpenGL ES for iOS

(singke) #1

CHAPTER 5: Textures (^145)
static const GLfloat textureCoords[] = //1
{
0.0, 0.0,
1.0, 0.0,
0.0, 1.0,
1.0, 1.0
};
static float transY = 0.0f;
glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, (GLfloat)(sinf(transY)/2.0f), 0.0f);
transY += 0.075f;
glVertexPointer(2, GL_FLOAT, 0, squareVertices);
glEnableClientState(GL_VERTEX_ARRAY);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, squareColors);
glEnableClientState(GL_COLOR_ARRAY);
glEnable(GL_TEXTURE_2D); //2
glEnable(GL_BLEND); //3
glBlendFunc(GL_ONE, GL_SRC_COLOR); //4
glBindTexture(GL_TEXTURE_2D,m_Texture.name); //5
glTexCoordPointer(2, GL_FLOAT,0,textureCoords); //6
glEnableClientState(GL_TEXTURE_COORD_ARRAY); //7
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); //8
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY); //9
}
So, what’s going on here?
„ The texture coordinates are defined here in lines 1ff. Notice that as
referenced earlier they are all between 0 and 1. We’ll play with these
values a little later.
„ In line 2, the GL_TEXTURE_2D target is enabled. Desktop OpenGL
supports 1D and 3D textures but not ES.
„ Here is where blending can be enabled. Blending is where the source
color of the image and the destination color of the background are
blended (mixed) according to some equation that is switched on in
line 4.

Free download pdf