improved shader class
This commit is contained in:
parent
ce250f3467
commit
39cf068e91
4 changed files with 68 additions and 3 deletions
|
@ -2,6 +2,7 @@
|
||||||
#define SHADER_H
|
#define SHADER_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
class Shader
|
class Shader
|
||||||
{
|
{
|
||||||
|
@ -17,6 +18,15 @@ public:
|
||||||
void setBool(const std::string &name, bool value) const;
|
void setBool(const std::string &name, bool value) const;
|
||||||
void setInt(const std::string &name, int value) const;
|
void setInt(const std::string &name, int value) const;
|
||||||
void setFloat(const std::string &name, float value) const;
|
void setFloat(const std::string &name, float value) const;
|
||||||
|
void setVec2(const std::string &name, const glm::vec2 &value) const;
|
||||||
|
void setVec2(const std::string &name, float x, float y) const;
|
||||||
|
void setVec3(const std::string &name, const glm::vec3 &value) const;
|
||||||
|
void setVec3(const std::string &name, float x, float y, float z) const;
|
||||||
|
void setVec4(const std::string &name, const glm::vec4 &value) const;
|
||||||
|
void setVec4(const std::string &name, float x, float y, float z, float w) const;
|
||||||
|
void setMat2(const std::string &name, const glm::mat2 &mat) const;
|
||||||
|
void setMat3(const std::string &name, const glm::mat3 &mat) const;
|
||||||
|
void setMat4(const std::string &name, const glm::mat4 &mat) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -4,8 +4,10 @@ layout (location = 1) in vec2 aTexCoord;
|
||||||
|
|
||||||
out vec2 TexCoord;
|
out vec2 TexCoord;
|
||||||
|
|
||||||
|
uniform mat4 transform;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = vec4(aPos, 1.0);
|
gl_Position = transform * vec4(aPos, 1.0f);
|
||||||
TexCoord = aTexCoord;
|
TexCoord = vec2(aTexCoord.x, aTexCoord.y);
|
||||||
}
|
}
|
|
@ -73,6 +73,10 @@ int main()
|
||||||
Texture sataaAndagii("textures/saataa_andagii.png");
|
Texture sataaAndagii("textures/saataa_andagii.png");
|
||||||
Texture ohMyGah("textures/oh_my_gah.png");
|
Texture ohMyGah("textures/oh_my_gah.png");
|
||||||
|
|
||||||
|
glm::mat4 trans = glm::mat4(1.0f);
|
||||||
|
trans = glm::rotate(trans, glm::radians(90.0f), glm::vec3(0.0, 0.0, 1.0));
|
||||||
|
trans = glm::scale(trans, glm::vec3(0.5, 0.5, 0.5));
|
||||||
|
|
||||||
while(!glfwWindowShouldClose(window))
|
while(!glfwWindowShouldClose(window))
|
||||||
{
|
{
|
||||||
processInput(window);
|
processInput(window);
|
||||||
|
@ -81,6 +85,9 @@ int main()
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
ourShader.use();
|
ourShader.use();
|
||||||
|
trans = glm::rotate(trans, (float)glfwGetTime() / 100, glm::vec3(0.0f, 0.0f, 1.0f));
|
||||||
|
ourShader.setMat4("transform", trans);
|
||||||
|
|
||||||
ohMyGah.use();
|
ohMyGah.use();
|
||||||
glBindVertexArray(VAO);
|
glBindVertexArray(VAO);
|
||||||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
||||||
|
|
|
@ -99,3 +99,49 @@ void Shader::setFloat(const std::string &name, float value) const
|
||||||
{
|
{
|
||||||
glUniform1f(glGetUniformLocation(ID, name.c_str()), value);
|
glUniform1f(glGetUniformLocation(ID, name.c_str()), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Shader::setVec2(const std::string &name, const glm::vec2 &value) const
|
||||||
|
{
|
||||||
|
glUniform2fv(glGetUniformLocation(ID, name.c_str()), 1, &value[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Shader::setVec2(const std::string &name, float x, float y) const
|
||||||
|
{
|
||||||
|
glUniform2f(glGetUniformLocation(ID, name.c_str()), x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Shader::setVec3(const std::string &name, const glm::vec3 &value) const
|
||||||
|
{
|
||||||
|
glUniform3fv(glGetUniformLocation(ID, name.c_str()), 1, &value[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Shader::setVec3(const std::string &name, float x, float y, float z) const
|
||||||
|
{
|
||||||
|
glUniform3f(glGetUniformLocation(ID, name.c_str()), x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Shader::setVec4(const std::string &name, const glm::vec4 &value) const
|
||||||
|
{
|
||||||
|
glUniform4fv(glGetUniformLocation(ID, name.c_str()), 1, &value[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Shader::setVec4(const std::string &name, float x, float y, float z, float w) const
|
||||||
|
{
|
||||||
|
glUniform4f(glGetUniformLocation(ID, name.c_str()), x, y, z, w);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Shader::setMat2(const std::string &name, const glm::mat2 &mat) const
|
||||||
|
{
|
||||||
|
glUniformMatrix2fv(glGetUniformLocation(ID, name.c_str()), 1, GL_FALSE, &mat[0][0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Shader::setMat3(const std::string &name, const glm::mat3 &mat) const
|
||||||
|
{
|
||||||
|
glUniformMatrix3fv(glGetUniformLocation(ID, name.c_str()), 1, GL_FALSE, &mat[0][0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Shader::setMat4(const std::string &name, const glm::mat4 &mat) const
|
||||||
|
{
|
||||||
|
glUniformMatrix4fv(glGetUniformLocation(ID, name.c_str()), 1, GL_FALSE, &mat[0][0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue