Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- how draw object with diffuse texture after multi-textured object
- glClientActiveTexture(GL_TEXTURE0); // first texture
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glTexCoordPointer(2, GL_FLOAT, stride, texCoordOffset);
- glClientActiveTexture(GL_TEXTURE1); // second texture
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glTexCoordPointer(2, GL_FLOAT, stride, texCoordLightOffset);
- // Enable 2D texturing for the first texture.
- glActiveTexture(GL_TEXTURE0);
- glEnable(GL_TEXTURE_2D);
- // Enable 2D texturing for the second texture.
- glActiveTexture(GL_TEXTURE1);
- glEnable(GL_TEXTURE_2D);
- // We are trying for the multi-textured lighting effect from the OpenGL
- // ES 2.0 book, page 223, Figure 10-3. The relevant shader equation is
- // basecolor * (lightcolor + 0.25), so we set the constant as a base colour
- glColor4f(0.25f, 0.25f, 0.25f, 1.0f);
- // Set the light map has the current texture
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D,m_new_tex);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT,5.0f);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- // add the light map to the constant 0.25
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
- glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD);
- glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE);
- glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PREVIOUS);
- // Now set the background map (bricks) and modulate (multiply)
- glActiveTexture(GL_TEXTURE1);
- // we'll keep this code here as _texSelection will never be our lightmap
- glBindTexture(GL_TEXTURE_2D, m_sky);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 5.0f);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- /* Set the texture environment mode for this texture to combine */
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
- /* Set the method we're going to combine the two textures by. */
- glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
- /* Use the previous combine texture as source 0*/
- glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
- /* Use the current texture as source 1 */
- glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE);
- /*
- Set what we will operate on, in this case we are going to use
- just the texture colours.
- */
- glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
- glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
- glBindBuffer(GL_ARRAY_BUFFER, drawable.VertexBuffer);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, drawable.IndexBuffer);
- glDrawElements(GL_TRIANGLES, drawable.IndexCount, GL_UNSIGNED_SHORT, 0);
- glDisable(GL_TEXTURE_2D);
Add Comment
Please, Sign In to add comment