Created
May 11, 2024 16:43
-
-
Save awilki01/ff4b8fd344b5f7ab6173754e77ddf2ea to your computer and use it in GitHub Desktop.
Rectangle.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Rectangle.hpp" | |
Rectangle::Rectangle() | |
{ | |
mVertices[0] = 1.0f; mVertices[1] = 1.0f; mVertices[2] = 0.0f; | |
mVertices[3] = 1.0f; mVertices[4] = -1.0f; mVertices[5] = 0.0f; | |
mVertices[6] = -1.0f; mVertices[7] = -1.0f; mVertices[8] = 0.0f; | |
mVertices[9] = -1.0f; mVertices[10] = 1.0f; mVertices[11] = 0.0f; | |
mIndices[0] = 0; mIndices[1] = 1; mIndices[2] = 3; | |
mIndices[3] = 1; mIndices[4] = 2; mIndices[5] = 3; | |
mModel = glm::mat4(1.0); // initialize to identity matrix | |
glGenVertexArrays(1, &mVAO); | |
glGenBuffers(1, &mVBO); | |
glGenBuffers(1, &mEBO); | |
glBindVertexArray(mVAO); // Bind VAO and EBO together | |
glBindBuffer(GL_ARRAY_BUFFER, mVBO); | |
glBufferData(GL_ARRAY_BUFFER, sizeof(mVertices), mVertices, GL_STATIC_DRAW); | |
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mEBO); | |
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(mIndices), mIndices, GL_STATIC_DRAW); | |
// position attribute | |
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0); | |
glEnableVertexAttribArray(0); | |
} | |
Rectangle::~Rectangle() {} | |
void Rectangle::draw(const Shader& shader) | |
{ | |
// shader.use(); | |
shader.setMat4("model", mModel); | |
glBindVertexArray(mVAO); | |
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); | |
} | |
void Rectangle::scale(const Shader& shader, glm::vec3& vFactor) | |
{ | |
mModel = glm::scale(mModel, vFactor); | |
} | |
void Rectangle::translate(const Shader& shader, glm::vec3& vTranslate) | |
{ | |
mModel = glm::mat4(1.0); // TODO: Why do i have to initialize this here when its initilialized in constructor???? | |
mModel = glm::translate(mModel, vTranslate); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment