Made fonts selectable in config file; allow separate fonts for labels and normal text.

pull/3/head
Chris Laurel 2001-05-14 23:40:01 +00:00
parent 5469901ae5
commit dec27ee48e
9 changed files with 76 additions and 47 deletions

View File

@ -62,6 +62,8 @@ CelestiaConfig* ReadCelestiaConfig(string filename)
configParams->getString("GalaxyCatalog", config->galaxyCatalog);
configParams->getString("StarDatabase", config->starDatabaseFile);
configParams->getString("StarNameDatabase", config->starNamesFile);
configParams->getString("Font", config->mainFont);
configParams->getString("LabelFont", config->labelFont);
Value* solarSystemsVal = configParams->getValue("SolarSystemCatalogs");
if (solarSystemsVal != NULL)

View File

@ -25,6 +25,8 @@ struct CelestiaConfig
std::string favoritesFile;
std::string initScriptFile;
std::string demoScriptFile;
std::string mainFont;
std::string labelFont;
};

View File

@ -9,7 +9,6 @@
#include <string.h>
#include <cstdarg>
#include "gl.h"
#include "texfont.h"
#include "console.h"
using namespace std;
@ -45,13 +44,13 @@ Console::~Console()
}
void Console::setFont(TexFont* _font)
void Console::setFont(TextureFont* _font)
{
font = _font;
}
TexFont* Console::getFont()
TextureFont* Console::getFont()
{
return font;
}
@ -184,7 +183,7 @@ void Console::render()
return;
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, font->texobj);
glBindTexture(GL_TEXTURE_2D, font->getTextureName());
glPushMatrix();
for (int i = 0; i < nRows; i++)
@ -194,11 +193,11 @@ void Console::render()
glPushMatrix();
while (*s != '\0')
{
txfRenderGlyph(font, *s);
font->render((int) *s);
s++;
}
glPopMatrix();
glTranslatef(0, -(1 + font->max_ascent + font->max_descent), 0);
glTranslatef(0, -(1 + font->getHeight()), 0);
}
glPopMatrix();
}

View File

@ -16,7 +16,7 @@
#include <string>
#include <iostream>
#include "gl.h"
#include "texfont.h"
#include "texturefont.h"
using namespace std;
@ -46,8 +46,8 @@ class Console : public std::ostream
Console(int rows, int cols);
~Console();
void setFont(TexFont*);
TexFont* getFont();
void setFont(TextureFont*);
TextureFont* getFont();
void render();
void clear();
@ -72,7 +72,7 @@ class Console : public std::ostream
int nColumns;
char** text;
TexFont* font;
TextureFont* font;
int cursorRow;
int cursorColumn;

View File

@ -66,7 +66,7 @@ void Overlay::setWindowSize(int w, int h)
windowHeight = h;
}
void Overlay::setFont(TexFont* f)
void Overlay::setFont(TextureFont* f)
{
font = f;
}
@ -95,7 +95,7 @@ void Overlay::print(char c)
if (!useTexture)
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, font->texobj);
glBindTexture(GL_TEXTURE_2D, font->getTextureName());
useTexture = true;
}
@ -105,12 +105,12 @@ void Overlay::print(char c)
if (textBlock > 0)
{
glPopMatrix();
glTranslatef(0, -(1 + font->max_ascent + font->max_descent), 0);
glTranslatef(0, -(1 + font->getHeight()), 0);
glPushMatrix();
}
break;
default:
txfRenderGlyph(font, c);
font->render(c);
break;
}
}

View File

@ -12,7 +12,7 @@
#include <string>
#include <iostream>
#include "texfont.h"
#include "texturefont.h"
class Overlay;
@ -44,7 +44,7 @@ class Overlay : public std::ostream
void end();
void setWindowSize(int, int);
void setFont(TexFont*);
void setFont(TextureFont*);
void rect(float x, float y, float w, float h);
@ -58,7 +58,7 @@ class Overlay : public std::ostream
private:
int windowWidth;
int windowHeight;
TexFont* font;
TextureFont* font;
bool useTexture;
int textBlock;

View File

@ -14,7 +14,6 @@
#include "vecgl.h"
#include "perlin.h"
#include "spheremesh.h"
#include "texfont.h"
#include "console.h"
#include "gui.h"
#include "regcombine.h"
@ -49,8 +48,6 @@ static CTexture* galaxyTex = NULL;
static CTexture* shadowTex = NULL;
static CTexture* veilTex = NULL;
static TexFont* font = NULL;
Renderer::Renderer() :
windowWidth(0),
@ -227,11 +224,6 @@ bool Renderer::init(int winWidth, int winHeight)
shadowTex = CreateProceduralTexture(256, 256, GL_RGB, ShadowTextureEval);
shadowTex->bindName();
// font = txfLoadFont("fonts\\helvetica_14b.txf");
font = txfLoadFont("fonts/default.txf");
if (font != NULL)
txfEstablishTexture(font, 0, GL_FALSE);
// Initialize GL extensions
if (ExtensionSupported("GL_ARB_multitexture"))
InitExtMultiTexture();
@ -327,8 +319,6 @@ bool Renderer::init(int winWidth, int winHeight)
// TODO: Do a proper check for this extension before enabling
glEnable(GL_RESCALE_NORMAL_EXT);
console->setFont(font);
resize(winWidth, winHeight);
return true;
@ -355,6 +345,18 @@ void Renderer::setFieldOfView(float _fov)
}
TextureFont* Renderer::getFont() const
{
return font;
}
void Renderer::setFont(TextureFont* txf)
{
font = txf;
console->setFont(txf);
}
void Renderer::setRenderMode(int _renderMode)
{
renderMode = _renderMode;
@ -2165,8 +2167,11 @@ void Renderer::renderParticles(const vector<Particle>& particles,
void Renderer::renderLabels()
{
if (font == NULL)
return;
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, font->texobj);
glBindTexture(GL_TEXTURE_2D, font->getTextureName());
glMatrixMode(GL_PROJECTION);
glPushMatrix();
@ -2184,7 +2189,7 @@ void Renderer::renderLabels()
glTranslatef((int) labels[i].position.x + PixelOffset,
(int) labels[i].position.y + PixelOffset,
0);
txfRenderString(font, labels[i].text);
font->render(labels[i].text);
glPopMatrix();
}

View File

@ -21,6 +21,7 @@
#include "meshmanager.h"
#include "console.h"
#include "selection.h"
#include "texturefont.h"
class Renderer
@ -95,6 +96,9 @@ class Renderer
void addLabel(string, Color, Point3f);
void clearLabels();
void setFont(TextureFont*);
TextureFont* getFont() const;
public:
// Internal types
// TODO: Figure out how to make these private. Even with a friend
@ -173,6 +177,7 @@ class Renderer
TextureManager* textureManager;
MeshManager* meshManager;
Console* console;
TextureFont* font;
int renderMode;
int labelMode;

View File

@ -99,7 +99,7 @@ static FavoritesList* favorites = NULL;
static Simulation* sim = NULL;
static Renderer* renderer = NULL;
static Overlay* overlay = NULL;
static TexFont* font = NULL;
static TextureFont* font = NULL;
static CommandSequence* script = NULL;
static CommandSequence* demoScript = NULL;
@ -1009,6 +1009,9 @@ void RenderOverlay()
if (font == NULL)
return;
int height = font->getHeight();
int emWidth = font->getWidth("M");
overlay->begin();
// Time and date
@ -1016,7 +1019,7 @@ void RenderOverlay()
{
glPushMatrix();
glColor4f(0.7f, 0.7f, 1.0f, 1.0f);
glTranslatef(g_w - 130, g_h - 15, 0);
glTranslatef(g_w - 11 * emWidth, g_h - height, 0);
overlay->beginText();
*overlay << astro::Date(sim->getTime()) << '\n';
if (paused)
@ -1042,7 +1045,7 @@ void RenderOverlay()
if (hudDetail > 0)
{
glPushMatrix();
glTranslatef(0, 35, 0);
glTranslatef(0, height * 2 + 5, 0);
overlay->beginText();
double speed = sim->getObserver().getVelocity().length();
@ -1089,7 +1092,7 @@ void RenderOverlay()
modeName = "Following";
glPushMatrix();
glTranslatef(g_w - 130, 20, 0);
glTranslatef(g_w - emWidth * 11, height + 5, 0);
overlay->beginText();
glColor4f(0.6f, 0.6f, 1.0f, 1);
*overlay << modeName << '\n';
@ -1105,7 +1108,7 @@ void RenderOverlay()
glPushMatrix();
glColor4f(0.7f, 0.7f, 1.0f, 0.2f);
overlay->rect(0, 0, g_w, 70);
glTranslatef(0, 50, 0);
glTranslatef(0, height * 3 + 5, 0);
glColor4f(0.6f, 0.6f, 1.0f, 1);
*overlay << "Target name: " << typedText;
glPopMatrix();
@ -1116,7 +1119,7 @@ void RenderOverlay()
{
glPushMatrix();
glColor4f(1, 1, 1, 1);
glTranslatef(0, 80, 0);
glTranslatef(0, height * 5 + 5, 0);
overlay->beginText();
*overlay << messageText;
overlay->endText();
@ -1132,26 +1135,21 @@ void RenderOverlay()
alpha = 0.5f * (float) (5.0 - currentTime);
glColor4f(1, 1, 1, alpha);
int width = 0, maxAscent = 0, maxDescent = 0;
txfGetStringMetrics(font, welcomeMessage1, width, maxAscent, maxDescent);
glPushMatrix();
glTranslatef((g_w - width) / 2, g_h / 2, 0);
glTranslatef((g_w - font->getWidth(welcomeMessage1)) / 2, g_h / 2, 0);
*overlay << welcomeMessage1;
glPopMatrix();
txfGetStringMetrics(font, welcomeMessage2, width, maxAscent, maxDescent);
glPushMatrix();
glTranslatef((g_w - width) / 2, g_h / 2 - maxAscent, 0);
glTranslatef((g_w - font->getWidth(welcomeMessage2)) / 2, g_h / 2 - height, 0);
*overlay << welcomeMessage2;
glPopMatrix();
}
if (editMode)
{
int width = 0, maxAscent = 0, maxDescent = 0;
txfGetStringMetrics(font, "Edit Mode", width, maxAscent, maxDescent);
glPushMatrix();
glTranslatef((g_w - width) / 2, g_h - 15, 0);
glTranslatef((g_w - font->getWidth("Edit Mode")) / 2, g_h - height, 0);
glColor4f(1, 0, 1, 1);
*overlay << "Edit Mode";
glPopMatrix();
@ -1382,14 +1380,32 @@ int APIENTRY WinMain(HINSTANCE hInstance,
renderer->showAsterisms(asterisms);
if (config->mainFont == "")
font = LoadTextureFont("fonts/default.txf");
else
font = LoadTextureFont(string("fonts") + "/" + config->mainFont);
if (font == NULL)
{
cout << "Error loading font; text will not be visible.";
}
// Set up the overlay
overlay = new Overlay();
overlay->setWindowSize(g_w, g_h);
font = txfLoadFont("fonts/default.txf");
if (font != NULL)
overlay->setFont(font);
if (config->labelFont == "")
{
txfEstablishTexture(font, 0, GL_FALSE);
overlay->setFont(font);
renderer->setFont(font);
}
else
{
TextureFont* labelFont = LoadTextureFont(string("fonts") + "/" + config->labelFont);
if (labelFont == NULL)
renderer->setFont(font);
else
renderer->setFont(labelFont);
}
// Add favorites to locations menu