How to do it...

  1. In the initialization section of your OpenGL program, load the two images into texture memory in the same way as indicated in the previous recipe, Applying a 2D texture. Make sure that the brick texture is loaded into texture unit 0 and the moss texture in texture unit 1: 
 GLuint brick = Texture::loadTexture("brick1.jpg"); GLuint moss = Texture::loadTexture("moss.png");// Load brick texture file into channel 0glActiveTexture(GL_TEXTURE0);glBindTexture(GL_TEXTURE_2D, brick);// Load moss texture file into channel 1glActiveTexture(GL_TEXTURE1);glBindTexture(GL_TEXTURE_2D, moss); 
  1. Starting with the fragment shader from the recipe Applying a 2D texture, replace the declaration of the sampler variable Tex1 with the following ...

Get OpenGL 4 Shading Language Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.