mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 14:29:13 +02:00
works around GLUT bugs related to monospace glyphs
This commit is contained in:
parent
dc4dc887ac
commit
e811410f77
1 changed files with 34 additions and 3 deletions
|
@ -13,6 +13,13 @@
|
||||||
#include "world.h"
|
#include "world.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
// no clue which versions are affected...
|
||||||
|
#define WORKAROUND_BROKEN_GLUT_STROKES
|
||||||
|
// see http://www.opengl.org/resources/libraries/glut/spec3/node78.html
|
||||||
|
static float MONO_STROKE_WIDTH_GLUT = 104.76;
|
||||||
|
|
||||||
// Return the azimuth angle in degrees between two points.
|
// Return the azimuth angle in degrees between two points.
|
||||||
float azimuth_to(glm::vec3 head_pos, glm::vec3 source_pos) {
|
float azimuth_to(glm::vec3 head_pos, glm::vec3 source_pos) {
|
||||||
return atan2(head_pos.x - source_pos.x, head_pos.z - source_pos.z) * 180.0f / PIf;
|
return atan2(head_pos.x - source_pos.x, head_pos.z - source_pos.z) * 180.0f / PIf;
|
||||||
|
@ -107,12 +114,17 @@ double diffclock(timeval *clock1,timeval *clock2)
|
||||||
return diffms;
|
return diffms;
|
||||||
}
|
}
|
||||||
|
|
||||||
int widthText(float scale, int mono, char *string) {
|
int widthText(float scale, int mono, char const* string) {
|
||||||
int width = 0;
|
int width = 0;
|
||||||
if (!mono) {
|
if (!mono) {
|
||||||
width = scale * glutStrokeLength(GLUT_STROKE_ROMAN, (const unsigned char *) string);
|
width = scale * glutStrokeLength(GLUT_STROKE_ROMAN, (const unsigned char *) string);
|
||||||
} else {
|
} else {
|
||||||
|
#ifndef WORKAROUND_BROKEN_GLUT_STROKES
|
||||||
width = scale * glutStrokeLength(GLUT_STROKE_MONO_ROMAN, (const unsigned char *) string);
|
width = scale * glutStrokeLength(GLUT_STROKE_MONO_ROMAN, (const unsigned char *) string);
|
||||||
|
#else
|
||||||
|
// return value is unreliable, so just calculate it
|
||||||
|
width = scale * float(strlen(string)) * MONO_STROKE_WIDTH_GLUT;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
@ -134,8 +146,27 @@ void drawtext(int x, int y, float scale, float rotate, float thick, int mono,
|
||||||
len = (int) strlen(string);
|
len = (int) strlen(string);
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
if (!mono) glutStrokeCharacter(GLUT_STROKE_ROMAN, int(string[i]));
|
if (!mono) {
|
||||||
else glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN, int(string[i]));
|
glutStrokeCharacter(GLUT_STROKE_ROMAN, int(string[i]));
|
||||||
|
} else {
|
||||||
|
#ifdef WORKAROUND_BROKEN_GLUT_STROKES
|
||||||
|
if (string[i] != 'm') {
|
||||||
|
#endif
|
||||||
|
glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN, int(string[i]));
|
||||||
|
#ifdef WORKAROUND_BROKEN_GLUT_STROKES
|
||||||
|
} else {
|
||||||
|
// some glut implementations have a broken 'm'...
|
||||||
|
unsigned char tmpStr[2];
|
||||||
|
tmpStr[0] = string[i];
|
||||||
|
tmpStr[1] = '\0';
|
||||||
|
float scale = MONO_STROKE_WIDTH_GLUT / glutStrokeLength(GLUT_STROKE_ROMAN, tmpStr);
|
||||||
|
glScalef(scale, 1.0f, 1.0f);
|
||||||
|
glutStrokeCharacter(GLUT_STROKE_ROMAN, int(string[i]));
|
||||||
|
// stay humble on the stack - might be in projection mode
|
||||||
|
glScalef(1.0f / scale, 1.0f, 1.0f);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue