-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathBrowseFonts.sh
executable file
·86 lines (74 loc) · 1.95 KB
/
BrowseFonts.sh
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
#! /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.
#
text="$1";
set -eu
source "${BASH_SOURCE%/*}/../CmdlineGL.lib" || die "Can't find CmdlineGL.lib (${BASH_SOURCE%/*}/../CmdlineGL.lib)";
CmdlineGL_LoadLib RenderLoop ModelViewer
fonts=( `find /usr/share -name '*.ttf' | grep -i mono` )
font_n=${#fonts[@]}
font_i=
swap_font() {
if [[ -n "$font_i" ]]; then ftglDestroyFont font1; else font_i=0; true; fi
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
}
next_font() {
if (( font_i + 1 < font_n )); then
let ++font_i
swap_font
fi
}
prev_font() {
if (( font_i > 0 )); then
let font_i--
swap_font
fi
}
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
}
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
}
RenderLoop_DispatchEvent() {
if ! ModelViewer_DispatchEvent "$@"; then
if [[ "$1" == "K" && "$2" == "+" && "$3" == q ]]; then
RenderLoop_Done=1
elif [[ "$1" == "K" && "$2" == "+" && "$3" == ']' ]]; then
next_font
elif [[ "$1" == "K" && "$2" == "+" && "$3" == '[' ]]; then
prev_font
else
true
fi
fi
}
CmdlineGL_Start rw || die "Can't init CmdlineGL"
Init
RenderLoop_Run
cglQuit