@@ -334,16 +334,15 @@ int main()
334
334
// Unbind mesh from global state
335
335
mesh.unbind ();
336
336
337
- GLuint texture ;
337
+ GLuint diffuseMap, specularMap ;
338
338
colorShader.use ();
339
339
// Load texture to "texture" variable
340
- colorShader.loadTexture (PWD + " /../../assets/container2.png" , &texture, GL_TEXTURE_2D, GL_REPEAT, GL_LINEAR, 0 , GL_RGBA, 0 , GL_RGBA, GL_UNSIGNED_BYTE);
341
- // Set texture unit 0 active (unnecessary if we have only one texture, texture unit 0 is the default)
342
- glActiveTexture (GL_TEXTURE0);
343
- // Bind "texture" to texture unit 0
344
- glBindTexture (GL_TEXTURE0, texture);
340
+ colorShader.loadTexture (PWD + " /../../assets/container2.png" , &diffuseMap, GL_TEXTURE_2D, GL_REPEAT, GL_LINEAR, 0 , GL_RGBA, 0 , GL_RGBA, GL_UNSIGNED_BYTE);
345
341
// Make material's sampler2D to point to our texture at texture unit 0
346
342
colorShader.setInt (" material.diffuse" , 0 );
343
+
344
+ colorShader.loadTexture (PWD + " /../../assets/container2_specular.png" , &specularMap, GL_TEXTURE_2D, GL_REPEAT, GL_LINEAR, 0 , GL_RGBA, 0 , GL_RGBA, GL_UNSIGNED_BYTE);
345
+ colorShader.setInt (" material.specular" , 1 );
347
346
colorShader.unbind ();
348
347
349
348
// Create new Mesh object for light cube
@@ -438,6 +437,15 @@ int main()
438
437
model = glm::rotate (model, glm::radians (angle), rotationVec);
439
438
// Set changes made to model
440
439
colorShader.setMatrix4fv (" model" , 1 , GL_FALSE, glm::value_ptr (model));
440
+
441
+ // Set texture unit 0 active (unnecessary if we have only one texture, texture unit 0 is the default)
442
+ glActiveTexture (GL_TEXTURE0);
443
+ // Bind "diffuseMap" to texture unit 0
444
+ glBindTexture (GL_TEXTURE_2D, diffuseMap);
445
+
446
+ glActiveTexture (GL_TEXTURE1);
447
+ // Bind "specularMap" to texture unit 1
448
+ glBindTexture (GL_TEXTURE_2D, specularMap);
441
449
}
442
450
// Render model
443
451
mesh.render (GL_TRIANGLES, 36 , GL_UNSIGNED_INT, nullptr );
0 commit comments