Hey guys,
I have been learning Model View Projection matrices. When I multiply the coordinates by the Model_View_Projection matrix the W is always zero and I can not see the triangle.
void renderScene()
{
glm::mat4 ModelViewProject;
glm::mat4 View;
glm::mat4 Model(1.0);
glm::mat4 Projection = glm::perspective(60.0f, 1024.0f / 768.0f, 0.1f, 10.0f);
View = glm::lookAt(glm::vec3(0, 0, 0), glm::vec3(0, 0, -1), glm::vec3(0, 1, 0));
ModelViewProject = Projection * View * Model;
GLint transform = glGetUniformLocation(programId, "ModelViewProject");
glUniformMatrix4fv(transform, 1, false, glm::value_ptr(ModelViewProject));;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.0, 0.0, 0.0, 1.0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glutSwapBuffers();
}
if I however manually set the last coordinate in ModelViewProject matrix as 1 (which is W) I can see the triangle.
the vertex shader code is :
#version 410
attribute vec3 position;
attribute vec3 ColorIn;
varying vec3 theColor;
uniform mat4 ModelViewProject;
void main()
{
gl_Position = ModelViewProject * vec4(position, 1.0f);
theColor = ColorIn;
};
If I use Identity matrix as ModelViewProject I can also see the triangle.
What am I missing ??