mirror of
https://github.com/glest/glest-source.git
synced 2025-08-30 11:19:48 +02:00
- better quality font rendering and performance still good.
This commit is contained in:
@@ -156,37 +156,41 @@ void Logger::renderLoadingScreen() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int xLocation = metrics.getVirtualW() / 4;
|
||||||
if(Renderer::renderText3DEnabled) {
|
if(Renderer::renderText3DEnabled) {
|
||||||
renderer.renderText3D(
|
|
||||||
state, coreData.getMenuFontBig3D(), Vec3f(1.f),
|
|
||||||
metrics.getVirtualW()/4, 65*metrics.getVirtualH()/100, false);
|
|
||||||
|
|
||||||
renderer.renderText3D(
|
renderer.renderText3D(
|
||||||
current, coreData.getMenuFontNormal3D(), 1.0f,
|
state, coreData.getMenuFontBig3D(), Vec3f(1.f),
|
||||||
metrics.getVirtualW() / 4,
|
xLocation,
|
||||||
|
65 * metrics.getVirtualH() / 100, false);
|
||||||
|
|
||||||
|
renderer.renderText3D(
|
||||||
|
current, coreData.getMenuFontNormal3D(), Vec3f(1.f),
|
||||||
|
xLocation,
|
||||||
62 * metrics.getVirtualH() / 100, false);
|
62 * metrics.getVirtualH() / 100, false);
|
||||||
|
|
||||||
if(this->statusText != "") {
|
if(this->statusText != "") {
|
||||||
renderer.renderText3D(
|
renderer.renderText3D(
|
||||||
this->statusText, coreData.getMenuFontNormal3D(), 1.0f,
|
this->statusText, coreData.getMenuFontNormal3D(), 1.0f,
|
||||||
metrics.getVirtualW() / 4,
|
xLocation,
|
||||||
56 * metrics.getVirtualH() / 100, false);
|
56 * metrics.getVirtualH() / 100, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
renderer.renderText(
|
renderer.renderText(
|
||||||
state, coreData.getMenuFontBig(), Vec3f(1.f),
|
state, coreData.getMenuFontBig(), Vec3f(1.f),
|
||||||
metrics.getVirtualW()/4, 65*metrics.getVirtualH()/100, false);
|
xLocation,
|
||||||
|
65 * metrics.getVirtualH() / 100, false);
|
||||||
|
|
||||||
renderer.renderText(
|
renderer.renderText(
|
||||||
current, coreData.getMenuFontNormal(), 1.0f,
|
current, coreData.getMenuFontNormal(), 1.0f,
|
||||||
metrics.getVirtualW() / 4,
|
xLocation,
|
||||||
62 * metrics.getVirtualH() / 100, false);
|
62 * metrics.getVirtualH() / 100, false);
|
||||||
|
|
||||||
if(this->statusText != "") {
|
if(this->statusText != "") {
|
||||||
renderer.renderText(
|
renderer.renderText(
|
||||||
this->statusText, coreData.getMenuFontNormal(), 1.0f,
|
this->statusText, coreData.getMenuFontNormal(), 1.0f,
|
||||||
metrics.getVirtualW() / 4,
|
xLocation,
|
||||||
56 * metrics.getVirtualH() / 100, false);
|
56 * metrics.getVirtualH() / 100, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -72,9 +72,11 @@ void BattleEnd::update() {
|
|||||||
|
|
||||||
void BattleEnd::render(){
|
void BattleEnd::render(){
|
||||||
Renderer &renderer= Renderer::getInstance();
|
Renderer &renderer= Renderer::getInstance();
|
||||||
TextRenderer2D *textRenderer2D= renderer.getTextRenderer();
|
|
||||||
TextRenderer3D *textRenderer3D= renderer.getTextRenderer3D();
|
TextRenderer2D *textRenderer2D = renderer.getTextRenderer();
|
||||||
TextRenderer *textRenderer= NULL;
|
TextRenderer3D *textRenderer3D = renderer.getTextRenderer3D();
|
||||||
|
TextRenderer *textRenderer = NULL;
|
||||||
|
|
||||||
if(Renderer::renderText3DEnabled == true) {
|
if(Renderer::renderText3DEnabled == true) {
|
||||||
textRenderer= textRenderer3D;
|
textRenderer= textRenderer3D;
|
||||||
}
|
}
|
||||||
|
@@ -60,7 +60,7 @@ TextFTGL::TextFTGL(FontTextHandlerType type) : Text(type) {
|
|||||||
//printf("2D font [%s]\n",fontFile);
|
//printf("2D font [%s]\n",fontFile);
|
||||||
}
|
}
|
||||||
else if(type == ftht_3D) {
|
else if(type == ftht_3D) {
|
||||||
ftFont = new FTBufferFont(fontFile);
|
ftFont = new FTGLTextureFont(fontFile);
|
||||||
//printf("3D font [%s]\n",fontFile);
|
//printf("3D font [%s]\n",fontFile);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -110,7 +110,7 @@ void TextFTGL::init(string fontName, int fontSize) {
|
|||||||
//printf("2D font [%s]\n",fontFile);
|
//printf("2D font [%s]\n",fontFile);
|
||||||
}
|
}
|
||||||
else if(type == ftht_3D) {
|
else if(type == ftht_3D) {
|
||||||
ftFont = new FTBufferFont(fontFile);
|
ftFont = new FTGLTextureFont(fontFile);
|
||||||
//printf("3D font [%s]\n",fontFile);
|
//printf("3D font [%s]\n",fontFile);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "string_utils.h"
|
#include "string_utils.h"
|
||||||
#include "utf8.h"
|
#include "utf8.h"
|
||||||
|
#include "util.h"
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
using namespace Shared::Util;
|
using namespace Shared::Util;
|
||||||
@@ -32,41 +33,20 @@ namespace Shared { namespace Graphics { namespace Gl {
|
|||||||
TextRenderer2DGl::TextRenderer2DGl() {
|
TextRenderer2DGl::TextRenderer2DGl() {
|
||||||
rendering= false;
|
rendering= false;
|
||||||
this->font = NULL;
|
this->font = NULL;
|
||||||
|
|
||||||
//font3D = NULL;
|
|
||||||
//tester = new TextRenderer3DGl();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TextRenderer2DGl::~TextRenderer2DGl() {
|
TextRenderer2DGl::~TextRenderer2DGl() {
|
||||||
//delete font3D;
|
|
||||||
//font3D = NULL;
|
|
||||||
|
|
||||||
//delete tester;
|
|
||||||
//tester = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextRenderer2DGl::begin(Font2D *font) {
|
void TextRenderer2DGl::begin(Font2D *font) {
|
||||||
this->font = static_cast<Font2DGl*>(font);
|
this->font = static_cast<Font2DGl*>(font);
|
||||||
|
|
||||||
// if(font3D == NULL) {
|
|
||||||
// font3D = new Font3DGl();
|
|
||||||
// font3D->setYOffsetFactor(this->font->getYOffsetFactor());
|
|
||||||
// font3D->setType("", this->font->getType());
|
|
||||||
// font3D->setDepth(this->font->getWidth());
|
|
||||||
// }
|
|
||||||
// tester->begin(font3D);
|
|
||||||
// return;
|
|
||||||
|
|
||||||
assert(!rendering);
|
assert(!rendering);
|
||||||
rendering = true;
|
rendering = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextRenderer2DGl::render(const string &text, float x, float y, bool centered, Vec3f *color) {
|
void TextRenderer2DGl::render(const string &text, float x, float y, bool centered, Vec3f *color) {
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("**** RENDERING 2D text [%s]\n",text.c_str());
|
||||||
printf("**** RENDERING 2D text [%s]\n",text.c_str());
|
|
||||||
|
|
||||||
//tester->render(text, x, y, this->font->getWidth(),centered);
|
|
||||||
//return;
|
|
||||||
|
|
||||||
assert(rendering);
|
assert(rendering);
|
||||||
|
|
||||||
@@ -393,7 +373,26 @@ void TextRenderer3DGl::begin(Font3D *font) {
|
|||||||
void TextRenderer3DGl::render(const string &text, float x, float y, bool centered, Vec3f *color) {
|
void TextRenderer3DGl::render(const string &text, float x, float y, bool centered, Vec3f *color) {
|
||||||
assert(rendering);
|
assert(rendering);
|
||||||
|
|
||||||
internalRender(text, x, y, centered, color);
|
string renderText = text;
|
||||||
|
if(Font::fontIsMultibyte == true) {
|
||||||
|
if(font->getTextHandler() != NULL) {
|
||||||
|
if(Font::fontIsRightToLeft == true) {
|
||||||
|
//printf("\n\n#A [%s]\n",renderText.c_str());
|
||||||
|
//bool isRLM = utf8::starts_with_rlm(text.begin(), text.end() + text.size());
|
||||||
|
|
||||||
|
//printf("\n\nORIGINAL TEXT [%s] isRLM = %d\n\n",text.c_str(),isRLM);
|
||||||
|
//for(int i = 0; i < renderText.size(); ++i) {
|
||||||
|
// printf("i = %d c [%c][%d][%X]\n",i,renderText[i],renderText[i],renderText[i]);
|
||||||
|
//}
|
||||||
|
//if(isRLM == true) {
|
||||||
|
if(is_string_all_ascii(renderText) == false) {
|
||||||
|
strrev_utf8(renderText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internalRender(renderText, x, y, centered, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextRenderer3DGl::internalRender(const string &text, float x, float y, bool centered, Vec3f *color) {
|
void TextRenderer3DGl::internalRender(const string &text, float x, float y, bool centered, Vec3f *color) {
|
||||||
@@ -447,91 +446,91 @@ void TextRenderer3DGl::internalRender(const string &text, float x, float y, boo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//glScalef(scale, scale, scale);
|
|
||||||
float scaleX = 0.65;
|
float scaleX = 0.65;
|
||||||
float scaleY = 0.75;
|
float scaleY = 0.75;
|
||||||
float scaleZ = 1.0;
|
float scaleZ = 1.0;
|
||||||
|
//float scaleX = 1;
|
||||||
|
//float scaleY = 1;
|
||||||
|
//float scaleZ = 1;
|
||||||
|
|
||||||
//x = translatePos.x;
|
|
||||||
float yScaleFactor = (metrics->getHeight() * (1.0 - scaleY));
|
float yScaleFactor = (metrics->getHeight() * (1.0 - scaleY));
|
||||||
translatePos.y += yScaleFactor;
|
translatePos.y += yScaleFactor;
|
||||||
//y = translatePos.y;
|
|
||||||
|
|
||||||
glTranslatef(translatePos.x, translatePos.y, translatePos.z);
|
glTranslatef(translatePos.x, translatePos.y, translatePos.z);
|
||||||
glScalef(scaleX, scaleY, scaleZ);
|
glScalef(scaleX, scaleY, scaleZ);
|
||||||
|
|
||||||
//font->getTextHandler()->Render(text.c_str());
|
//font->getTextHandler()->Render(text.c_str());
|
||||||
|
|
||||||
if(Font::fontIsMultibyte == true) {
|
if(font->getTextHandler() != NULL) {
|
||||||
if(font->getTextHandler() != NULL) {
|
if(text.find("\n") == text.npos && text.find("\t") == text.npos) {
|
||||||
if(text.find("\n") == text.npos && text.find("\t") == text.npos) {
|
font->getTextHandler()->Render(text.c_str());
|
||||||
font->getTextHandler()->Render(text.c_str());
|
}
|
||||||
}
|
else {
|
||||||
else {
|
int line=0;
|
||||||
int line=0;
|
bool lastCharacterWasSpecial = true;
|
||||||
bool lastCharacterWasSpecial = true;
|
vector<string> parts;
|
||||||
vector<string> parts;
|
char szBuf[4096]="";
|
||||||
char szBuf[4096]="";
|
|
||||||
|
|
||||||
for (int i=0; text[i] != '\0'; ++i) {
|
for (int i=0; text[i] != '\0'; ++i) {
|
||||||
szBuf[0] = '\0';
|
szBuf[0] = '\0';
|
||||||
sprintf(szBuf,"%c",text[i]);
|
sprintf(szBuf,"%c",text[i]);
|
||||||
|
|
||||||
switch(text[i]) {
|
switch(text[i]) {
|
||||||
case '\t':
|
case '\t':
|
||||||
|
parts.push_back(szBuf);
|
||||||
|
lastCharacterWasSpecial = true;
|
||||||
|
//rasterPos= Vec2f((rasterPos.x / size + 3.f) * size, y-(size + 1.f) * line);
|
||||||
|
//glRasterPos2f(rasterPos.x, rasterPos.y);
|
||||||
|
break;
|
||||||
|
case '\n':
|
||||||
|
parts.push_back(szBuf);
|
||||||
|
lastCharacterWasSpecial = true;
|
||||||
|
//line++;
|
||||||
|
//rasterPos= Vec2f(static_cast<float>(x), y - (fontFTGL->LineHeight(text.c_str()) * 2.f) * line);
|
||||||
|
//glRasterPos2f(rasterPos.x, rasterPos.y);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
//glCallList(font->getHandle()+utext[i]);
|
||||||
|
if(lastCharacterWasSpecial == true) {
|
||||||
parts.push_back(szBuf);
|
parts.push_back(szBuf);
|
||||||
lastCharacterWasSpecial = true;
|
}
|
||||||
//rasterPos= Vec2f((rasterPos.x / size + 3.f) * size, y-(size + 1.f) * line);
|
else {
|
||||||
//glRasterPos2f(rasterPos.x, rasterPos.y);
|
parts[parts.size()-1] += szBuf;
|
||||||
break;
|
}
|
||||||
case '\n':
|
lastCharacterWasSpecial = false;
|
||||||
parts.push_back(szBuf);
|
|
||||||
lastCharacterWasSpecial = true;
|
|
||||||
//line++;
|
|
||||||
//rasterPos= Vec2f(static_cast<float>(x), y - (fontFTGL->LineHeight(text.c_str()) * 2.f) * line);
|
|
||||||
//glRasterPos2f(rasterPos.x, rasterPos.y);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
//glCallList(font->getHandle()+utext[i]);
|
|
||||||
if(lastCharacterWasSpecial == true) {
|
|
||||||
parts.push_back(szBuf);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
parts[parts.size()-1] += szBuf;
|
|
||||||
}
|
|
||||||
lastCharacterWasSpecial = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool needsRecursiveRender = false;
|
bool needsRecursiveRender = false;
|
||||||
for (unsigned int i=0; i < parts.size(); ++i) {
|
for (unsigned int i=0; i < parts.size(); ++i) {
|
||||||
switch(parts[i][0]) {
|
switch(parts[i][0]) {
|
||||||
case '\t':
|
case '\t':
|
||||||
//translatePos= Vec3f((translatePos.x / size + 3.f) * size, y-(size + 1.f) * line, translatePos.z);
|
//translatePos= Vec3f((translatePos.x / size + 3.f) * size, y-(size + 1.f) * line, translatePos.z);
|
||||||
translatePos= Vec3f((translatePos.x / size + 3.f) * size, translatePos.y, translatePos.z);
|
translatePos= Vec3f((translatePos.x / size + 3.f) * size, translatePos.y, translatePos.z);
|
||||||
needsRecursiveRender = true;
|
needsRecursiveRender = true;
|
||||||
break;
|
break;
|
||||||
case '\n':
|
case '\n':
|
||||||
{
|
{
|
||||||
line++;
|
line++;
|
||||||
float yLineValue = font->getTextHandler()->LineHeight(parts[i].c_str());
|
float yLineValue = font->getTextHandler()->LineHeight(parts[i].c_str());
|
||||||
translatePos= Vec3f(translatePos.x, translatePos.y - yLineValue, translatePos.z);
|
translatePos= Vec3f(translatePos.x, translatePos.y - yLineValue, translatePos.z);
|
||||||
needsRecursiveRender = true;
|
needsRecursiveRender = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if(needsRecursiveRender == true) {
|
if(needsRecursiveRender == true) {
|
||||||
internalRender(parts[i], translatePos.x, translatePos.y, false, color);
|
internalRender(parts[i], translatePos.x, translatePos.y, false, color);
|
||||||
needsRecursiveRender = false;
|
needsRecursiveRender = false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
font->getTextHandler()->Render(parts[i].c_str());
|
font->getTextHandler()->Render(parts[i].c_str());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
}
|
||||||
|
else {
|
||||||
|
if(Font::fontIsMultibyte == true) {
|
||||||
//setlocale(LC_CTYPE, "en_ca.UTF-8");
|
//setlocale(LC_CTYPE, "en_ca.UTF-8");
|
||||||
|
|
||||||
//wstring wText = widen(text);
|
//wstring wText = widen(text);
|
||||||
@@ -554,77 +553,6 @@ void TextRenderer3DGl::internalRender(const string &text, float x, float y, boo
|
|||||||
//glListBase(font->getHandle());
|
//glListBase(font->getHandle());
|
||||||
//glCallLists(utfText.length(), GL_UNSIGNED_SHORT, &utfText[0]);
|
//glCallLists(utfText.length(), GL_UNSIGNED_SHORT, &utfText[0]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
if(font->getTextHandler() != NULL) {
|
|
||||||
if(text.find("\n") == text.npos && text.find("\t") == text.npos) {
|
|
||||||
font->getTextHandler()->Render(text.c_str());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
int line=0;
|
|
||||||
bool lastCharacterWasSpecial = true;
|
|
||||||
vector<string> parts;
|
|
||||||
char szBuf[4096]="";
|
|
||||||
|
|
||||||
for (int i=0; text[i] != '\0'; ++i) {
|
|
||||||
szBuf[0] = '\0';
|
|
||||||
sprintf(szBuf,"%c",text[i]);
|
|
||||||
|
|
||||||
switch(text[i]) {
|
|
||||||
case '\t':
|
|
||||||
parts.push_back(szBuf);
|
|
||||||
lastCharacterWasSpecial = true;
|
|
||||||
//rasterPos= Vec2f((rasterPos.x / size + 3.f) * size, y-(size + 1.f) * line);
|
|
||||||
//glRasterPos2f(rasterPos.x, rasterPos.y);
|
|
||||||
break;
|
|
||||||
case '\n':
|
|
||||||
parts.push_back(szBuf);
|
|
||||||
lastCharacterWasSpecial = true;
|
|
||||||
//line++;
|
|
||||||
//rasterPos= Vec2f(static_cast<float>(x), y - (fontFTGL->LineHeight(text.c_str()) * 2.f) * line);
|
|
||||||
//glRasterPos2f(rasterPos.x, rasterPos.y);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
//glCallList(font->getHandle()+utext[i]);
|
|
||||||
if(lastCharacterWasSpecial == true) {
|
|
||||||
parts.push_back(szBuf);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
parts[parts.size()-1] += szBuf;
|
|
||||||
}
|
|
||||||
lastCharacterWasSpecial = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool needsRecursiveRender = false;
|
|
||||||
for (unsigned int i=0; i < parts.size(); ++i) {
|
|
||||||
switch(parts[i][0]) {
|
|
||||||
case '\t':
|
|
||||||
//translatePos= Vec3f((translatePos.x / size + 3.f) * size, y-(size + 1.f) * line, translatePos.z);
|
|
||||||
translatePos= Vec3f((translatePos.x / size + 3.f) * size, translatePos.y, translatePos.z);
|
|
||||||
needsRecursiveRender = true;
|
|
||||||
break;
|
|
||||||
case '\n':
|
|
||||||
{
|
|
||||||
line++;
|
|
||||||
float yLineValue = font->getTextHandler()->LineHeight(parts[i].c_str());
|
|
||||||
translatePos= Vec3f(translatePos.x, translatePos.y - yLineValue, translatePos.z);
|
|
||||||
needsRecursiveRender = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if(needsRecursiveRender == true) {
|
|
||||||
internalRender(parts[i], translatePos.x, translatePos.y, false, color);
|
|
||||||
needsRecursiveRender = false;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
font->getTextHandler()->Render(parts[i].c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
for (int i=0; utext[i]!='\0'; ++i) {
|
for (int i=0; utext[i]!='\0'; ++i) {
|
||||||
glCallList(font->getHandle()+utext[i]);
|
glCallList(font->getHandle()+utext[i]);
|
||||||
@@ -633,8 +561,6 @@ void TextRenderer3DGl::internalRender(const string &text, float x, float y, boo
|
|||||||
}
|
}
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
//glPopMatrix();
|
|
||||||
//glPopAttrib();
|
|
||||||
|
|
||||||
if(color != NULL) {
|
if(color != NULL) {
|
||||||
glPopAttrib();
|
glPopAttrib();
|
||||||
|
Reference in New Issue
Block a user