Improve material loading and add coordinate system model

This commit is contained in:
2020-03-26 22:57:08 +01:00
parent 4893a36197
commit 251adef6b5
16 changed files with 308 additions and 47 deletions

View File

@@ -0,0 +1,47 @@
#ifndef MATERIAL_H
#define MATERIAL_H
#include <opengl-playground/opengltexture.hpp>
#include <memory>
#include <vector>
#include <glm/glm.hpp>
class Material
{
public:
Material();
Material(std::shared_ptr<OpenGlTexture> diffuse_texture,
std::shared_ptr<OpenGlTexture> ambient_texture,
std::shared_ptr<OpenGlTexture> specular_texture);
Material(const glm::vec3 &diff_color, const glm::vec3 &ambient_color, const glm::vec3 &specular_color);
void setSpecularColor(const glm::vec3 &color);
void setAmbientColor(const glm::vec3 &color);
void setDiffuseColor(const glm::vec3 &color);
void pushSpecularTexture(std::shared_ptr<OpenGlTexture> texture);
void pushAmbientTexture(std::shared_ptr<OpenGlTexture> texture);
void pushDiffuseTexture(std::shared_ptr<OpenGlTexture> texture);
void pushSpecularTexture(const std::vector<std::shared_ptr<OpenGlTexture>> &textures);
void pushAmbientTexture(const std::vector<std::shared_ptr<OpenGlTexture>> &textures);
void pushDiffuseTexture(const std::vector<std::shared_ptr<OpenGlTexture>> &textures);
const std::vector<std::shared_ptr<OpenGlTexture>> &getSpecularTextures();
const std::vector<std::shared_ptr<OpenGlTexture>> &getAmbientTextures();
const std::vector<std::shared_ptr<OpenGlTexture>> &getDiffuseTextures();
const glm::vec3 &getDiffuseColor();
const glm::vec3 &getAmbientColor();
const glm::vec3 &getSpecularColor();
float shininess_strength;
float shininess;
private:
std::vector<std::shared_ptr<OpenGlTexture>> diffuse_textures;
std::vector<std::shared_ptr<OpenGlTexture>> ambient_textures;
std::vector<std::shared_ptr<OpenGlTexture>> specular_textures;
glm::vec3 diff_color;
glm::vec3 ambient_color;
glm::vec3 specular_color;
};
#endif // MATERIAL_H

View File

@@ -6,16 +6,17 @@
#include <opengl-playground/vertex.hpp>
#include <opengl-playground/opengltexture.hpp>
#include <opengl-playground/openglgraphics.hpp>
#include <opengl-playground/material.hpp>
class Mesh : public OpenGlGraphics
{
public:
Mesh(std::vector<Vertex> vertices, std::vector<unsigned int> indices,
std::vector<std::shared_ptr<OpenGlTexture>> textures,
const Material &mat,
std::shared_ptr<OpenGlShaderProgram> shader);
std::vector<Vertex> vertices;
std::vector<unsigned int> indices;
std::vector<std::shared_ptr<OpenGlTexture>> textures;
Material material;
void realize();
void render();
void render(const glm::mat4 &model_matrix, const glm::mat4 &normal_matrix);

View File

@@ -22,7 +22,7 @@ class Model : public OpenGlGraphics
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);
std::vector<std::shared_ptr<OpenGlTexture>> loadMaterialTextures(aiMaterial *mat, aiTextureType type);
void processNode(aiNode *node, const aiScene *scene);
Mesh processMesh(aiMesh *mesh, const aiScene *scene);
};

View File

@@ -22,6 +22,7 @@ class OpenGlShaderProgram
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);
void setUniformBool(const std::string &uniform, bool value);
private:
bool compiled;
GLuint shader_program;

View File

@@ -4,12 +4,10 @@
#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(const std::string &texture_path);
OpenGlTexture();
OpenGlTexture(const OpenGlTexture &tex) = delete;
OpenGlTexture(const OpenGlTexture &&tex) = delete;
@@ -19,12 +17,10 @@ class OpenGlTexture
void use(unsigned int slot);
void use();
const std::string &getPath();
TextureType getType();
float blend;
private:
std::string texture_path;
TextureType type;
protected:
GLuint texture;