Pro OpenGL ES for iOS

(singke) #1

CHAPTER 6: Will It Blend? (^187)
[self multiTexture:m_Texture0.name tex1:m_Texture1.name];
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
transY += 0.075f;
}
There is a new call here shown in lines 1 and 2, glClientActiveTexture(), which sets
what texture unit to operate on. This is on the client side, not the hardware side of
things, and indicates which texture unit is to receive the texture coordinate array. Don’t
get this confused with glActiveTexture(), used in Listing 6-5 below, that actually turns
a specific texture unit on.
The other additional method we need is multiTexture, shown in Listing 6-5. This is a
very simple default case. The fancy stuff comes later.
Listing 6-5. Sets Up the Texture Combiners
-(void)multiTexture:(GLuint)tex0 tex1:(GLuint)tex1
{
GLfloat combineParameter=GL_MODULATE; //1
// Set up the first texture.
glActiveTexture(GL_TEXTURE0); //2
glBindTexture(GL_TEXTURE_2D, tex0); //3
// Set up the second texture.
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, tex1);
// Set the texture environment mode for this texture to combine.
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, combineParameter); //4
}
Here’s what is going on:
„ Line 1 specifies what the combiners should do. Table 6-2 lists all the
possible values.
„ glActiveTexture() makes active a specific hardware texture unit in
line 2.
„ Line 3 should not be a mystery, because you have seen it before. In
this example, the first texture is bound to a specific hardware texture
unit. The following two lines do the same for the second texture.
„ Now tell the system what to do with the textures in line 4. Table 6-2
lists all the possible parameters. (In the table, P is previous, S is
source, subscript a is alpha, and c is color and is used only when color
and alpha have to be considered separately.)

Free download pdf