Compare commits
2 Commits
3f0224ac2d
...
430b1fb364
| Author | SHA1 | Date | |
|---|---|---|---|
| 430b1fb364 | |||
| f3cf6c3798 |
1023
assets/models/a.obj
Normal file
1023
assets/models/a.obj
Normal file
File diff suppressed because it is too large
Load Diff
34
assets/models/b.obj
Normal file
34
assets/models/b.obj
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
# Vertices
|
||||||
|
v -0.500000 -0.500000 -0.500000
|
||||||
|
v 0.500000 -0.500000 -0.500000
|
||||||
|
v 0.500000 0.500000 -0.500000
|
||||||
|
v -0.500000 0.500000 -0.500000
|
||||||
|
v -0.500000 -0.500000 0.500000
|
||||||
|
v 0.500000 -0.500000 0.500000
|
||||||
|
v 0.500000 0.500000 0.500000
|
||||||
|
v -0.500000 0.500000 0.500000
|
||||||
|
|
||||||
|
# Texture Coordinates
|
||||||
|
vt 0.000000 0.000000
|
||||||
|
vt 1.000000 0.000000
|
||||||
|
vt 1.000000 1.000000
|
||||||
|
vt 0.000000 1.000000
|
||||||
|
|
||||||
|
# Faces
|
||||||
|
f 1/1 2/2 3/3
|
||||||
|
f 3/3 4/4 1/1
|
||||||
|
|
||||||
|
f 5/1 6/2 7/3
|
||||||
|
f 7/3 8/4 5/1
|
||||||
|
|
||||||
|
f 8/2 4/3 1/4
|
||||||
|
f 1/4 5/1 8/2
|
||||||
|
|
||||||
|
f 7/2 6/3 2/4
|
||||||
|
f 2/4 3/1 7/2
|
||||||
|
|
||||||
|
f 1/4 2/3 6/2
|
||||||
|
f 6/2 5/1 1/4
|
||||||
|
|
||||||
|
f 4/4 3/3 7/2
|
||||||
|
f 7/2 8/1 4/4
|
||||||
16743
assets/models/robot.obj
Normal file
16743
assets/models/robot.obj
Normal file
File diff suppressed because it is too large
Load Diff
26074
assets/models/teapot_n_glass.obj
Normal file
26074
assets/models/teapot_n_glass.obj
Normal file
File diff suppressed because it is too large
Load Diff
@ -6,6 +6,6 @@ uniform sampler2D ourTexture;
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
//FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);
|
FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);
|
||||||
FragColor = texture(ourTexture, TexCoord);
|
//FragColor = texture(ourTexture, TexCoord);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#ifndef _MESH3D
|
#ifndef _MESH3D
|
||||||
#define _MESH3D
|
#define _MESH3D
|
||||||
|
|
||||||
|
#include "Texture2D.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@ -8,10 +9,14 @@ namespace djalim {
|
|||||||
|
|
||||||
class Mesh3D {
|
class Mesh3D {
|
||||||
public:
|
public:
|
||||||
// Constructor
|
Mesh3D();
|
||||||
Mesh3D(const std::string& filepath);
|
Mesh3D(const std::string& filepath);
|
||||||
std::vector<float> meshVertices;
|
std::vector<float> meshVertices;
|
||||||
|
int numMeshVertices = 0;
|
||||||
void loadOBJFile(const std::string& filepath);
|
void loadOBJFile(const std::string& filepath);
|
||||||
|
Texture2D texture;
|
||||||
|
GLuint VBO;
|
||||||
|
GLuint VAO;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,8 +6,10 @@
|
|||||||
#include "ShaderProgram.h"
|
#include "ShaderProgram.h"
|
||||||
#include "Texture2D.h"
|
#include "Texture2D.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "Mesh3D.h"
|
||||||
|
|
||||||
#define NBCALLBACKS 1
|
#define NBCALLBACKS 1
|
||||||
|
|
||||||
@ -19,7 +21,7 @@ struct Object3D {
|
|||||||
GLuint VAO;
|
GLuint VAO;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::map<std::string,Object3D> Objects3D;
|
typedef std::map<std::string,djalim::Mesh3D> Objects3D;
|
||||||
|
|
||||||
static bool gWireframe = false;
|
static bool gWireframe = false;
|
||||||
|
|
||||||
@ -37,7 +39,6 @@ namespace djalim {
|
|||||||
double previousSeconds = 0.0;
|
double previousSeconds = 0.0;
|
||||||
double elapsedSeconds;
|
double elapsedSeconds;
|
||||||
int frameCount = 0;
|
int frameCount = 0;
|
||||||
std::map<std::string,Texture2D> textures;
|
|
||||||
ShaderProgram shaderProgram;
|
ShaderProgram shaderProgram;
|
||||||
|
|
||||||
Objects3D objects;
|
Objects3D objects;
|
||||||
@ -49,7 +50,7 @@ namespace djalim {
|
|||||||
|
|
||||||
void onUpdate();
|
void onUpdate();
|
||||||
void loadHints();
|
void loadHints();
|
||||||
void createObject(std::string name, std::string textures, std::vector<float>& vertices);
|
void createObject(std::string name, std::string textures, std::string filepath);
|
||||||
void loadCallbacks();
|
void loadCallbacks();
|
||||||
void showFps();
|
void showFps();
|
||||||
void onCreate();
|
void onCreate();
|
||||||
|
|||||||
@ -25,6 +25,8 @@ struct objFace {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
djalim::Mesh3D::Mesh3D(){}
|
||||||
|
|
||||||
djalim::Mesh3D::Mesh3D(const std::string& filepath) {
|
djalim::Mesh3D::Mesh3D(const std::string& filepath) {
|
||||||
loadOBJFile(filepath);
|
loadOBJFile(filepath);
|
||||||
}
|
}
|
||||||
@ -54,6 +56,7 @@ void djalim::Mesh3D::loadOBJFile(const std::string& filepath){
|
|||||||
//std::cout << "found vertice: (" << x << ", " << y << ", " << z << ")" << std::endl;
|
//std::cout << "found vertice: (" << x << ", " << y << ", " << z << ")" << std::endl;
|
||||||
objVertex v = {x, y, z};
|
objVertex v = {x, y, z};
|
||||||
vertices.push_back(v);
|
vertices.push_back(v);
|
||||||
|
numMeshVertices++;
|
||||||
}
|
}
|
||||||
else if (type == "vn"){
|
else if (type == "vn"){
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
@ -70,8 +73,8 @@ void djalim::Mesh3D::loadOBJFile(const std::string& filepath){
|
|||||||
vertexTexture.push_back(vt);
|
vertexTexture.push_back(vt);
|
||||||
}
|
}
|
||||||
else if (type == "f"){
|
else if (type == "f"){
|
||||||
std::cout << "found face" << std::endl;
|
// std::cout << "found face" << std::endl;
|
||||||
std::cout << ss.str() << std::endl;
|
// std::cout << ss.str() << std::endl;
|
||||||
objFace face;
|
objFace face;
|
||||||
// TODO Find a more elegant way to do this
|
// TODO Find a more elegant way to do this
|
||||||
for (int i = 0; i < 3; i++){
|
for (int i = 0; i < 3; i++){
|
||||||
|
|||||||
@ -21,8 +21,8 @@ bool Texture2D::loadTexture(const std::string& filename, bool generateMipmaps) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Texture loaded successfully: " << filename << std::endl;
|
//std::cout << "Texture loaded successfully: " << filename << std::endl;
|
||||||
std::cout << "Width: " << width << ", Height: " << height << ", Components: " << components << std::endl;
|
//std::cout << "Width: " << width << ", Height: " << height << ", Components: " << components << std::endl;
|
||||||
|
|
||||||
glGenTextures(1, &mTexture);
|
glGenTextures(1, &mTexture);
|
||||||
glBindTexture(GL_TEXTURE_2D, mTexture);
|
glBindTexture(GL_TEXTURE_2D, mTexture);
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
|
#include "Mesh3D.h"
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -41,11 +42,14 @@ djalim::OpenGlEngine::OpenGlEngine(const char* title, int width, int height) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void djalim::OpenGlEngine::createObject(std::string name, std::string textures, std::vector<float>& vertices){
|
void djalim::OpenGlEngine::createObject(std::string name, std::string textures, std::string filepath){
|
||||||
|
|
||||||
objects[name];
|
|
||||||
|
Mesh3D obj = Mesh3D(filepath);
|
||||||
|
|
||||||
|
objects[name] = obj;
|
||||||
|
|
||||||
bool textureLoaded = objects[name].texture.loadTexture(textures);
|
bool textureLoaded = obj.texture.loadTexture(textures);
|
||||||
|
|
||||||
if (!textureLoaded) {
|
if (!textureLoaded) {
|
||||||
std::cerr << "Failed to load " << name << " texture!" << std::endl;
|
std::cerr << "Failed to load " << name << " texture!" << std::endl;
|
||||||
@ -64,10 +68,8 @@ void djalim::OpenGlEngine::createObject(std::string name, std::string textures,
|
|||||||
|
|
||||||
//glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
//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);
|
||||||
std::cout << "Loading 3D objects with "<< vertices.size() << " vertices"<< std::endl;
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*vertices.size(), vertices.data(), GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
// Attribut de position
|
// Attribut de position
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
|
||||||
|
|||||||
@ -49,7 +49,7 @@ void djalim::cube(GLFWwindow* window, djalim::ShaderProgram shader, Objects3D& o
|
|||||||
shader.setUniform("projection", projection); // Assurez-vous que setUniform pour mat4 est implémenté
|
shader.setUniform("projection", projection); // Assurez-vous que setUniform pour mat4 est implémenté
|
||||||
|
|
||||||
// Matrice de Vue
|
// Matrice de Vue
|
||||||
glm::mat4 view = glm::lookAt(glm::vec3(0.0f, 0.0f, 3.0f), // Position caméra
|
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::vec3(0.0f, 0.0f, 0.0f), // Cible
|
||||||
glm::vec3(0.0f, 1.0f, 0.0f)); // Axe Haut
|
glm::vec3(0.0f, 1.0f, 0.0f)); // Axe Haut
|
||||||
shader.setUniform("view", view);
|
shader.setUniform("view", view);
|
||||||
@ -61,7 +61,7 @@ void djalim::cube(GLFWwindow* window, djalim::ShaderProgram shader, Objects3D& o
|
|||||||
|
|
||||||
// Dessiner le cube
|
// Dessiner le cube
|
||||||
glBindVertexArray(objects["cube"].VAO);
|
glBindVertexArray(objects["cube"].VAO);
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
glDrawArrays(GL_TRIANGLES, 0, objects["cube"].numMeshVertices*3);
|
||||||
|
|
||||||
//std::cout << objects["cube"].VAO << std::endl;
|
//std::cout << objects["cube"].VAO << std::endl;
|
||||||
|
|
||||||
|
|||||||
@ -4,8 +4,7 @@
|
|||||||
#include "Mesh3D.h"
|
#include "Mesh3D.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
//djalim::OpenGlEngine engine = djalim::OpenGlEngine("Mon app", 800, 600);
|
djalim::OpenGlEngine engine = djalim::OpenGlEngine("Mon app", 800, 600);
|
||||||
//engine.start();
|
engine.start();
|
||||||
djalim::Mesh3D mesh = djalim::Mesh3D("../assets/models/UTAH_BLEND.obj");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -48,7 +48,7 @@ void djalim::OpenGlEngine::onCreate(){
|
|||||||
};
|
};
|
||||||
|
|
||||||
stbi_set_flip_vertically_on_load(true);
|
stbi_set_flip_vertically_on_load(true);
|
||||||
createObject("cube", "../assets/textures/prof.png", vertices);
|
createObject("cube", "../assets/textures/prof.png", "../assets/models/UTAH_BLEND.obj");
|
||||||
|
|
||||||
// textures["cube"] = Texture2D();
|
// textures["cube"] = Texture2D();
|
||||||
// bool textureLoaded = textures["cube"].loadTexture("../assets/textures/prof.png");
|
// bool textureLoaded = textures["cube"].loadTexture("../assets/textures/prof.png");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user