Commit 95027911a2421a54fb78a70f677609d6b776dc40

Thomas de Grivel 2024-01-15T17:42:22

wip OpenGL 3.3

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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
diff --git a/libc3/window/sdl2/demo/flies.c b/libc3/window/sdl2/demo/flies.c
index d78d908..d79b9bf 100644
--- a/libc3/window/sdl2/demo/flies.c
+++ b/libc3/window/sdl2/demo/flies.c
@@ -164,7 +164,6 @@ bool flies_render (s_sequence *seq)
   s_map *map;
   s_gl_matrix_4f matrix;
   s_gl_matrix_4f matrix_1;
-  s_gl_matrix_4f matrix_2;
   uw r;
   uw random_bits = 0;
   f64 x;
@@ -209,7 +208,7 @@ bool flies_render (s_sequence *seq)
   gl_font_set_size(&g_font_flies, board_item_h,
                    (f64) window->gl_h / window->h);
   gl_text_update_1(&g_text_flies_in, a);
-  gl_text_render(&g_text_flies_in);
+  gl_ortho_text_render(&g_ortho, &g_text_flies_in);
   buf_init(&buf, false, sizeof(a), a);
   buf_write_1(&buf, "Out ");
   buf_inspect_uw(&buf, fly_out);
@@ -219,124 +218,123 @@ bool flies_render (s_sequence *seq)
     gl_matrix_4f_translate(&g_ortho.model_matrix, x, 0.0, 0.0);
     gl_ortho_update_model_matrix(&g_ortho);
     gl_text_update_1(&g_text_flies_out, a);
-    gl_text_render(&g_text_flies_out);
-    g_ortho.model_matrix = matrix;
-    gl_matrix_4f_translate(&g_ortho.model_matrix, 0.0, board_item_h, 0.0);
-    glBlendColor(0.6f, 0.7f, 0.9f, 1.0f);
-    gl_ortho_rect(&g_ortho, 0, 0, board_w, board_h);
-    address[1] = 0;
-    while (address[1] < BOARD_SIZE) {
-      y = board_item_h * address[1];
-      address[0] = 0;
-      while (address[0] < BOARD_SIZE) {
-        x = board_item_w * address[0];
-        matrix_1 = g_ortho.model_matrix; {
-          gl_matrix_4f_translate(&g_ortho.model_matrix, x,
-                                 board_h - board_item_h - y, 0.0);
-          board_item = (u8 *) array_data(board, address);
-          assert(board_item);
-          switch (*board_item) {
-          case BOARD_ITEM_SPACE:
-            break;
-          case BOARD_ITEM_BLOCK:
-            glBindTexture(GL_TEXTURE_2D, 0);
-            glBlendColor(0.0f, 0.0f, 1.0f, 1.0f);
-            gl_ortho_rect(&g_ortho, 0, 0, board_item_w + 1.0, board_item_h + 1.0);
+    gl_ortho_text_render(&g_ortho, &g_text_flies_out);
+  } g_ortho.model_matrix = matrix;
+  gl_matrix_4f_translate(&g_ortho.model_matrix, 0.0, board_item_h, 0.0);
+  glBlendColor(0.6f, 0.7f, 0.9f, 1.0f);
+  gl_ortho_rect(&g_ortho, 0, 0, board_w, board_h);
+  address[1] = 0;
+  while (address[1] < BOARD_SIZE) {
+    y = board_item_h * address[1];
+    address[0] = 0;
+    while (address[0] < BOARD_SIZE) {
+      x = board_item_w * address[0];
+      matrix = g_ortho.model_matrix; {
+        gl_matrix_4f_translate(&g_ortho.model_matrix, x,
+                               board_h - board_item_h - y, 0.0);
+        board_item = (u8 *) array_data(board, address);
+        assert(board_item);
+        switch (*board_item) {
+        case BOARD_ITEM_SPACE:
+          break;
+        case BOARD_ITEM_BLOCK:
+          glBindTexture(GL_TEXTURE_2D, 0);
+          glBlendColor(0.0f, 0.0f, 1.0f, 1.0f);
+          gl_ortho_rect(&g_ortho, 0, 0, board_item_w + 1.0, board_item_h + 1.0);
+          break;
+        case BOARD_ITEM_FLY:
+          matrix_1 = g_ortho.model_matrix; {
+            gl_matrix_4f_translate(&g_ortho.model_matrix,
+                                   -board_item_w / 2.0,
+                                   -board_item_h / 2.0, 0.0);
+            gl_matrix_4f_scale(&g_ortho.model_matrix, fly_scale,
+                               fly_scale, 1.0);
+            gl_ortho_update_model_matrix(&g_ortho);
+            gl_sprite_render(&g_sprite_fly, 0);
+          } g_ortho.model_matrix = matrix_1;
+          if (address[0] == BOARD_SIZE / 2 &&
+              address[1] == BOARD_SIZE - 1) {
+            array_data_set(board, address, &g_board_item_space);
+            (*fly_out)++;
+            fly_init(map);
             break;
-          case BOARD_ITEM_FLY:
-            matrix_2 = g_ortho.model_matrix; {
-              gl_matrix_4f_translate(&g_ortho.model_matrix,
-                                     -board_item_w / 2.0,
-                                     -board_item_h / 2.0, 0.0);
-              gl_matrix_4f_scale(&g_ortho.model_matrix, fly_scale,
-                                 fly_scale, 1.0);
-              gl_ortho_update_model_matrix(&g_ortho);
-              gl_sprite_render(&g_sprite_fly, 0);
-            } g_ortho.model_matrix = matrix_2;
-            if (address[0] == BOARD_SIZE / 2 &&
-                address[1] == BOARD_SIZE - 1) {
-              array_data_set(board, address, &g_board_item_space);
-              (*fly_out)++;
-              fly_init(map);
-              break;
+          }
+          fly_address[0] = address[0];
+          fly_address[1] = address[1];
+          i = 0;
+          while (i < 3) {
+            j = 0;
+            while (j < 9) {
+              directions[j] = true;
+              j++;
             }
-            fly_address[0] = address[0];
-            fly_address[1] = address[1];
-            i = 0;
-            while (i < 3) {
-              j = 0;
-              while (j < 9) {
-                directions[j] = true;
-                j++;
+            while (directions[0] | directions[1] | directions[2] |
+                   directions[3] | directions[4] | directions[5] |
+                   directions[6] | directions[7] | directions[8]) {
+              if (random_bits < 4) {
+                r = arc4random();
+                random_bits = 32;
               }
-              while (directions[0] | directions[1] | directions[2] |
-                     directions[3] | directions[4] | directions[5] |
-                     directions[6] | directions[7] | directions[8]) {
-                if (random_bits < 4) {
-                  r = arc4random();
-                  random_bits = 32;
-                }
-                direction = r % 16;
-                r >>= 4;
-                random_bits -= 4;
-                if (direction >= 12)
-                  direction = direction_prev;
-                if (direction >= 9)
-                  direction = (direction - 6) % 3 + 6;
-                fly_prev_address[0] = fly_address[0];
-                fly_prev_address[1] = fly_address[1];
-                switch (direction) {
-                case 0: fly_address[0]--; fly_address[1]--; break;
-                case 1:                   fly_address[1]--; break;
-                case 2: fly_address[0]++; fly_address[1]--; break;
-                case 3: fly_address[0]--;                 ; break;
-                case 4:                                   ; break;
-                case 5: fly_address[0]++;                 ; break;
-                case 6: fly_address[0]--; fly_address[1]++; break;
-                case 7:                   fly_address[1]++; break;
-                case 8: fly_address[0]++; fly_address[1]++; break;
-                }
-                if (fly_address[0] < BOARD_SIZE &&
-                    fly_address[1] < BOARD_SIZE &&
-                    (board_item = (u8 *) array_data(board,
-                                                    fly_address)) &&
-                    *board_item == g_board_item_space) {
-                  array_data_set(board, fly_prev_address,
-                                 &g_board_item_space);
-                  array_data_set(board, fly_address, &g_board_item_fly);
-                  direction_prev = direction;
-                  break;
-                }
-                directions[direction] = false;
-                fly_address[0] = fly_prev_address[0];
-                fly_address[1] = fly_prev_address[1];
+              direction = r % 16;
+              r >>= 4;
+              random_bits -= 4;
+              if (direction >= 12)
+                direction = direction_prev;
+              if (direction >= 9)
+                direction = (direction - 6) % 3 + 6;
+              fly_prev_address[0] = fly_address[0];
+              fly_prev_address[1] = fly_address[1];
+              switch (direction) {
+              case 0: fly_address[0]--; fly_address[1]--; break;
+              case 1:                   fly_address[1]--; break;
+              case 2: fly_address[0]++; fly_address[1]--; break;
+              case 3: fly_address[0]--;                 ; break;
+              case 4:                                   ; break;
+              case 5: fly_address[0]++;                 ; break;
+              case 6: fly_address[0]--; fly_address[1]++; break;
+              case 7:                   fly_address[1]++; break;
+              case 8: fly_address[0]++; fly_address[1]++; break;
               }
-              i++;
-            }
-            *fly_time += 1;
-            if (*fly_time > FLY_TIME_MAX) {
-              array_data_set(board, fly_address, &g_board_item_dead_fly);
-              fly_init(map);
+              if (fly_address[0] < BOARD_SIZE &&
+                  fly_address[1] < BOARD_SIZE &&
+                  (board_item = (u8 *) array_data(board,
+                                                  fly_address)) &&
+                  *board_item == g_board_item_space) {
+                array_data_set(board, fly_prev_address,
+                               &g_board_item_space);
+                array_data_set(board, fly_address, &g_board_item_fly);
+                direction_prev = direction;
+                break;
+              }
+              directions[direction] = false;
+              fly_address[0] = fly_prev_address[0];
+              fly_address[1] = fly_prev_address[1];
             }
-            break;
-          case BOARD_ITEM_DEAD_FLY:
-            matrix_2 = g_ortho.model_matrix; {
-              gl_matrix_4f_translate(&g_ortho.model_matrix,
-                                     -board_item_w / 2.0,
-                                     -board_item_h / 2.0, 0.0);
-              gl_matrix_4f_scale(&g_ortho.model_matrix, dead_fly_scale,
-                                 dead_fly_scale, 1.0);
-              gl_ortho_update_model_matrix(&g_ortho);
-              gl_sprite_render(&g_sprite_dead_fly, 0);
-            } g_ortho.model_matrix = matrix_2;
-            break;
+            i++;
           }
-        } g_ortho.model_matrix = matrix_1;;
-        address[0]++;
-      }
-      address[1]++;
+          *fly_time += 1;
+          if (*fly_time > FLY_TIME_MAX) {
+            array_data_set(board, fly_address, &g_board_item_dead_fly);
+            fly_init(map);
+          }
+          break;
+        case BOARD_ITEM_DEAD_FLY:
+          matrix_1 = g_ortho.model_matrix; {
+            gl_matrix_4f_translate(&g_ortho.model_matrix,
+                                   -board_item_w / 2.0,
+                                   -board_item_h / 2.0, 0.0);
+            gl_matrix_4f_scale(&g_ortho.model_matrix, dead_fly_scale,
+                               dead_fly_scale, 1.0);
+            gl_ortho_update_model_matrix(&g_ortho);
+            gl_sprite_render(&g_sprite_dead_fly, 0);
+          } g_ortho.model_matrix = matrix_1;
+          break;
+        }
+      } g_ortho.model_matrix = matrix;
+      address[0]++;
     }
-  } g_ortho.model_matrix = matrix;
+    address[1]++;
+  }
   return true;
 }
 
diff --git a/libc3/window/sdl2/demo/window_sdl2_demo.c b/libc3/window/sdl2/demo/window_sdl2_demo.c
index d0a5a03..5934648 100644
--- a/libc3/window/sdl2/demo/window_sdl2_demo.c
+++ b/libc3/window/sdl2/demo/window_sdl2_demo.c
@@ -202,7 +202,6 @@ bool window_sdl2_demo_load (s_window_sdl2 *window)
   return true;
 }
 
-/*
 static void render_text (s_gl_text *text, f64 x, f64 y)
 {
   assert(glGetError() == GL_NO_ERROR);
@@ -217,39 +216,39 @@ static void render_text (s_gl_text *text, f64 x, f64 y)
   gl_ortho_update_model_matrix(&g_ortho);
   glBlendColor(1.0f, 1.0f, 1.0f, 1.0f);
   assert(glGetError() == GL_NO_ERROR);
-  gl_text_render(text);
+  gl_ortho_text_render(&g_ortho, text);
   assert(glGetError() == GL_NO_ERROR);
   gl_matrix_4f_translate(&g_ortho.model_matrix, 1.0, 0.0, 0.0);
   gl_ortho_update_model_matrix(&g_ortho);
-  gl_text_render(text);
+  gl_ortho_text_render(&g_ortho, text);
   gl_matrix_4f_translate(&g_ortho.model_matrix, 1.0, 0.0, 0.0);
   gl_ortho_update_model_matrix(&g_ortho);
-  gl_text_render(text);
+  gl_ortho_text_render(&g_ortho, text);
   gl_matrix_4f_translate(&g_ortho.model_matrix, 0.0, 1.0, 0.0);
   gl_ortho_update_model_matrix(&g_ortho);
-  gl_text_render(text);
+  gl_ortho_text_render(&g_ortho, text);
   gl_matrix_4f_translate(&g_ortho.model_matrix, -1.0, 0.0, 0.0);
   gl_ortho_update_model_matrix(&g_ortho);
-  gl_text_render(text);
+  gl_ortho_text_render(&g_ortho, text);
   gl_matrix_4f_translate(&g_ortho.model_matrix, -1.0, 0.0, 0.0);
   gl_ortho_update_model_matrix(&g_ortho);
-  gl_text_render(text);
+  gl_ortho_text_render(&g_ortho, text);
   gl_matrix_4f_translate(&g_ortho.model_matrix, 0.0, 1.0, 0.0);
   gl_ortho_update_model_matrix(&g_ortho);
-  gl_text_render(text);
+  gl_ortho_text_render(&g_ortho, text);
   gl_matrix_4f_translate(&g_ortho.model_matrix, 1.0, 0.0, 0.0);
   gl_ortho_update_model_matrix(&g_ortho);
-  gl_text_render(text);
+  gl_ortho_text_render(&g_ortho, text);
   gl_matrix_4f_translate(&g_ortho.model_matrix, 1.0, 0.0, 0.0);
   gl_ortho_update_model_matrix(&g_ortho);
-  gl_text_render(text);
+  gl_ortho_text_render(&g_ortho, text);
   glBlendColor(0.0f, 0.0f, 0.0f, 1.0f);
   gl_matrix_4f_translate(&g_ortho.model_matrix, -1.0, -1.0, 0.0);
   gl_ortho_update_model_matrix(&g_ortho);
-  gl_text_render(text);
+  gl_ortho_text_render(&g_ortho, text);
   assert(glGetError() == GL_NO_ERROR);
 }
-*/
+
 bool window_sdl2_demo_render (s_window_sdl2 *window)
 {
   s_sequence *seq;
@@ -274,56 +273,30 @@ bool window_sdl2_demo_render (s_window_sdl2 *window)
   glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
                       GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
   assert(glGetError() == GL_NO_ERROR);
-  /*
   gl_font_set_size(&g_font_courier_new, 20,
                    (f64) window->gl_h / window->h);
   gl_text_update_1(&g_text_seq_title, seq->title);
   render_text(&g_text_seq_title, 20.0f, 30.0f);
-  */
   /* progress bar */
-  /*
+  gl_matrix_4f_init_identity(&g_ortho.model_matrix);
   glDisable(GL_BLEND);
   assert(glGetError() == GL_NO_ERROR);
-  assert(glGetError() == GL_NO_ERROR);
-  glBindTexture(GL_TEXTURE_2D, 0);
+  gl_ortho_bind_texture(&g_ortho, 0);
   assert(glGetError() == GL_NO_ERROR);
   glBlendColor(1.0f, 1.0f, 1.0f, 1.0f);
-  gl_matrix_4f_init_identity(&g_ortho.model_matrix);
-  gl_matrix_4f_translate(&g_ortho.model_matrix, 19.0, 11.0, 0);
-  gl_matrix_4f_scale(&g_ortho.model_matrix,
-                     (window->w - 40.0) * seq->t / seq->duration + 2.0,
-                     4.0, 0);
-  gl_ortho_update_model_matrix(&g_ortho);
-  gl_square_render(&g_square);
-  */
-  /*
-    glRectd(19, 11,
-    19 + (window->w - 40.0) * seq->t / seq->duration + 2,
-    11 + 4);
-  */
-  /*
+  gl_ortho_rect(&g_ortho, 19, 11,
+                (window->w - 40.0) * seq->t / seq->duration + 2,
+                4);
   glBlendColor(0.0f, 0.0f, 0.0f, 1.0f);
-  gl_matrix_4f_init_identity(&g_ortho.model_matrix);
-  gl_matrix_4f_translate(&g_ortho.model_matrix, 20.0, 12.0, 0);
-  gl_matrix_4f_scale(&g_ortho.model_matrix,
-                     (window->w - 40.0) * seq->t / seq->duration,
-                     2.0, 0);
-  gl_ortho_update_model_matrix(&g_ortho);
-  gl_square_render(&g_square);
-  */
-  /*
-    glRectd(20, 12,
-    20 + (window->w - 40.0) * seq->t / seq->duration,
-    12 + 2);
-  */
+  gl_ortho_rect(&g_ortho, 20, 12,
+                (window->w - 40.0) * seq->t / seq->duration,
+                2);
   /* fps */
-  /*
   char fps[32];
   snprintf(fps, sizeof(fps), "%.1f", (f64) seq->frame / seq->t);
   gl_text_update_1(&g_text_fps, fps);
   glEnable(GL_BLEND);
   render_text(&g_text_fps, 20, window->h - 30);
-  */
   gl_ortho_render_end(&g_ortho);
   return true;
 }
diff --git a/libc3/window/sdl2/gl_ortho.c b/libc3/window/sdl2/gl_ortho.c
index db7aad7..ac5e2a7 100644
--- a/libc3/window/sdl2/gl_ortho.c
+++ b/libc3/window/sdl2/gl_ortho.c
@@ -13,8 +13,9 @@
 #include <math.h>
 #include <libc3/c3.h>
 #include "gl_deprecated.h"
-#include "gl_ortho.h"
 #include "gl_matrix_4f.h"
+#include "gl_ortho.h"
+#include "gl_square.h"
 
 static const char * g_gl_ortho_vertex_shader_src =
   "#version 330 core\n"
@@ -51,10 +52,26 @@ static const char * g_gl_ortho_fragment_shader_src =
   "    FragColor = vec4(1, 1, 1, 1);\n"
   "}\n";
 
+void gl_ortho_bind_texture (s_gl_ortho *ortho, GLuint texture)
+{
+  assert(ortho);
+  assert(glGetError() == GL_NO_ERROR);
+  if (! texture) {
+    glUniform1i(ortho->gl_enable_texture_loc, 0);
+    assert(glGetError() == GL_NO_ERROR);
+    return;
+  }
+  glUniform1i(ortho->gl_enable_texture_loc, 1);
+  assert(glGetError() == GL_NO_ERROR);
+  glUniform1i(ortho->gl_texture_loc, texture);  
+  assert(glGetError() == GL_NO_ERROR);
+}
+
 void gl_ortho_clean (s_gl_ortho *ortho)
 {
   assert(ortho);
   glDeleteProgram(ortho->gl_shader_program);
+  gl_square_clean(&ortho->square);
 }
 
 void gl_ortho_delete (s_gl_ortho *ortho)
@@ -69,6 +86,8 @@ s_gl_ortho * gl_ortho_init (s_gl_ortho *ortho)
   GLint success;
   GLuint vertex_shader;
   assert(ortho);
+  if (! gl_square_init(&ortho->square, 2, 2))
+    return NULL;
   gl_matrix_4f_init_identity(&ortho->projection_matrix);
   gl_matrix_4f_ortho(&ortho->projection_matrix, -1, 1, -1, 1, 0, 1);
   ortho->position.x = 0.0f;
@@ -149,6 +168,21 @@ s_gl_ortho * gl_ortho_new (void)
   return ortho;
 }
 
+void gl_ortho_rect (s_gl_ortho *ortho, f32 x, f32 y, f32 w, f32 h)
+{
+  s_gl_matrix_4f matrix;
+  assert(ortho);
+  assert(glGetError() == GL_NO_ERROR);
+  matrix = ortho->model_matrix;
+  gl_matrix_4f_translate(&ortho->model_matrix, x, y, 0.0f);
+  gl_matrix_4f_scale(&ortho->model_matrix, w, h, 1.0f);
+  gl_ortho_update_model_matrix(ortho);
+  assert(glGetError() == GL_NO_ERROR);
+  gl_square_render(&ortho->square);
+  assert(glGetError() == GL_NO_ERROR);
+  ortho->model_matrix = matrix;
+}
+
 void gl_ortho_render (s_gl_ortho *ortho)
 {
   GLenum error;
@@ -203,6 +237,15 @@ void gl_ortho_resize (s_gl_ortho *ortho, f32 x1, f32 x2, f32 y1, f32 y2,
                      clip_z_near, clip_z_far);
 }
 
+void gl_ortho_text_render (s_gl_ortho *ortho, const s_gl_text *text)
+{
+  assert(ortho);
+  assert(text);
+  gl_ortho_bind_texture(ortho, text->texture);
+  gl_ortho_rect(ortho, 0, 0, text->w, text->h);
+  gl_ortho_bind_texture(ortho, 0);
+}
+
 void gl_ortho_update_model_matrix (s_gl_ortho *ortho)
 {
   assert(ortho);
diff --git a/libc3/window/sdl2/gl_ortho.h b/libc3/window/sdl2/gl_ortho.h
index a9f6fc5..8e06d15 100644
--- a/libc3/window/sdl2/gl_ortho.h
+++ b/libc3/window/sdl2/gl_ortho.h
@@ -25,10 +25,15 @@ void         gl_ortho_delete (s_gl_ortho *ortho);
 s_gl_ortho * gl_ortho_new (void);
 
 /* Operators. */
+void         gl_ortho_bind_texture (s_gl_ortho *ortho, GLuint texture);
+void         gl_ortho_rect (s_gl_ortho *ortho, f32 x1, f32 x2, f32 y1,
+                            f32 y2);
 void         gl_ortho_render (s_gl_ortho *ortho);
 void         gl_ortho_render_end (s_gl_ortho *ortho);
 void         gl_ortho_resize (s_gl_ortho *ortho, f32 x1, f32 x2, f32 y1,
                               f32 y2, f32 clip_z_near, f32 clip_z_far);
+void         gl_ortho_text_render (s_gl_ortho *ortho,
+                                   const s_gl_text *text);
 void         gl_ortho_update_model_matrix (s_gl_ortho *ortho);
 void         gl_ortho_update_view_matrix (s_gl_ortho *ortho);
 
diff --git a/libc3/window/sdl2/gl_square.c b/libc3/window/sdl2/gl_square.c
index f56f6b2..8be5864 100644
--- a/libc3/window/sdl2/gl_square.c
+++ b/libc3/window/sdl2/gl_square.c
@@ -82,7 +82,7 @@ s_gl_square * gl_square_init (s_gl_square *square, uw seg_u, uw seg_v)
     }
     i++;
   }
-  gl_object_update(&square->object);
+  gl_object_update(&tmp.object);
   *square = tmp;
   return square;
 }
diff --git a/libc3/window/sdl2/gl_text.h b/libc3/window/sdl2/gl_text.h
index af0f262..26b74cb 100644
--- a/libc3/window/sdl2/gl_text.h
+++ b/libc3/window/sdl2/gl_text.h
@@ -34,7 +34,4 @@ bool gl_text_update (s_gl_text *text);
 bool gl_text_update_1 (s_gl_text *text, const char *p);
 bool gl_text_update_buf (s_gl_text *text, s_buf *buf);
 
-/* Observers. */
-void gl_text_render (const s_gl_text *text);
-
 #endif /* GL_TEXT_H */
diff --git a/libc3/window/sdl2/types.h b/libc3/window/sdl2/types.h
index 520cecd..918be94 100644
--- a/libc3/window/sdl2/types.h
+++ b/libc3/window/sdl2/types.h
@@ -83,6 +83,7 @@ typedef bool (*f_window_sdl2_sequence_render) (s_sequence *seq,
 typedef void (*f_window_sdl2_unload) (s_window_sdl2 *window);
 
 /* 1 */
+
 struct gl_font {
   FT_Face ft_face;
   f32 point_size;
@@ -247,6 +248,7 @@ struct window_sdl2 {
 };
 
 /* 2 */
+
 struct gl_camera {
   f32 aspect_ratio;
   f32 clip_z_far;
@@ -265,29 +267,6 @@ struct gl_cylinder {
   uw segments_v;
 };
 
-struct gl_ortho {
-  f32 x1;
-  f32 x2;
-  f32 y1;
-  f32 y2;
-  f32 clip_z_near;
-  f32 clip_z_far;
-  s_gl_point_3f position;
-  s_gl_point_3f rotation;
-  s_gl_point_3f scale;
-  s_gl_matrix_4f projection_matrix;
-  u32         gl_projection_matrix_loc;
-  s_gl_matrix_4f view_matrix;
-  u32         gl_view_matrix_loc;
-  s_gl_matrix_4f model_matrix;
-  u32         gl_model_matrix_loc;
-  u32 gl_color_loc;
-  u32 gl_enable_texture_loc;
-  u32 gl_texture_loc;
-  u32 gl_shader_program;
-  s_gl_square square;
-};
-
 struct gl_sphere {
   s_gl_object object;
   uw segments_u;
@@ -340,4 +319,29 @@ struct sdl2_sprite {
   GLuint *texture;
 };
 
+/* 3 */
+
+struct gl_ortho {
+  f32 x1;
+  f32 x2;
+  f32 y1;
+  f32 y2;
+  f32 clip_z_near;
+  f32 clip_z_far;
+  s_gl_point_3f position;
+  s_gl_point_3f rotation;
+  s_gl_point_3f scale;
+  s_gl_matrix_4f projection_matrix;
+  u32         gl_projection_matrix_loc;
+  s_gl_matrix_4f view_matrix;
+  u32         gl_view_matrix_loc;
+  s_gl_matrix_4f model_matrix;
+  u32         gl_model_matrix_loc;
+  u32 gl_color_loc;
+  u32 gl_enable_texture_loc;
+  u32 gl_texture_loc;
+  u32 gl_shader_program;
+  s_gl_square square;
+};
+
 #endif /* LIBC3_WINDOW_SDL2_TYPES_H */