#! /bin/bash # # This example displays each font in the /usr/share directory by # rendering it as an extruded font. Iterate through the list with # '[' and ']' keys. # setglobal text = $1; set -eu source "$(BASH_SOURCE%/*)/../CmdlineGL.lib" || die "Can't find CmdlineGL.lib ($(BASH_SOURCE%/*)/../CmdlineGL.lib)"; CmdlineGL_LoadLib RenderLoop ModelViewer setglobal fonts = ''( `find /usr/share -name '*.ttf' | grep -i mono` ) setglobal font_n = $(#fonts[@]) setglobal font_i = '' proc swap_font { if [[ -n "$font_i" ]] { ftglDestroyFont font1; } else { setglobal font_i = '0'; true; } echo "$font_i/$font_n $(fonts[font_i])" # Load font file and configure font rendering parameters ftglCreateExtrudeFont font1 $(fonts[font_i]) ftglSetFontFaceSize font1 72 72 ftglSetFontDepth font1 20 } proc next_font { if sh-expr ' font_i + 1 < font_n ' { let ++font_i swap_font } } proc prev_font { if sh-expr ' font_i > 0 ' { let font_i-- swap_font } } proc Init { # Initialize CmdlineGL for rendering only (no input or feedback) glEnable GL_NORMALIZE GL_DEPTH_TEST GL_CULL_FACE glShadeModel GL_SMOOTH # set up lighting (otherwise no change as it rotates) glEnable GL_LIGHTING GL_LIGHT0 glLight GL_LIGHT0 GL_AMBIENT .8 .8 .8 0 glLight GL_LIGHT0 GL_DIFFUSE 1 .8 .8 0 glLight GL_LIGHT0 GL_SPECULAR .8 .8 .8 0 glLight GL_LIGHT0 GL_POSITION 10 10 10 1 swap_font } proc RenderLoop_Render { ModelViewer_Update glLoadIdentity ModelViewer_ApplyMatrix glTranslate -40 0 0 glScale 1/40 glColor 0.5 0.5 0.5 1 ftglRenderFont font1 $(fonts[font_i]) FTGL_RENDER_ALL glFlush cglSwapBuffers glClear GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT } proc RenderLoop_DispatchEvent { if ! ModelViewer_DispatchEvent @Argv { if [[ "$1" == "K" && "$2" == "+" && "$3" == q ]] { setglobal RenderLoop_Done = '1' } elif [[ "$1" == "K" && "$2" == "+" && "$3" == ']' ]] { next_font } elif [[ "$1" == "K" && "$2" == "+" && "$3" == '[' ]] { prev_font } else { true } } } CmdlineGL_Start rw || die "Can't init CmdlineGL" Init RenderLoop_Run cglQuit