diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2022-08-20 11:56:05 -0400 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2022-08-20 11:56:05 -0400 |
commit | 1405d648b6264cfda7c46f5b251258335abaee83 (patch) | |
tree | 555baeceb4beebeb2a3cc69cc736fc2680faa742 | |
parent | 9562fde36d6d28188210eb6053b9e2f9a9242702 (diff) |
transparency with font on ui box
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | src/text.cpp | 26 | ||||
-rw-r--r-- | src/text.hpp | 4 | ||||
-rw-r--r-- | src/ui.cpp | 16 |
4 files changed, 26 insertions, 22 deletions
@@ -39,7 +39,7 @@ LIBDIR = lib LIBS = -L$(LIBDIR) -lSDL2 -lpthread -lentityx -lluajit -ldl -lGLEW -lGL \ -lSDL2_image -lSOIL -lfreetype -CXXFLAGS = -ggdb -std=c++17 -Wall -Wextra -Werror -pedantic \ +CXXFLAGS = -ggdb -g3 -std=c++17 -Wall -Wextra -Werror -pedantic \ -Wno-class-memaccess -Wno-implicit-fallthrough -m64 -O1 CXXINCS = -Isrc -I$(LIBDIR)/LuaJIT/src -I$(LIBDIR)/entityx \ diff --git a/src/text.cpp b/src/text.cpp index c25eeae..5490224 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -87,8 +87,8 @@ void TextSystem::loadFont(const std::string& name, glGenTextures(1, &font.tex); glBindTexture(GL_TEXTURE_2D, font.tex); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, width, height, - 0, GL_RED, GL_UNSIGNED_BYTE, 0); + glTexImage2D(GL_TEXTURE_2D, 0, GL_INTENSITY8, width, height, + 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, 0); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); @@ -120,7 +120,7 @@ void TextSystem::loadFont(const std::string& name, auto* g = face->glyph; glTexSubImage2D(GL_TEXTURE_2D, 0, offsetX, offsetY, g->bitmap.width, g->bitmap.rows, - GL_RED, GL_UNSIGNED_BYTE, + GL_LUMINANCE, GL_UNSIGNED_BYTE, g->bitmap.buffer); auto& d = font.data[c-32]; @@ -144,17 +144,21 @@ void TextSystem::put(const std::string& font, { if (fontData.find(font) == fontData.end()) return; - - y += fontData[font].fontSize; - auto& vector = fontData[font].text; - if (auto i = std::find_if(vector.begin(), vector.end(), [&x, &y](const Text& t) { - return t.x == x && t.y == y; }); i != vector.end()) { - vector.erase(i); + + y = -(y + fontData[font].fontSize); + + const auto it = std::find_if(vector.begin(), vector.end(), + [&x, &y](const Text& t) { + return t.x == static_cast<int>(x) && t.y == static_cast<int>(y); + }); + if (it != vector.end()) { + *it = Text(text, x, y); + } else { + // Invert y axis so positive grows south. + fontData[font].text.emplace_back(text, x, y); } - // Invert y axis so positive grows south. - fontData[font].text.emplace_back(text, x, -y, -9.0f); shouldUpdateVBOs = true; } diff --git a/src/text.hpp b/src/text.hpp index 604710d..0f98688 100644 --- a/src/text.hpp +++ b/src/text.hpp @@ -50,8 +50,8 @@ struct FT_Info { struct Text { std::string text; - float x; - float y; + int x; + int y; float z; Text(std::string _text, float _x, float _y, float _z = 0.0f) : @@ -8,7 +8,7 @@ #include <string> static NewRenderEvent NRE (0, 0, 0, 0); -static const unsigned int NRE_TEX_DATA = 0xFF0000FF; +static const unsigned int NRE_TEX_DATA = 0xBBBBBBBB; static std::basic_string<TextMeshData> buffer; void UISystem::configure(entityx::EntityManager&, entityx::EventManager&) @@ -28,7 +28,7 @@ void UISystem::update(entityx::EntityManager&, glGenTextures(1, &NRE.tex); glBindTexture(GL_TEXTURE_2D, NRE.tex); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, &NRE_TEX_DATA); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &NRE_TEX_DATA); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); @@ -36,12 +36,12 @@ void UISystem::update(entityx::EntityManager&, glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - buffer += { 30, -50, -8, 0, 0, 1 }; - buffer += { 160, -50, -8, 0, 0, 1 }; - buffer += { 160, -10, -8, 0, 0, 1 }; - buffer += { 160, -10, -8, 0, 0, 1 }; - buffer += { 30, -10, -8, 0, 0, 1 }; - buffer += { 30, -50, -8, 0, 0, 1 }; + buffer += { 30, -50, -5, 0, 0, 1 }; + buffer += { 160, -50, -5, 0, 0, 1 }; + buffer += { 160, -10, -5, 0, 0, 1 }; + buffer += { 160, -10, -5, 0, 0, 1 }; + buffer += { 30, -10, -5, 0, 0, 1 }; + buffer += { 30, -50, -5, 0, 0, 1 }; glBindBuffer(GL_ARRAY_BUFFER, NRE.vbo); glBufferData(GL_ARRAY_BUFFER, |