Render Cube
Render Cube
{
constexpr float widthBottom = 0.5f;
constexpr float widthTop = 0.5f;
constexpr float length = 0.7f;
constexpr float offsetX = 0.2f; // Offset to create the parallelogram effect
// top face
-widthTop / 2 + offsetX, height, -length / 2, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
0.0f,
widthTop / 2 + offsetX, height, -length / 2, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
0.0f,
widthTop / 2 + offsetX, height, length / 2, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
1.0f,
widthTop / 2 + offsetX, height, length / 2, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
1.0f,
-widthTop / 2 + offsetX, height, length / 2, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f,
0.0f,
-widthTop / 2 + offsetX, height, -length / 2, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
0.0f,
// front face
-widthBottom / 2, 0.0f, length / 2, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f,
widthBottom / 2, 0.0f, length / 2, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
widthTop / 2 + offsetX, height, length / 2, 0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 1.0f,
widthTop / 2 + offsetX, height, length / 2, 0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 1.0f,
-widthTop / 2 + offsetX, height, length / 2, 0.0f, 0.0f, 1.0f, 1.0f,
1.0f, 0.0f,
-widthBottom / 2, 0.0f, length / 2, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f,
// back face
-widthBottom / 2, 0.0f, -length / 2, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f,
0.0f,
widthBottom / 2, 0.0f, -length / 2, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f,
widthTop / 2 + offsetX, height, -length / 2, 0.0f, 0.0f, -1.0f, 0.0f,
0.0f, 1.0f,
widthTop / 2 + offsetX, height, -length / 2, 0.0f, 0.0f, -1.0f, 0.0f,
0.0f, 1.0f,
-widthTop / 2 + offsetX, height, -length / 2, 0.0f, 0.0f, -1.0f, 1.0f,
1.0f, 0.0f,
-widthBottom / 2, 0.0f, -length / 2, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f,
0.0f,
// left face
-widthBottom / 2, 0.0f, -length / 2, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
-widthBottom / 2, 0.0f, length / 2, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
-widthTop / 2 + offsetX, height, length / 2, -1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f,
-widthTop / 2 + offsetX, height, length / 2, -1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f,
-widthTop / 2 + offsetX, height, -length / 2, -1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f,
-widthBottom / 2, 0.0f, -length / 2, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
// right face
widthBottom / 2, 0.0f, -length / 2, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
widthBottom / 2, 0.0f, length / 2, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
widthTop / 2 + offsetX, height, length / 2, 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f,
widthTop / 2 + offsetX, height, length / 2, 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f,
widthTop / 2 + offsetX, height, -length / 2, 1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f,
widthBottom / 2, 0.0f, -length / 2, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f
};
glGenVertexArrays(1, &cubeVAO);
glGenBuffers(1, &cubeVBO);
// fill buffer
glBindBuffer(GL_ARRAY_BUFFER, cubeVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
// link vertex attributes
glBindVertexArray(cubeVAO);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), (void*)0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), (void*)(3 *
sizeof(float)));
glEnableVertexAttribArray(3);
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), (void*)(6 *
sizeof(float)));
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
// render Cube
glBindVertexArray(cubeVAO);
glDrawArrays(GL_TRIANGLES, 0, 36);
glBindVertexArray(0);
// process all input: query GLFW whether relevant keys are pressed/released this
frame and react accordingly
void processInput(GLFWwindow* window)
{
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);