From d9f9b0c2824fce772467f1bfe792134538f7fefe Mon Sep 17 00:00:00 2001 From: devZoGok Date: Wed, 18 Dec 2019 12:26:15 +0200 Subject: [PATCH] implemented material texture changing --- gui.vert | 10 ---------- material.h | 17 +++++++++++------ mesh.cpp | 1 - mesh.h | 2 +- quad.cpp | 3 +-- quad.h | 2 +- texture.h | 2 ++ 7 files changed, 16 insertions(+), 21 deletions(-) diff --git a/gui.vert b/gui.vert index 50d31a2..7312e2e 100755 --- a/gui.vert +++ b/gui.vert @@ -5,23 +5,13 @@ layout (location=2) in vec2 aTexCoords; out vec2 texCoords; -uniform bool spatialToScreen; uniform vec2 screen; uniform vec3 pos; -uniform mat4 proj; -uniform mat4 view; -uniform mat4 model; void main(){ - if(!spatialToScreen){ float x,y; x=(aVert.x+pos.x-screen.x*.5)/(screen.x*.5); y=(screen.y*.5-(aVert.y+pos.y))/(screen.y*.5); gl_Position=vec4(x,y,pos.z+aVert.z,1); - } - else{ - vec3 pos=vec3(proj*view*model*vec4(aVert,1)); - gl_Position=vec4(pos.xy,aVert.z,1); - } texCoords=aTexCoords; } diff --git a/material.h b/material.h index 6103d85..cbb77bc 100755 --- a/material.h +++ b/material.h @@ -14,11 +14,14 @@ namespace vb01{ Material(Type=MATERIAL_2D); ~Material(); void update(); - void addDiffuseMap(std::string diffuseMap){diffuseMapTextures.push_back(new Texture(diffuseMap));} - void addDiffuseMap(std::string diffuseMap[6]){diffuseMapTextures.push_back(new Texture(diffuseMap));} - void addDiffuseMap(Texture *texture){diffuseMapTextures.push_back(texture);} - void addNormalMap(std::string normalMap){normalMapTextures.push_back(new Texture(normalMap));} - void addSpecularMap(std::string specularMap){specularMapTextures.push_back(new Texture(specularMap));} + inline void addDiffuseMap(std::string diffuseMap){diffuseMapTextures.push_back(new Texture(diffuseMap));} + inline void addDiffuseMap(std::string diffuseMap[6]){diffuseMapTextures.push_back(new Texture(diffuseMap));} + inline void addDiffuseMap(Texture *texture){diffuseMapTextures.push_back(texture);} + inline void setDiffuseMap(Texture *texture, int i){diffuseMapTextures[i]=texture;} + inline void addNormalMap(std::string normalMap){normalMapTextures.push_back(new Texture(normalMap));} + inline void setNormalMap(Texture *texture, int i){normalMapTextures[i]=texture;} + inline void addSpecularMap(std::string specularMap){specularMapTextures.push_back(new Texture(specularMap));} + inline void setSpecularMap(Texture *texture, int i){specularMapTextures[i]=texture;} inline void setDiffuseColor(Vector4 diffuse){this->diffuseColor=diffuse;} inline void setSpecularColor(Vector4 specular){this->specularColor=specular;} inline void setLightingEnabled(bool lighting){this->lightingEnabled=lighting;} @@ -27,8 +30,10 @@ namespace vb01{ inline bool isLightingEnabled(){return lightingEnabled;} inline bool isTexturingEnabled(){return texturingEnabled;} inline bool isDiffuseColorEnabled(){return diffuseColorEnabled;} - inline Shader* getShader(){return shader;} inline Texture* getDiffuseMap(int i){return diffuseMapTextures[i];} + inline Texture* getNormalMap(int i){return normalMapTextures[i];} + inline Texture* getSpecularMap(int i){return specularMapTextures[i];} + inline Shader* getShader(){return shader;} inline Type getType(){return type;} private: Type type; diff --git a/mesh.cpp b/mesh.cpp index a7e724a..1237781 100755 --- a/mesh.cpp +++ b/mesh.cpp @@ -106,7 +106,6 @@ namespace vb01{ shader->setMat4(model,"model"); if(material->getType()==Material::MATERIAL_GUI){ shader->setVec2(Vector2((float)width,(float)height),"screen"); - //shader->setBool(spatialToScreen,"spatialToScreen"); if(node) shader->setVec3(pos,"pos"); } diff --git a/mesh.h b/mesh.h index 2d85fb2..ed2bae8 100755 --- a/mesh.h +++ b/mesh.h @@ -40,7 +40,7 @@ namespace vb01{ Mesh(); void construct(); - bool staticVerts=true,castShadow=false,spatialToScreen=false; + bool staticVerts=true,castShadow=false; Vertex *vertices; unsigned int *indices,VAO,VBO,EBO; int numTris; diff --git a/quad.cpp b/quad.cpp index dbf3043..27e86f6 100755 --- a/quad.cpp +++ b/quad.cpp @@ -1,10 +1,9 @@ #include"quad.h" namespace vb01{ - Quad::Quad(Vector3 size,bool spatial,bool spatialToScreen) : Mesh(){ + Quad::Quad(Vector3 size,bool spatial) : Mesh(){ this->spatial=spatial; this->staticVerts=false; - this->spatialToScreen=spatialToScreen; int numPolyVerts=3; numTris=2; diff --git a/quad.h b/quad.h index e59f04f..917c5e4 100755 --- a/quad.h +++ b/quad.h @@ -7,7 +7,7 @@ namespace vb01{ class Quad : public Mesh{ public: - Quad(Vector3,bool=true,bool=false); + Quad(Vector3,bool=true); void setSize(Vector3); private: Vector3 size; diff --git a/texture.h b/texture.h index 4fbe853..fbf3210 100755 --- a/texture.h +++ b/texture.h @@ -17,12 +17,14 @@ namespace vb01{ Texture(std::string[6]); void select(int=0); inline unsigned int* getTexture(){return &texture;} + inline std::string getPath(){return path;} private: TextureType type=TextureType::TEXTURE_2D; unsigned int texture; int width,height,numChannels; float weight; unsigned char *data; + std::string path="",paths[6]; }; }