diff --git a/Makefile b/Makefile index 128c887..f01b056 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ OBJ= $(patsubst $(SRC_PATH)/%.cpp,$(OBJ_PATH)/%.o,$(CPP_SRC)) \ #//OBJ= $(OBJS:.o) # CC specifies which compiler we're using -CC = g++ +CC = clang++ RM = rm # INCLUDE_PATHS specifies the additional include paths we'll need diff --git a/compile_flags.txt b/compile_flags.txt new file mode 100644 index 0000000..50cce8b --- /dev/null +++ b/compile_flags.txt @@ -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 + diff --git a/include/line.hpp b/include/line.hpp deleted file mode 100644 index e289f20..0000000 --- a/include/line.hpp +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef LINE_H -#define LINE_H - -#include -#include -#include - -#include -#include - -#include - -using std::vector; -using glm::vec3; -using glm::mat4; - -class Line { -public: - vec3 position; - vec3 rotation; - vec3 scale; - - vector vertices; - vector indices; - - unsigned int VAO; - unsigned int VBO; - unsigned int EBO; - -Line(const vec3 position, const vec3 rotation, const vec3 scale, vector v, vector i); - - void generateImage(); - void draw(Shader s); - mat4 translationMatrix(); - mat4 rotationMatrix(); - mat4 scaleMatrix(); - mat4 modelMatrix(); -}; - -#endif - diff --git a/include/object.hpp b/include/object.hpp index 72aa1cf..2e68fc8 100644 --- a/include/object.hpp +++ b/include/object.hpp @@ -6,7 +6,6 @@ #include #include -#include #include @@ -31,6 +30,7 @@ public: vec3 scale; vector vertexData; + vector indexData; vector vertices; vector 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 v, vector 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); diff --git a/include/renderer.hpp b/include/renderer.hpp new file mode 100644 index 0000000..6bf3686 --- /dev/null +++ b/include/renderer.hpp @@ -0,0 +1,13 @@ +#ifndef RENDERER_H +#define RENDERER_H + +#include "object.hpp" + +class Renderer { +public: + + +}; + +#endif + diff --git a/src/line.cpp b/src/line.cpp deleted file mode 100644 index 85f346e..0000000 --- a/src/line.cpp +++ /dev/null @@ -1,110 +0,0 @@ -#include -#include -#include -#include - -#include -#include -#include - -#include - -using std::vector; -using glm::vec3; -using glm::mat4; - -Line::Line(const vec3 p, const vec3 r, const vec3 s, vector v, vector 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(); -} - diff --git a/src/main.cpp b/src/main.cpp index 77d5bc2..d3f0063 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,7 +10,6 @@ #include #include -#include using glm::vec2; using glm::vec3; @@ -223,8 +222,8 @@ void processInput(GLFWwindow *window) void createShaderProgram() { - shader = Shader("/Users/rochesterx/Documents/Programming/OpenGL/src/shaders/vertex.glsl", "/Users/rochesterx/Documents/Programming/OpenGL/src/shaders/fragment.glsl"); - gridShader = Shader("/Users/rochesterx/Documents/Programming/OpenGL/src/shaders/gridvertex.glsl", "/Users/rochesterx/Documents/Programming/OpenGL/src/shaders/gridfragment.glsl"); + shader = Shader("src/shaders/vertex.glsl", "src/shaders/fragment.glsl"); + gridShader = Shader("src/shaders/gridvertex.glsl", "src/shaders/gridfragment.glsl"); shader.use(); } @@ -277,8 +276,8 @@ void init() createShaderProgram(); - Texture texture("assets/container.jpg"); - Texture texture2("assets/awesomeface.png"); + //Texture texture("assets/container.jpg"); + //Texture texture2("assets/awesomeface.png"); //Object cube(vec3(0, 0, 0), vec3(0, 0, 0), vec3(1, 1, 1), vertices, indices, texture); objects = { //Object(vec3(0, 0, 0), vec3(0, 0, 0), vec3(3, 3, 3), "assets/dragon.obj"), diff --git a/src/shaders/fragment.glsl b/src/shaders/fragment.glsl index 68633a4..5136335 100644 --- a/src/shaders/fragment.glsl +++ b/src/shaders/fragment.glsl @@ -37,6 +37,7 @@ void main() vec3 result = (ambient + diffuse + specular) * objectColor; FragColor = vec4(result, 1.0); + //FragColor = vec4(vec3(gl_FragCoord.z), 1.0); //FragColor = vec4(ourColor * gl_FragCoord.w, 1); }