Load and render ttf fonts
This commit is contained in:
parent
178b31822a
commit
6df76c20df
10 changed files with 145 additions and 21 deletions
|
@ -138,6 +138,9 @@ byte *GfxOpenGL::setupScreen(int screenW, int screenH, bool fullscreen) {
|
|||
_scaleW = _screenWidth / (float)_gameWidth;
|
||||
_scaleH = _screenHeight / (float)_gameHeight;
|
||||
|
||||
_globalScaleW = _screenWidth / (float)_globalWidth;
|
||||
_globalScaleH = _screenHeight / (float)_globalHeight;
|
||||
|
||||
_isFullscreen = g_system->getFeatureState(OSystem::kFeatureFullscreenMode);
|
||||
_useDepthShader = false;
|
||||
_useDimShader = false;
|
||||
|
@ -1456,8 +1459,76 @@ void GfxOpenGL::drawTextObject(const TextObject *text) {
|
|||
|
||||
glColor3ub(color.getRed(), color.getGreen(), color.getBlue());
|
||||
const FontUserData *userData = (const FontUserData *)font->getUserData();
|
||||
if (!userData)
|
||||
error("Could not get font userdata");
|
||||
if (!userData) {
|
||||
//error("Could not get font userdata");
|
||||
const FontTTF *f = static_cast<const FontTTF *>(font);
|
||||
Graphics::Font *gf = f->_font;
|
||||
Graphics::Surface surface;
|
||||
int height = 1024;
|
||||
int width = 1024;
|
||||
surface.create(height, width, Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24));
|
||||
gf->drawString(&surface, text->getLines()[0], 0, 0, 1024, 0xFFFFFFFF);
|
||||
|
||||
|
||||
byte *bitmap = (byte *)surface.getPixels();
|
||||
|
||||
|
||||
GLuint texid;
|
||||
glGenTextures(1, &texid);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, texid);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, bitmap);
|
||||
|
||||
float x = text->getX();
|
||||
|
||||
float y = text->getY();
|
||||
|
||||
if (!text->isGlobal()) {
|
||||
x -= gf->getStringWidth(text->getLines()[0]);
|
||||
x *= _globalScaleW;
|
||||
y *= _globalScaleH;
|
||||
|
||||
width *= _globalScaleW;
|
||||
height *= _globalScaleH;
|
||||
} else {
|
||||
x *= _scaleW;
|
||||
y *= _scaleH;
|
||||
|
||||
width *= _scaleW;
|
||||
height *= _scaleH;
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, texid);
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0.0f, 0.0f);
|
||||
glVertex2f(x, y);
|
||||
glTexCoord2f(1.0f, 0.0f);
|
||||
glVertex2f((x + width), y);
|
||||
glTexCoord2f(1.0f, 1.0f);
|
||||
glVertex2f((x + width), (y + height));
|
||||
glTexCoord2f(0.0f, 1.0f);
|
||||
glVertex2f(x, (y + height));
|
||||
glEnd();
|
||||
|
||||
|
||||
glDeleteTextures(1, &texid);
|
||||
|
||||
surface.free();
|
||||
|
||||
glColor3f(1, 1, 1);
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glDisable(GL_BLEND);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_LIGHTING);
|
||||
glDepthMask(GL_TRUE);
|
||||
return;
|
||||
}
|
||||
|
||||
float sizeW = userData->size * _scaleW;
|
||||
float sizeH = userData->size * _scaleH;
|
||||
GLuint texture = userData->texture;
|
||||
|
@ -1473,9 +1544,8 @@ void GfxOpenGL::drawTextObject(const TextObject *text) {
|
|||
if (g_grim->getGameType() == GType_GRIM)
|
||||
w += font->getBaseOffsetY();
|
||||
float z = x + font->getCharStartingCol(character);
|
||||
// TODO: We can't scale in the remastered version
|
||||
//z *= _scaleW;
|
||||
//w *= _scaleH;
|
||||
z *= _scaleW;
|
||||
w *= _scaleH;
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
float width = 1 / 16.f;
|
||||
float cx = ((character - 1) % 16) / 16.0f;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue