I'm following the OpenGL tutorials on opengl-tutorial.org, and in tutorial 4 the author proposed, as a side "project", to send two "objects" to OpenGL and we have only ever rendered one object before. Specifically, he asks this:
Draw the cube AND the triangle, at different locations. You will need to generate 2 MVP matrices, to make 2 draw calls in the main loop, but only 1 shader is required.
We define the MVP
matrix like this:
GLuint MatrixID = glGetUniformLocation(programID, "MVP");
glm::mat4 Projection = glm::perspective(90.0f, 4.0f / 3.0f, 0.1f, 100.0f);
// Camera matrix
glm::mat4 View = glm::lookAt(
glm::vec3(0,0,3), // Camera is at (4,3,3), in World Space
glm::vec3(0,0,0), // and looks at the origin
glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
);
glm::mat4 Model = glm::mat4(1.0f);
glm::mat4 MVP = Projection * View * Model;
Now I understand that only one MVP matrix is used per object. But I have a few questions.
How do I create a MVP matrix for each object? Do I have to re-create the View and Model matrices for every object (IE specify a new one for each object)?
I thought
glm::lookAt
was used as the "camera" of sorts, so I shouldn't have to create a new "Camera" for each object, should I?What does the
Model
matrix do? The author says it is a identity matrix right now, but if I change that to say 100, nothing happens! I thought that theModel
matrix was the matrix that defined where the model was rendered, but I can't seem to change where the model is rendered without modifying theView
matrix (which makes sense).