annotate samples/freetype.tp @ 324:615f23450f8f

Freetype sample: Build texture of glyphs in a more intelligent way
author Michael Pavone <pavone@retrodev.com>
date Mon, 23 Mar 2015 21:21:43 -0700
parents 3edd0169311a
children 50760ba52b11
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
321
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #{
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2 import: [
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
3 video
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
4 timer
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
5 ] from: (sdl subsystems)
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
6
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
7 import: [
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
8 quit
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
9 ] from: (sdl eventTypes)
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
10
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
11 import: [
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
12 streaming
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
13 ] from: (sdl textureAccess)
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
14
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
15 import: [
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
16 bgra8888
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
17 ] from: (sdl pixelFormats)
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
18
324
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
19 import: [
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
20 render
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
21 linearDesign
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
22 ] from: (freetype loadFlags)
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
23
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
24 makeAtlas <- :renderer face size dpi color {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
25 face setCharSize: size res: dpi
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
26 slot <- face glyphSlot
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
27
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
28 glyphs <- #[]
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
29 //TODO: Use a bytearray once that has an append method
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
30 pixels <- #[]
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
31 foreach: (face charmap) :char glyphIndex {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
32 face loadGlyph: glyphIndex flags: (render or linearDesign)
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
33 pixelStart <- pixels length
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
34 _width <- slot bitmapWidth
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
35 _height <- slot bitmapRows
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
36 pitch <- slot bitmapPitch
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
37 buffer <- slot bitmapData
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
38
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
39 y <- 0
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
40 while: { y < _height } do: {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
41 x <- 0
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
42 idx <- y * pitch
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
43 while: { x < _width } do: {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
44 pixels append: (buffer get: idx)
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
45
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
46 x <- x + 1
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
47 idx <- idx + 1
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
48 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
49 y <- y + 1
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
50 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
51
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
52 glyphs append: #{
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
53 width <- _width
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
54 height <- _height
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
55 pixelOffset <- pixelStart
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
56 hAdvance <- slot linearHoriAdvance
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
57 vAdvance <- slot linearVertAdvance
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
58 leftOffset <- (slot bitmapLeft)
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
59 topOffset <- (slot bitmapTop)
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
60 charCode <- char
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
61
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
62 atlasX <- -1
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
63 atlasY <- -1
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
64
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
65 <= <- :other {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
66 if: height > (other height) {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
67 true
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
68 } else: {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
69 if: height < (other height) {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
70 false
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
71 } else: {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
72 width >= (other width)
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
73 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
74 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
75 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
76 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
77 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
78 glyphs sort
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
79 maxDim <- 2048
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
80 aWidth <- 128
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
81 minSize <- maxDim * maxDim
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
82 minSizeWidth <- -1
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
83 aHeight <- maxDim
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
84
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
85 while: { aWidth <= maxDim } do: {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
86 print: "Checking width: " . aWidth . "\n"
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
87 curX <- 0
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
88 curY <- 0
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
89 minHeight <- 0
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
90 avail <- glyphs foldr: [] with: :acc val {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
91 val | acc
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
92 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
93 while: { (not: (avail empty?)) && curY <= maxDim } do: {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
94 curGlyph <- avail value
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
95 if: curX + (curGlyph width) < aWidth {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
96 if: curY + (curGlyph height) < maxDim {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
97 curX <- curX + (curGlyph width)
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
98 avail <- avail tail
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
99 if: (curGlyph height) > minHeight {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
100 minHeight <- curGlyph height
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
101 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
102 } else: {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
103 curY <- maxDim + 1
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
104 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
105 } else: {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
106 skinny <- option none
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
107 if: aWidth > curX {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
108 availPixels <- aWidth - curX
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
109
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
110 skinny <- avail find: :val {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
111 (val width) <= availPixels
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
112 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
113 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
114
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
115 skinny value: :curGlyph {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
116 curX <- curX + (curGlyph width)
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
117 if: (curGlyph height) > minHeight {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
118 minHeight <- curGlyph height
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
119 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
120 avail <- avail filter: :glyph {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
121 (glyph charCode) != (curGlyph charCode)
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
122 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
123 } none: {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
124 curY <- curY + minHeight
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
125 minHeight <- 0
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
126 curX <- 0
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
127 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
128 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
129 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
130 if: (avail empty?) {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
131 aHeight <- curY + minHeight
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
132 p2Height <- 1
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
133 while: { p2Height < aHeight } do: {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
134 p2Height <- lshift: p2Height by: 1
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
135 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
136
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
137 size <- aWidth * p2Height
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
138 if: size < minSize {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
139 minSize <- size
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
140 minSizeWidth <- aWidth
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
141 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
142 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
143 aWidth <- aWidth * 2
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
144 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
145 if: minSizeWidth > -1 {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
146 print: "Best width: " . minSizeWidth . ", height: " . (minSize / minSizeWidth) . "\n"
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
147 aWidth <- minSizeWidth
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
148 aHeight <- minSize / minSizeWidth
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
149
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
150 (renderer createTexture: bgra8888 access: streaming width: aWidth height: aHeight) value: :drawTex {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
151 drawTex blendMode!: ((sdl blendModes) blend)
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
152 //TODO: Use "update" with a static texture
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
153 drawTex lockRect: (sdl rect: 0 0 size: aWidth aHeight) with: :bytearr pitch {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
154 n <- aHeight * pitch
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
155 i <- 0
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
156 while: { i < n } do: {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
157 bytearr set: i 0u8
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
158 i <- i + 1
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
159 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
160 curX <- 0
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
161 curY <- 0
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
162 minHeight <- 0
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
163 avail <- glyphs foldr: [] with: :acc val {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
164 val | acc
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
165 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
166 while: { not: (avail empty?) } do: {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
167 curGlyph <- avail value
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
168 if: curX + (curGlyph width) < aWidth {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
169 curGlyph atlasX!: curX
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
170 curGlyph atlasY!: curY
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
171 y <- 0
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
172 dstY <- curY
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
173 idx <- curGlyph pixelOffset
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
174 while: { y < (curGlyph height) } do: {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
175 dstIdx <- dstY * pitch + curX * 4
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
176 x <- 0
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
177 while: { x < (curGlyph width) } do: {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
178 //FIXME: This will probably only work on little endian machines
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
179 bytearr set: dstIdx (pixels get: idx)
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
180 dstIdx <- dstIdx + 1
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
181 bytearr set: dstIdx (color r)
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
182 dstIdx <- dstIdx + 1
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
183 bytearr set: dstIdx (color g)
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
184 dstIdx <- dstIdx + 1
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
185 bytearr set: dstIdx (color b)
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
186 dstIdx <- dstIdx + 1
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
187
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
188 idx <- idx + 1
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
189 x <- x + 1
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
190 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
191 y <- y + 1
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
192 dstY <- dstY + 1
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
193 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
194
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
195 curX <- curX + (curGlyph width)
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
196 avail <- avail tail
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
197 if: (curGlyph height) > minHeight {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
198 minHeight <- curGlyph height
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
199 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
200 } else: {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
201 skinny <- option none
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
202 if: aWidth > curX {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
203 availPixels <- aWidth - curX
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
204 skinny <- avail find: :val {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
205 (val width) <= availPixels
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
206 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
207 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
208
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
209 skinny value: :curGlyph {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
210 curX <- curX + (curGlyph width)
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
211 if: (curGlyph height) > minHeight {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
212 minHeight <- curGlyph height
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
213 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
214 avail <- avail filter: :glyph {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
215 (glyph charCode) != (curGlyph charCode)
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
216 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
217 } none: {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
218 curY <- curY + minHeight
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
219 minHeight <- 0
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
220 curX <- 0
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
221 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
222 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
223 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
224 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
225 glyphDict <- dict hash
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
226 foreach: glyphs :idx glyph {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
227 glyphDict set: (glyph charCode) glyph
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
228 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
229 option value: #{
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
230 texture <- drawTex
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
231 width <- aWidth
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
232 height <- aHeight
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
233 glyphs <- glyphDict
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
234 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
235 } none: {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
236 print: "Failed to create texture for atlas"
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
237 option none
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
238 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
239 } else: {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
240 print: "Font is too big for a 2048x2048 texture!"
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
241 option none
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
242 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
243 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
244
321
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
245 hex2 <- :num {
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
246 val <- hex: num
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
247 if: (val length) < 2 {
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
248 val <- "0" . val
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
249 }
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
250 val
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
251 }
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
252
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
253 main <- :args {
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
254 retcode <- 0
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
255 dpi <- 96
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
256 arg <- 1
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
257 expectVal <- false
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
258 optName <- ""
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
259 path <- ""
324
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
260 windowWidth <- 512
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
261 windowHeight <- 512
321
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
262 while: { arg < (args length) } do: {
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
263 curArg <- args get: arg
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
264 if: expectVal {
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
265 if: optName = "--dpi" || optName = "-d" {
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
266 dpi <- curArg int32
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
267 } else: {
324
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
268 if: optName = "--height" {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
269 windowHeight <- curArg int32
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
270 } else: {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
271 if: optName = "--width" {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
272 windowWidth <- curArg int32
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
273 } else: {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
274 print: "Unrecognized option: " . optName . "\n"
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
275 }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
276 }
321
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
277 }
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
278 expectVal <- false
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
279 } else: {
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
280 if: (curArg startsWith?: "-") {
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
281 expectVal <- true
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
282 optName <- curArg
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
283 } else: {
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
284 path <- curArg
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
285 }
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
286 }
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
287 arg <- arg + 1
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
288 }
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
289 ft <- freetype init
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
290 maybeFace <- ft faceFromPath: path index: 0
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
291 charCodes <- #[]
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
292 maybeFace value: :face {
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
293 charMap <- face charmap
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
294 foreach: charMap :char glyph {
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
295 print: "Char: " . char . ", glyph index: " . glyph . "\n"
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
296 charCodes append: char
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
297 }
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
298
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
299 if: (sdl init: (video or timer)) = 0 {
324
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
300 (sdl createWindow: "Freetype Test" pos: 0 0 size: windowWidth windowHeight flags: 0u32) value: :window {
321
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
301 (window createRenderer: -1 flags: ((window renderOpts) accelerated)) value: :renderer {
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
302 renderer drawColor!: (sdl r: 255u8 g: 255u8 b: 255u8)
324
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
303
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
304 (makeAtlas: renderer face 12.0 dpi (sdl r: 0u8 g: 0u8 b: 0u8)) value: :atlas {
321
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
305 continue? <- true
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
306 while: { continue? } do: {
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
307 renderer clear
324
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
308 y <- 0
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
309 x <- 0
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
310 while: { y < (atlas height) } do: {
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
311 copyWidth <- if: (atlas width) < windowWidth { atlas width } else: { windowWidth }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
312 copyHeight <- if: (atlas height) < windowHeight { atlas height } else: { windowHeight }
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
313 (atlas texture) copyRect: (sdl rect: 0 y size: copyWidth copyHeight) To: (sdl rect: x 0 size: copyWidth copyHeight)
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
314 y <- y + windowHeight
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
315 x <- x + copyWidth
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
316 }
321
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
317 renderer present
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
318 event <- option none
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
319 while: {
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
320 event <- sdl pollEvent
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
321 event value?
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
322 } do: {
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
323 event value: :ev {
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
324 if: (ev type) = quit {
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
325 continue? <- false
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
326 }
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
327 } none: {}
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
328 }
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
329 }
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
330 } none: {
324
615f23450f8f Freetype sample: Build texture of glyphs in a more intelligent way
Michael Pavone <pavone@retrodev.com>
parents: 321
diff changeset
331 retcode <- -1
321
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
332 }
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
333 } none: {
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
334 print: "Failed to create renderer\n"
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
335 retcode <- 1
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
336 }
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
337 window destroy
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
338 } none: {
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
339 print: "Failed to create window\n"
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
340 retcode <- 1
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
341 }
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
342 } else: {
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
343 print: "Failed to initialize SDL\n"
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
344 retcode <- 1
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
345 }
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
346 } none: {
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
347 retcode <- 1
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
348 print: "Failed to load font face from " . path . "\n"
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
349 }
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
350
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
351 ft destroy
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
352 retcode
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
353 }
3edd0169311a Add basic binding to Freetype2
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
354 }