unsigned int iV_GetCountedTextWidth(const char *string, size_t string_length) { float boundingbox[8]; float pixel_width, point_width; glcMeasureCountedString(GL_FALSE, string_length, string); if (!glcGetStringMetric(GLC_BOUNDS, boundingbox)) { debug(LOG_ERROR, "Couldn't retrieve a bounding box for the string \"%s\" of length %u", string, (unsigned int)string_length); return 0; } point_width = getGLCPointWidth(boundingbox); pixel_width = getGLCPointToPixel(point_width); return (unsigned int)pixel_width; }
unsigned int iV_GetTextHeight(const char *string) { float boundingbox[8]; float pixel_height, point_height; glcMeasureString(GL_FALSE, string); if (!glcGetStringMetric(GLC_BOUNDS, boundingbox)) { debug(LOG_ERROR, "Couldn't retrieve a bounding box for the string \"%s\"", string); return 0; } point_height = getGLCPointHeight(boundingbox); pixel_height = getGLCPointToPixel(point_height); return (unsigned int)pixel_height; }
void display(void) { int i = 0; GLfloat baseline[4] = {0.f, 0.f, 0.f, 0.f}; GLfloat bbox[8] = {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f(1.f, 0.f, 0.f); glRasterPos2f(50.f, 50.f); glcRenderString("Hello world!"); /* Render "H" and its bounding box */ glColor3f(0.f, 1.f, 1.f); glTranslatef(50.f, 50.f, 0.f); glcGetCharMetric('H', GLC_BOUNDS, bbox); glBegin(GL_LINE_LOOP); for (i = 0; i < 4; i++) glVertex2fv(&bbox[2*i]); glEnd(); /* Translate the model view matrix of the width of "H" */ glcGetCharMetric('H', GLC_BASELINE, baseline); glTranslatef(baseline[2] - baseline[0], baseline[3] - baseline[1], 0.f); /* Render the bouding box of "ello" */ glcMeasureString(GL_FALSE, "ello"); glcGetStringMetric(GLC_BOUNDS, bbox); glBegin(GL_LINE_LOOP); for (i = 0; i < 4; i++) glVertex2fv(&bbox[2*i]); glEnd(); glLoadIdentity(); glFlush(); }
void display(void) { int i = 0; GLfloat bbox[8] = {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}; GLfloat bbox2[8] = {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}; char string[20]; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Render GLC_BITMAP without kerning */ glLoadIdentity(); glColor3f(1.f, 0.f, 0.f); glRasterPos2f(50.f, 50.f); glcDisable(GLC_KERNING_QSO); glcRenderStyle(GLC_BITMAP); glcLoadIdentity(); glcScale(100.f, 100.f); glcRenderString("VAV"); glcMeasureString(GL_FALSE, "VAV"); glcGetStringMetric(GLC_BOUNDS, bbox); glColor3f(0.f, 1.f, 1.f); glTranslatef(50.f, 50.f, 0.f); glBegin(GL_LINE_LOOP); for (i = 0; i < 4; i++) glVertex2fv(&bbox[2*i]); glEnd(); /* Display the dimensions */ snprintf(string, 20, "%f", bbox[2] - bbox[0]); glcEnable(GLC_HINTING_QSO); glcScale(0.15f, 0.15f); glcMeasureString(GL_FALSE, string); glcGetStringMetric(GLC_BOUNDS, bbox2); glColor3f(1.f, 1.f, 1.f); glBegin(GL_LINE); glVertex2fv(bbox); glVertex2f(bbox[0], bbox[1] - 40.f); glVertex2fv(&bbox[2]); glVertex2f(bbox[2], bbox[3] - 40.f); glVertex2f(bbox[0], bbox[1] - 30.f); glVertex2f(bbox[2], bbox[3] - 30.f); glEnd(); glBegin(GL_LINE_LOOP); glVertex2f(bbox[0] + 5.f, bbox[1] - 25.f); glVertex2f(bbox[0], bbox[1] - 30.f); glVertex2f(bbox[0] + 5.f, bbox[1] - 35.f); glEnd(); glBegin(GL_LINE_LOOP); glVertex2f(bbox[2] - 5.f, bbox[1] - 25.f); glVertex2f(bbox[2], bbox[1] - 30.f); glVertex2f(bbox[2] - 5.f, bbox[1] - 35.f); glEnd(); glLoadIdentity(); glRasterPos2f(floor((bbox[2] - bbox[0] - (bbox2[2] - bbox2[0])) * 50.f) / 100.f + 50.f, floorf((bbox[1] + 23.f) * 100.f) / 100.f); glcRenderString(string); glcDisable(GLC_HINTING_QSO); /* Render GLC_TEXTURE without kerning */ glLoadIdentity(); glcRenderStyle(GLC_TEXTURE); glColor3f(1.f, 0.f, 0.f); glScalef(100.f, 100.f, 1.f); glTranslatef(3.f, 0.5f, 0.f); glPushMatrix(); /* In order to reproduce the conditions of bug #1987563, GLC_GL_OBJECTS must * be disabled when rendering GLC_TEXTURE w/o kerning. */ glcRenderString("VAV"); glPopMatrix(); glcMeasureString(GL_TRUE, "VAV"); glcGetStringCharMetric(1, GLC_BOUNDS, bbox); glColor3f(0.f, 1.f, 0.f); glBegin(GL_LINE_LOOP); for (i = 0; i < 4; i++) glVertex2fv(&bbox[2*i]); glEnd(); glcGetStringMetric(GLC_BOUNDS, bbox); glColor3f(0.f, 1.f, 1.f); glBegin(GL_LINE_LOOP); for (i = 0; i < 4; i++) glVertex2fv(&bbox[2*i]); glEnd(); /* Display the dimensions */ snprintf(string, 20, "%f", (bbox[2] - bbox[0]) * 100.f); glcEnable(GLC_HINTING_QSO); glcMeasureString(GL_FALSE, string); glcGetStringMetric(GLC_BOUNDS, bbox2); glColor3f(1.f, 1.f, 1.f); glBegin(GL_LINE); glVertex2fv(bbox); glVertex2f(bbox[0], bbox[1] - 0.4f); glVertex2fv(&bbox[2]); glVertex2f(bbox[2], bbox[3] - 0.4f); glVertex2f(bbox[0], bbox[1] - 0.3f); glVertex2f(bbox[2], bbox[3] - 0.3f); glEnd(); glBegin(GL_LINE_LOOP); glVertex2f(bbox[0] + 0.05f, bbox[1] - 0.25f); glVertex2f(bbox[0], bbox[1] - 0.3f); glVertex2f(bbox[0] + 0.05f, bbox[1] - 0.35f); glEnd(); glBegin(GL_LINE_LOOP); glVertex2f(bbox[2] - 0.05f, bbox[1] - 0.25f); glVertex2f(bbox[2], bbox[1] - 0.3f); glVertex2f(bbox[2] - 0.05f, bbox[1] - 0.35f); glEnd(); /* When hinting is enabled, characters must be rendered at integer positions * otherwise hinting is compromised and characters look fuzzy. */ glTranslatef(floorf((bbox[2] - bbox[0] - (bbox2[2] - bbox2[0]) * 0.15f) * 50.f) / 100.f, floorf((bbox[1] - 0.27f) * 100.f) / 100.f, 0.f); glScalef(0.15f, 0.15f, 1.f); glcRenderString(string); glcDisable(GLC_HINTING_QSO); /* Render GLC_BITMAP with kerning */ glColor3f(1.f, 0.f, 0.f); glcEnable(GLC_KERNING_QSO); glcRenderStyle(GLC_BITMAP); glcLoadIdentity(); glcScale(100.f, 100.f); glLoadIdentity(); glRasterPos2f(50.f, 150.f); glcRenderString("VAV"); glcMeasureString(GL_FALSE, "VAV"); glcGetStringMetric(GLC_BOUNDS, bbox); glColor3f(0.f, 1.f, 1.f); glTranslatef(50.f, 150.f, 0.f); glBegin(GL_LINE_LOOP); for (i = 0; i < 4; i++) glVertex2fv(&bbox[2*i]); glEnd(); /* Display the dimensions */ snprintf(string, 20, "%f", bbox[4] - bbox[6]); glcEnable(GLC_HINTING_QSO); glcScale(0.15f, 0.15f); glcMeasureString(GL_FALSE, string); glcGetStringMetric(GLC_BOUNDS, bbox2); glColor3f(1.f, 1.f, 1.f); glBegin(GL_LINE); glVertex2fv(&bbox[4]); glVertex2f(bbox[4], bbox[5] + 40.f); glVertex2fv(&bbox[6]); glVertex2f(bbox[6], bbox[7] + 40.f); glVertex2f(bbox[4], bbox[5] + 30.f); glVertex2f(bbox[6], bbox[7] + 30.f); glEnd(); glBegin(GL_LINE_LOOP); glVertex2f(bbox[4] - 5.f, bbox[5] + 25.f); glVertex2f(bbox[4], bbox[5] + 30.f); glVertex2f(bbox[4] - 5.f, bbox[5] + 35.f); glEnd(); glBegin(GL_LINE_LOOP); glVertex2f(bbox[6] + 5.f, bbox[7] + 25.f); glVertex2f(bbox[6], bbox[7] + 30.f); glVertex2f(bbox[6] + 5.f, bbox[7] + 35.f); glEnd(); glLoadIdentity(); glRasterPos2f(floorf((bbox[4] - bbox[6] - (bbox2[4] - bbox2[6])) * 50.f) / 100.f + 50.f, bbox[7] + 183.f); glcRenderString(string); glcScale(2.f, 2.f); glcMeasureString(GL_FALSE, "GL_BITMAP"); glcGetStringMetric(GLC_BOUNDS, bbox2); glRasterPos2f(floorf((bbox[2] - bbox[0] - (bbox2[2] - bbox2[0])) * 50.f) / 100.f + 50.f, 300.f); glcRenderString("GL_BITMAP"); glcDisable(GLC_HINTING_QSO); /* Render GLC_TEXTURE with kerning */ glLoadIdentity(); glcRenderStyle(GLC_TEXTURE); glColor3f(1.f, 0.f, 0.f); glScalef(100.f, 100.f, 1.f); glTranslatef(3.f, 1.5f, 0.f); glPushMatrix(); glcRenderString("VAV"); glPopMatrix(); glcMeasureString(GL_TRUE, "VAV"); glcGetStringCharMetric(1, GLC_BOUNDS, bbox); glColor3f(0.f, 1.f, 0.f); glBegin(GL_LINE_LOOP); for (i = 0; i < 4; i++) glVertex2fv(&bbox[2*i]); glEnd(); glcGetStringMetric(GLC_BOUNDS, bbox); glColor3f(0.f, 1.f, 1.f); glBegin(GL_LINE_LOOP); for (i = 0; i < 4; i++) glVertex2fv(&bbox[2*i]); glEnd(); /* Display the dimensions */ snprintf(string, 20, "%f", (bbox[4] - bbox[6]) * 100.f); glcEnable(GLC_HINTING_QSO); glcMeasureString(GL_FALSE, string); glcGetStringMetric(GLC_BOUNDS, bbox2); glColor3f(1.f, 1.f, 1.f); glBegin(GL_LINE); glVertex2fv(&bbox[4]); glVertex2f(bbox[4], bbox[5] + 0.4f); glVertex2fv(&bbox[6]); glVertex2f(bbox[6], bbox[7] + 0.4f); glVertex2f(bbox[4], bbox[5] + 0.3f); glVertex2f(bbox[6], bbox[7] + 0.3f); glEnd(); glBegin(GL_LINE_LOOP); glVertex2f(bbox[6] + 0.05f, bbox[7] + 0.25f); glVertex2f(bbox[6], bbox[7] + 0.3f); glVertex2f(bbox[6] + 0.05f, bbox[7] + 0.35f); glEnd(); glBegin(GL_LINE_LOOP); glVertex2f(bbox[4] - 0.05f, bbox[5] + 0.25f); glVertex2f(bbox[4], bbox[5] + 0.3f); glVertex2f(bbox[4] - 0.05f, bbox[5] + 0.35f); glEnd(); glPushMatrix(); glTranslatef(floorf((bbox[4] - bbox[6] - (bbox2[4] - bbox2[6]) * 0.15f) *50.f) / 100.f, floorf((bbox[5] + 0.33f) * 100.f) / 100.f, 0.f); glScalef(0.15f, 0.15f, 1.f); glcRenderString(string); glPopMatrix(); glcMeasureString(GL_FALSE, "GL_TEXTURE"); glcGetStringMetric(GLC_BOUNDS, bbox2); glTranslatef(floorf((bbox[2] - bbox[0] - (bbox2[2] - bbox2[0]) * 0.3f) * 50.f) / 100.f, 1.5f, 0.f); glScalef(0.3f, 0.3f, 1.f); glcRenderString("GL_TEXTURE"); glcDisable(GLC_HINTING_QSO); glFlush(); }