slightly better font handling, enjoy!

git-svn-id: svn://svn.icculus.org/netradiant/trunk@313 61c419a2-8eb2-4b30-bcec-8cead039b335
This commit is contained in:
divverent 2009-04-09 10:16:31 +00:00
parent cbfac4f225
commit df072b781c
6 changed files with 30 additions and 11 deletions

View File

@ -1999,6 +1999,8 @@ struct OpenGLBinding
GLuint m_font;
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

View File

@ -107,7 +107,7 @@ void glfont_release(GLFont& font)
GLFont glfont_create(const char* font_string)
{
GLuint font_list_base = glGenLists (256);
gint font_height = 0;
gint font_height = 0, font_ascent = 0, font_descent = 0;
PangoFontDescription* font_desc = pango_font_description_from_string (font_string);
@ -117,8 +117,12 @@ GLFont glfont_create(const char* font_string)
{
PangoFontMetrics* font_metrics = pango_font_get_metrics (font, 0);
font_height = pango_font_metrics_get_ascent (font_metrics) +
pango_font_metrics_get_descent (font_metrics);
font_ascent = pango_font_metrics_get_ascent (font_metrics);
font_descent = pango_font_metrics_get_descent (font_metrics);
font_height = font_ascent + font_descent;
font_ascent = PANGO_PIXELS (font_ascent);
font_descent = PANGO_PIXELS (font_descent);
font_height = PANGO_PIXELS (font_height);
pango_font_metrics_unref (font_metrics);
@ -127,15 +131,15 @@ GLFont glfont_create(const char* font_string)
pango_font_description_free (font_desc);
// fix for pango/gtkglext metrix bug
if(font_height > 16)
if(font_height > 256)
font_height = 16;
return GLFont(font_list_base, font_height);
return GLFont(font_list_base, font_ascent, font_descent, font_height);
}
void glfont_release(GLFont& font)
{
glDeleteLists(font.getDisplayList(), 256);
font = GLFont(0, 0);
font = GLFont(0, 0, 0, 0);
}
#endif

View File

@ -28,8 +28,10 @@ class GLFont
{
GLuint m_displayList;
int m_pixelHeight;
int m_pixelAscent;
int m_pixelDescent;
public:
GLFont(GLuint displayList, int pixelHeight) : m_displayList(displayList), m_pixelHeight(pixelHeight)
GLFont(GLuint displayList, int asc, int desc, int pixelHeight) : m_displayList(displayList), m_pixelHeight(pixelHeight), m_pixelAscent(asc), m_pixelDescent(desc)
{
}
GLuint getDisplayList() const
@ -40,6 +42,14 @@ public:
{
return m_pixelHeight;
}
int getPixelAscent() const
{
return m_pixelAscent;
}
int getPixelDescent() const
{
return m_pixelDescent;
}
};
GLFont glfont_create(const char* font_string);

View File

@ -1691,11 +1691,11 @@ void CamWnd::Cam_Draw()
if(g_camwindow_globals_private.m_showStats)
{
glRasterPos3f(1.0f, static_cast<float>(m_Camera.height) - 1.0f, 0.0f);
glRasterPos3f(1.0f, static_cast<float>(m_Camera.height) - GlobalOpenGL().m_fontDescent, 0.0f);
extern const char* Renderer_GetStats();
GlobalOpenGL().drawString(Renderer_GetStats());
glRasterPos3f(1.0f, static_cast<float>(m_Camera.height) - 11.0f, 0.0f);
glRasterPos3f(1.0f, static_cast<float>(m_Camera.height) - GlobalOpenGL().m_fontDescent - GlobalOpenGL().m_fontHeight, 0.0f);
extern const char* Cull_GetStats();
GlobalOpenGL().drawString(Cull_GetStats());
}

View File

@ -3305,7 +3305,7 @@ void GridStatus_onTextureLockEnabledChanged()
namespace
{
GLFont g_font(0, 0);
GLFont g_font(0, 0, 0, 0);
}
void GlobalGL_sharedContextCreated()
@ -3331,6 +3331,8 @@ void GlobalGL_sharedContextCreated()
GlobalOpenGL().m_font = g_font.getDisplayList();
GlobalOpenGL().m_fontHeight = g_font.getPixelHeight();
GlobalOpenGL().m_fontAscent = g_font.getPixelAscent();
GlobalOpenGL().m_fontDescent = g_font.getPixelDescent();
}
void GlobalGL_sharedContextDestroyed()

View File

@ -1842,7 +1842,8 @@ void XYWnd::XY_DrawGrid(void) {
// draw coordinate text if needed
if ( g_xywindow_globals_private.show_coordinates) {
glColor3fv(vector3_to_array(g_xywindow_globals.color_gridtext));
float offx = m_vOrigin[nDim2] + h - 6 / m_fScale, offy = m_vOrigin[nDim1] - w + 1 / m_fScale;
float offx = m_vOrigin[nDim2] + h - (1 + GlobalOpenGL().m_fontAscent) / m_fScale;
float offy = m_vOrigin[nDim1] - w + 1 / m_fScale;
for (x = xb - fmod(xb, stepx); x <= xe ; x += stepx) {
glRasterPos2f (x, offx);
sprintf (text, "%g", x);