diff --git a/2dGameProject/2dGameProject.vcxproj b/2dGameProject/2dGameProject.vcxproj
index 35bf7ad..8e81ab8 100644
--- a/2dGameProject/2dGameProject.vcxproj
+++ b/2dGameProject/2dGameProject.vcxproj
@@ -131,9 +131,12 @@
+
+
+
diff --git a/2dGameProject/2dGameProject.vcxproj.filters b/2dGameProject/2dGameProject.vcxproj.filters
index 16353f8..889019a 100644
--- a/2dGameProject/2dGameProject.vcxproj.filters
+++ b/2dGameProject/2dGameProject.vcxproj.filters
@@ -21,10 +21,19 @@
Source Files
+
+ Source Files
+
Header Files
+
+ Header Files
+
+
+ Source Files
+
\ No newline at end of file
diff --git a/2dGameProject/Square.cpp b/2dGameProject/Square.cpp
new file mode 100644
index 0000000..8b908ec
--- /dev/null
+++ b/2dGameProject/Square.cpp
@@ -0,0 +1,60 @@
+#include "Square.h"
+#include
+#include
+#include
+#include "deff.h"
+
+Square::Square(glm::vec3 position, glm::vec3 scale, glm::vec4 color) {
+ //Initialize Member Variables
+ this->position = position;
+ this->scale = scale;
+ this->color = color;
+ model_transform = glm::mat4(1.0f);
+ model_transform = glm::translate(model_transform, position);
+ model_transform = glm::scale(model_transform, scale);
+
+ //Generate Resources
+ glGenVertexArrays(1, &VAO);
+ unsigned int buffers[2];
+ glGenBuffers(2, buffers);
+ VBO = buffers[0];
+ EBO = buffers[1];
+
+ //Initialize Resources
+ float vertexData[] = {
+ 0.0f, 0.0f, 0.0f, color.r, color.g, color.b, color.a,
+ 1.0f, 0.0f, 0.0f, color.r, color.g, color.b, color.a,
+ 1.0f, 1.0f, 0.0f, color.r, color.g, color.b, color.a,
+ 0.0f, 1.0f, 0.0f, color.r, color.g, color.b, color.a
+ };
+
+ unsigned int indices[]{
+ 0, 1, 2,
+ 0, 2, 3
+ };
+
+ glBindVertexArray(VAO);
+ glBindBuffer(GL_ARRAY_BUFFER, VBO);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(vertexData), vertexData, GL_STATIC_DRAW);
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
+ glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 7 * sizeof(float), (void*)0);
+ glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 7 * sizeof(float), (void*)(3 * sizeof(float)));
+ glEnableVertexAttribArray(0);
+ glEnableVertexAttribArray(1);
+
+ glBindVertexArray(NULL);
+}
+
+Square::~Square() {
+ unsigned int buffers[] = { VBO, EBO };
+ glDeleteBuffers(2, buffers);
+ glDeleteVertexArrays(1, &VAO);
+}
+
+void Square::Draw() {
+ glUniformMatrix4fv(UNIFORM_MODEL_MAT, 1, GL_FALSE, glm::value_ptr(model_transform));
+ glBindVertexArray(VAO);
+ glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
+ glBindVertexArray(NULL);
+}
\ No newline at end of file
diff --git a/2dGameProject/Square.h b/2dGameProject/Square.h
new file mode 100644
index 0000000..6eb44d7
--- /dev/null
+++ b/2dGameProject/Square.h
@@ -0,0 +1,18 @@
+#pragma once
+#include
+
+class Square {
+
+private:
+ unsigned int VAO, VBO, EBO;
+ glm::vec3 position;
+ glm::vec3 scale;
+ glm::vec4 color;
+ glm::mat4 model_transform;
+
+public:
+ Square(glm::vec3 position, glm::vec3 scale, glm::vec4 color);
+ ~Square();
+ void Draw();
+};
+
diff --git a/2dGameProject/deff.h b/2dGameProject/deff.h
new file mode 100644
index 0000000..a353d13
--- /dev/null
+++ b/2dGameProject/deff.h
@@ -0,0 +1,4 @@
+#pragma once
+
+#define UNIFORM_PROJ_MAT 0
+#define UNIFORM_MODEL_MAT 1
\ No newline at end of file
diff --git a/2dGameProject/main.cpp b/2dGameProject/main.cpp
index 5712632..94ce199 100644
--- a/2dGameProject/main.cpp
+++ b/2dGameProject/main.cpp
@@ -1,5 +1,4 @@
#define GLFW_INCLUDE_NONE
-
#include
#include
#include "Window.h"
@@ -12,6 +11,9 @@
#include
#include
#include
+#include "Square.h"
+#include "deff.h"
+#include
int OpenGLVersion;
spdlog::logger logger("none");
@@ -36,10 +38,11 @@ float squareColors[] = {
};
const char* vertexShaderSource = "#version 330 core\n"
+"#extension GL_ARB_explicit_uniform_location: enable\n"
"layout (location = 0) in vec3 aPos;\n"
"layout (location = 1) in vec4 color;\n"
-"uniform mat4 projection;\n"
-"uniform mat4 model;\n"
+"layout (location = 0) uniform mat4 projection;\n"
+"layout (location = 1) uniform mat4 model;\n"
"out vec4 vertexColor;\n"
"void main()\n"
"{\n"
@@ -93,19 +96,11 @@ int main() {
init();
Window* window = new Window(640, 480, "Test Window");
-
+ //window->setWindowedFullscreen();
window->beginRender();
+ glfwSwapInterval(0);
openGLContextInit();
- unsigned int VAO;
- glGenVertexArrays(1, &VAO);
- glBindVertexArray(VAO);
-
- unsigned int VBO;
- glGenBuffers(1, &VBO);
- glBindBuffer(GL_ARRAY_BUFFER, VBO);
- glBufferData(GL_ARRAY_BUFFER, sizeof(square), square, GL_STATIC_DRAW);
-
unsigned int vertexShader;
vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, &vertexShaderSource, NULL);
@@ -149,58 +144,30 @@ int main() {
glDeleteShader(vertexShader);
glDeleteShader(fragmentShader);
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
- glEnableVertexAttribArray(0);
- unsigned int colorBuffer;
- glGenBuffers(1, &colorBuffer);
- glBindBuffer(GL_ARRAY_BUFFER, colorBuffer);
- glBufferData(GL_ARRAY_BUFFER, sizeof(squareColors), squareColors, GL_STATIC_DRAW);
- glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, (void*)0);
- glEnableVertexAttribArray(1);
-
- unsigned int EBO;
- glGenBuffers(1, &EBO);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
- glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(squareIndices), squareIndices, GL_STATIC_DRAW);
-
- glBindVertexArray(NULL);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, NULL);
- glBindBuffer(GL_ARRAY_BUFFER, NULL);
- bool up = false;
- float interval = 0.001;
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- unsigned int projMatLocation = glGetUniformLocation(shaderProgram, "projection");
- glUniformMatrix4fv(projMatLocation, 1, GL_FALSE, glm::value_ptr(glm::ortho(0.0f, 800.0f, 0.0f, 600.0f)));
-
- unsigned int modelMatLocation = glGetUniformLocation(shaderProgram, "model");
- glUniformMatrix4fv(modelMatLocation, 1, GL_FALSE, glm::value_ptr(glm::scale(glm::translate(glm::mat4(1.0), glm::vec3(400, 300, 0)), glm::vec3(100, 100, 1))));
+ glUniformMatrix4fv(UNIFORM_PROJ_MAT, 1, GL_FALSE, glm::value_ptr(glm::ortho(0.0f, 800.0f, 600.0f, 0.0f)));
+ std::array squares;
+ for (int i = 0; i < 100 * 100; i++) {
+ int x = i % 100;
+ int y = i / 100;
+ squares[i] = new Square(glm::vec3(x*6, y*6, 0.0f), glm::vec3(6.0f, 6.0f, 1.0f), glm::vec4(0.0f, 1.0f, 0.0f, 1.0f));
+ }
+ //Square square({ 0, 0, 0 }, { 6, 6, 0 }, {0.0f, 1.0f, 0.0f, 1.0f});
while (!window->isClosing()) {
- if (up) {
- squareColors[0] += interval;
- if (squareColors[0] >= 1.0) {
- squareColors[0] = 1.0;
- up = false;
- }
- } else {
- squareColors[0] -= interval;
- if (squareColors[0] <= 0.0) {
- squareColors[0] = 0.0;
- up = true;
- }
+ //square.Draw();
+ for (auto square : squares) {
+ square->Draw();
}
- glBindBuffer(GL_ARRAY_BUFFER, colorBuffer);
- glBufferData(GL_ARRAY_BUFFER, sizeof(squareColors), squareColors, GL_STATIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER, NULL);
- glClear(GL_COLOR_BUFFER_BIT);
- glBindVertexArray(VAO);
- glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
- glBindVertexArray(NULL);
window->endRender();
glfwPollEvents();
}
+ for (auto square : squares) {
+ delete square;
+ }
+
deinit();
return 0;