From 2ad685b874c3accc769efb05be49ef3c7766f4db Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Thu, 27 Oct 2022 23:17:39 +0200 Subject: [PATCH] Reverted back to old array thing --- headers/renderer.hpp | 5 ++--- src/main.cpp | 26 +++++++++++++++----------- src/renderer.cpp | 18 +++++++++--------- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/headers/renderer.hpp b/headers/renderer.hpp index b5ff243..40f5109 100644 --- a/headers/renderer.hpp +++ b/headers/renderer.hpp @@ -21,16 +21,15 @@ namespace Renderer { class RenderObject { public: - RenderObject(std::vector verts, std::vector indices); + RenderObject(float verts[], unsigned int indices[]); void render(GLFWwindow* win, glm::mat4 cameraTransform, glm::mat4 projectionTransform); void transform(glm::mat4 T); private: Shaders::Shader shader; + unsigned int vertCount; unsigned int EBO; unsigned int VBO; unsigned int VAO; - std::vector vertsVec; - std::vector indicesVec; }; class Renderer3D { diff --git a/src/main.cpp b/src/main.cpp index 96debd9..31a55fe 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -49,8 +49,6 @@ int main() { return 1; } - Renderer::Renderer3D renderer(win); - glfwMakeContextCurrent(win); if ( !gladLoadGLLoader((GLADloadproc)glfwGetProcAddress) ) { @@ -58,18 +56,18 @@ int main() { return 1; } - std::vector verts({ + float verts[] = { 0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.5f, -0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, -0.5f, -0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f - }); + }; // Vert struc: x y z r g b tx ty - std::vector indices({ + unsigned int indices[] = { 0, 1, 3, 1, 2, 3 - }); + }; glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); glfwSetFramebufferSizeCallback(win, framebuffer_size_callback); @@ -77,10 +75,15 @@ int main() { float borderColor[] = {1.0f, 1.0f, 1.0f, 1.0f}; glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor); - Renderer::RenderObject ro(verts, indices); - renderer.spawnObject(ro); - // ro.setTexture(RUSTY_METAL_TEXTURE); + printf("%u %u\n", sizeof(indices), sizeof(verts)); + Renderer::Obj2D ro2(indices, sizeof(indices), verts, sizeof(verts)); + ro2.setTexture(RUSTY_METAL_TEXTURE); + // Renderer::RenderObject ro(verts, indices); + // Renderer::Renderer3D renderer(win); + // renderer.spawnObject(ro); + // ro.setTexture(RUSTY_METAL_TEXTURE); + // Window width & height while (!glfwWindowShouldClose(win)) { // Handle input @@ -99,9 +102,10 @@ int main() { glm::mat4 T = glm::mat4(1.0f); T = glm::rotate(T, rotang, glm::vec3(1.0, 0.0, 1.0)); T = glm::scale(T, glm::vec3(0.5, 0.5, 0.5)); - ro.transform(T); + ro2.transform(T); + ro2.render(win); - renderer.render(); + //renderer.render(); // glfw glfwSwapBuffers(win); diff --git a/src/renderer.cpp b/src/renderer.cpp index 707f818..66a60be 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -39,27 +40,26 @@ namespace Renderer { } // RenderObject - RenderObject::RenderObject(std::vector verts, std::vector indices) + RenderObject::RenderObject(float verts[], unsigned int indices[]) : shader(VERT_SHADER_SRC_FILE, FRAG_SHADER_SRC_FILE) { - vertsVec = verts; - indicesVec = indices; - - float* vertsArray = &vertsVec[0]; - unsigned int* indicesArray = &indicesVec[0]; // Vertex Array Object glGenVertexArrays(1, &VAO); // gen the VAO glBindVertexArray(VAO); // bind it // Copy the verts into the buffer + // unsigned int vertsSize = sizeof(verts); + unsigned int vertsSize = 4; glGenBuffers(1, &VBO); glBindBuffer(GL_ARRAY_BUFFER, VBO); - glBufferData(GL_ARRAY_BUFFER, vertsVec.size(), vertsArray, GL_DYNAMIC_DRAW); // for moving stuff + glBufferData(GL_ARRAY_BUFFER, vertsSize, verts, GL_DYNAMIC_DRAW); // for moving stuff // Copy the indices for the verts into another buffer + // vertCount = sizeof(indices); + vertCount = 6; glGenBuffers(1, &EBO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, indicesVec.size(), indicesArray, GL_STATIC_DRAW); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, vertCount, indices, GL_STATIC_DRAW); // Shader stuff // Pos @@ -82,7 +82,7 @@ namespace Renderer { shader.use(); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); - glDrawElements(GL_TRIANGLES, indicesVec.size(), GL_UNSIGNED_INT, 0); + glDrawElements(GL_TRIANGLES, vertCount, GL_UNSIGNED_INT, 0); } void RenderObject::transform(glm::mat4 T) {