mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-20 05:23:04 +01:00
Get basic TTF support working in OpenGL
co-authored-by: Michael Steenbeek <m.o.steenbeek@gmail.com>
This commit is contained in:
@@ -7,10 +7,13 @@
|
||||
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "../Context.h"
|
||||
#include "../common.h"
|
||||
#include "../config/Config.h"
|
||||
#include "../core/String.hpp"
|
||||
#include "../drawing/Drawing.h"
|
||||
#include "../drawing/IDrawingContext.h"
|
||||
#include "../drawing/IDrawingEngine.h"
|
||||
#include "../interface/Viewport.h"
|
||||
#include "../localisation/Formatting.h"
|
||||
#include "../localisation/Localisation.h"
|
||||
@@ -525,6 +528,7 @@ static void ttf_draw_string_raw_sprite(rct_drawpixelinfo* dpi, std::string_view
|
||||
|
||||
#ifndef NO_TTF
|
||||
|
||||
static int _ttfGlId = 0;
|
||||
static void ttf_draw_string_raw_ttf(rct_drawpixelinfo* dpi, std::string_view text, text_draw_info* info)
|
||||
{
|
||||
if (!ttf_initialise())
|
||||
@@ -554,6 +558,37 @@ static void ttf_draw_string_raw_ttf(rct_drawpixelinfo* dpi, std::string_view tex
|
||||
int32_t width = surface->w;
|
||||
int32_t height = surface->h;
|
||||
|
||||
if (OpenRCT2::GetContext()->GetDrawingEngineType() == DrawingEngine::OpenGL)
|
||||
{
|
||||
auto pixels = reinterpret_cast<uint8_t*>(const_cast<void*>(surface->pixels));
|
||||
auto pixelsLen = static_cast<size_t>(surface->pitch) * surface->h;
|
||||
for (size_t pp = 0; pp < pixelsLen; pp++)
|
||||
{
|
||||
if (pixels[pp] != 0)
|
||||
{
|
||||
pixels[pp] = colour;
|
||||
}
|
||||
else
|
||||
{
|
||||
pixels[pp] = PALETTE_INDEX_0;
|
||||
}
|
||||
}
|
||||
|
||||
auto baseId = uint32_t(0x7FFFF) - 1024;
|
||||
auto imageId = baseId + _ttfGlId;
|
||||
auto drawingEngine = dpi->DrawingEngine;
|
||||
auto drawingContext = drawingEngine->GetDrawingContext(dpi);
|
||||
drawingEngine->InvalidateImage(imageId);
|
||||
drawingContext->DrawBitmap(imageId, surface->pixels, surface->pitch, surface->h, drawX, drawY);
|
||||
|
||||
_ttfGlId++;
|
||||
if (_ttfGlId >= 1023)
|
||||
{
|
||||
_ttfGlId = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t overflowX = (dpi->x + dpi->width) - (drawX + width);
|
||||
int32_t overflowY = (dpi->y + dpi->height) - (drawY + height);
|
||||
if (overflowX < 0)
|
||||
|
||||
Reference in New Issue
Block a user