[译]GLUT教程

Lighthouse3d.com >> GLUT Tutorial >> Fonts >> Stroke Fonts

笔划字体是用线条生成的.跟位图字体相反,笔划字体看上去像三维对,例如,字体可以旋转,测量和转化.

本节我们将会使用GLUT函数来生成一些笔划字体到屏幕.基础函数是glutStrokeCharacter.原型如下:

void glutStrokeCharacter(void *font, int character)

font - 用到的字体的名字

character - 要渲染的字母,符号,数字等..

字体的可选常量值有:

GLUT_STROKE_ROMAN

GLUT_STROKE_MONO_ROMAN (fixed width font: 104.76 units wide).

下面文本演示了如何调用glutStrokeCharacter函数来输出单个字符到当前本地坐标:

glutStrokeCharacter(GLUT_STROKE_ROMAN,'3');

跟位图字体相反,笔划字体的渲染定位的声明方式跟原始图片一样,例如用转化,旋转和测量.

下面函数在本地世界坐标中从指定位置开始渲染一串字符串:

void renderStrokeFontString(
        float x,
        float y,
        float z,
        void *font,
        char *string) {

    char *c;
    glPushMatrix();
    glTranslatef(x, y,z);

    for (c=string; *c != ''; c++) {
        glutStrokeCharacter(font, *c);
    }

    glPopMatrix();
}

注意: GLUT是用线条来绘制笔划字体的,因此我们要用glLineWidth函数来指定线条的宽度.该函数用了浮点型来指定宽度.

和位图字体一样,GLUT提供一个函数来返回字宽.glutStrokeWidth函数的原型如下:

int glutStrokeWidth(void *font, int character);

font -  GLUT中预定义的字体之一

character - 我们想要知道字宽的字符

原文地址:https://www.cnblogs.com/live41/p/3393752.html