Use per-vertex coloring in a single batch

Signed-off-by: Ayush Thoren <ayushthoren@gmail.com>
This commit is contained in:
Ayush Thoren 2026-03-09 18:29:59 -07:00
parent 1f8f90894b
commit ced36874bc
2 changed files with 9 additions and 12 deletions

View file

@ -289,7 +289,7 @@ static bool isSectionFormatCode(wchar_t ca)
return l == L'l' || l == L'o' || l == L'n' || l == L'm' || l == L'r' || l == L'k'; return l == L'l' || l == L'o' || l == L'n' || l == L'm' || l == L'r' || l == L'k';
} }
void Font::draw(const wstring &str, bool dropShadow) void Font::draw(const wstring &str, bool dropShadow, int baseColor)
{ {
// Bind the texture // Bind the texture
textures->bindTexture(m_textureLocation); textures->bindTexture(m_textureLocation);
@ -299,6 +299,7 @@ void Font::draw(const wstring &str, bool dropShadow)
Tesselator *t = Tesselator::getInstance(); Tesselator *t = Tesselator::getInstance();
t->begin(); t->begin();
t->color(baseColor & 0x00ffffff, (baseColor >> 24) & 255);
for (int i = 0; i < static_cast<int>(cleanStr.length()); ++i) for (int i = 0; i < static_cast<int>(cleanStr.length()); ++i)
{ {
@ -310,10 +311,8 @@ void Font::draw(const wstring &str, bool dropShadow)
wchar_t ca = cleanStr[i+1]; wchar_t ca = cleanStr[i+1];
if (!isSectionFormatCode(ca)) if (!isSectionFormatCode(ca))
{ {
t->end(); addCharacterQuad(167);
renderCharacter(167); addCharacterQuad(ca);
renderCharacter(ca);
t->begin();
i += 1; i += 1;
continue; continue;
} }
@ -337,10 +336,8 @@ void Font::draw(const wstring &str, bool dropShadow)
noise = false; noise = false;
if (colorN < 0 || colorN > 15) colorN = 15; if (colorN < 0 || colorN > 15) colorN = 15;
if (dropShadow) colorN += 16; if (dropShadow) colorN += 16;
int color = colors[colorN]; baseColor = (baseColor & 0xff000000) | colors[colorN];
t->end(); t->color(baseColor & 0x00ffffff, (baseColor >> 24) & 255);
glColor3f((color >> 16) / 255.0F, ((color >> 8) & 255) / 255.0F, (color & 255) / 255.0F);
t->begin();
} }
i += 1; i += 1;
continue; continue;
@ -373,11 +370,11 @@ void Font::draw(const wstring& str, int x, int y, int color, bool dropShadow)
if (dropShadow) // divide RGB by 4, preserve alpha if (dropShadow) // divide RGB by 4, preserve alpha
color = (color & 0xfcfcfc) >> 2 | (color & (-1 << 24)); color = (color & 0xfcfcfc) >> 2 | (color & (-1 << 24));
glColor4f((color >> 16 & 255) / 255.0F, (color >> 8 & 255) / 255.0F, (color & 255) / 255.0F, (color >> 24 & 255) / 255.0F); glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
xPos = x; xPos = x;
yPos = y; yPos = y;
draw(str, dropShadow); draw(str, dropShadow, color);
} }
} }

View file

@ -65,7 +65,7 @@ public:
private: private:
wstring reorderBidi(const wstring &str); wstring reorderBidi(const wstring &str);
void draw(const wstring &str, bool dropShadow); void draw(const wstring &str, bool dropShadow, int baseColor);
void draw(const wstring& str, int x, int y, int color, bool dropShadow); void draw(const wstring& str, int x, int y, int color, bool dropShadow);
void drawLiteral(const wstring& str, int x, int y, int color); // no § parsing void drawLiteral(const wstring& str, int x, int y, int color); // no § parsing
int MapCharacter(wchar_t c); // 4J added int MapCharacter(wchar_t c); // 4J added