mirror of
https://github.com/JoeyDeVries/LearnOpenGL.git
synced 2026-01-30 20:13:22 +08:00
Normal mapping code
Normal mapping code for normal mapping tutorial (+ few extra's for next tutorial)
This commit is contained in:
@@ -19,6 +19,10 @@ struct Vertex {
|
||||
glm::vec3 Normal;
|
||||
// TexCoords
|
||||
glm::vec2 TexCoords;
|
||||
// Tangent
|
||||
glm::vec3 Tangent;
|
||||
// Bitangent
|
||||
glm::vec3 Bitangent;
|
||||
};
|
||||
|
||||
struct Texture {
|
||||
@@ -53,6 +57,7 @@ public:
|
||||
// Bind appropriate textures
|
||||
GLuint diffuseNr = 1;
|
||||
GLuint specularNr = 1;
|
||||
GLuint normalNr = 1;
|
||||
for(GLuint i = 0; i < this->textures.size(); i++)
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0 + i); // Active proper texture unit before binding
|
||||
@@ -64,9 +69,11 @@ public:
|
||||
ss << diffuseNr++; // Transfer GLuint to stream
|
||||
else if(name == "texture_specular")
|
||||
ss << specularNr++; // Transfer GLuint to stream
|
||||
else if(name == "texture_normal")
|
||||
ss << normalNr++; // Transfer GLuint to stream
|
||||
number = ss.str();
|
||||
// Now set the sampler to the correct texture unit
|
||||
glUniform1f(glGetUniformLocation(shader.Program, (name + number).c_str()), i);
|
||||
glUniform1i(glGetUniformLocation(shader.Program, (name + number).c_str()), i);
|
||||
// And finally bind the texture
|
||||
glBindTexture(GL_TEXTURE_2D, this->textures[i].id);
|
||||
}
|
||||
@@ -118,6 +125,12 @@ private:
|
||||
// Vertex Texture Coords
|
||||
glEnableVertexAttribArray(2);
|
||||
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)offsetof(Vertex, TexCoords));
|
||||
// Vertex Tangent
|
||||
glEnableVertexAttribArray(3);
|
||||
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)offsetof(Vertex, Tangent));
|
||||
// Vertex Bitangent
|
||||
glEnableVertexAttribArray(4);
|
||||
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)offsetof(Vertex, Bitangent));
|
||||
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user