Add model loading and simple phong color shading
This commit is contained in:
@@ -11,11 +11,14 @@ class GlobalCanvasSettings
|
||||
static const glm::mat4 &getViewMatrix();
|
||||
static const glm::mat4 &getProjectionMatrix();
|
||||
static const glm::mat4 &getPVMatrix();
|
||||
static const glm::vec3 &getCameraPosition();
|
||||
static void setCameraPosition(const glm::vec3 &cam_pos);
|
||||
private:
|
||||
static void calculatePVMatrix();
|
||||
static glm::mat4 m_proj;
|
||||
static glm::mat4 m_view;
|
||||
static glm::mat4 m_proj_view;
|
||||
static glm::vec3 m_cam_pos;
|
||||
};
|
||||
|
||||
#endif // GLOBALCANVASSETTINGS_H
|
||||
|
28
include/opengl-playground/mesh.hpp
Normal file
28
include/opengl-playground/mesh.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef MESH_H
|
||||
#define MESH_H
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <vector>
|
||||
#include <opengl-playground/vertex.hpp>
|
||||
#include <opengl-playground/opengltexture.hpp>
|
||||
#include <opengl-playground/openglgraphics.hpp>
|
||||
|
||||
class Mesh : public OpenGlGraphics
|
||||
{
|
||||
public:
|
||||
Mesh(std::vector<Vertex> vertices, std::vector<unsigned int> indices,
|
||||
std::vector<std::shared_ptr<OpenGlTexture>> textures,
|
||||
std::shared_ptr<OpenGlShaderProgram> shader);
|
||||
std::vector<Vertex> vertices;
|
||||
std::vector<unsigned int> indices;
|
||||
std::vector<std::shared_ptr<OpenGlTexture>> textures;
|
||||
void realize();
|
||||
void render();
|
||||
void render(const glm::mat4 &model_matrix, const glm::mat4 &normal_matrix);
|
||||
private:
|
||||
unsigned int vao;
|
||||
unsigned int vbo;
|
||||
unsigned int ebo;
|
||||
};
|
||||
|
||||
#endif // MESH_H
|
30
include/opengl-playground/model.hpp
Normal file
30
include/opengl-playground/model.hpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef MODEL_H
|
||||
#define MODEL_H
|
||||
|
||||
#include <opengl-playground/openglgraphics.hpp>
|
||||
#include <opengl-playground/mesh.hpp>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/postprocess.h>
|
||||
|
||||
class Model : public OpenGlGraphics
|
||||
{
|
||||
public:
|
||||
Model(const std::string &path, const glm::vec4 &static_color, std::shared_ptr<OpenGlShaderProgram> shader);
|
||||
void render();
|
||||
void realize();
|
||||
private:
|
||||
std::string model_path;
|
||||
glm::vec4 static_color;
|
||||
/* Model Data */
|
||||
std::vector<Mesh> meshes;
|
||||
std::vector<std::shared_ptr<OpenGlTexture>> allocated_textures;
|
||||
std::string directory;
|
||||
std::vector<std::shared_ptr<OpenGlTexture>> loadMaterialTextures(aiMaterial *mat, aiTextureType type, TextureType tex_type);
|
||||
void processNode(aiNode *node, const aiScene *scene);
|
||||
Mesh processMesh(aiMesh *mesh, const aiScene *scene);
|
||||
};
|
||||
|
||||
#endif // MODEL_H
|
@@ -16,9 +16,11 @@ class OpenGlGraphics
|
||||
virtual void render() = 0;
|
||||
void setModelMatrix(const glm::mat4 &model_matrix);
|
||||
glm::mat4 getModelMatrix();
|
||||
glm::mat4 getNormalMatrix();
|
||||
protected:
|
||||
std::shared_ptr<OpenGlShaderProgram> shaderprog;
|
||||
glm::mat4 model_matrix;
|
||||
glm::mat4 normal_matrix;
|
||||
};
|
||||
|
||||
#endif // OPENGLGRAPHICS_H
|
||||
|
@@ -19,6 +19,7 @@ class OpenGlShaderProgram
|
||||
void setUniformFloat(const std::string &uniform, float value);
|
||||
void setUniformInt(const std::string &uniform, int value);
|
||||
void setUniformVec2(const std::string &uniform, float *vector);
|
||||
void setUniformVec3(const std::string &uniform, const glm::vec3 &vector);
|
||||
void setUniformMat4(const std::string &uniform, const glm::mat4 &matrix);
|
||||
void setUniformVec4(const std::string &uniform, const glm::vec4 &vector);
|
||||
private:
|
||||
|
@@ -2,17 +2,28 @@
|
||||
#define OPENGLTEXTURE_HPP
|
||||
|
||||
#include <epoxy/gl.h>
|
||||
#include <string>
|
||||
|
||||
typedef enum {TEXTURE_DIFFUSE, TEXTURE_SPECULAR} TextureType;
|
||||
|
||||
class OpenGlTexture
|
||||
{
|
||||
public:
|
||||
OpenGlTexture(TextureType type, const std::string &texture_path);
|
||||
OpenGlTexture();
|
||||
OpenGlTexture(const OpenGlTexture &tex) = delete;
|
||||
OpenGlTexture(const OpenGlTexture &&tex) = delete;
|
||||
~OpenGlTexture();
|
||||
void setRGBDataFromBytes(unsigned int width, unsigned int height, char *buffer);
|
||||
void loadFromImagePath(const std::string &base_directory);
|
||||
void use(unsigned int slot);
|
||||
void use();
|
||||
const std::string &getPath();
|
||||
TextureType getType();
|
||||
|
||||
private:
|
||||
std::string texture_path;
|
||||
TextureType type;
|
||||
|
||||
protected:
|
||||
GLuint texture;
|
||||
|
13
include/opengl-playground/vertex.hpp
Normal file
13
include/opengl-playground/vertex.hpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef VERTEX_H
|
||||
#define VERTEX_H
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
struct Vertex
|
||||
{
|
||||
glm::vec3 Position;
|
||||
glm::vec3 Normal;
|
||||
glm::vec2 TextureCoords;
|
||||
};
|
||||
|
||||
#endif // VERTEX_H
|
7656
include/stb/stb_image.h
Normal file
7656
include/stb/stb_image.h
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user