diff --git a/gui.frag b/gui.frag index 476ec8b..f4bf50a 100755 --- a/gui.frag +++ b/gui.frag @@ -11,11 +11,12 @@ uniform vec4 diffuseColor; uniform sampler2D tex; void main(){ - vec4 c = texturingEnabled?texture(tex, texCoords) : diffuseColor; + vec4 c = (texturingEnabled ? texture(tex, texCoords) : diffuseColor); if(diffuseColorEnabled){ float alpha = texture(tex, texCoords).w; c = vec4(diffuseColor.xyz, alpha); } + if(guiPlane){ float gamma = 1, exposure = 1; @@ -27,5 +28,6 @@ void main(){ c.rgb = pow(c.rgb, vec3(1 / gamma)); } + FragColor = c; } diff --git a/gui.vert b/gui.vert index b86ecc6..17b5eff 100755 --- a/gui.vert +++ b/gui.vert @@ -1,7 +1,7 @@ #version 330 core -layout (location=0) in vec3 aVert; -layout (location=2) in vec2 aTexCoords; +layout (location = 0) in vec3 aVert; +layout (location = 2) in vec2 aTexCoords; out vec2 texCoords; @@ -9,9 +9,9 @@ uniform vec2 screen; uniform vec3 pos; void main(){ - 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); - texCoords=aTexCoords; + 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); + texCoords = aTexCoords; } diff --git a/material.cpp b/material.cpp index 7320b84..bea5309 100755 --- a/material.cpp +++ b/material.cpp @@ -106,6 +106,10 @@ namespace vb01{ if(diffuseColorEnabled) shader->setVec4(diffuseColor, "diffuseColor"); } + else if(type == MATERIAL_TEXT){ + shader->setInt(0, "textTex"); + //shader->setInt(1, "diffuseMap"); + } if(texturingEnabled){ vector textures; diff --git a/quad.cpp b/quad.cpp index d95d259..6e15119 100755 --- a/quad.cpp +++ b/quad.cpp @@ -1,4 +1,4 @@ -#include"quad.h" +#include "quad.h" namespace vb01{ Quad::Quad(Vector3 size, bool spatial) : Mesh(){ @@ -18,7 +18,7 @@ namespace vb01{ void Quad::setSize(Vector3 size){ this->size = size; - Vertex v1,v2,v3,v4,v5,v6; + Vertex v1, v2, v3, v4, v5, v6; if(spatial){ v1.pos = Vector3(size.x / 2, size.y / 2, 0); v2.pos = Vector3(-size.x / 2, size.y / 2, 0); diff --git a/quad.h b/quad.h index b9b1c03..8c23d05 100755 --- a/quad.h +++ b/quad.h @@ -1,8 +1,8 @@ #ifndef QUAD_H #define QUAD_H -#include"vector.h" -#include"mesh.h" +#include "vector.h" +#include "mesh.h" namespace vb01{ class Quad : public Mesh{ diff --git a/text.cpp b/text.cpp index e945ca4..a2a48c4 100755 --- a/text.cpp +++ b/text.cpp @@ -3,6 +3,7 @@ #include "shader.h" #include "texture.h" #include "node.h" +#include "material.h" #include #include @@ -19,16 +20,11 @@ namespace vb01{ } Text::~Text(){ - delete shader; - glDeleteVertexArrays(1, &VAO); glDeleteBuffers(1, &VBO); } void Text::initFont(string fontPath){ - string basePath = "../../vb01/text."; - shader = new Shader(basePath + "vert", basePath + "frag"); - FT_Library ft; FT_Face face; if(FT_Init_FreeType(&ft)) @@ -62,8 +58,8 @@ namespace vb01{ Root *root = Root::getSingleton(); int width = root->getWidth(), height = root->getHeight(); - shader->use(); - shader->setVec4(color, "color"); + material->update(); + Shader *shader = material->getShader(); shader->setVec2(Vector2(width, height), "screen"); shader->setVec3(node->getPosition(), "pos"); diff --git a/text.frag b/text.frag index 30e9533..e99f506 100755 --- a/text.frag +++ b/text.frag @@ -4,9 +4,10 @@ in vec2 texCoords; out vec4 FragColor; -uniform sampler2D tex; -uniform vec4 color; +uniform sampler2D textTex, diffuseMap; +uniform vec4 diffuseColor; void main(){ - FragColor = vec4(color.xyz, texture(tex, texCoords).r); + float alpha = texture(textTex, texCoords).r; + FragColor = vec4(diffuseColor.xyz, diffuseColor.w * alpha); } diff --git a/text.h b/text.h index 8f7216b..5e01359 100755 --- a/text.h +++ b/text.h @@ -10,6 +10,7 @@ namespace vb01{ class Node; class Texture; class Shader; + class Material; class Text{ public: @@ -27,11 +28,12 @@ namespace vb01{ inline Node* getNode(){return node;} inline void setNode(Node *node){this->node = node;} inline void setScale(float s){this->scale = s;} - inline void setColor(Vector4 c){this->color = c;} inline int getLength(){return entry.length();} inline std::wstring getText(){return entry;} inline bool isHorizontal(){return horizontal;} inline void setHorizontal(bool h){this->horizontal = h;} + inline Material* getMaterial(){return material;} + inline void setMaterial(Material *mat){this->material = mat;} private: void initFont(std::string); void prepareGlyphs(Glyph, Vector2); @@ -39,13 +41,12 @@ namespace vb01{ Glyph* getGlyph(u16); Node *node = nullptr; + Material *material = nullptr; std::wstring entry; std::vector characters; - Shader *shader = nullptr; unsigned int VAO, VBO; float scale = 1; bool horizontal = true; - Vector4 color = Vector4::VEC_IJKL; }; }