/* 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. */ /*************************************************** * file: stroke.c * * purpose: * THIS EXAMPLE OF USING GLUT STROKE FONTS, * is taken from the openGL repositories, and * slightly modified. * * Illustrates the use of two stroke fonts: * STROKE_ROMAN, STROKE_MONO_ROMAN * * A rotating marquee is displayed. * * Right-button click will stop rotation, * and present a menu: * (a) main menu (quit, help) * (b) chose message * (c) chose color * (d) chose font * * ***************************************************/ #include #include void *font = GLUT_STROKE_ROMAN; void *fonts[] = {GLUT_STROKE_ROMAN, GLUT_STROKE_MONO_ROMAN}; // char defaultMessage[] = "GLUT means OpenGL."; char defaultMessage[] = "For Help, Click Right Button!"; char *message = defaultMessage; // Parameters to center view window int CENTER_X = -1000; // for OpenGL logo: default value X=-750 int CENTER_Y = 0; // default value Y=0 // Motion parameters double angle = 0.0; double delangle = 0.0; double transx = 0.0; double delx = -0.2; double transy = 0.0; double dely = 0.0; void selectFont(int newfont) { font = fonts[newfont]; glutPostRedisplay(); } /*************************************************** * Color Selection ***************************************************/ typedef GLfloat color3[3]; // color data type color3 myColor = {1.0, 1.0, 1.0}; // default white color void selectColor(int c) { switch (c) { case 0: myColor[0] = 1.0; myColor[1] = 1.0; myColor[2] = 1.0; break; case 1: myColor[0] = 1.0; myColor[1] = 0.0; myColor[2] = 0.0; break; case 2: myColor[0] = 0.0; myColor[1] = 1.0; myColor[2] = 0.0; break; case 3: myColor[0] = 0.0; myColor[1] = 0.0; myColor[2] = 1.0; break; case 4: //yellow myColor[0] = 1.0; myColor[1] = 1.0; myColor[2] = 0.0; break; case 5: //magenta myColor[0] = 1.0; myColor[1] = 0.0; myColor[2] = 1.0; break; case 6: //cyan myColor[0] = 0.0; myColor[1] = 1.0; myColor[2] = 1.0; break; } }//selectColor void selectMessage(int msg) { switch (msg) { case 0: message = defaultMessage; break; case 1: message = "abcdefghijklmnop"; break; case 2: message = "ABCDEFGHIJKLMNOP"; break; case 3: message = "GLUT means OpenGL."; } }//selectMessage void selectMotion(int m) { switch (m) { case 0: // freeze delangle = 0.0; delx = 0.0; dely = 0.0; angle = 0.0; transx = 0.0; transy = 0.0; break; case 1: // +rotate delangle += 0.2; break; case 2: // +x delx += 0.5; break; case 3: // +y delx += 0.5; break; case 4: // -rotate delangle -= 0.2; break; case 5: // -x delx -= 0.5; break; case 6: // -y delx -= 0.5; break; } }//selectMotion void help () { printf("Help message \n"); }//help void mainMenu(int msg) { switch (msg) { case 1: exit(); break; case 2: help(); break; }//switch }//mainMenu void tick(void) { angle += delangle; transx += delx; transy += dely; glutPostRedisplay(); }//tick void display(void) { int len, i; glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); glRotatef(angle, 0.0, 0.0, 1.0); glTranslatef(CENTER_X+transx, CENTER_Y+transy, 0); glColor3f(myColor[0], myColor[1], myColor[2]); // pen color len = (int) strlen(message); for (i = 0; i < len; i++) { glutStrokeCharacter(font, message[i]); } glPopMatrix(); glutSwapBuffers(); }//display int main(int argc, char **argv) { int i, fontSubmenu, colorSubmenu, messageSubmenu, motionSubmenu; 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"); // projection glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, 2000, 0, 2000); glMatrixMode(GL_MODELVIEW); // rendering glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glLineWidth(2.0); // glTranslatef(1000, 1000, 0); glClearColor(0.0, 0.0, 0.0, 1.0); // background black glColor3f(1.0, 1.0, 1.0); // foreground white // register callbacks glutDisplayFunc(display); glutIdleFunc(tick); // Menu Setup // Color Submenu colorSubmenu = glutCreateMenu(selectColor); glutAddMenuEntry("White", 0); glutAddMenuEntry("Red", 1); glutAddMenuEntry("Green", 2); glutAddMenuEntry("Blue", 3); glutAddMenuEntry("Yellow", 4); glutAddMenuEntry("Magenta", 5); glutAddMenuEntry("Cyan", 6); // Message Submenu messageSubmenu = glutCreateMenu(selectMessage); glutAddMenuEntry("Default", 0); glutAddMenuEntry("abc", 1); glutAddMenuEntry("ABC", 2); glutAddMenuEntry("GlutLogo", 3); // Font Menu fontSubmenu = glutCreateMenu(selectFont); glutAddMenuEntry("Roman", 0); glutAddMenuEntry("Mono Roman", 1); // Motion Menu motionSubmenu = glutCreateMenu(selectMotion); glutAddMenuEntry("Reset", 0); glutAddMenuEntry("+Rotate", 1); glutAddMenuEntry("+X", 2); glutAddMenuEntry("+Y", 3); glutAddMenuEntry("-Rotate", 4); glutAddMenuEntry("-X", 5); glutAddMenuEntry("-Y", 6); // Main Menu glutCreateMenu(mainMenu); glutAddMenuEntry("Quit", 1); glutAddMenuEntry("Help", 2); glutAddSubMenu("Fonts", fontSubmenu); glutAddSubMenu("Messages", messageSubmenu); glutAddSubMenu("Colors", colorSubmenu); glutAddSubMenu("Motion", motionSubmenu); // Attach Main Menu to Right Button glutAttachMenu(GLUT_RIGHT_BUTTON); // Loop glutMainLoop(); return 0; /* ANSI C requires main to return int. */ }//main