Improve ship nickname rendering
This commit is contained in:
1 parent
e18484ea62
commit
e050d7d0ec
7 files changed
+45
-29
No files matched your search
@@ -835,6 +835,15 @@ namespace ZL {
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::RenderUniform4fv(const std::string& uniformName, const float* value)
|
||||
{
|
||||
auto shader = shaderManager.GetCurrentShader();
|
||||
auto uniform = shader->uniformList.find(uniformName);
|
||||
if (uniform != shader->uniformList.end()) {
|
||||
glUniform4fv(uniform->second, 1, value);
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::RenderUniform1i(const std::string& uniformName, const int value)
|
||||
{
|
||||
auto shader = shaderManager.GetCurrentShader();
|
||||
|
||||
@@ -138,6 +138,7 @@ namespace ZL {
|
||||
void RenderUniformMatrix4fv(const std::string& uniformName, bool transpose, const float* value);
|
||||
void RenderUniform1i(const std::string& uniformName, const int value);
|
||||
void RenderUniform3fv(const std::string& uniformName, const float* value);
|
||||
void RenderUniform4fv(const std::string& uniformName, const float* value);
|
||||
void RenderUniform1f(const std::string& uniformName, float value);
|
||||
|
||||
void VertexAttribPointer2fv(const std::string& attribName, int stride, const char* pointer);
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
#include "Environment.h"
|
||||
#include "render/OpenGlExtensions.h" // если у тебя там gl* указатели
|
||||
#include "render/OpenGlExtensions.h"
|
||||
#include <iostream>
|
||||
#include <array>
|
||||
|
||||
namespace ZL {
|
||||
|
||||
@@ -25,8 +26,6 @@ bool TextRenderer::init(Renderer& renderer, const std::string& ttfPath, int pixe
|
||||
{
|
||||
r = &renderer;
|
||||
|
||||
// Добавим шейдер (если у тебя shaderManager работает так же, как с default)
|
||||
// Подстрой под твой AddShaderFromFiles: тут без zip.
|
||||
r->shaderManager.AddShaderFromFiles(shaderName,
|
||||
"resources/shaders/text2d.vertex",
|
||||
"resources/shaders/text2d.fragment",
|
||||
@@ -109,7 +108,7 @@ bool TextRenderer::loadGlyphs(const std::string& ttfPath, int pixelSize)
|
||||
return true;
|
||||
}
|
||||
|
||||
void TextRenderer::drawText(const std::string& text, float x, float y, float scale, bool centered)
|
||||
void TextRenderer::drawText(const std::string& text, float x, float y, float scale, bool centered, std::array<float, 4> color)
|
||||
{
|
||||
if (!r) return;
|
||||
|
||||
@@ -127,8 +126,6 @@ void TextRenderer::drawText(const std::string& text, float x, float y, float sca
|
||||
r->shaderManager.PushShader(shaderName);
|
||||
|
||||
// Орто-проекция в пикселях: (0..W, 0..H)
|
||||
// ВАЖНО: мы рисуем в координатах Game::drawBoxesLabels() как uiX/uiY
|
||||
// Здесь предположим, что (0,0) внизу слева.
|
||||
float W = (float)Environment::width;
|
||||
float H = (float)Environment::height;
|
||||
|
||||
@@ -142,9 +139,7 @@ void TextRenderer::drawText(const std::string& text, float x, float y, float sca
|
||||
r->RenderUniformMatrix4fv("uProjection", false, proj.data());
|
||||
r->RenderUniform1i("uText", 0);
|
||||
|
||||
// белый цвет
|
||||
float color[3] = {1.0f, 1.0f, 1.0f};
|
||||
r->RenderUniform3fv("uColor", color);
|
||||
r->RenderUniform4fv("uColor", color.data());
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
// glBindVertexArray(vao);
|
||||
@@ -184,9 +179,7 @@ void TextRenderer::drawText(const std::string& text, float x, float y, float sca
|
||||
};
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, g.texID);
|
||||
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(verts), verts);
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
|
||||
penX += (g.advance >> 6) * scale;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <unordered_map>
|
||||
#include <Eigen/Dense>
|
||||
#include "render/Renderer.h"
|
||||
#include <array>
|
||||
|
||||
|
||||
namespace ZL {
|
||||
@@ -22,7 +23,7 @@ public:
|
||||
~TextRenderer();
|
||||
|
||||
bool init(Renderer& renderer, const std::string& ttfPath, int pixelSize);
|
||||
void drawText(const std::string& text, float x, float y, float scale, bool centered);
|
||||
void drawText(const std::string& text, float x, float y, float scale, bool centered, std::array<float, 4> color = { 1.f,1.f,1.f,1.f });
|
||||
|
||||
private:
|
||||
bool loadGlyphs(const std::string& ttfPath, int pixelSize);
|
||||
|
||||
Reference in new issue
Block a user