Make a few parameters in gl_text const references

Originally committed to SVN as r4252.
This commit is contained in:
Thomas Goyne 2010-04-30 16:15:18 +00:00
parent 47beda4c89
commit ae82498273
2 changed files with 16 additions and 86 deletions

View file

@ -48,42 +48,27 @@
#include "gl_text.h" #include "gl_text.h"
#include "utils.h" #include "utils.h"
/// @brief Constructor
///
OpenGLText::OpenGLText() { OpenGLText::OpenGLText() {
r = g = b = a = 1.0f; r = g = b = a = 1.0f;
} }
/// @brief Destructor
///
OpenGLText::~OpenGLText() { OpenGLText::~OpenGLText() {
Reset(); Reset();
} }
/// @brief Reset /// @brief Reset
///
void OpenGLText::Reset() { void OpenGLText::Reset() {
textures.clear(); textures.clear();
glyphs.clear(); glyphs.clear();
} }
/// @brief Get instance /// @brief Get instance
/// @return /// @return
///
OpenGLText& OpenGLText::GetInstance() { OpenGLText& OpenGLText::GetInstance() {
static OpenGLText instance; static OpenGLText instance;
return instance; return instance;
} }
/// @brief Set font /// @brief Set font
/// @param face /// @param face
/// @param size /// @param size
@ -108,8 +93,6 @@ void OpenGLText::DoSetFont(wxString face,int size,bool bold,bool italics) {
Reset(); Reset();
} }
/// @brief Set colour /// @brief Set colour
/// @param col /// @param col
/// @param alpha /// @param alpha
@ -121,14 +104,11 @@ void OpenGLText::DoSetColour(wxColour col,float alpha) {
a = alpha; a = alpha;
} }
/// @brief Print /// @brief Print
/// @param text /// @param text
/// @param x /// @param x
/// @param y /// @param y
/// void OpenGLText::DoPrint(const wxString &text,int x,int y) {
void OpenGLText::DoPrint(wxString text,int x,int y) {
// Set OpenGL // Set OpenGL
glEnable(GL_BLEND); glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
@ -150,15 +130,8 @@ void OpenGLText::DoPrint(wxString text,int x,int y) {
glDisable(GL_BLEND); glDisable(GL_BLEND);
} }
/// @brief Draw a string at (x,y)
void OpenGLText::DrawString(const wxString &text,int x,int y) {
/// @brief Draw a string
/// @param text
/// @param x
/// @param y
/// @return
///
void OpenGLText::DrawString(wxString text,int x,int y) {
// Variables // Variables
size_t len = text.Length(); size_t len = text.Length();
OpenGLTextGlyph glyph; OpenGLTextGlyph glyph;
@ -186,16 +159,11 @@ void OpenGLText::DrawString(wxString text,int x,int y) {
} }
} }
/// @brief Calculate text extent /// @brief Calculate text extent
/// @param text /// @param text Text to get the extents of
/// @param w /// @param w [out] Width
/// @param h /// @param h [out] Height
/// @return void OpenGLText::DoGetExtent(const wxString &text,int &w,int &h) {
///
void OpenGLText::DoGetExtent(wxString text,int &w,int &h) {
// Variables
size_t len = text.Length(); size_t len = text.Length();
OpenGLTextGlyph glyph; OpenGLTextGlyph glyph;
lineHeight = 0; lineHeight = 0;
@ -229,12 +197,9 @@ void OpenGLText::DoGetExtent(wxString text,int &w,int &h) {
h = dy+lineHeight; h = dy+lineHeight;
} }
/// @brief Get a glyph /// @brief Get a glyph
/// @param i /// @param i
/// @return /// @return
///
OpenGLTextGlyph OpenGLText::GetGlyph(int i) { OpenGLTextGlyph OpenGLText::GetGlyph(int i) {
glyphMap::iterator res = glyphs.find(i); glyphMap::iterator res = glyphs.find(i);
@ -245,12 +210,8 @@ OpenGLTextGlyph OpenGLText::GetGlyph(int i) {
return CreateGlyph(i); return CreateGlyph(i);
} }
/// @brief Create a glyph /// @brief Create a glyph
/// @param n /// @param n
/// @return
///
OpenGLTextGlyph OpenGLText::CreateGlyph(int n) { OpenGLTextGlyph OpenGLText::CreateGlyph(int n) {
// Create glyph // Create glyph
OpenGLTextGlyph glyph; OpenGLTextGlyph glyph;
@ -277,12 +238,9 @@ OpenGLTextGlyph OpenGLText::CreateGlyph(int n) {
return glyph; return glyph;
} }
/// @brief Texture constructor /// @brief Texture constructor
/// @param w /// @param w
/// @param h /// @param h
///
OpenGLTextTexture::OpenGLTextTexture(int w,int h) { OpenGLTextTexture::OpenGLTextTexture(int w,int h) {
using std::max; using std::max;
// Properties // Properties
@ -307,10 +265,6 @@ OpenGLTextTexture::OpenGLTextTexture(int w,int h) {
if (glGetError()) throw _T("Internal OpenGL text renderer error: Could not allocate Text Texture"); if (glGetError()) throw _T("Internal OpenGL text renderer error: Could not allocate Text Texture");
} }
/// @brief Texture destructor
///
OpenGLTextTexture::~OpenGLTextTexture() { OpenGLTextTexture::~OpenGLTextTexture() {
if (tex) { if (tex) {
glDeleteTextures(1,&tex); glDeleteTextures(1,&tex);
@ -318,12 +272,9 @@ OpenGLTextTexture::~OpenGLTextTexture() {
} }
} }
/// @brief Can fit a glyph in it? /// @brief Can fit a glyph in it?
/// @param glyph /// @param glyph
/// @return /// @return
///
bool OpenGLTextTexture::TryToInsert(OpenGLTextGlyph &glyph) { bool OpenGLTextTexture::TryToInsert(OpenGLTextGlyph &glyph) {
// Get size // Get size
int w = glyph.w; int w = glyph.w;
@ -350,11 +301,8 @@ bool OpenGLTextTexture::TryToInsert(OpenGLTextGlyph &glyph) {
} }
} }
/// @brief Insert /// @brief Insert
/// @param glyph /// @param glyph
///
void OpenGLTextTexture::Insert(OpenGLTextGlyph &glyph) { void OpenGLTextTexture::Insert(OpenGLTextGlyph &glyph) {
// Glyph data // Glyph data
wxString str = wxChar(glyph.value); wxString str = wxChar(glyph.value);
@ -378,9 +326,7 @@ void OpenGLTextTexture::Insert(OpenGLTextGlyph &glyph) {
dc.SetFont(OpenGLText::GetFont()); dc.SetFont(OpenGLText::GetFont());
dc.SetTextForeground(wxColour(255,255,255)); dc.SetTextForeground(wxColour(255,255,255));
dc.DrawText(str,0,0); dc.DrawText(str,0,0);
//bmp.SaveFile(wxString::Format(_T("glyph%i.bmp"),glyph.value),wxBITMAP_TYPE_BMP);
wxImage img = bmp.ConvertToImage(); wxImage img = bmp.ConvertToImage();
//img.SaveFile(str + _T(".bmp"));
// Convert to alpha // Convert to alpha
int imgw = img.GetWidth(); int imgw = img.GetWidth();
@ -403,12 +349,9 @@ void OpenGLTextTexture::Insert(OpenGLTextGlyph &glyph) {
if (glGetError()) throw _T("Internal OpenGL text renderer error: Error uploading glyph data to video memory."); if (glGetError()) throw _T("Internal OpenGL text renderer error: Error uploading glyph data to video memory.");
} }
/// @brief Draw a glyph at (x,y)
/// @brief Draw a glyph
/// @param x /// @param x
/// @param y /// @param y
///
void OpenGLTextGlyph::Draw(int x,int y) { void OpenGLTextGlyph::Draw(int x,int y) {
// Store matrix and translate // Store matrix and translate
glPushMatrix(); glPushMatrix();
@ -437,22 +380,15 @@ void OpenGLTextGlyph::Draw(int x,int y) {
glPopMatrix(); glPopMatrix();
} }
/// @brief Glyph Destructor
///
OpenGLTextGlyph::~OpenGLTextGlyph() { OpenGLTextGlyph::~OpenGLTextGlyph() {
if (tempBmp) delete tempBmp; if (tempBmp) delete tempBmp;
tempBmp = NULL; tempBmp = NULL;
} }
/// DOCME /// DOCME
wxBitmap *OpenGLTextGlyph::tempBmp = NULL; wxBitmap *OpenGLTextGlyph::tempBmp = NULL;
/// @brief DOCME /// @brief DOCME
///
void OpenGLTextGlyph::GetMetrics() { void OpenGLTextGlyph::GetMetrics() {
// Glyph data // Glyph data
wxCoord desc,lead; wxCoord desc,lead;
@ -462,11 +398,7 @@ void OpenGLTextGlyph::GetMetrics() {
if (!tempBmp) tempBmp = new wxBitmap(16,16,24); if (!tempBmp) tempBmp = new wxBitmap(16,16,24);
// Get text extents // Get text extents
{
wxMemoryDC dc(*tempBmp); wxMemoryDC dc(*tempBmp);
dc.SetFont(OpenGLText::GetFont()); dc.SetFont(OpenGLText::GetFont());
dc.GetTextExtent(str,&w,&h,&desc,&lead); dc.GetTextExtent(str,&w,&h,&desc,&lead);
} }
}

View file

@ -187,9 +187,9 @@ private:
static OpenGLText& GetInstance(); static OpenGLText& GetInstance();
void DoSetFont(wxString face,int size,bool bold,bool italics); void DoSetFont(wxString face,int size,bool bold,bool italics);
void DoSetColour(wxColour col,float alpha); void DoSetColour(wxColour col,float alpha);
void DoPrint(wxString text,int x,int y); void DoPrint(const wxString &text,int x,int y);
void DrawString(wxString text,int x,int y); void DrawString(const wxString &text,int x,int y);
void DoGetExtent(wxString text,int &w,int &h); void DoGetExtent(const wxString &text,int &w,int &h);
public: public:
@ -217,14 +217,12 @@ public:
/// @param x /// @param x
/// @param y /// @param y
/// ///
static void Print(wxString text,int x,int y) { GetInstance().DoPrint(text,x,y); } static void Print(const wxString &text,int x,int y) { GetInstance().DoPrint(text,x,y); }
/// @brief DOCME /// @brief DOCME
/// @param text /// @param text
/// @param w /// @param w
/// @param h /// @param h
/// ///
static void GetExtent(wxString text,int &w,int &h) { GetInstance().DoGetExtent(text,w,h); } static void GetExtent(const wxString &text,int &w,int &h) { GetInstance().DoGetExtent(text,w,h); }
}; };