# Example of GLUT text functions, applied to character strings # New functions are added to encapsulate the text-function calls # # Dave Pape # 27 September 2004 import sys from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * def drawStrokeString(text, font=GLUT_STROKE_ROMAN): for c in text: glutStrokeCharacter(font, ord(c)) def drawBitmapString(text, font=GLUT_BITMAP_TIMES_ROMAN_24): for c in text: glutBitmapCharacter(font, ord(c)) viewRotY = 0 viewRotX = 0 strokeText0 = "Stroke Text - Roman" strokeText1 = "Stroke Text - MonoRoman" bitmapText0 = "Bitmap Text - TimesRoman 24" bitmapText1 = "Bitmap Text - Helvetica 10" def draw(): global viewRotX, viewRotY glClearColor(0.5, 0.7, 1.0, 0.0) glClear(GL_COLOR_BUFFER_BIT) glLoadIdentity() glRotatef(viewRotX, 1.0, 0.0, 0.0) glRotatef(viewRotY, 0.0, 1.0, 0.0) glColor4f(1, 1, 1, 1) glutWireTeapot(1) glColor4f(1, 0, 0, 1) glPushMatrix() glTranslatef(-1, -1.5, 0) glScalef(0.005, 0.005, 0.005) drawStrokeString(strokeText0) glPopMatrix() glPushMatrix() glTranslatef(-1, -3, 0) glScalef(0.005, 0.005, 0.005) drawStrokeString(strokeText1, GLUT_STROKE_MONO_ROMAN) glPopMatrix() glRasterPos3f(-3, 1, 0) drawBitmapString(bitmapText0) glRasterPos3f(-3, 2, 0) drawBitmapString(bitmapText1, GLUT_BITMAP_HELVETICA_12) glutSwapBuffers() def keyboard(key, x, y): if key == chr(27): sys.exit(0) def specialkey(key,x,y): global viewRotX, viewRotY if key == GLUT_KEY_LEFT: viewRotY = viewRotY + 3 elif key == GLUT_KEY_RIGHT: viewRotY = viewRotY - 3 elif key == GLUT_KEY_UP: viewRotX = viewRotX + 3 elif key == GLUT_KEY_DOWN: viewRotX = viewRotX - 3 glutPostRedisplay() glutInit([]) glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE) glutInitWindowSize(400,400) glutCreateWindow(sys.argv[0]) glutDisplayFunc(draw) glutKeyboardFunc(keyboard) glutSpecialFunc(specialkey) glMatrixMode(GL_PROJECTION) glLoadIdentity() glOrtho(-10, 10, -10, 10, -10, 10) glMatrixMode(GL_MODELVIEW) glutMainLoop()