#include <GL/glut.h>
002.
#include <stdlib.h>
003.
#include <string.h>
004.
005.
#define PT
1
006.
#define STROKE
2
007.
#define END
3
008.
009.
typedef struct charpoint {
010.
GLfloat x, y;
011.
int
type;
012.
} CP;
013.
014.
CP Adata[] = {
015.
{
0
,
0
, PT}, {
0
,
9
, PT}, {
1
,
10
, PT}, {
4
,
10
, PT},
016.
{
5
,
9
, PT}, {
5
,
0
, STROKE}, {
0
,
5
, PT}, {
5
,
5
, END}
017.
};
018.
019.
CP Edata[] = {
020.
{
5
,
0
, PT}, {
0
,
0
, PT}, {
0
,
10
, PT}, {
5
,
10
, STROKE},
021.
{
0
,
5
, PT}, {
4
,
5
, END}
022.
};
023.
024.
CP Pdata[] = {
025.
{
0
,
0
, PT}, {
0
,
10
, PT}, {
4
,
10
, PT}, {
5
,
9
, PT}, {
5
,
6
, PT},
026.
{
4
,
5
, PT}, {
0
,
5
, END}
027.
};
028.
029.
CP Rdata[] = {
030.
{
0
,
0
, PT}, {
0
,
10
, PT}, {
4
,
10
, PT}, {
5
,
9
, PT}, {
5
,
6
, PT},
031.
{
4
,
5
, PT}, {
0
,
5
, STROKE}, {
3
,
5
, PT}, {
5
,
0
, END}
032.
};
033.
034.
CP Sdata[] = {
035.
{
0
,
1
, PT}, {
1
,
0
, PT}, {
4
,
0
, PT}, {
5
,
1
, PT}, {
5
,
4
, PT},
036.
{
4
,
5
, PT}, {
1
,
5
, PT}, {
0
,
6
, PT}, {
0
,
9
, PT}, {
1
,
10
, PT},
037.
{
4
,
10
, PT}, {
5
,
9
, END}
038.
};
039.
040.
041.
042.
043.
static
void
drawLetter(CP *l)
044.
{
045.
glBegin(GL_LINE_STRIP);
046.
while
(
1
) {
047.
switch
(l->type) {
048.
case
PT:
049.
glVertex2fv(&l->x);
050.
break
;
051.
case
STROKE:
052.
glVertex2fv(&l->x);
053.
glEnd();
054.
glBegin(GL_LINE_STRIP);
055.
break
;
056.
case
END:
057.
glVertex2fv(&l->x);
058.
glEnd();
059.
glTranslatef(
8.0
,
0.0
,
0.0
);
060.
return
;
061.
}
062.
l++;
063.
}
064.
}
065.
066.
067.
static
void
init (
void
)
068.
{
069.
GLuint base;
070.
071.
glShadeModel (GL_FLAT);
072.
073.
base = glGenLists (
128
);
074.
glListBase(base);
075.
076.
glNewList(base+
'A'
, GL_COMPILE); drawLetter(Adata); glEndList();
077.
glNewList(base+
'E'
, GL_COMPILE); drawLetter(Edata); glEndList();
078.
glNewList(base+
'P'
, GL_COMPILE); drawLetter(Pdata); glEndList();
079.
glNewList(base+
'R'
, GL_COMPILE); drawLetter(Rdata); glEndList();
080.
glNewList(base+
'S'
, GL_COMPILE); drawLetter(Sdata); glEndList();
081.
glNewList(base+
' '
, GL_COMPILE); glTranslatef(
8.0
,
0.0
,
0.0
); glEndList();
082.
}
083.
084.
char
*test1 =
"A SPARE SERAPE APPEARS AS"
;
085.
char
*test2 =
"APES PREPARE RARE PEPPERS"
;
086.
087.
static
void
printStrokedString(
char
*s)
088.
{
089.
GLsizei len = strlen(s);
090.
glCallLists(len, GL_BYTE, (GLbyte *)s);
091.
092.
093.
}
094.
095.
void
display(
void
)
096.
{
097.
glClear(GL_COLOR_BUFFER_BIT);
098.
glColor3f(
1.0
,
1.0
,
1.0
);
099.
glPushMatrix();
100.
glScalef(
2.0
,
2.0
,
2.0
);
101.
glTranslatef(
10.0
,
30.0
,
0.0
);
102.
printStrokedString(test1);
103.
glPopMatrix();
104.
glPushMatrix();
105.
glScalef(
2.0
,
2.0
,
2.0
);
106.
glTranslatef(
10.0
,
13.0
,
0.0
);
107.
printStrokedString(test2);
108.
glPopMatrix();
109.
glFlush();
110.
}
111.
112.
void
reshape(
int
w,
int
h)
113.
{
114.
glViewport(
0
,
0
, (GLsizei) w, (GLsizei) h);
115.
glMatrixMode (GL_PROJECTION);
116.
glLoadIdentity ();
117.
gluOrtho2D (
0.0
, (GLdouble) w,
0.0
, (GLdouble) h);
118.
}
119.
120.
void
keyboard(unsigned
char
key,
int
x,
int
y)
121.
{
122.
switch
(key) {
123.
case
' '
:
124.
glutPostRedisplay();
125.
break
;
126.
case
27
:
127.
exit(
0
);
128.
}
129.
}
130.
131.
132.
133.
134.
135.
int
main(
int
argc,
char
** argv)
136.
{
137.
glutInit(&argc, argv);
138.
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
139.
glutInitWindowSize (
440
,
120
);
140.
glutCreateWindow (
"stroke"
);
141.
init ();
142.
glutReshapeFunc(reshape);
143.
glutKeyboardFunc(keyboard);
144.
glutDisplayFunc(display);
145.
glutMainLoop();
146.
return
0
;
147.
}