Refactor start

This commit is contained in:
RochesterX
2026-01-28 10:48:41 -05:00
parent d36115878b
commit 23877f7a3f
8 changed files with 48 additions and 198 deletions

View File

@@ -1,41 +0,0 @@
#ifndef LINE_H
#define LINE_H
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
#include <shader.hpp>
#include <texture.hpp>
#include <vector>
using std::vector;
using glm::vec3;
using glm::mat4;
class Line {
public:
vec3 position;
vec3 rotation;
vec3 scale;
vector<float> vertices;
vector<unsigned int> indices;
unsigned int VAO;
unsigned int VBO;
unsigned int EBO;
Line(const vec3 position, const vec3 rotation, const vec3 scale, vector<float> v, vector<unsigned int> i);
void generateImage();
void draw(Shader s);
mat4 translationMatrix();
mat4 rotationMatrix();
mat4 scaleMatrix();
mat4 modelMatrix();
};
#endif

View File

@@ -6,7 +6,6 @@
#include <glm/glm.hpp>
#include <shader.hpp>
#include <texture.hpp>
#include <vector>
@@ -31,6 +30,7 @@ public:
vec3 scale;
vector<float> vertexData;
vector<unsigned int> indexData;
vector<Vertex> vertices;
vector<vec3> normals;
@@ -41,8 +41,6 @@ public:
unsigned int VBO;
unsigned int EBO;
Texture texture1;
Object()
{
@@ -261,10 +259,24 @@ public:
break;
}
vertices[indices[i]].normal = normals[normalIndices[i]];
//vertices[indices[i]].normal = normals[normalIndices[i]];
vertexData.push_back(vertices[indices[i]].position.x);
vertexData.push_back(vertices[indices[i]].position.y);
vertexData.push_back(vertices[indices[i]].position.z);
vertexData.push_back(vertices[indices[i]].color.x);
vertexData.push_back(vertices[indices[i]].color.y);
vertexData.push_back(vertices[indices[i]].color.z);
vertexData.push_back(normals[normalIndices[i]].x);
vertexData.push_back(normals[normalIndices[i]].y);
vertexData.push_back(normals[normalIndices[i]].z);
indexData.push_back(i);
}
// Generate vertexData
/* Generate vertexData
for (int i = 0; i < vertices.size(); i++)
{
Vertex vertex = vertices[i];
@@ -289,7 +301,7 @@ public:
//std::cout << vertex.color.y << " ";
//std::cout << vertex.color.z << std::endl;
}
*/
//std::cout << "Length of vertices: " << vertices.size() << std::endl;
//std::cout << "Path of this one " << path << std::endl << std::endl;
@@ -302,7 +314,7 @@ public:
glGenBuffers(1, &EBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(unsigned int), &indices[0], GL_STATIC_DRAW);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexData.size() * sizeof(unsigned int), &indexData[0], GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
@@ -314,37 +326,6 @@ public:
glEnableVertexAttribArray(2);
}
/*
Object(const vec3 p, const vec3 r, const vec3 s, vector<float> v, vector<unsigned int> i, Texture t1 = nullptr)
{
this->position = p;
this->rotation = r;
this->scale = s;
this->vertexData = v;
this->indices = i;
this->texture1 = t1;
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, vertexData.size() * sizeof(float), &vertexData[0], GL_STATIC_DRAW);
glGenBuffers(1, &EBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(unsigned int), &indices[0], GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), (void*)(3 * sizeof(float)));
glEnableVertexAttribArray(1);
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), (void*)(6 * sizeof(float)));
glEnableVertexAttribArray(2);
}
*/
void draw(Shader s)
{
/*mat4 mod = rotationMatrix();
@@ -359,13 +340,11 @@ public:
s.setMat4("modelMatrix", &modelMatrix()[0][0]);
s.setMat4("normalMatrix", &normalMatrix()[0][0]);
texture1.activate(0);
s.use();
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, 0);
glDrawElements(GL_TRIANGLES, indexData.size(), GL_UNSIGNED_INT, 0);
s.setInt("texture1", 0);
s.setVec3("lightColor", 1.0, 1.0, 1.0);
s.setVec3("objectColor", 0.8, 0.4, 0.2);
s.setVec3("lightPos", sin(glfwGetTime() / 3.0f) * 10, 8.0, cos(glfwGetTime() / 3.0f) * 10);

13
include/renderer.hpp Normal file
View File

@@ -0,0 +1,13 @@
#ifndef RENDERER_H
#define RENDERER_H
#include "object.hpp"
class Renderer {
public:
};
#endif