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 0.0f,
0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f
};
where the last two coordinates of each line are texture coordinates.
In the vertex shader, I am simply multiplying the vertex position by the viewMatrix, and am not currently considering applying any modelMatrix or projectionMatrix yet.
Here is my vertex shader:
layout (location = 0) in vec3 aPos;
uniform mat4 modelMatrix;
uniform mat4 viewMatrix;
uniform mat4 projectionMatrix;
void main()
{
gl_Position =viewMatrix * vec4(aPos, 1.0f);
}
Now when I change the viewMatrix like so:
viewMatrix_ = glm::lookAt(glm::vec3(0, 0.0f, 2.0f), glm::vec3(0.0, 0.0, 0.0), glm::vec3(0.0, 1.0, 0.0));
my object completely disappears.
Here is my render loop:
while (!glfwWindowShouldClose(window_)) {
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // also clear the depth buffer now!
auto elapsedTime = GetElapsedTime();
shaderProgram_.Use();
// change the color
HSV::RGB timeColor = HSV::HSVtoRGB(static_cast<int>(elapsedTime* 100) % 360, 100, 100);
shaderProgram_.SetUniformVec3("ResColor", { timeColor.r / 255, timeColor.g / 255, timeColor.b / 255 });
viewMatrix_ = glm::lookAt(glm::vec3(0, 0.0f, 2.0f), glm::vec3(0.0, 0.0, 0.0), glm::vec3(0.0, 1.0, 0.0));
shaderProgram_.SetUniformMat4("viewMatrix", viewMatrix_);
glBindVertexArray(VAO_);
glDrawArrays(GL_TRIANGLES, 0, 36);
//glDrawElements(GL_TRIANGLES, 30, GL_UNSIGNED_INT, 0);
glfwSwapBuffers(window_);
glfwPollEvents();
}