- reworked fonts to now use 3d matrix positioning and render performance is much better.

*NOTE: Still need to deal with some letters getting partially chopped off in some cases.
This commit is contained in:
Mark Vejvoda
2011-06-10 03:09:19 +00:00
parent ca75809f2d
commit 06999a8f88
18 changed files with 528 additions and 156 deletions

View File

@@ -52,6 +52,7 @@ GraphicComponent::GraphicComponent(std::string containerName, std::string objNam
h = 0;
text = "";
font = NULL;
font3D = NULL;
}
void GraphicComponent::clearRegisteredComponents(std::string containerName) {
@@ -209,6 +210,7 @@ void GraphicComponent::init(int x, int y, int w, int h) {
this->w= w;
this->h= h;
font= CoreData::getInstance().getMenuFontNormal();
font3D= CoreData::getInstance().getMenuFontNormal3D();
enabled= true;
}
@@ -422,6 +424,7 @@ void GraphicMessageBox::setY(int y) {
void GraphicMessageBox::init(const string &button1Str) {
font= CoreData::getInstance().getMenuFontNormal();
font3D= CoreData::getInstance().getMenuFontNormal3D();
h= defH;
w= defW;

View File

@@ -25,6 +25,7 @@ using std::string;
using std::vector;
using Shared::Graphics::Font2D;
using Shared::Graphics::Font3D;
using namespace Shared::Graphics;
using Shared::Graphics::Vec3f;
@@ -49,6 +50,7 @@ protected:
int x, y, w, h;
string text;
Font2D *font;
Font3D *font3D;
bool enabled;
bool editable;
bool visible;
@@ -84,6 +86,7 @@ public:
virtual int getH() const {return h;}
virtual const string &getText() const {return text;}
virtual Font2D *getFont() {return font;}
virtual Font3D *getFont3D() {return font3D;}
virtual bool getEnabled() const {return enabled;}
virtual bool getEditable() const {return editable;}
virtual bool getVisible() const {return visible;}
@@ -94,6 +97,7 @@ public:
virtual void setH(int h) {this->h= h;}
virtual void setText(const string &text) {this->text= text;}
virtual void setFont(Font2D *font) {this->font= font;}
virtual void setFont3D(Font3D *font) {this->font3D= font3D;}
virtual void setEnabled(bool enabled) {this->enabled= enabled;}
virtual void setEditable(bool editable) {this->editable= editable;}
virtual void setVisible(bool value) {this->visible = value;}

View File

@@ -136,30 +136,60 @@ void Logger::renderLoadingScreen() {
else {
renderer.renderBackground(loadingTexture);
}
renderer.renderText(
state, coreData.getMenuFontBig(), Vec3f(1.f),
metrics.getVirtualW()/4, 65*metrics.getVirtualH()/100, false);
renderer.renderText(
current, coreData.getMenuFontNormal(), 1.0f,
metrics.getVirtualW() / 4,
62 * metrics.getVirtualH() / 100, false);
if(showProgressBar == true) {
renderer.renderProgressBar(
progress,
metrics.getVirtualW() / 4,
59 * metrics.getVirtualH() / 100,
coreData.getDisplayFontSmall(),
350,""); // no string here, because it has to be language specific and does not give much information
if(Renderer::renderText3DEnabled) {
renderer.renderProgressBar3D(
progress,
metrics.getVirtualW() / 4,
59 * metrics.getVirtualH() / 100,
coreData.getDisplayFontSmall3D(),
350,""); // no string here, because it has to be language specific and does not give much information
}
else {
renderer.renderProgressBar(
progress,
metrics.getVirtualW() / 4,
59 * metrics.getVirtualH() / 100,
coreData.getDisplayFontSmall(),
350,""); // no string here, because it has to be language specific and does not give much information
}
}
if(this->statusText != "") {
renderer.renderText(
this->statusText, coreData.getMenuFontNormal(), 1.0f,
metrics.getVirtualW() / 4,
56 * metrics.getVirtualH() / 100, false);
}
if(Renderer::renderText3DEnabled) {
renderer.renderText3D(
state, coreData.getMenuFontBig3D(), Vec3f(1.f),
metrics.getVirtualW()/4, 65*metrics.getVirtualH()/100, false);
renderer.renderText3D(
current, coreData.getMenuFontNormal3D(), 1.0f,
metrics.getVirtualW() / 4,
62 * metrics.getVirtualH() / 100, false);
if(this->statusText != "") {
renderer.renderText3D(
this->statusText, coreData.getMenuFontNormal3D(), 1.0f,
metrics.getVirtualW() / 4,
56 * metrics.getVirtualH() / 100, false);
}
}
else {
renderer.renderText(
state, coreData.getMenuFontBig(), Vec3f(1.f),
metrics.getVirtualW()/4, 65*metrics.getVirtualH()/100, false);
renderer.renderText(
current, coreData.getMenuFontNormal(), 1.0f,
metrics.getVirtualW() / 4,
62 * metrics.getVirtualH() / 100, false);
if(this->statusText != "") {
renderer.renderText(
this->statusText, coreData.getMenuFontNormal(), 1.0f,
metrics.getVirtualW() / 4,
56 * metrics.getVirtualH() / 100, false);
}
}
if(buttonCancel.getEnabled() == true) {
renderer.renderButton(&buttonCancel);

View File

@@ -41,6 +41,7 @@ ChatManager::ChatManager() {
yPos=150;
maxTextLenght=64;
font=CoreData::getInstance().getConsoleFont();
font3D=CoreData::getInstance().getConsoleFont3D();
}
void ChatManager::init(Console* console, int thisTeamIndex, const bool inMenu, string manualPlayerNameOverride) {

View File

@@ -18,6 +18,7 @@
using std::string;
using Shared::Graphics::Font2D;
using Shared::Graphics::Font3D;
namespace Glest{ namespace Game{
@@ -42,6 +43,7 @@ private:
int yPos;
int maxTextLenght;
Font2D *font;
Font3D *font3D;
public:
@@ -64,7 +66,9 @@ public:
int getMaxTextLenght() const {return maxTextLenght;}
void setMaxTextLenght(int maxTextLenght) {this->maxTextLenght= maxTextLenght;}
Font2D *getFont() const {return font;}
Font3D *getFont3D() const {return font3D;}
void setFont(Font2D *font) {this->font= font;}
void setFont3D(Font3D *font) {this->font3D= font;}
void addText(string text);
void switchOnEdit();

View File

@@ -39,6 +39,7 @@ Console::Console() {
yPos=20;
lineHeight=20;
font=CoreData::getInstance().getConsoleFont();
font3D=CoreData::getInstance().getConsoleFont3D();
stringToHighlight="";
}

View File

@@ -28,6 +28,7 @@ using namespace std;
namespace Glest { namespace Game {
using Shared::Graphics::Font2D;
using Shared::Graphics::Font3D;
using Shared::Graphics::Vec3f;
// =====================================================
// class Console
@@ -67,6 +68,7 @@ private:
int yPos;
int lineHeight;
Font2D *font;
Font3D *font3D;
public:
Console();
@@ -80,7 +82,9 @@ public:
int getLineHeight() const {return lineHeight;}
void setLineHeight(int lineHeight) {this->lineHeight= lineHeight;}
Font2D *getFont() const {return font;}
Font3D *getFont3D() const {return font3D;}
void setFont(Font2D *font) {this->font= font;}
void setFont3D(Font3D *font) {this->font3D= font;}
string getStringToHighlight() const { return stringToHighlight;}
void setStringToHighlight(string stringToHighlight) { this->stringToHighlight = stringToHighlight;}

View File

@@ -1919,9 +1919,16 @@ void Game::render2d(){
if(!scriptManager.getDisplayText().empty() && !scriptManager.getMessageBoxEnabled()){
Vec4f fontColor = getGui()->getDisplay()->getColor();
renderer.renderText(
scriptManager.getDisplayText(), coreData.getMenuFontNormal(),
Vec3f(fontColor.x,fontColor.y,fontColor.z), 200, 680, false);
if(Renderer::renderText3DEnabled == true) {
renderer.renderText3D(
scriptManager.getDisplayText(), coreData.getMenuFontNormal3D(),
Vec3f(fontColor.x,fontColor.y,fontColor.z), 200, 680, false);
}
else {
renderer.renderText(
scriptManager.getDisplayText(), coreData.getMenuFontNormal(),
Vec3f(fontColor.x,fontColor.y,fontColor.z), 200, 680, false);
}
}
if(program != NULL) program->renderProgramMsgBox();
@@ -2040,16 +2047,29 @@ void Game::render2d(){
int mh= metrics.getMinimapH();
const Vec4f fontColor=getGui()->getDisplay()->getColor();
renderer.renderTextShadow(str, coreData.getMenuFontNormal(),
fontColor, 10, metrics.getVirtualH() - mh - 60, false);
if(Renderer::renderText3DEnabled == true) {
renderer.renderTextShadow3D(str, coreData.getMenuFontNormal3D(),
fontColor, 10, metrics.getVirtualH() - mh - 60, false);
}
else {
renderer.renderTextShadow(str, coreData.getMenuFontNormal(),
fontColor, 10, metrics.getVirtualH() - mh - 60, false);
}
for(int i = 0; i < world.getFactionCount(); ++i) {
string factionInfo = factionDebugInfo[i];
Vec3f playerColor = world.getFaction(i)->getTexture()->getPixmapConst()->getPixel3f(0, 0);
renderer.renderText(factionInfo, coreData.getMenuFontBig(),
Vec4f(playerColor.x,playerColor.y,playerColor.z,1.0),
10, metrics.getVirtualH() - mh - 90 - 280 - (i * 16), false);
if(Renderer::renderText3DEnabled == true) {
renderer.renderText3D(factionInfo, coreData.getMenuFontBig3D(),
Vec4f(playerColor.x,playerColor.y,playerColor.z,1.0),
10, metrics.getVirtualH() - mh - 90 - 280 - (i * 16), false);
}
else {
renderer.renderText(factionInfo, coreData.getMenuFontBig(),
Vec4f(playerColor.x,playerColor.y,playerColor.z,1.0),
10, metrics.getVirtualH() - mh - 90 - 280 - (i * 16), false);
}
}
if((renderer.getShowDebugUILevel() & debugui_unit_titles) == debugui_unit_titles) {
@@ -2070,10 +2090,18 @@ void Game::render2d(){
int mh= metrics.getMinimapH();
const Vec4f fontColor=getGui()->getDisplay()->getColor();
renderer.renderTextShadow(
NetworkManager::getInstance().getGameNetworkInterface()->getNetworkStatus(),
coreData.getMenuFontNormal(),
fontColor, mx + mw + 5 , metrics.getVirtualH()-30-20, false);
if(Renderer::renderText3DEnabled == true) {
renderer.renderTextShadow3D(
NetworkManager::getInstance().getGameNetworkInterface()->getNetworkStatus(),
coreData.getMenuFontNormal3D(),
fontColor, mx + mw + 5 , metrics.getVirtualH()-30-20, false);
}
else {
renderer.renderTextShadow(
NetworkManager::getInstance().getGameNetworkInterface()->getNetworkStatus(),
coreData.getMenuFontNormal(),
fontColor, mx + mw + 5 , metrics.getVirtualH()-30-20, false);
}
}
}

View File

@@ -38,6 +38,8 @@ namespace Glest { namespace Game{
uint32 Renderer::SurfaceData::nextUniqueId = 1;
bool Renderer::renderText3DEnabled = true;
// =====================================================
// class MeshCallbackTeamColor
// =====================================================
@@ -955,6 +957,91 @@ void Renderer::renderTextureQuad(int x, int y, int w, int h, const Texture2D *te
assertGl();
}
void Renderer::renderConsoleLine3D(int lineIndex, int xPosition, int yPosition, int lineHeight,
Font3D* font, string stringToHightlight, const ConsoleLineInfo *lineInfo) {
Vec4f fontColor;
const Metrics &metrics= Metrics::getInstance();
FontMetrics *fontMetrics= font->getMetrics();
if(game != NULL) {
fontColor = game->getGui()->getDisplay()->getColor();
}
else {
// white shadowed is default ( in the menu for example )
//fontColor=Vec4f(1.f, 1.f, 1.f, 0.0f);
fontColor=Vec4f(lineInfo->color.x,lineInfo->color.y,lineInfo->color.z, 0.0f);
}
Vec4f defaultFontColor = fontColor;
if(lineInfo->PlayerIndex >= 0) {
std::map<int,Texture2D *> &crcPlayerTextureCache = CacheManager::getCachedItem< std::map<int,Texture2D *> >(GameConstants::playerTextureCacheLookupKey);
Vec3f playerColor = crcPlayerTextureCache[lineInfo->PlayerIndex]->getPixmap()->getPixel3f(0, 0);
fontColor.x = playerColor.x;
fontColor.y = playerColor.y;
fontColor.z = playerColor.z;
GameNetworkInterface *gameNetInterface = NetworkManager::getInstance().getGameNetworkInterface();
if(gameNetInterface != NULL && gameNetInterface->getGameSettings() != NULL) {
const GameSettings *gameSettings = gameNetInterface->getGameSettings();
string playerName = gameSettings->getNetworkPlayerNameByPlayerIndex(lineInfo->PlayerIndex);
if(playerName != lineInfo->originalPlayerName && lineInfo->originalPlayerName != "") {
playerName = lineInfo->originalPlayerName;
}
//printf("playerName [%s], line [%s]\n",playerName.c_str(),line.c_str());
//string headerLine = "*" + playerName + ":";
string headerLine = playerName + ": ";
if(fontMetrics == NULL) {
throw runtime_error("fontMetrics == NULL");
}
renderTextShadow3D(
headerLine,
font,
fontColor,
xPosition, lineIndex * lineHeight + yPosition);
fontColor = defaultFontColor;
//xPosition += (8 * (playerName.length() + 2));
// Proper font spacing after username portion of chat text rendering
xPosition += (metrics.toVirtualX(fontMetrics->getTextWidth(headerLine)));
}
}
else if(lineInfo->originalPlayerName != "") {
string playerName = lineInfo->originalPlayerName;
string headerLine = playerName + ": ";
if(fontMetrics == NULL) {
throw runtime_error("fontMetrics == NULL");
}
renderTextShadow3D(
headerLine,
font,
fontColor,
xPosition, lineIndex * lineHeight + yPosition);
fontColor = defaultFontColor;
//xPosition += (8 * (playerName.length() + 2));
// Proper font spacing after username portion of chat text rendering
xPosition += (metrics.toVirtualX(fontMetrics->getTextWidth(headerLine)));
}
else {
fontColor = defaultFontColor;
}
if(stringToHightlight!="" && lineInfo->text.find(stringToHightlight)!=string::npos){
fontColor=Vec4f(1.f, 0.5f, 0.5f, 0.0f);
}
renderTextShadow3D(
lineInfo->text,
font,
fontColor,
xPosition, (lineIndex * lineHeight) + yPosition);
}
void Renderer::renderConsoleLine(int lineIndex, int xPosition, int yPosition, int lineHeight,
Font2D* font, string stringToHightlight, const ConsoleLineInfo *lineInfo) {
Vec4f fontColor;
@@ -1052,23 +1139,43 @@ void Renderer::renderConsole(const Console *console,const bool showFullConsole,
if(showFullConsole) {
for(int i = 0; i < console->getStoredLineCount(); ++i) {
const ConsoleLineInfo &lineInfo = console->getStoredLineItem(i);
renderConsoleLine(i, console->getXPos(), console->getYPos(),
console->getLineHeight(), console->getFont(), console->getStringToHighlight(), &lineInfo);
if(renderText3DEnabled == true) {
renderConsoleLine3D(i, console->getXPos(), console->getYPos(),
console->getLineHeight(), console->getFont3D(),
console->getStringToHighlight(), &lineInfo);
}
else {
renderConsoleLine(i, console->getXPos(), console->getYPos(),
console->getLineHeight(), console->getFont(),
console->getStringToHighlight(), &lineInfo);
}
}
}
else if(showMenuConsole) {
int allowedMaxLines = (overrideMaxConsoleLines >= 0 ? overrideMaxConsoleLines : maxConsoleLines);
for(int i = 0; i < console->getStoredLineCount() && i < allowedMaxLines; ++i) {
const ConsoleLineInfo &lineInfo = console->getStoredLineItem(i);
renderConsoleLine(i, console->getXPos(), console->getYPos(),
console->getLineHeight(), console->getFont(), console->getStringToHighlight(), &lineInfo);
if(renderText3DEnabled == true) {
renderConsoleLine3D(i, console->getXPos(), console->getYPos(),
console->getLineHeight(), console->getFont3D(), console->getStringToHighlight(), &lineInfo);
}
else {
renderConsoleLine(i, console->getXPos(), console->getYPos(),
console->getLineHeight(), console->getFont(), console->getStringToHighlight(), &lineInfo);
}
}
}
else {
for(int i = 0; i < console->getLineCount(); ++i) {
const ConsoleLineInfo &lineInfo = console->getLineItem(i);
renderConsoleLine(i, console->getXPos(), console->getYPos(),
console->getLineHeight(), console->getFont(), console->getStringToHighlight(), &lineInfo);
if(renderText3DEnabled == true) {
renderConsoleLine3D(i, console->getXPos(), console->getYPos(),
console->getLineHeight(), console->getFont3D(), console->getStringToHighlight(), &lineInfo);
}
else {
renderConsoleLine(i, console->getXPos(), console->getYPos(),
console->getLineHeight(), console->getFont(), console->getStringToHighlight(), &lineInfo);
}
}
}
glPopAttrib();
@@ -1081,7 +1188,7 @@ void Renderer::renderChatManager(const ChatManager *chatManager) {
if(chatManager->getEditEnabled()) {
string text="";
if(chatManager->getInMenu()){
if(chatManager->getInMenu()) {
text += lang.get("Chat");
}
else if(chatManager->getTeamMode()) {
@@ -1100,23 +1207,35 @@ void Renderer::renderChatManager(const ChatManager *chatManager) {
fontColor=Vec4f(1.f, 1.f, 1.f, 0.0f);
}
renderTextShadow(
text,
chatManager->getFont(),
fontColor,
chatManager->getXPos(), chatManager->getYPos());
//textRenderer->begin(CoreData::getInstance().getConsoleFont());
//textRenderer->render(text, 300, 150);
//textRenderer->end();
if(renderText3DEnabled == true) {
renderTextShadow3D(
text,
chatManager->getFont3D(),
fontColor,
chatManager->getXPos(), chatManager->getYPos());
}
else {
renderTextShadow(
text,
chatManager->getFont(),
fontColor,
chatManager->getXPos(), chatManager->getYPos());
}
}
else
{
if (chatManager->getInMenu()) {
string text = ">> "+lang.get("PressEnterToChat")+" <<";
fontColor = Vec4f(0.5f, 0.5f, 0.5f, 0.5f);
renderTextShadow(text, chatManager->getFont(), fontColor,
chatManager->getXPos(), chatManager->getYPos());
if(renderText3DEnabled == true) {
renderTextShadow3D(text, chatManager->getFont3D(), fontColor,
chatManager->getXPos(), chatManager->getYPos());
}
else {
renderTextShadow(text, chatManager->getFont(), fontColor,
chatManager->getXPos(), chatManager->getYPos());
}
}
}
}
@@ -1169,10 +1288,18 @@ void Renderer::renderResourceStatus() {
glDisable(GL_TEXTURE_2D);
renderTextShadow(
str, CoreData::getInstance().getDisplayFontSmall(),
fontColor,
j*100+220, metrics.getVirtualH()-30, false);
if(renderText3DEnabled == true) {
renderTextShadow3D(
str, CoreData::getInstance().getDisplayFontSmall3D(),
fontColor,
j*100+220, metrics.getVirtualH()-30, false);
}
else {
renderTextShadow(
str, CoreData::getInstance().getDisplayFontSmall(),
fontColor,
j*100+220, metrics.getVirtualH()-30, false);
}
++j;
}
@@ -1440,10 +1567,20 @@ void Renderer::renderLabel(GraphicLabel *label,const Vec4f *color) {
}
if(color != NULL) {
renderText(lines[i], label->getFont(), (*color), textPos.x, textPos.y, label->getCentered());
if(renderText3DEnabled == true) {
renderText3D(lines[i], label->getFont3D(), (*color), textPos.x, textPos.y, label->getCentered());
}
else {
renderText(lines[i], label->getFont(), (*color), textPos.x, textPos.y, label->getCentered());
}
}
else {
renderText(lines[i], label->getFont(), GraphicComponent::getFade(), textPos.x, textPos.y, label->getCentered());
if(renderText3DEnabled == true) {
renderText3D(lines[i], label->getFont3D(), GraphicComponent::getFade(), textPos.x, textPos.y, label->getCentered());
}
else {
renderText(lines[i], label->getFont(), GraphicComponent::getFade(), textPos.x, textPos.y, label->getCentered());
}
}
}
glPopAttrib();
@@ -1555,24 +1692,25 @@ void Renderer::renderButton(GraphicButton *button, const Vec4f *fontColorOverrid
glEnd();
}
Vec2i textPos= Vec2i(x+w/2, y+h/2);
Vec2i textPos= Vec2i(x + w / 2, y + h / 2);
if(button->getEditable()) {
Font2D *font = button->getFont();
//Font3D *font3d = ConvertFont2DTo3D(button->getFont());
renderText(
button->getText(), font, color,
x+w/2, y+h/2, true);
//delete font3d;
// renderText(
// button->getText(), button->getFont(), color,
// x+w/2, y+h/2, true);
if(renderText3DEnabled == true) {
renderText3D(button->getText(), button->getFont3D(), color,x + w / 2, y + h / 2, true);
}
else {
renderText(button->getText(), button->getFont(), color,x + w / 2, y + h / 2, true);
}
}
else {
renderText(
button->getText(), button->getFont(),disabledTextColor,
x+w/2, y+h/2, true);
if(renderText3DEnabled == true) {
renderText3D(button->getText(), button->getFont3D(),disabledTextColor,
x + w / 2, y + h / 2, true);
}
else {
renderText(button->getText(), button->getFont(),disabledTextColor,
x + w / 2, y + h / 2, true);
}
}
glPopAttrib();
@@ -1976,16 +2114,31 @@ void Renderer::renderMessageBox(GraphicMessageBox *messageBox) {
fontColor=Vec4f(1.f, 1.f, 1.f, 1.0f);
//}
//text
renderTextShadow(
messageBox->getText(), messageBox->getFont(), fontColor,
messageBox->getX()+15, messageBox->getY()+7*messageBox->getH()/10,
false );
if(renderText3DEnabled == true) {
//text
renderTextShadow3D(
messageBox->getText(), messageBox->getFont3D(), fontColor,
messageBox->getX()+15, messageBox->getY()+7*messageBox->getH()/10,
false );
renderTextShadow(
messageBox->getHeader(), messageBox->getFont(),fontColor,
messageBox->getX()+15, messageBox->getY()+93*messageBox->getH()/100,
false );
renderTextShadow3D(
messageBox->getHeader(), messageBox->getFont3D(),fontColor,
messageBox->getX()+15, messageBox->getY()+93*messageBox->getH()/100,
false );
}
else {
//text
renderTextShadow(
messageBox->getText(), messageBox->getFont(), fontColor,
messageBox->getX()+15, messageBox->getY()+7*messageBox->getH()/10,
false );
renderTextShadow(
messageBox->getHeader(), messageBox->getFont(),fontColor,
messageBox->getX()+15, messageBox->getY()+93*messageBox->getH()/100,
false );
}
}
// ==================== complex rendering ====================
@@ -3459,7 +3612,7 @@ void Renderer::renderMinimap(){
assertGl();
}
void Renderer::renderDisplay(){
void Renderer::renderDisplay() {
CoreData &coreData= CoreData::getInstance();
const Metrics &metrics= Metrics::getInstance();
@@ -3467,39 +3620,77 @@ void Renderer::renderDisplay(){
glPushAttrib(GL_ENABLE_BIT);
//infoString
renderTextShadow(
display->getInfoText().c_str(),
coreData.getDisplayFont(),
display->getColor(),
metrics.getDisplayX(),
metrics.getDisplayY()+Display::infoStringY);
//title
renderTextShadow(
display->getTitle().c_str(),
coreData.getDisplayFont(),
display->getColor(),
metrics.getDisplayX()+40,
metrics.getDisplayY() + metrics.getDisplayH() - 20);
glColor3f(0.0f, 0.0f, 0.0f);
//text
renderTextShadow(
display->getText().c_str(),
coreData.getDisplayFont(),
display->getColor(),
metrics.getDisplayX() -1,
metrics.getDisplayY() + metrics.getDisplayH() - 56);
//progress Bar
if(display->getProgressBar()!=-1){
renderProgressBar(
display->getProgressBar(),
if(renderText3DEnabled == true) {
//infoString
renderTextShadow3D(
display->getInfoText().c_str(),
coreData.getDisplayFont3D(),
display->getColor(),
metrics.getDisplayX(),
metrics.getDisplayY() + metrics.getDisplayH()-50,
coreData.getDisplayFontSmall());
metrics.getDisplayY()+Display::infoStringY);
//title
renderTextShadow3D(
display->getTitle().c_str(),
coreData.getDisplayFont3D(),
display->getColor(),
metrics.getDisplayX()+40,
metrics.getDisplayY() + metrics.getDisplayH() - 20);
glColor3f(0.0f, 0.0f, 0.0f);
//text
renderTextShadow3D(
display->getText().c_str(),
coreData.getDisplayFont3D(),
display->getColor(),
metrics.getDisplayX() -1,
metrics.getDisplayY() + metrics.getDisplayH() - 56);
//progress Bar
if(display->getProgressBar() != -1) {
renderProgressBar3D(
display->getProgressBar(),
metrics.getDisplayX(),
metrics.getDisplayY() + metrics.getDisplayH()-50,
coreData.getDisplayFontSmall3D());
}
}
else {
//infoString
renderTextShadow(
display->getInfoText().c_str(),
coreData.getDisplayFont(),
display->getColor(),
metrics.getDisplayX(),
metrics.getDisplayY()+Display::infoStringY);
//title
renderTextShadow(
display->getTitle().c_str(),
coreData.getDisplayFont(),
display->getColor(),
metrics.getDisplayX()+40,
metrics.getDisplayY() + metrics.getDisplayH() - 20);
glColor3f(0.0f, 0.0f, 0.0f);
//text
renderTextShadow(
display->getText().c_str(),
coreData.getDisplayFont(),
display->getColor(),
metrics.getDisplayX() -1,
metrics.getDisplayY() + metrics.getDisplayH() - 56);
//progress Bar
if(display->getProgressBar()!=-1){
renderProgressBar(
display->getProgressBar(),
metrics.getDisplayX(),
metrics.getDisplayY() + metrics.getDisplayH()-50,
coreData.getDisplayFontSmall());
}
}
//up images

View File

@@ -186,6 +186,8 @@ public:
//light
static const float maxLightDist;
static bool renderText3DEnabled;
public:
enum Shadows {
sDisabled,
@@ -196,6 +198,7 @@ public:
};
private:
//config
int maxLights;
bool photoMode;
@@ -326,6 +329,8 @@ public:
Font3D *newFont3D(ResourceScope rs);
TextRenderer2D *getTextRenderer() const {return textRenderer;}
TextRenderer3D *getTextRenderer3D() const {return textRenderer3D;}
void manageParticleSystem(ParticleSystem *particleSystem, ResourceScope rs);
void cleanupParticleSystems(vector<ParticleSystem *> &particleSystems,ResourceScope rs);
void cleanupUnitParticleSystems(vector<UnitParticleSystem *> &particleSystems,ResourceScope rs);
@@ -346,7 +351,9 @@ public:
void renderBackground(const Texture2D *texture);
void renderTextureQuad(int x, int y, int w, int h, const Texture2D *texture, float alpha=1.f,const Vec3f *color=NULL);
void renderConsole(const Console *console, const bool showAll=false, const bool showMenuConsole=false, int overrideMaxConsoleLines=-1);
void renderConsoleLine3D(int lineIndex, int xPosition, int yPosition, int lineHeight, Font3D* font, string stringToHightlight, const ConsoleLineInfo *lineInfo);
void renderConsoleLine(int lineIndex, int xPosition, int yPosition, int lineHeight, Font2D* font, string stringToHightlight, const ConsoleLineInfo *lineInfo);
void renderChatManager(const ChatManager *chatManager);
void renderResourceStatus();
void renderSelectionQuad();
@@ -358,9 +365,8 @@ public:
void renderText3D(const string &text, Font3D *font, float alpha, int x, int y, bool centered);
void renderText3D(const string &text, Font3D *font, const Vec3f &color, int x, int y, bool centered);
void renderText3D(const string &text, Font3D *font, const Vec4f &color, int x, int y, bool centered);
void renderTextShadow3D(const string &text, Font3D *font,const Vec4f &color, int x, int y, bool centered);
void renderProgressBar3D(int size, int x, int y, Font3D *font, int customWidth,
string prefixLabel,bool centeredText);
void renderTextShadow3D(const string &text, Font3D *font,const Vec4f &color, int x, int y, bool centered=false);
void renderProgressBar3D(int size, int x, int y, Font3D *font, int customWidth=-1, string prefixLabel="", bool centeredText=true);
//components
void renderLabel(GraphicLabel *label);

View File

@@ -72,7 +72,16 @@ void BattleEnd::update() {
void BattleEnd::render(){
Renderer &renderer= Renderer::getInstance();
TextRenderer2D *textRenderer= renderer.getTextRenderer();
TextRenderer2D *textRenderer2D= renderer.getTextRenderer();
TextRenderer3D *textRenderer3D= renderer.getTextRenderer3D();
TextRenderer *textRenderer= NULL;
if(Renderer::renderText3DEnabled == true) {
textRenderer= textRenderer3D;
}
else {
textRenderer= textRenderer2D;
}
Lang &lang= Lang::getInstance();
renderer.clearBuffers();
@@ -137,7 +146,13 @@ void BattleEnd::render(){
}
bool disableStatsColorCoding = Config::getInstance().getBool("DisableBattleEndColorCoding","false");
textRenderer->begin(CoreData::getInstance().getMenuFontNormal());
if(Renderer::renderText3DEnabled == true) {
textRenderer3D->begin(CoreData::getInstance().getMenuFontNormal3D());
}
else {
textRenderer2D->begin(CoreData::getInstance().getMenuFontNormal());
}
int lm= 20;
int bm= 100;
@@ -292,7 +307,12 @@ void BattleEnd::render(){
textRenderer->end();
textRenderer->begin(CoreData::getInstance().getMenuFontVeryBig());
if(Renderer::renderText3DEnabled == true) {
textRenderer3D->begin(CoreData::getInstance().getMenuFontVeryBig3D());
}
else {
textRenderer2D->begin(CoreData::getInstance().getMenuFontVeryBig());
}
string header = stats.getDescription() + " - ";

View File

@@ -32,12 +32,13 @@ namespace Glest{ namespace Game{
// class Text
// =====================================================
Text::Text(const string &text, const Vec2i &pos, int time, Font2D *font) {
Text::Text(const string &text, const Vec2i &pos, int time, Font2D *font, Font3D *font3D) {
this->text= text;
this->pos= pos;
this->time= time;
this->texture= NULL;
this->font= font;
this->font3D = font3D;
}
Text::Text(const Texture2D *texture, const Vec2i &pos, const Vec2i &size, int time) {
@@ -72,8 +73,8 @@ Intro::Intro(Program *program):
mouse2d = 0;
texts.push_back(Text(coreData.getLogoTexture(), Vec2i(w/2-128, h/2-64), Vec2i(256, 128), 4000));
texts.push_back(Text(glestVersionString, Vec2i(w/2+45, h/2-45), 4000, coreData.getMenuFontNormal()));
texts.push_back(Text("www.megaglest.org", Vec2i(w/2, h/2), 12000, coreData.getMenuFontVeryBig()));
texts.push_back(Text(glestVersionString, Vec2i(w/2+45, h/2-45), 4000, coreData.getMenuFontNormal(),coreData.getMenuFontNormal3D()));
texts.push_back(Text("www.megaglest.org", Vec2i(w/2, h/2), 12000, coreData.getMenuFontVeryBig(),coreData.getMenuFontVeryBig3D()));
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@@ -124,11 +125,20 @@ void Intro::render() {
//disappearing
alpha= 1.f- static_cast<float>(difTime-appearTime-showTime)/disapearTime;
}
if(!text->getText().empty()){
renderer.renderText(
text->getText(), text->getFont(), alpha,
text->getPos().x, text->getPos().y, true);
if(text->getText().empty() == false) {
if(Renderer::renderText3DEnabled) {
renderer.renderText3D(
text->getText(), text->getFont3D(), alpha,
text->getPos().x, text->getPos().y, true);
}
else {
renderer.renderText(
text->getText(), text->getFont(), alpha,
text->getPos().x, text->getPos().y, true);
}
}
if(text->getTexture()!=NULL){
renderer.renderTextureQuad(
text->getPos().x, text->getPos().y,

View File

@@ -26,6 +26,7 @@ using Shared::Graphics::Vec2i;
using Shared::Graphics::Vec2f;
using Shared::Graphics::Vec3f;
using Shared::Graphics::Font2D;
using Shared::Graphics::Font3D;
using Shared::Graphics::Texture2D;
namespace Glest{ namespace Game{
@@ -34,21 +35,23 @@ namespace Glest{ namespace Game{
// class Text
// =====================================================
class Text{
class Text {
private:
string text;
Vec2i pos;
Vec2i size;
int time;
Font2D *font;
Font3D *font3D;
const Texture2D *texture;
public:
Text(const string &text, const Vec2i &pos, int time, Font2D *font);
Text(const string &text, const Vec2i &pos, int time, Font2D *font, Font3D *font3D);
Text(const Texture2D *texture, const Vec2i &pos, const Vec2i &size, int time);
const string &getText() const {return text;}
Font2D *getFont() {return font;}
Font3D *getFont3D() {return font3D;}
const Vec2i &getPos() const {return pos;}
const Vec2i &getSize() const {return size;}
int getTime() const {return time;}

View File

@@ -2455,6 +2455,8 @@ int glestMain(int argc, char** argv) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("**WARNING** Forcing Legacy Fonts Enabled\n");
}
Renderer::renderText3DEnabled = config.getBool("Enable3DFontRendering",intToStr(Renderer::renderText3DEnabled).c_str());
// Set some statics based on ini entries
SystemFlags::ENABLE_THREADED_LOGGING = config.getBool("ThreadedLogging","true");
FontGl::setDefault_fontType(config.getString("DefaultFont",FontGl::getDefault_fontType().c_str()));

View File

@@ -111,9 +111,16 @@ void MainMenu::render() {
renderer.renderMouse2d(mouseX, mouseY, mouse2dAnim);
if(renderer.getShowDebugUI() == true) {
renderer.renderText(
"FPS: " + intToStr(lastFps),
coreData.getMenuFontNormal(), Vec3f(1.f), 10, 10, false);
if(Renderer::renderText3DEnabled) {
renderer.renderText3D(
"FPS: " + intToStr(lastFps),
coreData.getMenuFontNormal3D(), Vec3f(1.f), 10, 10, false);
}
else {
renderer.renderText(
"FPS: " + intToStr(lastFps),
coreData.getMenuFontNormal(), Vec3f(1.f), 10, 10, false);
}
}
renderer.swapBuffers();

View File

@@ -38,7 +38,7 @@ public:
virtual ~TextRenderer2DGl();
virtual void begin(Font2D *font);
virtual void render(const string &text, int x, int y, bool centered, Vec3f *color=NULL);
virtual void render(const string &text, float x, float y, bool centered=false, Vec3f *color=NULL);
virtual void end();
};
@@ -51,12 +51,14 @@ private:
Font3DGl *font;
bool rendering;
void internalRender(const string &text, float x, float y, bool centered, Vec3f *color);
public:
TextRenderer3DGl();
virtual ~TextRenderer3DGl();
virtual void begin(Font3D *font);
virtual void render(const string &text, float x, float y, bool centered);
virtual void render(const string &text, float x, float y, bool centered=false, Vec3f *color=NULL);
virtual void end();
};

View File

@@ -25,26 +25,32 @@ namespace Shared { namespace Graphics {
// class TextRenderer2D
// =====================================================
class TextRenderer2D {
class TextRenderer {
public:
virtual void render(const string &text, float x, float y, bool centered=false, Vec3f *color=NULL) = 0;
virtual void end()= 0;
};
class TextRenderer2D : public TextRenderer {
public:
virtual ~TextRenderer2D(){};
virtual void begin(Font2D *font)= 0;
virtual void render(const string &text, int x, int y, bool centered= false,Vec3f *color=NULL)= 0;
virtual void end()= 0;
//virtual void render(const string &text, int x, int y, bool centered= false,Vec3f *color=NULL)= 0;
//virtual void end()= 0;
};
// =====================================================
// class TextRenderer3D
// =====================================================
class TextRenderer3D {
class TextRenderer3D : public TextRenderer {
public:
virtual ~TextRenderer3D(){};
virtual void begin(Font3D *font)= 0;
virtual void render(const string &text, float x, float y, bool centered= false)= 0;
virtual void end()= 0;
//virtual void render(const string &text, float x, float y, bool centered= false,Vec3f *color=NULL)= 0;
//virtual void end()= 0;
};
}}//end namespace

View File

@@ -61,7 +61,10 @@ void TextRenderer2DGl::begin(Font2D *font) {
rendering = true;
}
void TextRenderer2DGl::render(const string &text, int x, int y, bool centered, Vec3f *color) {
void TextRenderer2DGl::render(const string &text, float x, float y, bool centered, Vec3f *color) {
printf("**** RENDERING 2D text [%s]\n",text.c_str());
//tester->render(text, x, y, this->font->getWidth(),centered);
//return;
@@ -387,21 +390,34 @@ void TextRenderer3DGl::begin(Font3D *font) {
assertGl();
}
void TextRenderer3DGl::render(const string &text, float x, float y, bool centered) {
void TextRenderer3DGl::render(const string &text, float x, float y, bool centered, Vec3f *color) {
assert(rendering);
internalRender(text, x, y, centered, color);
}
void TextRenderer3DGl::internalRender(const string &text, float x, float y, bool centered, Vec3f *color) {
//assert(rendering);
if(color != NULL) {
glPushAttrib(GL_CURRENT_BIT);
glColor3fv(color->ptr());
}
const unsigned char *utext= NULL;
assertGl();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glPushAttrib(GL_POLYGON_BIT);
glLoadIdentity();
//glPushAttrib(GL_POLYGON_BIT);
int size = font->getSize();
//float scale= size / 15.f;
float scale= 1.0f;
//float scale= size;
Vec3f translatePos;
FontMetrics *metrics= font->getMetrics();
if(font->getTextHandler() != NULL) {
if(centered) {
@@ -418,7 +434,6 @@ void TextRenderer3DGl::render(const string &text, float x, float y, bool center
else {
utext= reinterpret_cast<const unsigned char*>(text.c_str());
if(centered) {
FontMetrics *metrics= font->getMetrics();
//glTranslatef(x-scale*metrics->getTextWidth(text)/2.f, y-scale*metrics->getHeight()/2.f, 0);
translatePos.x = x-scale*metrics->getTextWidth(text)/2.f;
translatePos.y = y-scale*metrics->getHeight()/2.f;
@@ -433,11 +448,20 @@ void TextRenderer3DGl::render(const string &text, float x, float y, bool center
}
//glScalef(scale, scale, scale);
float scaleX = 0.65;
float scaleY = 0.75;
float scaleZ = 1.0;
//x = translatePos.x;
float yScaleFactor = (metrics->getHeight() * (1.0 - scaleY));
translatePos.y += yScaleFactor;
//y = translatePos.y;
glTranslatef(translatePos.x, translatePos.y, translatePos.z);
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(text.find("\n") == text.npos && text.find("\t") == text.npos) {
@@ -479,19 +503,30 @@ void TextRenderer3DGl::render(const string &text, float x, float y, bool center
}
}
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);
glTranslatef(translatePos.x, translatePos.y, 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);
needsRecursiveRender = true;
break;
case '\n':
{
line++;
translatePos= Vec3f(static_cast<float>(x), y - (font->getTextHandler()->LineHeight(parts[i].c_str())) * line, translatePos.z);
glTranslatef(translatePos.x, translatePos.y, translatePos.z);
float yLineValue = font->getTextHandler()->LineHeight(parts[i].c_str());
translatePos= Vec3f(translatePos.x, translatePos.y - yLineValue, translatePos.z);
needsRecursiveRender = true;
}
break;
default:
font->getTextHandler()->Render(parts[i].c_str());
if(needsRecursiveRender == true) {
internalRender(parts[i], translatePos.x, translatePos.y, false, color);
needsRecursiveRender = false;
}
else {
font->getTextHandler()->Render(parts[i].c_str());
}
}
}
}
@@ -562,19 +597,30 @@ void TextRenderer3DGl::render(const string &text, float x, float y, bool center
}
}
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);
glTranslatef(translatePos.x, translatePos.y, 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);
needsRecursiveRender = true;
break;
case '\n':
{
line++;
translatePos= Vec3f(static_cast<float>(x), y - (font->getTextHandler()->LineHeight(parts[i].c_str())) * line, translatePos.z);
glTranslatef(translatePos.x, translatePos.y, translatePos.z);
float yLineValue = font->getTextHandler()->LineHeight(parts[i].c_str());
translatePos= Vec3f(translatePos.x, translatePos.y - yLineValue, translatePos.z);
needsRecursiveRender = true;
}
break;
default:
font->getTextHandler()->Render(parts[i].c_str());
if(needsRecursiveRender == true) {
internalRender(parts[i], translatePos.x, translatePos.y, false, color);
needsRecursiveRender = false;
}
else {
font->getTextHandler()->Render(parts[i].c_str());
}
}
}
}
@@ -585,10 +631,14 @@ void TextRenderer3DGl::render(const string &text, float x, float y, bool center
}
}
}
*/
glPopMatrix();
glPopAttrib();
//glPopMatrix();
//glPopAttrib();
if(color != NULL) {
glPopAttrib();
}
assertGl();
}