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

@@ -15,7 +15,7 @@ OBJ= $(patsubst $(SRC_PATH)/%.cpp,$(OBJ_PATH)/%.o,$(CPP_SRC)) \
#//OBJ= $(OBJS:.o) #//OBJ= $(OBJS:.o)
# CC specifies which compiler we're using # CC specifies which compiler we're using
CC = g++ CC = clang++
RM = rm RM = rm
# INCLUDE_PATHS specifies the additional include paths we'll need # INCLUDE_PATHS specifies the additional include paths we'll need

9
compile_flags.txt Normal file
View File

@@ -0,0 +1,9 @@
-I/usr/local/include
-I/opt/X11/include
-I/opt/homebrew/opt/glfw/include
-I/opt/homebrew/opt/glew/include
-I/opt/homebrew/opt/glm/include
-I./include
-I./include/glad
-std=c++11

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

View File

@@ -1,110 +0,0 @@
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
#include <stb_image.h>
#include <Line.hpp>
#include <shader.hpp>
#include <texture.hpp>
#include <iostream>
using std::vector;
using glm::vec3;
using glm::mat4;
Line::Line(const vec3 p, const vec3 r, const vec3 s, vector<float> v, vector<unsigned int> i)
{
this->position = p;
this->rotation = r;
this->scale = s;
this->vertices = v;
this->indices = i;
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(float), &vertices[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, 6 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)(3 * sizeof(float)));
glEnableVertexAttribArray(1);
}
void Line::draw(Shader s) {
/*mat4 mod = rotationMatrix();
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
std::cout << mod[i][j] << "\t";
}
std::cout << std::endl;
}*/
s.setMat4("modelMatrix", &modelMatrix()[0][0]);
s.use();
glBindVertexArray(VAO);
glDrawElements(GL_LINES, indices.size(), GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
}
mat4 Line::translationMatrix()
{
return mat4(
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
position.x, position.y, position.z, 1
);
}
mat4 Line::rotationMatrix()
{
mat4 x(
1, 0, 0, 0,
0, cos(rotation.x), sin(rotation.x), 0,
0, -sin(rotation.x), cos(rotation.x), 0,
0, 0, 0, 1
);
mat4 y(
cos(rotation.y), 0, -sin(rotation.y), 0,
0, 1, 0, 0,
sin(rotation.y), 0, cos(rotation.y), 0,
0, 0, 0, 1
);
mat4 z(
cos(rotation.z), sin(rotation.z), 0, 0,
-sin(rotation.z), cos(rotation.z), 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
);
return z * y * x;
}
mat4 Line::scaleMatrix()
{
return mat4(
scale.x, 0, 0, 0,
0, scale.y, 0, 0,
0, 0, scale.z, 0,
0, 0, 0, 1
);
}
mat4 Line::modelMatrix()
{
return translationMatrix() * rotationMatrix() * scaleMatrix();
}

View File

@@ -10,7 +10,6 @@
#include <camera.hpp> #include <camera.hpp>
#include <iostream> #include <iostream>
#include <vector>
using glm::vec2; using glm::vec2;
using glm::vec3; using glm::vec3;
@@ -223,8 +222,8 @@ void processInput(GLFWwindow *window)
void createShaderProgram() void createShaderProgram()
{ {
shader = Shader("/Users/rochesterx/Documents/Programming/OpenGL/src/shaders/vertex.glsl", "/Users/rochesterx/Documents/Programming/OpenGL/src/shaders/fragment.glsl"); shader = Shader("src/shaders/vertex.glsl", "src/shaders/fragment.glsl");
gridShader = Shader("/Users/rochesterx/Documents/Programming/OpenGL/src/shaders/gridvertex.glsl", "/Users/rochesterx/Documents/Programming/OpenGL/src/shaders/gridfragment.glsl"); gridShader = Shader("src/shaders/gridvertex.glsl", "src/shaders/gridfragment.glsl");
shader.use(); shader.use();
} }
@@ -277,8 +276,8 @@ void init()
createShaderProgram(); createShaderProgram();
Texture texture("assets/container.jpg"); //Texture texture("assets/container.jpg");
Texture texture2("assets/awesomeface.png"); //Texture texture2("assets/awesomeface.png");
//Object cube(vec3(0, 0, 0), vec3(0, 0, 0), vec3(1, 1, 1), vertices, indices, texture); //Object cube(vec3(0, 0, 0), vec3(0, 0, 0), vec3(1, 1, 1), vertices, indices, texture);
objects = { objects = {
//Object(vec3(0, 0, 0), vec3(0, 0, 0), vec3(3, 3, 3), "assets/dragon.obj"), //Object(vec3(0, 0, 0), vec3(0, 0, 0), vec3(3, 3, 3), "assets/dragon.obj"),

View File

@@ -37,6 +37,7 @@ void main()
vec3 result = (ambient + diffuse + specular) * objectColor; vec3 result = (ambient + diffuse + specular) * objectColor;
FragColor = vec4(result, 1.0); FragColor = vec4(result, 1.0);
//FragColor = vec4(vec3(gl_FragCoord.z), 1.0);
//FragColor = vec4(ourColor * gl_FragCoord.w, 1); //FragColor = vec4(ourColor * gl_FragCoord.w, 1);
} }