mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-13 15:40:57 +00:00
Improved the tinygl font rendering.
This commit is contained in:
parent
4725e4fbe5
commit
c69322d78b
@ -129,10 +129,11 @@ uint16 Font::getCharIndex(unsigned char c) const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Font::getStringLength(const Common::String &text) {
|
||||
int Font::getStringLength(const Common::String &text) const {
|
||||
int result = 0;
|
||||
for (uint32 i = 0; i < text.size(); ++i) {
|
||||
result += getCharWidth(text[i]);
|
||||
result += MAX(getCharDataWidth(text[i]), getCharWidth(text[i]));
|
||||
//result += getCharDataWidth(text[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public:
|
||||
~Font();
|
||||
|
||||
const Common::String &getFilename() const { return _filename; }
|
||||
int32 getHeight() { return _height; }
|
||||
int32 getHeight() const { return _height; }
|
||||
int32 getBaseOffsetY() const { return _baseOffsetY; }
|
||||
int32 getCharDataWidth(unsigned char c) const { return _charHeaders[getCharIndex(c)].dataWidth; }
|
||||
int32 getCharDataHeight(unsigned char c) const { return _charHeaders[getCharIndex(c)].dataHeight; }
|
||||
@ -45,7 +45,7 @@ public:
|
||||
int32 getCharStartingLine(unsigned char c) const { return _charHeaders[getCharIndex(c)].startingLine; }
|
||||
const byte *getCharData(unsigned char c) const { return _fontData + (_charHeaders[getCharIndex(c)].offset); }
|
||||
|
||||
int getStringLength(const Common::String &text);
|
||||
int getStringLength(const Common::String &text) const;
|
||||
|
||||
static const uint8 emerFont[][13];
|
||||
//private:
|
||||
|
@ -40,7 +40,6 @@ enum colorFormat {
|
||||
BM_RGB1555 = 2, // EMI-PS2
|
||||
BM_RGBA = 3 // EMI-PC
|
||||
};
|
||||
|
||||
class GfxBase {
|
||||
public:
|
||||
GfxBase() { ; }
|
||||
@ -88,8 +87,7 @@ public:
|
||||
|
||||
virtual void createFont(Font *font) = 0;
|
||||
virtual void destroyFont(Font *font) = 0;
|
||||
virtual void drawText(int x, int y, const Common::String &text, Font *font, Color &color) = 0;
|
||||
virtual void drawTextObject(TextObject *text) { }
|
||||
virtual void drawTextObject(TextObject *text) = 0;
|
||||
|
||||
virtual Bitmap *getScreenshot(int w, int h) = 0;
|
||||
virtual void storeDisplay() = 0;
|
||||
|
@ -823,9 +823,11 @@ void GfxOpenGL::createFont(Font *font) {
|
||||
|
||||
int width = font->getCharDataWidth(i), height = font->getCharDataHeight(i);
|
||||
|
||||
uint d = ((uint)font->getCharData(i) - start);
|
||||
uint d = (uint)font->getCharData(i) - start;
|
||||
for (int x = 0; x < height; ++x) {
|
||||
int pos = row * size * size * 2 * 16 + x * size * 16 * 2 + (((i-1)%16))*size*2;
|
||||
|
||||
// TODO: Make this line use less magic
|
||||
int pos = row * size * size * 2 * 16 + x * size * 16 * 2 + ((i-1)%16)*size*2;
|
||||
assert(pos < arraySize);
|
||||
memcpy(temp + pos, data + d * 2 + x * width * 2, width * 2);
|
||||
}
|
||||
@ -833,15 +835,12 @@ void GfxOpenGL::createFont(Font *font) {
|
||||
++row;
|
||||
|
||||
}
|
||||
//glPixelStorei(GL_UNPACK_ROW_LENGTH, size*16);
|
||||
glBindTexture(GL_TEXTURE_2D, textures[0]);
|
||||
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, size*16, size*16, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, temp);
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||
|
||||
|
||||
*((int *)font->_sizes) = size;
|
||||
|
||||
@ -859,10 +858,6 @@ void GfxOpenGL::destroyFont(Font *font) {
|
||||
}
|
||||
}
|
||||
|
||||
void GfxOpenGL::drawText(int x, int y, const Common::String &text, Font *font, Color &color) {
|
||||
|
||||
}
|
||||
|
||||
void GfxOpenGL::drawTextObject(TextObject *text) {
|
||||
if (!text)
|
||||
return;
|
||||
@ -899,7 +894,7 @@ void GfxOpenGL::drawTextObject(TextObject *text) {
|
||||
y = text->getLineY(j);
|
||||
for (uint i = 0; i < line.size(); ++i) {
|
||||
uint8 character = line[i];
|
||||
int w = y + font->getCharStartingLine(character);
|
||||
int w = y + font->getCharStartingLine(character) + font->getBaseOffsetY();
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
float width = 1/16.f;
|
||||
|
@ -87,7 +87,6 @@ public:
|
||||
|
||||
void createFont(Font *font);
|
||||
void destroyFont(Font *font);
|
||||
void drawText(int x, int y, const Common::String &text, Font *font, Color &color);
|
||||
void drawTextObject(TextObject *text);
|
||||
|
||||
Bitmap *getScreenshot(int w, int h);
|
||||
|
@ -699,20 +699,49 @@ void GfxTinyGL::createFont(Font *font) {
|
||||
void GfxTinyGL::destroyFont(Font *font) {
|
||||
}
|
||||
|
||||
void GfxTinyGL::drawText(int x, int y, const Common::String &text, Font *font, Color &fgColor) {
|
||||
y += font->getBaseOffsetY();
|
||||
uint16 *texData = new uint16[32 * 32];
|
||||
for (uint i = 0; i < text.size(); ++i) {
|
||||
uint8 character = text[i];
|
||||
int width = font->getCharDataWidth(character), height = font->getCharDataHeight(character);
|
||||
byte *data = (byte *)font->getCharData(character);
|
||||
void GfxTinyGL::drawTextObject(TextObject *text) {
|
||||
|
||||
int numLines = text->getNumLines();
|
||||
const Common::String *lines = text->getLines();
|
||||
const Font *font = text->getFont();
|
||||
const Color *fgColor = text->getFGColor();
|
||||
for (int j = 0; j < numLines; j++) {
|
||||
const Common::String ¤tLine = lines[j];
|
||||
|
||||
int width = font->getStringLength(currentLine) + 1;
|
||||
int height = font->getHeight();
|
||||
|
||||
uint8 *_textBitmap = new uint8[height * width];
|
||||
memset(_textBitmap, 0, height * width);
|
||||
|
||||
// Fill bitmap
|
||||
int startOffset = 0;
|
||||
for (unsigned int d = 0; d < currentLine.size(); d++) {
|
||||
int ch = currentLine[d];
|
||||
int8 startingLine = font->getCharStartingLine(ch) + font->getBaseOffsetY();
|
||||
int32 charDataWidth = font->getCharDataWidth(ch);
|
||||
int32 charWidth = font->getCharWidth(ch);
|
||||
int8 startingCol = font->getCharStartingCol(ch);
|
||||
for (int line = 0; line < font->getCharDataHeight(ch); line++) {
|
||||
int offset = startOffset + (width * (line + startingLine));
|
||||
for (int r = 0; r < charDataWidth; r++) {
|
||||
const byte pixel = *(font->getCharData(ch) + r + (charDataWidth * line));
|
||||
byte *dst = _textBitmap + offset + startingCol + r;
|
||||
if (*dst == 0 && pixel != 0)
|
||||
_textBitmap[offset + startingCol + r] = pixel;
|
||||
}
|
||||
if (line + startingLine >= font->getHeight())
|
||||
break;
|
||||
}
|
||||
startOffset += charWidth;
|
||||
}
|
||||
|
||||
uint16 *texData = new uint16[width * height];
|
||||
uint16 *texDataPtr = texData;
|
||||
|
||||
uint8 *bitmapData = data;
|
||||
uint8 r = fgColor.getRed();
|
||||
uint8 g = fgColor.getGreen();
|
||||
uint8 b = fgColor.getBlue();
|
||||
uint8 *bitmapData = _textBitmap;
|
||||
uint8 r = fgColor->getRed();
|
||||
uint8 g = fgColor->getGreen();
|
||||
uint8 b = fgColor->getBlue();
|
||||
uint16 color = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
|
||||
if (color == 0xf81f)
|
||||
color = 0xf81e;
|
||||
@ -727,14 +756,11 @@ void GfxTinyGL::drawText(int x, int y, const Common::String &text, Font *font, C
|
||||
WRITE_UINT16(texDataPtr, color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
TinyGLBlit((byte *)_zb->pbuf, (byte *)texData, x, y + font->getCharStartingLine(character), width, height, true);
|
||||
x += font->getCharWidth(character);
|
||||
|
||||
TinyGLBlit((byte *)_zb->pbuf, (byte *)texData, text->getLineX(j), text->getLineY(j), width, height, true);
|
||||
//_textObjectHandle[j] = g_driver->createTextBitmap(_textBitmap, _bitmapWidthPtr[j] + 1, _font->getHeight(), *_fgColor);
|
||||
delete[] texData;
|
||||
delete[] _textBitmap;
|
||||
}
|
||||
delete[] texData;
|
||||
}
|
||||
|
||||
void GfxTinyGL::createMaterial(Material *material, const char *data, const CMap *cmap) {
|
||||
|
@ -79,7 +79,7 @@ public:
|
||||
|
||||
void createFont(Font *font);
|
||||
void destroyFont(Font *font);
|
||||
void drawText(int x, int y, const Common::String &text, Font *font, Color &color);
|
||||
void drawTextObject(TextObject *text);
|
||||
|
||||
void dimScreen();
|
||||
void dimRegion(int x, int y, int w, int h, float level);
|
||||
|
@ -282,7 +282,6 @@ int TextObject::getLineY(int line) {
|
||||
}
|
||||
if (y < 0)
|
||||
y = 0;
|
||||
y += _font->getBaseOffsetY();
|
||||
y += _font->getHeight()*line;
|
||||
|
||||
return y;
|
||||
|
Loading…
x
Reference in New Issue
Block a user