diff --git a/src/core/Mesh3D.cpp b/src/core/Mesh3D.cpp index fe5ad61..9a037ae 100644 --- a/src/core/Mesh3D.cpp +++ b/src/core/Mesh3D.cpp @@ -86,6 +86,7 @@ void djalim::Mesh3D::loadOBJFile(const std::string& filepath){ face.vertices[i] = f; } faces.push_back(face); + numFaces++; } } // Pour chaque face diff --git a/src/core/engine.cpp b/src/core/engine.cpp index 093689c..70a393b 100644 --- a/src/core/engine.cpp +++ b/src/core/engine.cpp @@ -2,6 +2,8 @@ #include "Mesh3D.h" #include #include +#include +#include #include djalim::OpenGlEngine::OpenGlEngine(const char* title, int width, int height) { @@ -44,32 +46,33 @@ djalim::OpenGlEngine::OpenGlEngine(const char* title, int width, int height) { void djalim::OpenGlEngine::createObject(std::string name, std::string textures, std::string filepath){ - - Mesh3D obj = Mesh3D(filepath); - - objects[name] = obj; + // Load the mesh from the file + objects[name] = std::make_unique(Mesh3D(filepath)); - bool textureLoaded = obj.texture.loadTexture(textures); + bool textureLoaded = objects[name]->texture.loadTexture(textures); + + std::cout << &(objects[name]) << std::endl; if (!textureLoaded) { std::cerr << "Failed to load " << name << " texture!" << std::endl; exit(1); } + std::cout << "texture loaded" << std::endl; //glGenVertexArrays(1, &VAO); - glGenVertexArrays(1, &(objects[name].VAO)); + glGenVertexArrays(1, &(objects[name]->VAO)); //glGenBuffers(1, &VBO); - glGenBuffers(1, &(objects[name].VBO)); + glGenBuffers(1, &((objects[name])->VBO)); //glBindVertexArray(VAO); - glBindVertexArray(objects[name].VAO); + glBindVertexArray((objects[name])->VAO); //glBindBuffer(GL_ARRAY_BUFFER, VBO); - glBindBuffer(GL_ARRAY_BUFFER, objects[name].VBO); + glBindBuffer(GL_ARRAY_BUFFER, (objects[name])->VBO); - glBufferData(GL_ARRAY_BUFFER, sizeof(float)*obj.meshVertices.size(), obj.meshVertices.data(), GL_STATIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, sizeof(float)*(objects[name])->meshVertices.size(), (objects[name])->meshVertices.data(), GL_STATIC_DRAW); // Attribut de position glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0); diff --git a/src/loops/cube.cpp b/src/loops/cube.cpp index fb9df93..aed3eeb 100644 --- a/src/loops/cube.cpp +++ b/src/loops/cube.cpp @@ -9,39 +9,15 @@ #include #include -// void djalim::cube(GLFWwindow* window, djalim::ShaderProgram shader, GLuint VAO, std::map& textures){ -// -// shader.use(); -// shader.setUniform("ourTexture", 0); -// textures["cube"].bind(); -// -// // Matrice de Projection -// glm::mat4 projection = glm::perspective(glm::radians(45.0f), 800.0f / 600.0f, 0.1f, 100.0f); -// shader.setUniform("projection", projection); // Assurez-vous que setUniform pour mat4 est implémenté -// -// // Matrice de Vue -// glm::mat4 view = glm::lookAt(glm::vec3(0.0f, 0.0f, 3.0f), // Position caméra -// glm::vec3(0.0f, 0.0f, 0.0f), // Cible -// glm::vec3(0.0f, 1.0f, 0.0f)); // Axe Haut -// shader.setUniform("view", view); -// -// // Matrice Modèle -// glm::mat4 model = glm::mat4(1.0f); -// model = glm::rotate(model, (float)glfwGetTime() * glm::radians(50.0f), glm::vec3(0.5f, 1.0f, 0.0f)); -// shader.setUniform("model", model); -// -// // Dessiner le cube -// glBindVertexArray(VAO); -// glDrawArrays(GL_TRIANGLES, 0, 36); -// -// } void djalim::cube(GLFWwindow* window, djalim::ShaderProgram shader, Objects3D& objects){ shader.use(); shader.setUniform("ourTexture", 0); - objects["cube"].texture.bind(); + (objects["cube"])->texture.bind(); + + //std::cout << &(objects["cube"].texture) << std::endl; //textures["cube"].bind(); // Matrice de Projection @@ -49,19 +25,19 @@ void djalim::cube(GLFWwindow* window, djalim::ShaderProgram shader, Objects3D& o shader.setUniform("projection", projection); // Assurez-vous que setUniform pour mat4 est implémenté // Matrice de Vue - glm::mat4 view = glm::lookAt(glm::vec3(0.0f, 0.0f, 9.0f), // Position caméra - glm::vec3(0.0f, 0.0f, 0.0f), // Cible + glm::mat4 view = glm::lookAt(glm::vec3(0.0f, 0.0f, 11.0f), // Position caméra + glm::vec3(0.0f, 2.0f, 0.0f), // Cible glm::vec3(0.0f, 1.0f, 0.0f)); // Axe Haut shader.setUniform("view", view); // Matrice Modèle glm::mat4 model = glm::mat4(1.0f); - model = glm::rotate(model, (float)glfwGetTime() * glm::radians(50.0f), glm::vec3(0.5f, 1.0f, 0.0f)); + ///model = glm::rotate(model, (float)glfwGetTime() * glm::radians(50.0f), glm::vec3(0.5f, 1.0f, 0.0f)); shader.setUniform("model", model); // Dessiner le cube - glBindVertexArray(objects["cube"].VAO); - glDrawArrays(GL_TRIANGLES, 0, objects["cube"].numMeshVertices*3); + glBindVertexArray((objects["cube"])->VAO); + glDrawArrays(GL_TRIANGLES, 0, (objects["cube"])->numFaces * 3); //std::cout << objects["cube"].VAO << std::endl; diff --git a/src/main.cpp b/src/main.cpp index fc22cd8..428f29e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,10 +1,7 @@ -#define DEBUG true - #include "engine.h" -#include "Mesh3D.h" int main() { - djalim::OpenGlEngine engine = djalim::OpenGlEngine("Mon app", 800, 600); + djalim::OpenGlEngine engine = djalim::OpenGlEngine("Mon app", 1000, 1000); engine.start(); return 0; } diff --git a/src/onCreate.cpp b/src/onCreate.cpp index 2cfecbd..b3a6109 100644 --- a/src/onCreate.cpp +++ b/src/onCreate.cpp @@ -2,53 +2,10 @@ #include "Texture2D.h" void djalim::OpenGlEngine::onCreate(){ - glEnable(GL_DEPTH_TEST); - std::vector vertices { - -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, - 0.5f, -0.5f, -0.5f, 1.0f, 0.0f, - 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, - 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, - -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, - -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, - - -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, - 0.5f, -0.5f, 0.5f, 1.0f, 0.0f, - 0.5f, 0.5f, 0.5f, 1.0f, 1.0f, - 0.5f, 0.5f, 0.5f, 1.0f, 1.0f, - -0.5f, 0.5f, 0.5f, 0.0f, 1.0f, - -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, - - -0.5f, 0.5f, 0.5f, 1.0f, 0.0f, - -0.5f, 0.5f, -0.5f, 1.0f, 1.0f, - -0.5f, -0.5f, -0.5f, 0.0f, 1.0f, - -0.5f, -0.5f, -0.5f, 0.0f, 1.0f, - -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, - -0.5f, 0.5f, 0.5f, 1.0f, 0.0f, - - 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, - 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, - 0.5f, -0.5f, -0.5f, 0.0f, 1.0f, - 0.5f, -0.5f, -0.5f, 0.0f, 1.0f, - 0.5f, -0.5f, 0.5f, 0.0f, 0.0f, - 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, - - -0.5f, -0.5f, -0.5f, 0.0f, 1.0f, - 0.5f, -0.5f, -0.5f, 1.0f, 1.0f, - 0.5f, -0.5f, 0.5f, 1.0f, 0.0f, - 0.5f, -0.5f, 0.5f, 1.0f, 0.0f, - -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, - -0.5f, -0.5f, -0.5f, 0.0f, 1.0f, - - -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, - 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, - 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, - 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, - -0.5f, 0.5f, 0.5f, 0.0f, 0.0f, - -0.5f, 0.5f, -0.5f, 0.0f, 1.0f - }; + glEnable(GL_DEPTH_TEST); stbi_set_flip_vertically_on_load(true); - createObject("cube", "../assets/textures/prof.png", "../assets/models/UTAH_BLEND.obj"); + createObject("cube", "../assets/textures/robot_diffuse.jpg", "../assets/models/robot.obj"); // textures["cube"] = Texture2D(); // bool textureLoaded = textures["cube"].loadTexture("../assets/textures/prof.png"); diff --git a/src/onUpdate.cpp b/src/onUpdate.cpp index c0418da..6d4b1af 100644 --- a/src/onUpdate.cpp +++ b/src/onUpdate.cpp @@ -1,10 +1,10 @@ #include "engine.h" #include #include "loops.h" +#include void djalim::OpenGlEngine::onUpdate(){ - showFps(); - + showFps(); cube(window,shaderProgram,objects); }