From de1784e932944566574b510586a57a5d14b0a5bb Mon Sep 17 00:00:00 2001 From: omigamedev Date: Wed, 8 Feb 2017 00:20:26 +0000 Subject: [PATCH] added alpha blending for image and text, nodes position are clamped to be integer --- data/layout.xml | 2 +- engine/app.cpp | 8 ++++++-- engine/layout.cpp | 4 ++-- engine/layout.h | 4 ++++ 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/data/layout.xml b/data/layout.xml index 0cbb5b1..22b222a 100644 --- a/data/layout.xml +++ b/data/layout.xml @@ -84,7 +84,7 @@ - + diff --git a/engine/app.cpp b/engine/app.cpp index 5edde5f..6e83cf4 100644 --- a/engine/app.cpp +++ b/engine/app.cpp @@ -89,7 +89,8 @@ void App::init() "in vec2 uv;" "out vec4 frag;" "void main(){" - " frag = vec4(texture(tex, uv).r * col.rgb, col.a);" + " float a = texture(tex, uv).r;" + " frag = vec4(col.rgb, a);" "}"; #ifdef _WIN32 @@ -141,7 +142,10 @@ void App::init() glDisable(GL_DEPTH_TEST); glPointSize(5); glLineWidth(2); - + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendEquation(GL_FUNC_ADD); + //int n; //glGetIntegerv(GL_NUM_EXTENSIONS, &n); //for (int i = 0; i < n; i++) diff --git a/engine/layout.cpp b/engine/layout.cpp index 93214c4..6e7ccb6 100644 --- a/engine/layout.cpp +++ b/engine/layout.cpp @@ -46,8 +46,8 @@ void Node::update_internal(const glm::vec2& origin, const glm::mat4& proj) if (m_widget) { glm::mat4 pivot = glm::translate(glm::vec3(.5f, .5f, 0.f)); - glm::mat4 scale = glm::scale(glm::vec3(m_size, 1.f)); - glm::mat4 pos = glm::translate(glm::vec3(m_pos, 0)); + glm::mat4 scale = glm::scale(glm::vec3(glm::ceil(m_size), 1.f)); + glm::mat4 pos = glm::translate(glm::vec3(glm::floor(m_pos), 0)); m_widget->mvp = proj * pos * scale * pivot; m_widget->pos = pos; m_widget->scale = scale; diff --git a/engine/layout.h b/engine/layout.h index 41fdbee..b8ced21 100644 --- a/engine/layout.h +++ b/engine/layout.h @@ -253,7 +253,9 @@ public: ShaderManager::u_int(kShaderUniform::Tex, 0); ShaderManager::u_mat4(kShaderUniform::MVP, mvp); ShaderManager::u_vec4(kShaderUniform::Col, m_color); + glEnable(GL_BLEND); m_text_mesh.draw(); + glDisable(GL_BLEND); } virtual void parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* attr) override { @@ -323,6 +325,7 @@ public: { TextureManager::get(m_id).bind(); m_sampler.bind(0); + glEnable(GL_BLEND); if (m_use_atlas) { ShaderManager::use(kShader::Atlas); @@ -338,6 +341,7 @@ public: m_plane.draw_fill(); m_sampler.unbind(); TextureManager::get(m_id).unbind(); + glDisable(GL_BLEND); } virtual void parse_attributes(kAttribute id, const tinyxml2::XMLAttribute* attr) override {