From 16392a2dab40317db620ef846469faadaa994e9f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 6 Jul 2024 13:33:30 +0100 Subject: Replace deprecated GL_QUADS usage in text rendering --- ui/text.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'ui/text.cpp') diff --git a/ui/text.cpp b/ui/text.cpp index 5675061..bdaaba5 100644 --- a/ui/text.cpp +++ b/ui/text.cpp @@ -27,13 +27,20 @@ Text::operator=(const std::string_view s) return init += q.second.size(); }); quads.resize(glyphCount); - GLint current = 0; + GLushort current = 0; auto model = models.begin(); auto quad = quads.begin(); for (const auto & [texture, fquads] : tquads) { - model->first = texture; - model->second = {fquads.size() * 4, current * 4}; - current += static_cast(fquads.size()); + model->textureId = texture; + model->range.resize(fquads.size() * 6); + for (auto out = model->range.begin(); const auto & q [[maybe_unused]] : fquads) { + static constexpr std::array quadIndices {0, 1, 2, 2, 3, 0}; + std::transform(quadIndices.begin(), quadIndices.end(), out, [current](auto x) { + return current + x; + }); + current += 4; + out += 6; + } model++; quad = std::transform(fquads.begin(), fquads.end(), quad, [this](const Font::Quad & q) { return q * [this](const glm::vec4 & corner) { @@ -52,8 +59,8 @@ Text::render(const UIShader & shader, const Position &) const glActiveTexture(GL_TEXTURE0); glBindVertexArray(vao); for (const auto & m : models) { - glBindTexture(GL_TEXTURE_2D, m.first); - glDrawArrays(GL_QUADS, m.second.second, m.second.first); + glBindTexture(GL_TEXTURE_2D, m.textureId); + glDrawElements(GL_TRIANGLES, static_cast(m.range.size()), GL_UNSIGNED_SHORT, m.range.data()); } glBindVertexArray(0); glBindTexture(GL_TEXTURE_2D, 0); -- cgit v1.2.3