1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
/* Copyright (c) Mark J. Kilgard, 1994. */
/* This program is freely distributable without licensing fees
and is provided without guarantee or warrantee expressed or
implied. This program is -not- in the public domain. */
#include <string.h>
#include <GL/glut.h>
void *font = GLUT_STROKE_ROMAN;
void *fonts[] =
{GLUT_STROKE_ROMAN, GLUT_STROKE_MONO_ROMAN};
char defaultMessage[] = "GLUT means OpenGL.";
char *message = defaultMessage;
int angle = 0;
void
selectFont(int newfont)
{
font = fonts[newfont];
glutPostRedisplay();
}
void
selectMessage(int msg)
{
switch (msg) {
case 1:
message = "abcdefghijklmnop";
break;
case 2:
message = "ABCDEFGHIJKLMNOP";
break;
}
}
void
tick(void)
{
angle -= 2;
glutPostRedisplay();
}
void
display(void)
{
int len, i;
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(angle, 0.0, 0.0, 1.0);
glTranslatef(-750, 0, 0);
len = (int) strlen(message);
for (i = 0; i < len; i++) {
glutStrokeCharacter(font, message[i]);
}
glPopMatrix();
glutSwapBuffers();
}
int
main(int argc, char **argv)
{
int i, submenu;
glutInit(&argc, argv);
for (i = 1; i < argc; i++) {
if (!strcmp(argv[i], "-mono")) {
font = GLUT_STROKE_MONO_ROMAN;
}
}
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(600, 600);
glutCreateWindow("anti-aliased stroke font");
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, 2000, 0, 2000);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glLineWidth(3.0);
glTranslatef(1000, 1000, 0);
glClearColor(0.0, 0.0, 0.0, 1.0);
glColor3f(1.0, 1.0, 1.0);
glutDisplayFunc(display);
glutIdleFunc(tick);
submenu = glutCreateMenu(selectMessage);
glutAddMenuEntry("abc", 1);
glutAddMenuEntry("ABC", 2);
glutCreateMenu(selectFont);
glutAddMenuEntry("Roman", 0);
glutAddMenuEntry("Mono Roman", 1);
glutAddSubMenu("Messages", submenu);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}
|