#endif
+#include "gtkutil/glfont.h"
/// \brief A module which wraps a runtime-binding of the standard OpenGL functions.
/// Provides convenience functions for querying availabiliy of extensions, rendering text and error-checking.
/// \brief Asserts that there no OpenGL errors have occurred since the last call to glGetError.
void (*assertNoErrors)(const char *file, int line);
- GLuint m_font;
+ GLFont *m_font; // MUST be set!
int m_fontHeight;
int m_fontAscent;
int m_fontDescent;
/// \brief Renders \p string at the current raster-position of the current context.
void drawString(const char* string) const
{
- m_glListBase(m_font);
- m_glCallLists(GLsizei(strlen(string)), GL_UNSIGNED_BYTE, reinterpret_cast<const GLubyte*>(string));
+ m_font->printString(string);
}
/// \brief Renders \p character at the current raster-position of the current context.
*/
#include "glfont.h"
+#include "igl.h"
+
+// generic string printing with call lists
+class GLFontCallList: public GLFont
+{
+ GLuint m_displayList;
+ int m_pixelHeight;
+ int m_pixelAscent;
+ int m_pixelDescent;
+ public:
+ GLFontCallList(GLuint displayList, int asc, int desc, int pixelHeight) : m_displayList(displayList), m_pixelHeight(pixelHeight), m_pixelAscent(asc), m_pixelDescent(desc)
+ {
+ }
+ virtual ~GLFontCallList()
+ {
+ glDeleteLists(m_displayList, 256);
+ }
+ void printString(const char *s)
+ {
+ GlobalOpenGL().m_glListBase(m_displayList);
+ GlobalOpenGL().m_glCallLists(GLsizei(strlen(s)), GL_UNSIGNED_BYTE, reinterpret_cast<const GLubyte*>(s));
+ }
+ virtual int getPixelAscent() const
+ {
+ return m_pixelAscent;
+ }
+ virtual int getPixelDescent() const
+ {
+ return m_pixelDescent;
+ }
+ virtual int getPixelHeight() const
+ {
+ return m_pixelHeight;
+ }
+};
+
#ifdef _WIN32
#include <windows.h>
#endif
-#include <GL/gl.h>
#include "debugging/debugging.h"
// LordHavoc: this is code for direct Xlib bitmap character fetching, as an
#include <gdk/gdkx.h>
#include <GL/glx.h>
-GLFont glfont_create(const char* font_string)
+GLFont *glfont_create(const char* font_string)
{
GLuint font_list_base;
XFontStruct *fontInfo;
/* *height = fontInfo->ascent + fontInfo->descent;
*width = fontInfo->max_bounds.width; */
- return GLFont(font_list_base, fontInfo->ascent + fontInfo->descent);
-}
-
-void glfont_release(GLFont& font)
-{
- glDeleteLists(font.getDisplayList(), 256);
- font = GLFont(0, 0);
+ return new GLFontCallList(font_list_base, fontInfo->ascent, fontInfo->descent, fontInfo->ascent + fontInfo->descent);
}
#else
#include <gtk/gtkglwidget.h>
-GLFont glfont_create(const char* font_string)
+GLFont *glfont_create(const char* font_string)
{
GLuint font_list_base = glGenLists (256);
gint font_height = 0, font_ascent = 0, font_descent = 0;
if(font_height > 256)
font_height = 16;
- return GLFont(font_list_base, font_ascent, font_descent, font_height);
-}
-
-void glfont_release(GLFont& font)
-{
- glDeleteLists(font.getDisplayList(), 256);
- font = GLFont(0, 0, 0, 0);
+ return new GLFontCallList(font_list_base, font_ascent, font_descent, font_height);
}
#endif
-
-
// new font code ripped from ZeroRadiant (not in use yet)
#include <pango/pangoft2.h>
#include <pango/pango-utils.h>
-#include "igl.h"
-class GLFontInternal
+class GLFontInternal: public GLFont
{
const char *font_string;
int font_height;
int font_ascent_pango_units;
int font_descent_pango_units;
- //ft2_context = pango_ft2_get_context(72, 72);
+#if !PANGO_VERSION_CHECK(1,22,0)
+ ft2_context = pango_ft2_get_context(72, 72);
+#else
fontmap = pango_ft2_font_map_new();
pango_ft2_font_map_set_resolution(PANGO_FT2_FONT_MAP(fontmap), 72, 72);
ft2_context = pango_font_map_create_context(fontmap);
+#endif
font_desc = pango_font_description_from_string(font_string);
//pango_font_description_set_size(font_desc, 10 * PANGO_SCALE);
y_offset_bitmap_render_pango_units = (font_ascent * PANGO_SCALE) - font_ascent_pango_units;
}
- ~GLFontInternal()
+ virtual ~GLFontInternal()
{
g_object_unref(G_OBJECT(ft2_context));
g_object_unref(G_OBJECT(fontmap));
// just a hair outside of the viewport (meaning the current raster position is invalid),
// then no text will be rendered. The solution to this is a very hacky one. You can search
// Google for "glDrawPixels clipping".
- void printString(const char *s)
+ virtual void printString(const char *s)
{
// The idea for this code initially came from the font-pangoft2.c example that comes with GtkGLExt.
g_object_unref(G_OBJECT(layout));
}
+
+ virtual int getPixelAscent() const
+ {
+ return font_ascent;
+ }
+ virtual int getPixelDescent() const
+ {
+ return font_descent;
+ }
+ virtual int getPixelHeight() const
+ {
+ return font_height;
+ }
};
class GLFont
{
- GLuint m_displayList;
- int m_pixelHeight;
- int m_pixelAscent;
- int m_pixelDescent;
-public:
- GLFont(GLuint displayList, int asc, int desc, int pixelHeight) : m_displayList(displayList), m_pixelHeight(pixelHeight), m_pixelAscent(asc), m_pixelDescent(desc)
- {
- }
- GLuint getDisplayList() const
- {
- return m_displayList;
- }
- int getPixelHeight() const
- {
- return m_pixelHeight;
- }
- int getPixelAscent() const
- {
- return m_pixelAscent;
- }
- int getPixelDescent() const
- {
- return m_pixelDescent;
- }
+ public:
+ virtual int getPixelHeight() const = 0;
+ virtual int getPixelAscent() const = 0;
+ virtual int getPixelDescent() const = 0;
+ virtual void printString(const char *s) = 0;
+ virtual ~GLFont()
+ {
+ }
};
-GLFont glfont_create(const char* font_string);
-void glfont_release(GLFont& font);
+GLFont *glfont_create(const char* font_string);
+// release with delete
#endif
}
}
-namespace
-{
- GLFont g_font(0, 0, 0, 0);
-}
-
void GlobalGL_sharedContextCreated()
{
+ GLFont *g_font = NULL;
+
// report OpenGL information
globalOutputStream() << "GL_VENDOR: " << reinterpret_cast<const char*>(glGetString (GL_VENDOR)) << "\n";
globalOutputStream() << "GL_RENDERER: " << reinterpret_cast<const char*>(glGetString (GL_RENDERER)) << "\n";
g_font = glfont_create(fontname);
#endif
- GlobalOpenGL().m_font = g_font.getDisplayList();
- GlobalOpenGL().m_fontHeight = g_font.getPixelHeight();
- GlobalOpenGL().m_fontAscent = g_font.getPixelAscent();
- GlobalOpenGL().m_fontDescent = g_font.getPixelDescent();
+ GlobalOpenGL().m_font = g_font;
+ GlobalOpenGL().m_fontHeight = g_font->getPixelHeight();
+ GlobalOpenGL().m_fontAscent = g_font->getPixelAscent();
+ GlobalOpenGL().m_fontDescent = g_font->getPixelDescent();
}
void GlobalGL_sharedContextDestroyed()