// render the meshvoidDraw(Shader shader){// bind appropriate texturesunsignedint diffuseNr =1;unsignedint specularNr =1;unsignedint normalNr =1;unsignedint heightNr =1;for(unsignedint i =0; i < textures.size(); i++){glActiveTexture(GL_TEXTURE0 + i);// active proper texture unit before binding// retrieve texture number (the N in diffuse_textureN)
string number;
string name = textures[i].type;if(name =="texture_diffuse")
number = std::to_string(static_cast<longlong>(diffuseNr++));elseif(name =="texture_specular")
number = std::to_string(static_cast<longlong>(specularNr++));// transfer unsigned int to streamelseif(name =="texture_normal")
number = std::to_string(static_cast<longlong>(normalNr++));// transfer unsigned int to streamelseif(name =="texture_height")
number = std::to_string(static_cast<longlong>(heightNr++));// transfer unsigned int to stream// now set the sampler to the correct texture unitglUniform1i(glGetUniformLocation(shader.ID,(name + number).c_str()), i);// and finally bind the textureglBindTexture(GL_TEXTURE_2D, textures[i].id);}// draw meshglBindVertexArray(VAO);glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT,0);glBindVertexArray(0);// always good practice to set everything back to defaults once configured.glActiveTexture(GL_TEXTURE0);}