<s> import numpy <EOL> from freetype import * <EOL> import OpenGL . GL as gl <EOL> import OpenGL . GLUT as glut <EOL> base , texid = <NUM_LIT:0> , <NUM_LIT:0> <EOL> text = '''<STR_LIT>''' <EOL> def on_display ( ) : <EOL> global texid <EOL> gl . glClearColor ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> gl . glClear ( gl . GL_COLOR_BUFFER_BIT | gl . GL_DEPTH_BUFFER_BIT ) <EOL> gl . glBindTexture ( gl . GL_TEXTURE_2D , texid ) <EOL> gl . glColor ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> gl . glPushMatrix ( ) <EOL> gl . glTranslate ( <NUM_LIT:10> , <NUM_LIT:100> , <NUM_LIT:0> ) <EOL> gl . glPushMatrix ( ) <EOL> gl . glListBase ( base + <NUM_LIT:1> ) <EOL> gl . glCallLists ( [ ord ( c ) for c in text ] ) <EOL> gl . glPopMatrix ( ) <EOL> gl . glPopMatrix ( ) <EOL> glut . glutSwapBuffers ( ) <EOL> def on_reshape ( width , height ) : <EOL> gl . glViewport ( <NUM_LIT:0> , <NUM_LIT:0> , width , height ) <EOL> gl . glMatrixMode ( gl . GL_PROJECTION ) <EOL> gl . glLoadIdentity ( ) <EOL> gl . glOrtho ( <NUM_LIT:0> , width , <NUM_LIT:0> , height , - <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> gl . glMatrixMode ( gl . GL_MODELVIEW ) <EOL> gl . glLoadIdentity ( ) <EOL> def on_keyboard ( key , x , y ) : <EOL> if key == '<STR_LIT>' : sys . exit ( ) <EOL> def makefont ( filename , size ) : <EOL> global texid <EOL> face = Face ( filename ) <EOL> face . set_char_size ( size * <NUM_LIT:64> ) <EOL> if not face . is_fixed_width : <EOL> raise '<STR_LIT>' <EOL> width , height , ascender , descender = <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> <EOL> for c in range ( <NUM_LIT:32> , <NUM_LIT> ) : <EOL> face . load_char ( chr ( c ) , FT_LOAD_RENDER | FT_LOAD_FORCE_AUTOHINT ) <EOL> bitmap = face . glyph . bitmap <EOL> width = max ( width , bitmap . width ) <EOL> ascender = max ( ascender , face . glyph . bitmap_top ) <EOL> descender = max ( descender , bitmap . rows - face . glyph . bitmap_top ) <EOL> height = ascender + descender <EOL> Z = numpy . zeros ( ( height * <NUM_LIT:6> , width * <NUM_LIT:16> ) , dtype = numpy . ubyte ) <EOL> for j in range ( <NUM_LIT:6> ) : <EOL> for i in range ( <NUM_LIT:16> ) : <EOL> face . load_char ( chr ( <NUM_LIT:32> + j * <NUM_LIT:16> + i ) , FT_LOAD_RENDER | FT_LOAD_FORCE_AUTOHINT ) <EOL> bitmap = face . glyph . bitmap <EOL> x = i * width + face . glyph . bitmap_left <EOL> y = j * height + ascender - face . glyph . bitmap_top <EOL> Z [ y : y + bitmap . rows , x : x + bitmap . width ] . flat = bitmap . buffer <EOL> texid = gl . glGenTextures ( <NUM_LIT:1> ) <EOL> gl . glBindTexture ( gl . GL_TEXTURE_2D , texid ) <EOL> gl . glTexParameterf ( gl . GL_TEXTURE_2D , gl . GL_TEXTURE_MAG_FILTER , gl . GL_LINEAR ) <EOL> gl . glTexParameterf ( gl . GL_TEXTURE_2D , gl . GL_TEXTURE_MIN_FILTER , gl . GL_LINEAR ) <EOL> gl . glTexImage2D ( gl . GL_TEXTURE_2D , <NUM_LIT:0> , gl . GL_ALPHA , Z . shape [ <NUM_LIT:1> ] , Z . shape [ <NUM_LIT:0> ] , <NUM_LIT:0> , <EOL> gl . GL_ALPHA , gl . GL_UNSIGNED_BYTE , Z ) <EOL> dx , dy = width / float ( Z . shape [ <NUM_LIT:1> ] ) , height / float ( Z . shape [ <NUM_LIT:0> ] ) <EOL> base = gl . glGenLists ( <NUM_LIT:8> * <NUM_LIT:16> ) <EOL> for i in range ( <NUM_LIT:8> * <NUM_LIT:16> ) : <EOL> c = chr ( i ) <EOL> x = i % <NUM_LIT:16> <EOL> y = i // <NUM_LIT:16> - <NUM_LIT:2> <EOL> gl . glNewList ( base + i , gl . GL_COMPILE ) <EOL> if ( c == '<STR_LIT:\n>' ) : <EOL> gl . glPopMatrix ( ) <EOL> gl . glTranslatef ( <NUM_LIT:0> , - height , <NUM_LIT:0> ) <EOL> gl . glPushMatrix ( ) <EOL> elif ( c == '<STR_LIT:\t>' ) : <EOL> gl . glTranslatef ( <NUM_LIT:4> * width , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> elif ( i >= <NUM_LIT:32> ) : <EOL> gl . glBegin ( gl . GL_QUADS ) <EOL> gl . glTexCoord2f ( ( x ) * dx , ( y + <NUM_LIT:1> ) * dy ) , gl . glVertex ( <NUM_LIT:0> , - height ) <EOL> gl . glTexCoord2f ( ( x ) * dx , ( y ) * dy ) , gl . glVertex ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> gl . glTexCoord2f ( ( x + <NUM_LIT:1> ) * dx , ( y ) * dy ) , gl . glVertex ( width , <NUM_LIT:0> ) <EOL> gl . glTexCoord2f ( ( x + <NUM_LIT:1> ) * dx , ( y + <NUM_LIT:1> ) * dy ) , gl . glVertex ( width , - height ) <EOL> gl . glEnd ( ) <EOL> gl . glTranslatef ( width , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> gl . glEndList ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import sys <EOL> glut . glutInit ( sys . argv ) <EOL> glut . glutInitDisplayMode ( glut . GLUT_DOUBLE | glut . GLUT_RGB | glut . GLUT_DEPTH ) <EOL> glut . glutCreateWindow ( "<STR_LIT>" ) <EOL> glut . glutReshapeWindow ( <NUM_LIT> , <NUM_LIT:100> ) <EOL> glut . glutDisplayFunc ( on_display ) <EOL> glut . glutReshapeFunc ( on_reshape ) <EOL> glut . glutKeyboardFunc ( on_keyboard ) <EOL> gl . glTexEnvf ( gl . GL_TEXTURE_ENV , gl . GL_TEXTURE_ENV_MODE , gl . GL_MODULATE ) <EOL> gl . glEnable ( gl . GL_DEPTH_TEST ) <EOL> gl . glEnable ( gl . GL_BLEND ) <EOL> gl . glEnable ( gl . GL_COLOR_MATERIAL ) <EOL> gl . glColorMaterial ( gl . GL_FRONT_AND_BACK , gl . GL_AMBIENT_AND_DIFFUSE ) <EOL> gl . glBlendFunc ( gl . GL_SRC_ALPHA , gl . GL_ONE_MINUS_SRC_ALPHA ) <EOL> gl . glEnable ( gl . GL_TEXTURE_2D ) <EOL> makefont ( '<STR_LIT>' , <NUM_LIT:64> ) <EOL> glut . glutMainLoop ( ) </s>
