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:
parent
cbfac4f225
commit
df072b781c
|
|
@ -1999,6 +1999,8 @@ struct OpenGLBinding
|
||||||
|
|
||||||
GLuint m_font;
|
GLuint m_font;
|
||||||
int m_fontHeight;
|
int m_fontHeight;
|
||||||
|
int m_fontAscent;
|
||||||
|
int m_fontDescent;
|
||||||
|
|
||||||
/// \brief Renders \p string at the current raster-position of the current context.
|
/// \brief Renders \p string at the current raster-position of the current context.
|
||||||
void drawString(const char* string) const
|
void drawString(const char* string) const
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ void glfont_release(GLFont& font)
|
||||||
GLFont glfont_create(const char* font_string)
|
GLFont glfont_create(const char* font_string)
|
||||||
{
|
{
|
||||||
GLuint font_list_base = glGenLists (256);
|
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);
|
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);
|
PangoFontMetrics* font_metrics = pango_font_get_metrics (font, 0);
|
||||||
|
|
||||||
font_height = pango_font_metrics_get_ascent (font_metrics) +
|
font_ascent = pango_font_metrics_get_ascent (font_metrics);
|
||||||
pango_font_metrics_get_descent (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);
|
font_height = PANGO_PIXELS (font_height);
|
||||||
|
|
||||||
pango_font_metrics_unref (font_metrics);
|
pango_font_metrics_unref (font_metrics);
|
||||||
|
|
@ -127,15 +131,15 @@ GLFont glfont_create(const char* font_string)
|
||||||
pango_font_description_free (font_desc);
|
pango_font_description_free (font_desc);
|
||||||
|
|
||||||
// fix for pango/gtkglext metrix bug
|
// fix for pango/gtkglext metrix bug
|
||||||
if(font_height > 16)
|
if(font_height > 256)
|
||||||
font_height = 16;
|
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)
|
void glfont_release(GLFont& font)
|
||||||
{
|
{
|
||||||
glDeleteLists(font.getDisplayList(), 256);
|
glDeleteLists(font.getDisplayList(), 256);
|
||||||
font = GLFont(0, 0);
|
font = GLFont(0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,10 @@ class GLFont
|
||||||
{
|
{
|
||||||
GLuint m_displayList;
|
GLuint m_displayList;
|
||||||
int m_pixelHeight;
|
int m_pixelHeight;
|
||||||
|
int m_pixelAscent;
|
||||||
|
int m_pixelDescent;
|
||||||
public:
|
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
|
GLuint getDisplayList() const
|
||||||
|
|
@ -40,6 +42,14 @@ public:
|
||||||
{
|
{
|
||||||
return m_pixelHeight;
|
return m_pixelHeight;
|
||||||
}
|
}
|
||||||
|
int getPixelAscent() const
|
||||||
|
{
|
||||||
|
return m_pixelAscent;
|
||||||
|
}
|
||||||
|
int getPixelDescent() const
|
||||||
|
{
|
||||||
|
return m_pixelDescent;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
GLFont glfont_create(const char* font_string);
|
GLFont glfont_create(const char* font_string);
|
||||||
|
|
|
||||||
|
|
@ -1691,11 +1691,11 @@ void CamWnd::Cam_Draw()
|
||||||
|
|
||||||
if(g_camwindow_globals_private.m_showStats)
|
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();
|
extern const char* Renderer_GetStats();
|
||||||
GlobalOpenGL().drawString(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();
|
extern const char* Cull_GetStats();
|
||||||
GlobalOpenGL().drawString(Cull_GetStats());
|
GlobalOpenGL().drawString(Cull_GetStats());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3305,7 +3305,7 @@ void GridStatus_onTextureLockEnabledChanged()
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
GLFont g_font(0, 0);
|
GLFont g_font(0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalGL_sharedContextCreated()
|
void GlobalGL_sharedContextCreated()
|
||||||
|
|
@ -3331,6 +3331,8 @@ void GlobalGL_sharedContextCreated()
|
||||||
|
|
||||||
GlobalOpenGL().m_font = g_font.getDisplayList();
|
GlobalOpenGL().m_font = g_font.getDisplayList();
|
||||||
GlobalOpenGL().m_fontHeight = g_font.getPixelHeight();
|
GlobalOpenGL().m_fontHeight = g_font.getPixelHeight();
|
||||||
|
GlobalOpenGL().m_fontAscent = g_font.getPixelAscent();
|
||||||
|
GlobalOpenGL().m_fontDescent = g_font.getPixelDescent();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalGL_sharedContextDestroyed()
|
void GlobalGL_sharedContextDestroyed()
|
||||||
|
|
|
||||||
|
|
@ -1842,7 +1842,8 @@ void XYWnd::XY_DrawGrid(void) {
|
||||||
// draw coordinate text if needed
|
// draw coordinate text if needed
|
||||||
if ( g_xywindow_globals_private.show_coordinates) {
|
if ( g_xywindow_globals_private.show_coordinates) {
|
||||||
glColor3fv(vector3_to_array(g_xywindow_globals.color_gridtext));
|
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) {
|
for (x = xb - fmod(xb, stepx); x <= xe ; x += stepx) {
|
||||||
glRasterPos2f (x, offx);
|
glRasterPos2f (x, offx);
|
||||||
sprintf (text, "%g", x);
|
sprintf (text, "%g", x);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user