Mercurial > public > algo-animator
annotate main.c @ 14:d055228ca9a6
printing text with custom font
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Sun, 25 Jun 2023 15:51:39 +0100 |
parents | 074bde2db09a |
children | e2fcfcb43fee |
rev | line source |
---|---|
8 | 1 #include <stdio.h> |
9 | 2 #include <stdlib.h> |
7 | 3 #include <GL/glut.h> |
9 | 4 #include <math.h> |
10 | 5 #include <time.h> |
12 | 6 #include <stdbool.h> |
13
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
7 #include <ft2build.h> |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
8 #include FT_FREETYPE_H |
0 | 9 |
10 | |
6
40a8bdbe2005
Refactor to array of structures
Dennis C. M. <dennis@denniscm.com>
parents:
5
diff
changeset
|
11 #define WINDOW_HEIGHT 1080 |
40a8bdbe2005
Refactor to array of structures
Dennis C. M. <dennis@denniscm.com>
parents:
5
diff
changeset
|
12 #define WINDOW_WIDTH 1920 |
10 | 13 #define OFFSET 150 |
7 | 14 #define RECT_WIDTH 5 |
10 | 15 #define SPACE 1 |
7 | 16 |
17 | |
13
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
18 /* Global variables */ |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
19 |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
20 FT_Library ft_library; |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
21 FT_Face ft_face; |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
22 |
12 | 23 char algos[4][50] = { |
24 "Bubble sort", | |
25 "Selection sort", | |
26 "Insertion sort", | |
27 "Quick sort" | |
28 }; | |
29 | |
9 | 30 int selected_algo = 0; |
12 | 31 int refresh_counter = 0; |
32 int iter_counter = 0; | |
33 int arr_size; | |
9 | 34 |
10 | 35 int* arr; |
12 | 36 |
37 bool run; | |
0 | 38 |
39 | |
13
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
40 /* Algorithms */ |
12 | 41 |
13
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
42 // Bubble sort |
12 | 43 struct BubbleSortInfo { |
44 int step; | |
45 int i; | |
46 }; | |
47 | |
14
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
48 struct BubbleSortInfo bs = {1, 0}; |
12 | 49 |
9 | 50 void bubble_sort() { |
12 | 51 if (bs.i < arr_size - bs.step - 1) { |
52 int current = arr[bs.i]; | |
53 int next = arr[bs.i + 1]; | |
9 | 54 |
11 | 55 if (current > next) { |
12 | 56 arr[bs.i + 1] = current; |
57 arr[bs.i] = next; | |
11 | 58 } |
9 | 59 |
12 | 60 bs.i++; |
11 | 61 } else { |
12 | 62 bs.step++; |
63 bs.i = 0; | |
9 | 64 } |
65 } | |
66 | |
67 | |
13
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
68 /* Helper functions */ |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
69 |
10 | 70 void create_array() { |
71 arr_size = floor((WINDOW_WIDTH - RECT_WIDTH) / (RECT_WIDTH + SPACE)) + 1; | |
72 arr = (int*)malloc(arr_size * sizeof(int)); | |
73 | |
12 | 74 srand(time(NULL)); |
10 | 75 |
76 int min = OFFSET; | |
77 int max = WINDOW_HEIGHT - OFFSET; | |
78 | |
79 for (int i = 0; i < arr_size; i++) { | |
80 arr[i] = rand() % ((max - min) + 1) + min; | |
81 } | |
82 } | |
83 | |
84 | |
12 | 85 bool array_sorted() { |
86 for (int i = 0; i < arr_size - 1; i++) { | |
87 if (arr[i] > arr[i + 1]) { | |
88 return false; | |
89 } | |
10 | 90 } |
12 | 91 |
92 return true; | |
9 | 93 } |
94 | |
95 | |
96 void algo_selector(int direction) { | |
97 int selection = selected_algo + direction; | |
98 int lower = 0; | |
99 int upper = (sizeof(algos) / sizeof(algos[0])) - 1; | |
100 | |
101 if (selection >= lower && selection <= upper) { | |
102 selected_algo = selection; | |
103 } | |
104 } | |
105 | |
2
ea3c427d922d
draw a weird filled rectangle
Dennis C. M. <dennis@denniscm.com>
parents:
0
diff
changeset
|
106 |
13
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
107 /* Render functions */ |
8 | 108 |
109 void render_text(int x, int y, char* text) { | |
110 | |
13
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
111 // Get glyph index from character code |
14
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
112 FT_UInt glyph_index = FT_Get_Char_Index(ft_face, 'A'); |
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
113 |
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
114 if (glyph_index == 0) { |
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
115 fprintf(stderr, "Given character code has no glyph image in the face\n"); |
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
116 exit(1); |
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
117 } |
13
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
118 |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
119 // Load glyph image |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
120 if (FT_Load_Glyph(ft_face, glyph_index, FT_LOAD_DEFAULT)) { |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
121 fprintf(stderr, "Failed to load glyph.\n"); |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
122 exit(1); |
8 | 123 } |
13
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
124 |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
125 // Render glyph |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
126 if (FT_Render_Glyph(ft_face->glyph, FT_RENDER_MODE_NORMAL)) { |
14
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
127 fprintf(stderr, "Failed to render glyph.\n"); |
13
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
128 exit(1); |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
129 } |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
130 |
14
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
131 FT_GlyphSlot slot = ft_face->glyph; |
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
132 FT_Bitmap* glyph_bitmap = &slot->bitmap; |
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
133 |
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
134 glRasterPos2f(x, y); |
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
135 glDrawPixels( |
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
136 glyph_bitmap->width, |
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
137 glyph_bitmap->rows, |
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
138 GL_LUMINANCE, |
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
139 GL_UNSIGNED_BYTE, |
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
140 glyph_bitmap->buffer |
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
141 ); |
0 | 142 } |
143 | |
144 | |
145 void display() { | |
146 glClear(GL_COLOR_BUFFER_BIT); | |
14
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
147 |
3
e4003f606e07
draw multiple rectangles with loop
Dennis C. M. <dennis@denniscm.com>
parents:
2
diff
changeset
|
148 glBegin(GL_QUADS); |
e4003f606e07
draw multiple rectangles with loop
Dennis C. M. <dennis@denniscm.com>
parents:
2
diff
changeset
|
149 |
10 | 150 int x = 0; |
151 for (int i = 0; i < arr_size; i++) { | |
152 | |
153 // Bottom left | |
154 glVertex2f(x, OFFSET); | |
155 | |
156 // Top left | |
157 glVertex2f(x, arr[i]); | |
158 | |
159 // Top right | |
160 glVertex2f(x + RECT_WIDTH, arr[i]); | |
161 | |
162 // Bottom right | |
163 glVertex2f(x + RECT_WIDTH, OFFSET); | |
164 | |
165 x += RECT_WIDTH + SPACE; | |
3
e4003f606e07
draw multiple rectangles with loop
Dennis C. M. <dennis@denniscm.com>
parents:
2
diff
changeset
|
166 } |
e4003f606e07
draw multiple rectangles with loop
Dennis C. M. <dennis@denniscm.com>
parents:
2
diff
changeset
|
167 |
e4003f606e07
draw multiple rectangles with loop
Dennis C. M. <dennis@denniscm.com>
parents:
2
diff
changeset
|
168 glEnd(); |
6
40a8bdbe2005
Refactor to array of structures
Dennis C. M. <dennis@denniscm.com>
parents:
5
diff
changeset
|
169 |
7 | 170 // Render text |
4
035d3880da04
render text with number of elements on screen
Dennis C. M. <dennis@denniscm.com>
parents:
3
diff
changeset
|
171 char text[256]; |
9 | 172 |
173 sprintf(text, "Algorithm: %s", algos[selected_algo]); | |
13
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
174 render_text(20, WINDOW_HEIGHT - 50, text); |
8 | 175 |
10 | 176 sprintf(text, "Number of elements: %i", arr_size); |
13
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
177 render_text(20, WINDOW_HEIGHT - 75, text); |
9 | 178 |
12 | 179 sprintf(text, "Iterations: %i", iter_counter); |
13
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
180 render_text(20, WINDOW_HEIGHT - 100, text); |
12 | 181 |
13
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
182 render_text(20, OFFSET - 50, "Press 'a' or 's' to select an algorithm"); |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
183 render_text(20, OFFSET - 75, "Press 'enter' to run the algorithm"); |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
184 render_text(20, OFFSET - 100, "Press 'r' to reset array"); |
8 | 185 |
186 glutSwapBuffers(); | |
187 } | |
188 | |
6
40a8bdbe2005
Refactor to array of structures
Dennis C. M. <dennis@denniscm.com>
parents:
5
diff
changeset
|
189 |
13
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
190 /* Refresh function */ |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
191 |
12 | 192 void idle() { |
193 if (run) { | |
194 bubble_sort(); | |
195 refresh_counter++; | |
196 iter_counter++; | |
197 | |
198 if (refresh_counter == 90) { | |
199 glutPostRedisplay(); | |
200 refresh_counter = 0; | |
201 } | |
202 | |
203 } else { | |
204 glutPostRedisplay(); | |
205 } | |
206 | |
207 if (array_sorted()) { | |
208 run = false; | |
209 } | |
8 | 210 } |
211 | |
212 | |
13
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
213 /* User input handler */ |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
214 |
8 | 215 void keyboard(unsigned char key, int x, int y) { |
216 | |
10 | 217 // s |
9 | 218 if (key == 115) { |
219 algo_selector(1); | |
220 } | |
221 | |
10 | 222 // a |
9 | 223 if (key == 97) { |
224 algo_selector(-1); | |
225 } | |
226 | |
12 | 227 // r |
228 if (key == 114) { | |
229 create_array(); | |
230 iter_counter = 0; | |
231 refresh_counter = 0; | |
232 run = false; | |
233 bs = (struct BubbleSortInfo){0, 0}; | |
234 } | |
235 | |
10 | 236 // enter |
8 | 237 if (key == 13) { |
12 | 238 run = true; |
7 | 239 } |
0 | 240 } |
241 | |
242 | |
13
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
243 /* Set up functions */ |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
244 |
14
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
245 void setup_gl() { |
13
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
246 |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
247 // Set background dark |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
248 glClearColor(0.0, 0.0, 0.0, 1.0); |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
249 |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
250 // Set point color and size to 1 pixel |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
251 glColor3f(1.0, 0.7569, 0.0); |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
252 glPointSize(5.0); |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
253 |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
254 // Matrix projection and reset with identity |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
255 glMatrixMode(GL_PROJECTION); |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
256 glLoadIdentity(); |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
257 |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
258 /* |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
259 * Creates projection matrix |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
260 * x increases from left to right (0 to WINDOW_WIDTH) |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
261 * y increases from bottom to top (0 to WINDOW_HEIGHT) |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
262 */ |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
263 gluOrtho2D(0, WINDOW_WIDTH, 0, WINDOW_HEIGHT); |
14
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
264 |
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
265 /* |
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
266 * This fucking line... I spent a day rendering random symbols |
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
267 * because the padding that adds FreeType to each row of the bitmap |
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
268 * does not match the padding expected by GL. |
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
269 */ |
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
270 |
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
271 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
13
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
272 } |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
273 |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
274 |
14
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
275 void setup_freetype() { |
13
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
276 |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
277 // Init library |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
278 if (FT_Init_FreeType(&ft_library)) { |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
279 fprintf(stderr, "Failed to initialize FreeType library\n"); |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
280 exit(1); |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
281 } |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
282 |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
283 // Load font |
14
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
284 if (FT_New_Face(ft_library, "fonts/JetBrainsMono-Regular.ttf", 0, &ft_face)) { |
13
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
285 fprintf(stderr, "Failed to load font\n"); |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
286 exit(1); |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
287 } |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
288 |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
289 // Set font size |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
290 if (FT_Set_Pixel_Sizes(ft_face, 0, 24)) { |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
291 fprintf(stderr, "Failed to set font size.\n"); |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
292 FT_Done_Face(ft_face); |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
293 FT_Done_FreeType(ft_library); |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
294 |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
295 exit(1); |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
296 } |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
297 } |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
298 |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
299 |
0 | 300 int main(int argc, char** argv) { |
10 | 301 create_array(); |
7 | 302 |
0 | 303 glutInit(&argc, argv); |
8 | 304 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); |
6
40a8bdbe2005
Refactor to array of structures
Dennis C. M. <dennis@denniscm.com>
parents:
5
diff
changeset
|
305 glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT); |
13
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
306 glutCreateWindow("Algorithm animator"); |
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
307 |
14
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
308 setup_gl(); |
d055228ca9a6
printing text with custom font
Dennis C. M. <dennis@denniscm.com>
parents:
13
diff
changeset
|
309 setup_freetype(); |
13
074bde2db09a
printing text with custom font but incorrect letters
Dennis C. M. <dennis@denniscm.com>
parents:
12
diff
changeset
|
310 |
0 | 311 glutDisplayFunc(display); |
8 | 312 glutKeyboardFunc(keyboard); |
12 | 313 glutIdleFunc(idle); |
0 | 314 glutMainLoop(); |
315 | |
10 | 316 free(arr); |
7 | 317 |
0 | 318 return 0; |
319 } |