text uses material

This commit is contained in:
devZoGok
2021-10-19 19:06:41 +03:00
parent 808bb4cbfa
commit a4fed6f062
8 changed files with 29 additions and 25 deletions
+3 -1
View File
@@ -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;
}
+4
View File
@@ -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<Texture*> textures;
+3 -7
View File
@@ -3,6 +3,7 @@
#include "shader.h"
#include "texture.h"
#include "node.h"
#include "material.h"
#include <glad.h>
#include <glfw3.h>
@@ -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");
+4 -3
View File
@@ -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);
}
+4 -3
View File
@@ -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<Glyph> characters;
Shader *shader = nullptr;
unsigned int VAO, VBO;
float scale = 1;
bool horizontal = true;
Vector4 color = Vector4::VEC_IJKL;
};
}