Guest User

Untitled

a guest
Aug 15th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. how draw object with diffuse texture after multi-textured object
  2. glClientActiveTexture(GL_TEXTURE0); // first texture
  3. glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  4. glTexCoordPointer(2, GL_FLOAT, stride, texCoordOffset);
  5. glClientActiveTexture(GL_TEXTURE1); // second texture
  6. glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  7. glTexCoordPointer(2, GL_FLOAT, stride, texCoordLightOffset);
  8.  
  9. // Enable 2D texturing for the first texture.
  10. glActiveTexture(GL_TEXTURE0);
  11. glEnable(GL_TEXTURE_2D);
  12.  
  13. // Enable 2D texturing for the second texture.
  14. glActiveTexture(GL_TEXTURE1);
  15. glEnable(GL_TEXTURE_2D);
  16.  
  17. // We are trying for the multi-textured lighting effect from the OpenGL
  18. // ES 2.0 book, page 223, Figure 10-3. The relevant shader equation is
  19. // basecolor * (lightcolor + 0.25), so we set the constant as a base colour
  20. glColor4f(0.25f, 0.25f, 0.25f, 1.0f);
  21.  
  22.  
  23. // Set the light map has the current texture
  24. glActiveTexture(GL_TEXTURE0);
  25. glBindTexture(GL_TEXTURE_2D,m_new_tex);
  26.  
  27. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  28. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  29. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT,5.0f);
  30. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  31. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  32.  
  33. // add the light map to the constant 0.25
  34. glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
  35. glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD);
  36. glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE);
  37. glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PREVIOUS);
  38.  
  39. // Now set the background map (bricks) and modulate (multiply)
  40. glActiveTexture(GL_TEXTURE1);
  41. // we'll keep this code here as _texSelection will never be our lightmap
  42. glBindTexture(GL_TEXTURE_2D, m_sky);
  43. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  44. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  45. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 5.0f);
  46. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  47. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  48.  
  49. /* Set the texture environment mode for this texture to combine */
  50. glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
  51.  
  52. /* Set the method we're going to combine the two textures by. */
  53. glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
  54.  
  55. /* Use the previous combine texture as source 0*/
  56. glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
  57.  
  58. /* Use the current texture as source 1 */
  59. glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE);
  60.  
  61. /*
  62. Set what we will operate on, in this case we are going to use
  63. just the texture colours.
  64. */
  65. glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
  66. glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
  67.  
  68.  
  69. glBindBuffer(GL_ARRAY_BUFFER, drawable.VertexBuffer);
  70. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, drawable.IndexBuffer);
  71.  
  72. glDrawElements(GL_TRIANGLES, drawable.IndexCount, GL_UNSIGNED_SHORT, 0);
  73.  
  74. glDisable(GL_TEXTURE_2D);
Add Comment
Please, Sign In to add comment