I'm trying to multiply my cube's position by uniform model matrix but it's making my model invisible :(
There's my vertex shader:
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec2 aTex;
uniform mat4 model;
out vec2 aTexture;
void main() {
gl_Position = model * vec4(aPos, 1.0f);
aTexture = aTex;
}
And the cube render method:
void Cube::render(const GLSLShader& shader) const {
shader.use();
if (_texture != nullptr) {
_texture->use();
}
glm::mat4 m = glm::translate(m, glm::vec3(0.0f, 0.0f, 0.0f));
shader.addMat4Uniform("model", m);
glBindVertexArray(_vao);
glDrawArrays(GL_TRIANGLES, 0, 36);
}
addMat4Uniform method:
void GLSLShader::addMat4Uniform(const std::string& name, glm::mat4 val) const {
glUniformMatrix4fv(glGetUniformLocation(_shader_program, name.c_str()), 1,
GL_FALSE, glm::value_ptr(val));
}
When I'm multiplying by empty mat4 like:
glm::mat4 m; //= glm::translate(m, glm::vec3(0.0f, 0.0f, 0.0f));
shader.addMat4Uniform("model", m);
Everything is fine, but when I uncomment the glm::translate function cube becames invisible :(