[EDIT] code style guide - renderengine
This commit is contained in:
16
src/main.cpp
16
src/main.cpp
@@ -6,10 +6,10 @@
|
|||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
#include "models/Model.h"
|
#include "models/Model.h"
|
||||||
#include "renderEngine/Loader.h"
|
#include "renderEngine/loader.h"
|
||||||
#include "renderEngine/ObjLoader.h"
|
#include "renderEngine/obj_loader.h"
|
||||||
#include "renderEngine/Renderer.h"
|
#include "renderEngine/Renderer.h"
|
||||||
#include "shaders/StaticShader.h"
|
#include "shaders/static_shader.h"
|
||||||
#include "toolbox/math.h"
|
#include "toolbox/math.h"
|
||||||
|
|
||||||
#pragma comment(lib, "glfw3.lib")
|
#pragma comment(lib, "glfw3.lib")
|
||||||
@@ -45,13 +45,13 @@ int main(void)
|
|||||||
|
|
||||||
|
|
||||||
models::RawModel raw_model = LoadObjModel("res/Tree.obj");
|
models::RawModel raw_model = LoadObjModel("res/Tree.obj");
|
||||||
models::ModelTexture texture = { renderEngine::loader::LoadTexture("res/TreeTexture.png") };
|
models::ModelTexture texture = { render_engine::loader::LoadTexture("res/TreeTexture.png") };
|
||||||
models::TexturedModel model = { raw_model, texture };
|
models::TexturedModel model = { raw_model, texture };
|
||||||
entities::Entity entity(model, glm::vec3(0, -5, -20), glm::vec3(0, 0, 0), 1);
|
entities::Entity entity(model, glm::vec3(0, -5, -20), glm::vec3(0, 0, 0), 1);
|
||||||
|
|
||||||
shaders::StaticShader shader;
|
shaders::StaticShader shader;
|
||||||
shader.Init();
|
shader.Init();
|
||||||
renderEngine::renderer::Init(shader);
|
render_engine::renderer::Init(shader);
|
||||||
|
|
||||||
entities::Camera camera(glm::vec3(0, 0, 0), glm::vec3(0, 0, 0));
|
entities::Camera camera(glm::vec3(0, 0, 0), glm::vec3(0, 0, 0));
|
||||||
|
|
||||||
@@ -64,11 +64,11 @@ int main(void)
|
|||||||
camera.move(window);
|
camera.move(window);
|
||||||
|
|
||||||
// Render
|
// Render
|
||||||
renderEngine::renderer::Prepare();
|
render_engine::renderer::Prepare();
|
||||||
shader.Start();
|
shader.Start();
|
||||||
shader.LoadViewMatrix(camera);
|
shader.LoadViewMatrix(camera);
|
||||||
|
|
||||||
renderEngine::renderer::Render(entity, shader);
|
render_engine::renderer::Render(entity, shader);
|
||||||
|
|
||||||
// Finish up
|
// Finish up
|
||||||
shader.Stop();
|
shader.Stop();
|
||||||
@@ -78,7 +78,7 @@ int main(void)
|
|||||||
|
|
||||||
// Clean up
|
// Clean up
|
||||||
shader.CleanUp();
|
shader.CleanUp();
|
||||||
renderEngine::loader::CleanUp();
|
render_engine::loader::CleanUp();
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include "../stb_image.h"
|
#include "../stb_image.h"
|
||||||
#include "Loader.h"
|
#include "loader.h"
|
||||||
|
|
||||||
namespace renderEngine
|
namespace render_engine
|
||||||
{
|
{
|
||||||
namespace loader
|
namespace loader
|
||||||
{
|
{
|
||||||
static GLuint createVAO();
|
static GLuint create_vao();
|
||||||
static void storeDataInAttributeList(int attributeNumber, int coordinateSize, std::vector<float>& data);
|
static void store_data_in_attribute_list(int attribute_number, int coordinate_size, std::vector<float>& data);
|
||||||
static void bindIndicesBuffer(std::vector<unsigned int>& indices);
|
static void bind_indices_buffer(std::vector<unsigned int>& indices);
|
||||||
|
|
||||||
static std::vector<GLuint> vaos;
|
static std::vector<GLuint> vaos;
|
||||||
static std::vector<GLuint> vbos;
|
static std::vector<GLuint> vbos;
|
||||||
@@ -17,35 +17,35 @@ namespace renderEngine
|
|||||||
/*
|
/*
|
||||||
This function will generate a Model from vertex positions, textureCoordinates and indices.
|
This function will generate a Model from vertex positions, textureCoordinates and indices.
|
||||||
*/
|
*/
|
||||||
struct models::RawModel LoadToVAO(std::vector<float>& positions, std::vector<float>& textureCoords, std::vector<unsigned int>& indices)
|
struct models::RawModel LoadToVAO(std::vector<float>& positions, std::vector<float>& texture_coords, std::vector<unsigned int>& indices)
|
||||||
{
|
{
|
||||||
GLuint vaoID = createVAO();
|
GLuint vao_id = create_vao();
|
||||||
bindIndicesBuffer(indices);
|
bind_indices_buffer(indices);
|
||||||
storeDataInAttributeList(0, 3, positions);
|
store_data_in_attribute_list(0, 3, positions);
|
||||||
storeDataInAttributeList(1, 2, textureCoords);
|
store_data_in_attribute_list(1, 2, texture_coords);
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
return { vaoID, static_cast<int>(indices.size()) };
|
return { vao_id, static_cast<int>(indices.size()) };
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Loads an image as texture into openGL
|
Loads an image as texture into openGL
|
||||||
*/
|
*/
|
||||||
GLuint LoadTexture(std::string fileName)
|
GLuint LoadTexture(std::string file_name)
|
||||||
{
|
{
|
||||||
int width, height, bpp;
|
int width, height, bpp;
|
||||||
unsigned char* imgData = stbi_load(fileName.c_str(), &width, &height, &bpp, 4);
|
unsigned char* imgData = stbi_load(file_name.c_str(), &width, &height, &bpp, 4);
|
||||||
|
|
||||||
GLuint textureID;
|
GLuint texture_id;
|
||||||
glGenTextures(1, &textureID);
|
glGenTextures(1, &texture_id);
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
glBindTexture(GL_TEXTURE_2D, textureID);
|
glBindTexture(GL_TEXTURE_2D, texture_id);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imgData);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imgData);
|
||||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
|
||||||
stbi_image_free(imgData);
|
stbi_image_free(imgData);
|
||||||
textures.push_back(textureID);
|
textures.push_back(texture_id);
|
||||||
return textureID;
|
return texture_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -61,26 +61,26 @@ namespace renderEngine
|
|||||||
/*
|
/*
|
||||||
This function will create a new VAO for a new mesh.
|
This function will create a new VAO for a new mesh.
|
||||||
*/
|
*/
|
||||||
static GLuint createVAO()
|
static GLuint create_vao()
|
||||||
{
|
{
|
||||||
GLuint vaoID;
|
GLuint vao_id;
|
||||||
glGenVertexArrays(1, &vaoID);
|
glGenVertexArrays(1, &vao_id);
|
||||||
vaos.push_back(vaoID);
|
vaos.push_back(vao_id);
|
||||||
glBindVertexArray(vaoID);
|
glBindVertexArray(vao_id);
|
||||||
return vaoID;
|
return vao_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This function can store data (vbo) in a vao.
|
This function can store data (vbo) in a vao.
|
||||||
*/
|
*/
|
||||||
static void storeDataInAttributeList(int attributeNumber, int coordinateSize, std::vector<float>& data)
|
static void store_data_in_attribute_list(int attribute_number, int coordinate_size, std::vector<float>& data)
|
||||||
{
|
{
|
||||||
GLuint vboID;
|
GLuint vbo_id;
|
||||||
glGenBuffers(1, &vboID);
|
glGenBuffers(1, &vbo_id);
|
||||||
vbos.push_back(vboID);
|
vbos.push_back(vbo_id);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vboID);
|
glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * data.size(), &data[0], GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * data.size(), &data[0], GL_STATIC_DRAW);
|
||||||
glVertexAttribPointer(attributeNumber, coordinateSize, GL_FLOAT, GL_FALSE, 0, 0);
|
glVertexAttribPointer(attribute_number, coordinate_size, GL_FLOAT, GL_FALSE, 0, 0);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,12 +105,12 @@ namespace renderEngine
|
|||||||
3,1,2
|
3,1,2
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
static void bindIndicesBuffer(std::vector<unsigned int>& indices)
|
static void bind_indices_buffer(std::vector<unsigned int>& indices)
|
||||||
{
|
{
|
||||||
GLuint vboID;
|
GLuint vbo_id;
|
||||||
glGenBuffers(1, &vboID);
|
glGenBuffers(1, &vbo_id);
|
||||||
vbos.push_back(vboID);
|
vbos.push_back(vbo_id);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboID);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_id);
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(int) * indices.size(), &indices[0], GL_STATIC_DRAW);
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(int) * indices.size(), &indices[0], GL_STATIC_DRAW);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,19 +4,19 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include "../models/Model.h"
|
#include "../models/Model.h"
|
||||||
|
|
||||||
namespace renderEngine
|
namespace render_engine
|
||||||
{
|
{
|
||||||
namespace loader
|
namespace loader
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
This function generates a model from model data.
|
This function generates a model from model data.
|
||||||
*/
|
*/
|
||||||
struct models::RawModel LoadToVAO(std::vector<float>& positions, std::vector<float>& textureCoords, std::vector<unsigned int>& indices);
|
struct models::RawModel LoadToVAO(std::vector<float>& positions, std::vector<float>& texture_coords, std::vector<unsigned int>& indices);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Loads a texture from a file into openGL using stb_image.h
|
Loads a texture from a file into openGL using stb_image.h
|
||||||
*/
|
*/
|
||||||
GLuint LoadTexture(std::string fileName);
|
GLuint LoadTexture(std::string file_name);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Call this function when cleaning up all the meshes (when exiting the program).
|
Call this function when cleaning up all the meshes (when exiting the program).
|
||||||
|
|||||||
@@ -1,134 +0,0 @@
|
|||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
#include <sstream>
|
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
|
||||||
#include "Loader.h"
|
|
||||||
#include "ObjLoader.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Grotendeels van deze functies zijn gemaakt door:
|
|
||||||
* https://github.com/Hopson97/ThinMatrix-OpenGL-Engine/blob/master/Source/Render_Engine/OBJLoader.cpp
|
|
||||||
*/
|
|
||||||
|
|
||||||
static void split(const std::string& s, char delim, std::vector<std::string>& elems)
|
|
||||||
{
|
|
||||||
std::stringstream ss;
|
|
||||||
ss.str(s);
|
|
||||||
std::string item;
|
|
||||||
while (getline(ss, item, delim)) {
|
|
||||||
elems.push_back(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::vector<std::string> split(const std::string& s, char delim)
|
|
||||||
{
|
|
||||||
std::vector<std::string> elems;
|
|
||||||
split(s, delim, elems);
|
|
||||||
return elems;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void processVertex(const std::vector<std::string>& vertexData,
|
|
||||||
const std::vector<glm::vec3>& normals,
|
|
||||||
const std::vector<glm::vec2>& textures,
|
|
||||||
std::vector<GLuint>& indices,
|
|
||||||
std::vector<GLfloat>& textureArray,
|
|
||||||
std::vector<GLfloat>& normalArray)
|
|
||||||
{
|
|
||||||
GLuint currentVertexPointer = std::stoi(vertexData.at(0)) - 1;
|
|
||||||
indices.push_back(currentVertexPointer);
|
|
||||||
|
|
||||||
glm::vec2 currentTexture = textures.at(std::stoi(vertexData.at(1)) - 1);
|
|
||||||
textureArray[(currentVertexPointer * 2) % textureArray.size()] = currentTexture.x;
|
|
||||||
textureArray[(currentVertexPointer * 2 + 1) % textureArray.size()] = 1 - currentTexture.y;
|
|
||||||
|
|
||||||
glm::vec3 currentNorm = normals.at(std::stoi(vertexData.at(2)) - 1);
|
|
||||||
normalArray[currentVertexPointer * 3] = currentNorm.x;
|
|
||||||
normalArray[currentVertexPointer * 3 + 1] = currentNorm.y;
|
|
||||||
normalArray[currentVertexPointer * 3 + 2] = currentNorm.z;
|
|
||||||
}
|
|
||||||
|
|
||||||
models::RawModel LoadObjModel(std::string fileName)
|
|
||||||
{
|
|
||||||
std::ifstream inFile (fileName);
|
|
||||||
if ( !inFile.is_open() )
|
|
||||||
{
|
|
||||||
throw std::runtime_error ( "Could not open model file " + fileName + ".obj!" );
|
|
||||||
}
|
|
||||||
std::vector<glm::vec3> vertices;
|
|
||||||
std::vector<glm::vec3> normals;
|
|
||||||
std::vector<glm::vec2> textures;
|
|
||||||
std::vector<GLuint> indices;
|
|
||||||
std::vector<GLfloat> vertexArray;
|
|
||||||
std::vector<GLfloat> normalArray;
|
|
||||||
std::vector<GLfloat> textureArray;
|
|
||||||
std::string line;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
while (std::getline(inFile, line))
|
|
||||||
{
|
|
||||||
std::vector<std::string> splitline = split(line, ' ');
|
|
||||||
if (splitline.at(0) == "v")
|
|
||||||
{
|
|
||||||
glm::vec3 vertex;
|
|
||||||
vertex.x = std::stof(splitline.at(1));
|
|
||||||
vertex.y = std::stof(splitline.at(2));
|
|
||||||
vertex.z = std::stof(splitline.at(3));
|
|
||||||
vertices.push_back(vertex);
|
|
||||||
}
|
|
||||||
else if (splitline.at(0) == "vt")
|
|
||||||
{
|
|
||||||
glm::vec2 texture;
|
|
||||||
texture.x = std::stof(splitline.at(1));
|
|
||||||
texture.y = std::stof(splitline.at(2));
|
|
||||||
textures.push_back(texture);
|
|
||||||
}
|
|
||||||
else if (splitline.at(0) == "vn")
|
|
||||||
{
|
|
||||||
glm::vec3 normal;
|
|
||||||
normal.x = std::stof(splitline.at(1));
|
|
||||||
normal.y = std::stof(splitline.at(2));
|
|
||||||
normal.z = std::stof(splitline.at(3));
|
|
||||||
normals.push_back(normal);
|
|
||||||
}
|
|
||||||
else if (splitline.at(0) == "f")
|
|
||||||
{
|
|
||||||
normalArray = std::vector<GLfloat>(vertices.size() * 3);
|
|
||||||
textureArray = std::vector<GLfloat>(textures.size() * 2);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
std::vector<std::string> splitline = split(line, ' ');
|
|
||||||
std::vector<std::string> vertex1 = split(splitline.at(1), '/');
|
|
||||||
std::vector<std::string> vertex2 = split(splitline.at(2), '/');
|
|
||||||
std::vector<std::string> vertex3 = split(splitline.at(3), '/');
|
|
||||||
processVertex(vertex1, normals, textures, indices, textureArray, normalArray);
|
|
||||||
processVertex(vertex2, normals, textures, indices, textureArray, normalArray);
|
|
||||||
processVertex(vertex3, normals, textures, indices, textureArray, normalArray);
|
|
||||||
if (!std::getline(inFile, line))
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (const std::exception& e)
|
|
||||||
{
|
|
||||||
// Always go in here
|
|
||||||
}
|
|
||||||
|
|
||||||
inFile.close();
|
|
||||||
|
|
||||||
vertexArray = std::vector<GLfloat>( vertices.size() * 3 );
|
|
||||||
int p = 0;
|
|
||||||
for ( auto& vertex : vertices )
|
|
||||||
{
|
|
||||||
vertexArray[p++] = vertex.x;
|
|
||||||
vertexArray[p++] = vertex.y;
|
|
||||||
vertexArray[p++] = vertex.z;
|
|
||||||
}
|
|
||||||
|
|
||||||
return renderEngine::loader::LoadToVAO( vertexArray, textureArray, indices);
|
|
||||||
}
|
|
||||||
@@ -2,10 +2,10 @@
|
|||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "../models/Model.h"
|
#include "../models/Model.h"
|
||||||
#include "Renderer.h"
|
#include "renderer.h"
|
||||||
#include "../toolbox/math.h"
|
#include "../toolbox/math.h"
|
||||||
|
|
||||||
namespace renderEngine
|
namespace render_engine
|
||||||
{
|
{
|
||||||
namespace renderer
|
namespace renderer
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../entities/Entity.h"
|
#include "../entities/Entity.h"
|
||||||
#include "../shaders/StaticShader.h"
|
#include "../shaders/static_shader.h"
|
||||||
|
|
||||||
namespace renderEngine
|
namespace render_engine
|
||||||
{
|
{
|
||||||
namespace renderer
|
namespace renderer
|
||||||
{
|
{
|
||||||
|
|||||||
129
src/renderEngine/obj_loader.cpp
Normal file
129
src/renderEngine/obj_loader.cpp
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include <sstream>
|
||||||
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
#include "loader.h"
|
||||||
|
#include "obj_loader.h"
|
||||||
|
|
||||||
|
static void Split(const std::string& s, char delim, std::vector<std::string>& elems)
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss.str(s);
|
||||||
|
std::string item;
|
||||||
|
while (getline(ss, item, delim)) {
|
||||||
|
elems.push_back(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::vector<std::string> Split(const std::string& s, char delim)
|
||||||
|
{
|
||||||
|
std::vector<std::string> elems;
|
||||||
|
Split(s, delim, elems);
|
||||||
|
return elems;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ProcessVertex(const std::vector<std::string>& vertex_data,
|
||||||
|
const std::vector<glm::vec3>& normals,
|
||||||
|
const std::vector<glm::vec2>& textures,
|
||||||
|
std::vector<GLuint>& indices,
|
||||||
|
std::vector<GLfloat>& texture_array,
|
||||||
|
std::vector<GLfloat>& normal_array)
|
||||||
|
{
|
||||||
|
GLuint current_vertex_pointer = std::stoi(vertex_data.at(0)) - 1;
|
||||||
|
indices.push_back(current_vertex_pointer);
|
||||||
|
|
||||||
|
glm::vec2 current_texture = textures.at(std::stoi(vertex_data.at(1)) - 1);
|
||||||
|
texture_array[(current_vertex_pointer * 2) % texture_array.size()] = current_texture.x;
|
||||||
|
texture_array[(current_vertex_pointer * 2 + 1) % texture_array.size()] = 1 - current_texture.y;
|
||||||
|
|
||||||
|
glm::vec3 current_norm = normals.at(std::stoi(vertex_data.at(2)) - 1);
|
||||||
|
normal_array[current_vertex_pointer * 3] = current_norm.x;
|
||||||
|
normal_array[current_vertex_pointer * 3 + 1] = current_norm.y;
|
||||||
|
normal_array[current_vertex_pointer * 3 + 2] = current_norm.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
models::RawModel LoadObjModel(std::string file_name)
|
||||||
|
{
|
||||||
|
std::ifstream inFile (file_name);
|
||||||
|
if ( !inFile.is_open() )
|
||||||
|
{
|
||||||
|
throw std::runtime_error ( "Could not open model file " + file_name + ".obj!" );
|
||||||
|
}
|
||||||
|
std::vector<glm::vec3> vertices;
|
||||||
|
std::vector<glm::vec3> normals;
|
||||||
|
std::vector<glm::vec2> textures;
|
||||||
|
std::vector<GLuint> indices;
|
||||||
|
std::vector<GLfloat> vertex_array;
|
||||||
|
std::vector<GLfloat> normal_array;
|
||||||
|
std::vector<GLfloat> texture_array;
|
||||||
|
std::string line;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
while (std::getline(inFile, line))
|
||||||
|
{
|
||||||
|
std::vector<std::string> split_line = Split(line, ' ');
|
||||||
|
if (split_line.at(0) == "v")
|
||||||
|
{
|
||||||
|
glm::vec3 vertex;
|
||||||
|
vertex.x = std::stof(split_line.at(1));
|
||||||
|
vertex.y = std::stof(split_line.at(2));
|
||||||
|
vertex.z = std::stof(split_line.at(3));
|
||||||
|
vertices.push_back(vertex);
|
||||||
|
}
|
||||||
|
else if (split_line.at(0) == "vt")
|
||||||
|
{
|
||||||
|
glm::vec2 texture;
|
||||||
|
texture.x = std::stof(split_line.at(1));
|
||||||
|
texture.y = std::stof(split_line.at(2));
|
||||||
|
textures.push_back(texture);
|
||||||
|
}
|
||||||
|
else if (split_line.at(0) == "vn")
|
||||||
|
{
|
||||||
|
glm::vec3 normal;
|
||||||
|
normal.x = std::stof(split_line.at(1));
|
||||||
|
normal.y = std::stof(split_line.at(2));
|
||||||
|
normal.z = std::stof(split_line.at(3));
|
||||||
|
normals.push_back(normal);
|
||||||
|
}
|
||||||
|
else if (split_line.at(0) == "f")
|
||||||
|
{
|
||||||
|
normal_array = std::vector<GLfloat>(vertices.size() * 3);
|
||||||
|
texture_array = std::vector<GLfloat>(textures.size() * 2);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
std::vector<std::string> split = Split(line, ' ');
|
||||||
|
std::vector<std::string> vertex1 = Split(split.at(1), '/');
|
||||||
|
std::vector<std::string> vertex2 = Split(split.at(2), '/');
|
||||||
|
std::vector<std::string> vertex3 = Split(split.at(3), '/');
|
||||||
|
ProcessVertex(vertex1, normals, textures, indices, texture_array, normal_array);
|
||||||
|
ProcessVertex(vertex2, normals, textures, indices, texture_array, normal_array);
|
||||||
|
ProcessVertex(vertex3, normals, textures, indices, texture_array, normal_array);
|
||||||
|
if (!std::getline(inFile, line))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (const std::exception& e)
|
||||||
|
{
|
||||||
|
// Always go in here
|
||||||
|
}
|
||||||
|
|
||||||
|
inFile.close();
|
||||||
|
|
||||||
|
vertex_array = std::vector<GLfloat>( vertices.size() * 3 );
|
||||||
|
int p = 0;
|
||||||
|
for ( auto& vertex : vertices )
|
||||||
|
{
|
||||||
|
vertex_array[p++] = vertex.x;
|
||||||
|
vertex_array[p++] = vertex.y;
|
||||||
|
vertex_array[p++] = vertex.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
return render_engine::loader::LoadToVAO( vertex_array, texture_array, indices);
|
||||||
|
}
|
||||||
@@ -3,4 +3,4 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include "../models/Model.h"
|
#include "../models/Model.h"
|
||||||
|
|
||||||
models::RawModel LoadObjModel(std::string fileName);
|
models::RawModel LoadObjModel(std::string file_name);
|
||||||
@@ -1,11 +1,10 @@
|
|||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <GLFW/glfw3.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
#include "ShaderProgram.h"
|
#include "shader_program.h"
|
||||||
|
|
||||||
namespace shaders
|
namespace shaders
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "StaticShader.h"
|
#include "static_shader.h"
|
||||||
#include "../toolbox/math.h"
|
#include "../toolbox/math.h"
|
||||||
|
|
||||||
namespace shaders
|
namespace shaders
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
#include "ShaderProgram.h"
|
#include "shader_program.h"
|
||||||
#include "../entities/Camera.h"
|
#include "../entities/Camera.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -23,10 +23,10 @@
|
|||||||
<ClCompile Include="src\entities\Entity.cpp" />
|
<ClCompile Include="src\entities\Entity.cpp" />
|
||||||
<ClCompile Include="src\main.cpp" />
|
<ClCompile Include="src\main.cpp" />
|
||||||
<ClCompile Include="src\renderEngine\Loader.cpp" />
|
<ClCompile Include="src\renderEngine\Loader.cpp" />
|
||||||
<ClCompile Include="src\renderEngine\ObjLoader.cpp" />
|
<ClCompile Include="src\renderEngine\obj_loader.cpp" />
|
||||||
<ClCompile Include="src\renderEngine\Renderer.cpp" />
|
<ClCompile Include="src\renderEngine\Renderer.cpp" />
|
||||||
<ClCompile Include="src\shaders\ShaderProgram.cpp" />
|
<ClCompile Include="src\shaders\shader_program.cpp" />
|
||||||
<ClCompile Include="src\shaders\StaticShader.cpp" />
|
<ClCompile Include="src\shaders\static_shader.cpp" />
|
||||||
<ClCompile Include="src\toolbox\math.cpp" />
|
<ClCompile Include="src\toolbox\math.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -34,10 +34,10 @@
|
|||||||
<ClInclude Include="src\entities\Entity.h" />
|
<ClInclude Include="src\entities\Entity.h" />
|
||||||
<ClInclude Include="src\models\Model.h" />
|
<ClInclude Include="src\models\Model.h" />
|
||||||
<ClInclude Include="src\renderEngine\Loader.h" />
|
<ClInclude Include="src\renderEngine\Loader.h" />
|
||||||
<ClInclude Include="src\renderEngine\ObjLoader.h" />
|
<ClInclude Include="src\renderEngine\obj_loader.h" />
|
||||||
<ClInclude Include="src\renderEngine\Renderer.h" />
|
<ClInclude Include="src\renderEngine\Renderer.h" />
|
||||||
<ClInclude Include="src\shaders\ShaderProgram.h" />
|
<ClInclude Include="src\shaders\shader_program.h" />
|
||||||
<ClInclude Include="src\shaders\StaticShader.h" />
|
<ClInclude Include="src\shaders\static_shader.h" />
|
||||||
<ClInclude Include="src\stb_image.h" />
|
<ClInclude Include="src\stb_image.h" />
|
||||||
<ClInclude Include="src\toolbox\math.h" />
|
<ClInclude Include="src\toolbox\math.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -24,24 +24,24 @@
|
|||||||
<ClCompile Include="src\renderEngine\Loader.cpp">
|
<ClCompile Include="src\renderEngine\Loader.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="src\renderEngine\ObjLoader.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="src\renderEngine\Renderer.cpp">
|
<ClCompile Include="src\renderEngine\Renderer.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="src\shaders\ShaderProgram.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="src\shaders\StaticShader.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="src\main.cpp">
|
<ClCompile Include="src\main.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="src\toolbox\math.cpp">
|
<ClCompile Include="src\toolbox\math.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\shaders\shader_program.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\shaders\static_shader.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\renderEngine\obj_loader.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="src\entities\Camera.h">
|
<ClInclude Include="src\entities\Camera.h">
|
||||||
@@ -56,23 +56,23 @@
|
|||||||
<ClInclude Include="src\renderEngine\Loader.h">
|
<ClInclude Include="src\renderEngine\Loader.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="src\renderEngine\ObjLoader.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="src\renderEngine\Renderer.h">
|
<ClInclude Include="src\renderEngine\Renderer.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="src\shaders\ShaderProgram.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="src\shaders\StaticShader.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="src\stb_image.h">
|
<ClInclude Include="src\stb_image.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="src\toolbox\math.h">
|
<ClInclude Include="src\toolbox\math.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="src\shaders\shader_program.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="src\shaders\static_shader.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="src\renderEngine\obj_loader.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
Reference in New Issue
Block a user