- added freetype2 / FTGL support

This commit is contained in:
Mark Vejvoda
2011-06-06 21:38:25 +00:00
parent b6b13e2f0a
commit c808a5661a
28 changed files with 1412 additions and 376 deletions

View File

@@ -17,25 +17,31 @@
using std::string;
namespace Shared{ namespace Graphics{
class Text;
namespace Shared { namespace Graphics {
// =====================================================
// class FontMetrics
// =====================================================
class FontMetrics{
class FontMetrics {
private:
float *widths;
float height;
Text *textHandler;
public:
FontMetrics();
FontMetrics(Text *textHandler=NULL);
~FontMetrics();
void setWidth(int i, float width) {widths[i]= width;}
void setTextHandler(Text *textHandler);
Text * getTextHandler();
void setWidth(int i, float width) {this->widths[i] = width;}
void setHeight(float height) {this->height= height;}
float getTextWidth(const string &str) const;
float getTextWidth(const string &str);
float getHeight() const;
};
@@ -43,14 +49,14 @@ public:
// class Font
// =====================================================
class Font{
class Font {
public:
static int charCount;
static std::string fontTypeName;
static bool fontIsMultibyte;
public:
enum Width{
enum Width {
wNormal= 400,
wBold= 700
};
@@ -61,48 +67,53 @@ protected:
bool inited;
FontMetrics metrics;
Text *textHandler;
public:
//constructor & destructor
Font();
virtual ~Font(){};
virtual ~Font();
virtual void init()=0;
virtual void end()=0;
//get
string getType() const {return type;}
int getWidth() const {return width;}
const FontMetrics *getMetrics() const {return &metrics;}
//string getType() const {return type;}
int getWidth() const;
FontMetrics *getMetrics() {return &metrics;}
Text * getTextHandler() {return textHandler;}
//set
void setType(string type) {this->type= type;}
void setWidth(int width) {this->width= width;}
void setType(string typeX11, string typeGeneric);
void setWidth(int width);
};
// =====================================================
// class Font2D
// =====================================================
class Font2D: public Font{
class Font2D: public Font {
protected:
int size;
public:
Font2D();
virtual ~Font2D() {};
int getSize() const {return size;}
void setSize(int size) {this->size= size;}
int getSize() const;
void setSize(int size);
};
// =====================================================
// class Font3D
// =====================================================
class Font3D: public Font{
class Font3D: public Font {
protected:
float depth;
public:
Font3D();
virtual ~Font3D() {};
float getDepth() const {return depth;}
void setDepth(float depth) {this->depth= depth;}

View File

@@ -18,7 +18,7 @@
using namespace std;
namespace Shared{ namespace Graphics{
namespace Shared { namespace Graphics {
// =====================================================
// class FontManager
@@ -26,7 +26,7 @@ namespace Shared{ namespace Graphics{
/// Creates, Intializes, Finalizes, and Deletes fonts
// =====================================================
class FontManager{
class FontManager {
protected:
typedef vector<Font*> FontContainer;

View File

@@ -0,0 +1,43 @@
// ==============================================================
// This file is part of the MegaGlest Shared Library (www.megaglest.org)
//
// Copyright (C) 2011 Mark Vejvoda and others
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 3 of the
// License, or (at your option) any later version
// ==============================================================
#ifndef Text_h
#define Text_h
#include <string>
using std::string;
/**
* Base class upon which all text rendering calls are made.
*/
//====================================================================
class Text
{
public:
Text();
virtual ~Text();
virtual void init(string fontName, int fontSize);
virtual void SetFaceSize(int);
virtual int GetFaceSize();
virtual void Render(const char*, const int = -1);
virtual float Advance(const char*, const int = -1);
virtual float LineHeight(const char* = " ", const int = -1);
virtual void Render(const wchar_t*, const int = -1);
virtual float Advance(const wchar_t*, const int = -1);
virtual float LineHeight(const wchar_t* = L" ", const int = -1);
};
#endif // Text_h

View File

@@ -27,11 +27,18 @@ namespace Shared { namespace Graphics { namespace Gl {
class FontGl {
protected:
//#ifndef USE_FTGL
GLuint handle;
//#endif
static string default_fonttype;
public:
//#ifndef USE_FTGL
GLuint getHandle() const {return handle;}
//#endif
static string getDefault_fontType() { return default_fonttype; }
static void setDefault_fontType(string value) { default_fonttype = value; }
@@ -43,8 +50,9 @@ public:
/// OpenGL bitmap font
// =====================================================
class Font2DGl: public Font2D, public FontGl{
class Font2DGl: public Font2D, public FontGl {
public:
virtual void init();
virtual void end();
};
@@ -55,8 +63,9 @@ public:
/// OpenGL outline font
// =====================================================
class Font3DGl: public Font3D, public FontGl{
class Font3DGl: public Font3D, public FontGl {
public:
virtual void init();
virtual void end();
};

View File

@@ -0,0 +1,59 @@
// ==============================================================
// This file is part of the MegaGlest Shared Library (www.megaglest.org)
//
// Copyright (C) 2011 Mark Vejvoda and others
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 3 of the
// License, or (at your option) any later version
// ==============================================================
#ifndef TextFTGL_h
#define TextFTGL_h
#ifdef USE_FTGL
#include <FTGL/ftgl.h>
#include "font_text.h"
namespace Shared{ namespace Graphics{ namespace Gl{
/**
* Use FTGL for rendering text in OpenGL
*/
//====================================================================
class TextFTGL : public Text
{
public:
TextFTGL();
virtual ~TextFTGL();
virtual void init(string fontName, int fontSize);
virtual void SetFaceSize(int);
virtual int GetFaceSize();
virtual void Render(const char*, const int = -1);
virtual float Advance(const char*, const int = -1);
virtual float LineHeight(const char*, const int = -1);
virtual void Render(const wchar_t*, const int = -1);
virtual float Advance(const wchar_t*, const int = -1);
virtual float LineHeight(const wchar_t* = L" ", const int = -1);
private:
FTFont *ftFont;
//FTGLPixmapFont *ftFont;
const char* fontFile;
const char* findFont(const char *firstFontToTry=NULL);
void cleanupFont();
};
}}}//end namespace
#endif // USE_FTGL
#endif // TextFTGL_h

View File

@@ -15,24 +15,33 @@
#include "text_renderer.h"
#include "leak_dumper.h"
namespace Shared{ namespace Graphics{ namespace Gl{
namespace Shared { namespace Graphics { namespace Gl {
class Font2DGl;
class Font3DGl;
//#ifdef USE_FTGL
// class TextFTGL;
//#endif
// =====================================================
// class TextRenderer2DGl
// =====================================================
class TextRenderer2DGl: public TextRenderer2D{
class TextRenderer2DGl: public TextRenderer2D {
private:
const Font2DGl *font;
Font2DGl *font;
bool rendering;
//#ifdef USE_FTGL
// TextFTGL *fontFTGL;
//#endif
public:
TextRenderer2DGl();
virtual ~TextRenderer2DGl();
virtual void begin(const Font2D *font);
virtual void begin(Font2D *font);
virtual void render(const string &text, int x, int y, bool centered, Vec3f *color=NULL);
virtual void end();
};
@@ -43,13 +52,18 @@ public:
class TextRenderer3DGl: public TextRenderer3D{
private:
const Font3DGl *font;
Font3DGl *font;
bool rendering;
//#ifdef USE_FTGL
// TextFTGL *fontFTGL;
//#endif
public:
TextRenderer3DGl();
virtual ~TextRenderer3DGl();
virtual void begin(const Font3D *font);
virtual void begin(Font3D *font);
virtual void render(const string &text, float x, float y, float size, bool centered);
virtual void end();
};

View File

@@ -19,17 +19,17 @@
using std::string;
namespace Shared{ namespace Graphics{
namespace Shared { namespace Graphics {
// =====================================================
// class TextRenderer2D
// =====================================================
class TextRenderer2D{
class TextRenderer2D {
public:
virtual ~TextRenderer2D(){};
virtual void begin(const Font2D *font)= 0;
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;
};
@@ -38,11 +38,11 @@ public:
// class TextRenderer3D
// =====================================================
class TextRenderer3D{
class TextRenderer3D {
public:
virtual ~TextRenderer3D(){};
virtual void begin(const Font3D *font)= 0;
virtual void begin(Font3D *font)= 0;
virtual void render(const string &text, float x, float y, float size, bool centered= false)= 0;
virtual void end()= 0;
};