]> de.git.xonotic.org Git - xonotic/netradiant.git/commitdiff
refactoring font code to hopefully be closer to be able to exchange the font system...
authorRudolf Polzer <divVerent@xonotic.org>
Thu, 18 Nov 2010 15:52:51 +0000 (16:52 +0100)
committerRudolf Polzer <divVerent@xonotic.org>
Thu, 18 Nov 2010 16:01:21 +0000 (17:01 +0100)
include/igl.h
libs/gtkutil/glfont.cpp
libs/gtkutil/glfont.h
radiant/mainframe.cpp

index 7ea3b944d93d33ec27dc9e460f360d5c7786c4ca..8f7d7dc0f18443778b9308f9f3be3fc5446a0736 100644 (file)
@@ -1976,6 +1976,7 @@ typedef unsigned int GLhandleARB;
 
 #endif
 
 
 #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 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.
@@ -1997,7 +1998,7 @@ struct OpenGLBinding
   /// \brief Asserts that there no OpenGL errors have occurred since the last call to glGetError.
   void (*assertNoErrors)(const char *file, int line);
 
   /// \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;
   int m_fontHeight;
   int m_fontAscent;
   int m_fontDescent;
@@ -2005,8 +2006,7 @@ struct OpenGLBinding
   /// \brief Renders \p string at the current raster-position of the current context.
   void drawString(const char* string) const
   {
   /// \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.
   }
 
   /// \brief Renders \p character at the current raster-position of the current context.
index f2095a8bf73783acb4f2fab5f313638f14279633..eee1113e3f14b1a7b491fea0dac3d8bb2679c0ce 100644 (file)
@@ -20,10 +20,45 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
 #include "glfont.h"
 */
 
 #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
 #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 "debugging/debugging.h"
 
 // LordHavoc: this is code for direct Xlib bitmap character fetching, as an
@@ -38,7 +73,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include <gdk/gdkx.h>
 #include <GL/glx.h>
 
 #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;
 {
   GLuint font_list_base;
   XFontStruct *fontInfo;
@@ -91,20 +126,14 @@ GLFont glfont_create(const char* font_string)
 
 /*    *height = fontInfo->ascent + fontInfo->descent;
     *width = fontInfo->max_bounds.width;  */
 
 /*    *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>
 
 }
 
 #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;
 {
   GLuint font_list_base = glGenLists (256);
   gint font_height = 0, font_ascent = 0, font_descent = 0;
@@ -148,25 +177,16 @@ GLFont glfont_create(const char* font_string)
   if(font_height > 256)
          font_height = 16;
 
   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
 
 }
 #endif
 
-
-
 // new font code ripped from ZeroRadiant (not in use yet)
 
 #include <pango/pangoft2.h>
 #include <pango/pango-utils.h>
 // 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;
 {
        const char *font_string;
        int font_height;
@@ -185,10 +205,13 @@ class GLFontInternal
                int font_ascent_pango_units;
                int font_descent_pango_units;
 
                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);
                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);
 
                font_desc = pango_font_description_from_string(font_string);
                //pango_font_description_set_size(font_desc, 10 * PANGO_SCALE);
@@ -215,7 +238,7 @@ class GLFontInternal
                y_offset_bitmap_render_pango_units = (font_ascent * PANGO_SCALE) - font_ascent_pango_units;
        }
 
                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));
        {
                g_object_unref(G_OBJECT(ft2_context));
                g_object_unref(G_OBJECT(fontmap));
@@ -231,7 +254,7 @@ class GLFontInternal
        // 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".
        // 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.
 
        {
                // The idea for this code initially came from the font-pangoft2.c example that comes with GtkGLExt.
 
@@ -302,4 +325,17 @@ class GLFontInternal
 
                g_object_unref(G_OBJECT(layout));
        }
 
                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;
+       }
 };
 };
index 454c6a977904c671c6eded61294c201ff3902a3c..0d1e00009fa850cebc9d3fde3b73cf70b44c32e9 100644 (file)
@@ -26,33 +26,17 @@ typedef unsigned int GLuint;
 
 class GLFont
 {
 
 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
 
 #endif
index ea4edf31eee981c917760e8ca150573661df028d..18c82f95945a2c9998bf71a0ac37cb94890b34ed 100644 (file)
@@ -3316,13 +3316,10 @@ void GridStatus_onTextureLockEnabledChanged()
   }
 }
 
   }
 }
 
-namespace
-{
-  GLFont g_font(0, 0, 0, 0);
-}
-
 void GlobalGL_sharedContextCreated()
 {
 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";
   // 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";
@@ -3347,10 +3344,10 @@ void GlobalGL_sharedContextCreated()
   g_font = glfont_create(fontname);
 #endif
 
   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()
 }
 
 void GlobalGL_sharedContextDestroyed()