diff options
-rw-r--r-- | include/Text.hpp | 5 | ||||
-rw-r--r-- | src/Text.cpp | 12 |
2 files changed, 15 insertions, 2 deletions
diff --git a/include/Text.hpp b/include/Text.hpp index 60d0db1..d25d47b 100644 --- a/include/Text.hpp +++ b/include/Text.hpp @@ -2,6 +2,7 @@ #include "NetUtils.hpp" #include <SFML/Graphics/VertexArray.hpp> +#include <SFML/Graphics/VertexBuffer.hpp> #include <SFML/System/String.hpp> #include <SFML/System/Clock.hpp> #include <vector> @@ -140,7 +141,11 @@ namespace QuickMedia sf::String str; // TODO: Remove this for non-editable text??? also replace with std::string? then we get more efficient editing of text const bool bold_font; unsigned int characterSize; + // 1: Normal text + // 2: CJK + // 3: Emoji sf::VertexArray vertices[3]; + sf::VertexBuffer vertex_buffers[3]; float maxWidth; sf::Vector2f position; sf::Color color; diff --git a/src/Text.cpp b/src/Text.cpp index 2abc276..5668cf8 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -49,6 +49,10 @@ namespace QuickMedia vertices[0].setPrimitiveType(sf::PrimitiveType::Triangles); vertices[1].setPrimitiveType(sf::PrimitiveType::Triangles); vertices[2].setPrimitiveType(sf::PrimitiveType::Triangles); + for(int i = 0; i < 3; ++i) { + vertex_buffers[i] = sf::VertexBuffer(sf::PrimitiveType::Triangles, sf::VertexBuffer::Static); + vertex_buffers[i].create(0); + } setString(std::move(_str)); } @@ -585,6 +589,10 @@ namespace QuickMedia } boundingBox.height = num_lines * line_height; + for(int i = 0; i < 3; ++i) { + vertex_buffers[i].update(&vertices[i][0], vertices[i].getVertexCount(), 0); + } + //url_ranges.clear(); if(!editable) vertices_linear.clear(); @@ -899,14 +907,14 @@ namespace QuickMedia sf::RenderStates states; states.transform.translate(pos); states.texture = &font->getTexture(characterSize); - target.draw(vertices[i], states); + target.draw(vertex_buffers[i], states); } if(vertices[2].getVertexCount() > 0) { sf::RenderStates states; states.transform.translate(pos); states.texture = TextureLoader::get_texture("images/emoji.png"); - target.draw(vertices[2], states); + target.draw(vertex_buffers[2], states); } if(!editable) return true; |