0% found this document useful (0 votes)
18 views3 pages

Render Cube

Uploaded by

kisalovey78
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views3 pages

Render Cube

Uploaded by

kisalovey78
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

void renderCube()

{
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

const float vertices[] = {


// bottom face
-widthBottom / 2, 0.0f, -length / 2, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f, 0.0f,
widthBottom / 2, 0.0f, -length / 2, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
widthBottom / 2, 0.0f, length / 2, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f,
widthBottom / 2, 0.0f, length / 2, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f,
-widthBottom / 2, 0.0f, length / 2, 0.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f,
-widthBottom / 2, 0.0f, -length / 2, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f, 0.0f,

// 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);

if (glfwGetKey(window, GLFW_KEY_UP) == GLFW_PRESS)


pCamera->ProcessKeyboard(FORWARD, (float)deltaTime);
if (glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS)
pCamera->ProcessKeyboard(BACKWARD, (float)deltaTime);
if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS)
pCamera->ProcessKeyboard(LEFT, (float)deltaTime);
if (glfwGetKey(window, GLFW_KEY_RIGHT) == GLFW_PRESS)
pCamera->ProcessKeyboard(RIGHT, (float)deltaTime);
if (glfwGetKey(window, GLFW_KEY_PAGE_UP) == GLFW_PRESS)
pCamera->ProcessKeyboard(UP, (float)deltaTime);
if (glfwGetKey(window, GLFW_KEY_PAGE_DOWN) == GLFW_PRESS)
pCamera->ProcessKeyboard(DOWN, (float)deltaTime);

if (glfwGetKey(window, GLFW_KEY_R) == GLFW_PRESS) {


int width, height;
glfwGetWindowSize(window, &width, &height);
pCamera->Reset(width, height);

if (glfwGetKey(window, GLFW_KEY_L) == GLFW_PRESS)


rotateLight = !rotateLight; // Pornim rotația luminii la apăsarea tastei
"L"

if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)


{
cubeMovement = Up;
}
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
{
cubeMovement = Down;
}
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
{

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy