Commit 5f235a885a96ba31acfa57d6e4dd44c7048f53db

Thomas de Grivel 2024-01-16T21:09:36

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
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
diff --git a/libc3/window/sdl2/demo/earth.c b/libc3/window/sdl2/demo/earth.c
index d665427..6c93c53 100644
--- a/libc3/window/sdl2/demo/earth.c
+++ b/libc3/window/sdl2/demo/earth.c
@@ -117,7 +117,8 @@ bool earth_render (s_sequence *seq)
     assert(glGetError() == GL_NO_ERROR);
     //glEnable(GL_TEXTURE_2D);
     assert(glGetError() == GL_NO_ERROR);
-    gl_sprite_bind(&g_sprite_earth, 0);
+    gl_camera_bind_texture(camera,
+                           gl_sprite_texture(&g_sprite_earth, 0));
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
                     GL_LINEAR_MIPMAP_LINEAR);
     assert(glGetError() == GL_NO_ERROR);
diff --git a/libc3/window/sdl2/demo/flies.c b/libc3/window/sdl2/demo/flies.c
index d79b9bf..99ae8d5 100644
--- a/libc3/window/sdl2/demo/flies.c
+++ b/libc3/window/sdl2/demo/flies.c
@@ -164,6 +164,7 @@ 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;
@@ -193,8 +194,8 @@ bool flies_render (s_sequence *seq)
   board_w = board_item_w * BOARD_SIZE;
   board_h = board_item_h * BOARD_SIZE;
   board_x = (window->w - board_w) / 2.0;
-  fly_scale = 2.0 * board_item_w / g_sprite_fly.w;
-  dead_fly_scale = 2.0 * board_item_w / g_sprite_dead_fly.w;
+  fly_scale = 2.0 * board_item_w / g_sprite_fly.pt_w;
+  dead_fly_scale = 2.0 * board_item_w / g_sprite_dead_fly.pt_w;
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
                   GL_LINEAR_MIPMAP_LINEAR);
   gl_matrix_4f_init_identity(&g_ortho.model_matrix);
@@ -205,136 +206,144 @@ bool flies_render (s_sequence *seq)
   buf_write_1(&buf, "In ");
   buf_inspect_uw(&buf, fly_in);
   buf_write_u8(&buf, 0);
-  gl_font_set_size(&g_font_flies, board_item_h,
-                   (f64) window->gl_h / window->h);
+  gl_font_set_size(&g_font_flies, board_item_h);
   gl_text_update_1(&g_text_flies_in, a);
   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);
   buf_write_u8(&buf, 0);
-  x = board_item_w * (BOARD_SIZE / 2 + 1);
   matrix = g_ortho.model_matrix; {
+    x = board_item_w * (BOARD_SIZE / 2 + 1);
     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_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);
+    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;
-          }
-          fly_address[0] = address[0];
-          fly_address[1] = address[1];
-          i = 0;
-          while (i < 3) {
-            j = 0;
-            while (j < 9) {
-              directions[j] = true;
-              j++;
+          case BOARD_ITEM_BLOCK:
+            gl_ortho_bind_texture(&g_ortho, 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_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_ortho_bind_texture(&g_ortho,
+                                    gl_sprite_texture(&g_sprite_fly, 0));
+              gl_ortho_rect(&g_ortho, 0, 0, g_sprite_fly.pt_w,
+                            g_sprite_fly.pt_h);
+              gl_ortho_bind_texture(&g_ortho, 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;
             }
-            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;
+            fly_address[0] = address[0];
+            fly_address[1] = address[1];
+            i = 0;
+            while (i < 3) {
+              j = 0;
+              while (j < 9) {
+                directions[j] = true;
+                j++;
               }
-              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;
+              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];
               }
-              directions[direction] = false;
-              fly_address[0] = fly_prev_address[0];
-              fly_address[1] = fly_prev_address[1];
+              i++;
             }
-            i++;
-          }
-          *fly_time += 1;
-          if (*fly_time > FLY_TIME_MAX) {
-            array_data_set(board, fly_address, &g_board_item_dead_fly);
-            fly_init(map);
+            *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_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_ortho_bind_texture(&g_ortho,
+                                    gl_sprite_texture(&g_sprite_dead_fly, 0));
+              gl_ortho_rect(&g_ortho, 0, 0, g_sprite_dead_fly.pt_w,
+                            g_sprite_dead_fly.pt_h);
+              gl_ortho_bind_texture(&g_ortho, 0);
+            } g_ortho.model_matrix = matrix_2;
+            break;
           }
-          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_1;
+        address[0]++;
+      }
+      address[1]++;
     }
-    address[1]++;
-  }
+  } g_ortho.model_matrix = matrix;
   return true;
 }
 
diff --git a/libc3/window/sdl2/demo/toasters.c b/libc3/window/sdl2/demo/toasters.c
index 1773268..fd77abc 100644
--- a/libc3/window/sdl2/demo/toasters.c
+++ b/libc3/window/sdl2/demo/toasters.c
@@ -21,7 +21,7 @@
 #define TOASTERS_SCALE_TOAST   0.52
 #define TOASTERS_SCALE_TOASTER 0.4
 #define TOASTERS_SPACING \
-  (g_sprite_toaster.h * TOASTERS_SCALE_TOASTER * 2.0)
+  (g_sprite_toaster.pt_h * TOASTERS_SCALE_TOASTER * 2.0)
 
 static const f64 g_speed_x =  80.0;
 static const f64 g_speed_y = -40.0;
@@ -50,6 +50,7 @@ static void toast_render (s_tag *toast, s_window_sdl2 *window,
                           s_sequence *seq)
 {
   s_gl_matrix_4f matrix;
+  GLuint texture;
   f64 *x;
   f64 *y;
   if (toast->type == TAG_MAP) {
@@ -62,15 +63,18 @@ static void toast_render (s_tag *toast, s_window_sdl2 *window,
       toast->type = TAG_VOID;
       return;
     }
-    matrix = g_ortho.model_matrix;
-    gl_matrix_4f_translate(&g_ortho.model_matrix, *x,
-                           *y + g_sprite_toast.h, 0.0);
-    gl_matrix_4f_scale(&g_ortho.model_matrix,
-                       TOASTERS_SCALE_TOAST,
-                       -TOASTERS_SCALE_TOAST, 1);
-    gl_ortho_update_model_matrix(&g_ortho);
-    gl_sprite_render(&g_sprite_toast, 0);
-    g_ortho.model_matrix = matrix;
+    matrix = g_ortho.model_matrix; {
+      gl_matrix_4f_translate(&g_ortho.model_matrix, *x,
+                             *y + g_sprite_toast.pt_h, 0.0);
+      gl_matrix_4f_scale(&g_ortho.model_matrix,
+                         TOASTERS_SCALE_TOAST,
+                         -TOASTERS_SCALE_TOAST, 1);
+      gl_ortho_update_model_matrix(&g_ortho);
+      texture = gl_sprite_texture(&g_sprite_toast, 0);
+      gl_ortho_bind_texture(&g_ortho, texture);
+      gl_ortho_rect(&g_ortho, 0, 0, g_sprite_toast.pt_w,
+                    g_sprite_toast.pt_h);
+    } g_ortho.model_matrix = matrix;
   }
 }
 
@@ -88,6 +92,7 @@ static void toaster_render (s_tag *toaster, s_window_sdl2 *window,
                             s_sequence *seq)
 {
   s_gl_matrix_4f matrix;
+  GLuint texture;
   f64 *x;
   f64 *y;
   if (toaster->type == TAG_MAP) {
@@ -102,14 +107,18 @@ static void toaster_render (s_tag *toaster, s_window_sdl2 *window,
     }
     matrix = g_ortho.model_matrix;
     gl_matrix_4f_translate(&g_ortho.model_matrix, *x,
-                           *y + g_sprite_toaster.h, 0.0);
+                           *y + g_sprite_toaster.pt_h, 0.0);
     gl_matrix_4f_scale(&g_ortho.model_matrix,
                        TOASTERS_SCALE_TOASTER,
                        -TOASTERS_SCALE_TOASTER, 1);
     gl_ortho_update_model_matrix(&g_ortho);
-    gl_sprite_render(&g_sprite_toaster,
-                     fmod(seq->t * g_sprite_toaster.frame_count,
-                          g_sprite_toaster.frame_count));
+    texture = gl_sprite_texture(&g_sprite_toaster,
+                                fmod(seq->t *
+                                     g_sprite_toaster.frame_count,
+                                     g_sprite_toaster.frame_count));
+    gl_ortho_bind_texture(&g_ortho, texture);
+    gl_ortho_rect(&g_ortho, 0, 0, g_sprite_toaster.pt_w,
+                  g_sprite_toaster.pt_h);
     g_ortho.model_matrix = matrix;
   }
 }
diff --git a/libc3/window/sdl2/demo/window_sdl2_demo.c b/libc3/window/sdl2/demo/window_sdl2_demo.c
index 2e92cce..84107f7 100644
--- a/libc3/window/sdl2/demo/window_sdl2_demo.c
+++ b/libc3/window/sdl2/demo/window_sdl2_demo.c
@@ -141,8 +141,10 @@ bool window_sdl2_demo_key (s_window_sdl2 *window, SDL_Keysym *keysym)
 
 bool window_sdl2_demo_load (s_window_sdl2 *window)
 {
+  f32 point_per_pixel;
   assert(window);
   assert(glGetError() == GL_NO_ERROR);
+  point_per_pixel = (f32) window->w / window->gl_w;
   if (window->sequence_count != WINDOW_SDL2_DEMO_SEQUENCE_COUNT) {
     fprintf(stderr, "window_sdl2_demo_load: "
             "window->sequence_count = %lu\n", window->sequence_count);
@@ -153,7 +155,8 @@ bool window_sdl2_demo_load (s_window_sdl2 *window)
     return false;
   gl_ortho_resize(&g_ortho, 0, window->w, 0, window->h, 0, 1);
   if (! gl_font_init(&g_font_courier_new,
-                     "fonts/Courier New/Courier New.ttf"))
+                     "fonts/Courier New/Courier New.ttf",
+                     point_per_pixel))
     return false;
   if (! gl_text_init_1(&g_text_seq_title, &g_font_courier_new, ""))
     return false;
@@ -168,27 +171,28 @@ bool window_sdl2_demo_load (s_window_sdl2 *window)
                 lightspeed_load, lightspeed_render, lightspeed_unload,
                 window);
   if (! gl_sprite_init(&g_sprite_toaster, "img/flaps.256.png",
-                       4, 1, 4))
+                       4, 1, 4, point_per_pixel))
     return false;
   if (! gl_sprite_init(&g_sprite_toast, "img/toast.128.png",
-                       1, 1, 1))
+                       1, 1, 1, point_per_pixel))
     return false;
   sequence_init(window->sequence + 2, 60.0, "03. Toasters",
                 toasters_load, toasters_render, toasters_unload,
                 window);
   if (! gl_font_init(&g_font_flies,
-                     "fonts/Courier New/Courier New.ttf"))
+                     "fonts/Courier New/Courier New.ttf",
+                     point_per_pixel))
     return false;
   if (! gl_sprite_init(&g_sprite_fly, "img/fly-noto.png",
-                       1, 1, 1))
+                       1, 1, 1, point_per_pixel))
     return false;
   if (! gl_sprite_init(&g_sprite_dead_fly, "img/fly-dead.png",
-                       1, 1, 1))
+                       1, 1, 1, point_per_pixel))
     return false;
   sequence_init(window->sequence + 3, 60.0, "04. Flies",
                 flies_load, flies_render, flies_unload, window);
   if (! gl_sprite_init(&g_sprite_earth, "img/earth.png",
-                       1, 1, 1))
+                       1, 1, 1, point_per_pixel))
     return false;
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
   assert(glGetError() == GL_NO_ERROR);
@@ -279,8 +283,7 @@ 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_font_set_size(&g_font_courier_new, 20);
   gl_text_update_1(&g_text_seq_title, seq->title);
   gl_matrix_4f_init_identity(&g_ortho.model_matrix);
   render_text(&g_text_seq_title, 20.0f, 30.0f);
diff --git a/libc3/window/sdl2/gl_camera.c b/libc3/window/sdl2/gl_camera.c
index fb58028..5bb5e71 100644
--- a/libc3/window/sdl2/gl_camera.c
+++ b/libc3/window/sdl2/gl_camera.c
@@ -15,15 +15,54 @@
 #include "gl_camera.h"
 #include "gl_matrix_4f.h"
 
-static const char * g_gl_camera_vertex_shader_src = "#version 330 core\n"
-"layout (location = 0) in vec3 aPos;\n"
-"layout (location = 1) in vec3 aNormal;\n"
-"layout (location = 2) in vec2 aTexCoord;\n"
-"uniform mat4 matrix;\n"
-"\n"
-"void main() {\n"
-"  gl_Position = vec4(matrix * vec4(aPos, 1.0));\n"
-"}\n";
+static const char * g_gl_camera_vertex_shader_src =
+  "#version 330 core\n"
+  "layout (location = 0) in vec3 iPos;\n"
+  "layout (location = 1) in vec3 iNormal;\n"
+  "layout (location = 2) in vec2 iTexCoord;\n"
+  "out vec3 oFragNormal;\n"
+  "out vec2 oTexCoord;\n"
+  "uniform mat4 uProjectionMatrix;\n"
+  "uniform mat4 uViewMatrix;\n"
+  "uniform mat4 uModelMatrix;\n"
+  "void main() {\n"
+  "  gl_Position = vec4(uProjectionMatrix * uViewMatrix *\n"
+  "                     uModelMatrix * vec4(iPos, 1.0));\n"
+  "  oFragNormal = vec3(mat3(transpose(inverse(uModelMatrix))) *\n"
+  "                     iNormal);\n"
+  "  oTexCoord = iTexCoord;\n"
+  "}\n";
+
+static const char * g_gl_camera_fragment_shader_src =
+  "#version 330 core\n"
+  "in vec3 iFragNormal;\n"
+  "in vec2 iTexCoord;\n"
+  "out vec4 oFragColor;\n"
+  "uniform bool uEnableTex2D;\n"
+  "uniform sampler2D uTex2D;\n"
+  "void main() {\n"
+  "  if (uEnableTex2D) {\n"
+  "    vec4 texColor = texture(uTex2D, iTexCoord);\n"
+  "    oFragColor = texColor;\n"
+  "  }\n"
+  "  else\n"
+  "    oFragColor = vec4(1, 1, 1, 1);\n"
+  "}\n";
+
+void gl_camera_bind_texture (s_gl_camera *camera, GLuint texture)
+{
+  assert(camera);
+  assert(glGetError() == GL_NO_ERROR);
+  if (! texture) {
+    glUniform1i(camera->gl_enable_tex2d_loc, 0);
+    assert(glGetError() == GL_NO_ERROR);
+    return;
+  }
+  glUniform1i(camera->gl_enable_tex2d_loc, 1);
+  assert(glGetError() == GL_NO_ERROR);
+  glUniform1i(camera->gl_tex2d_loc, texture);  
+  assert(glGetError() == GL_NO_ERROR);
+}
 
 void gl_camera_clean (s_gl_camera *camera)
 {
@@ -39,8 +78,9 @@ void gl_camera_delete (s_gl_camera *camera)
 
 s_gl_camera * gl_camera_init (s_gl_camera *camera, uw w, uw h)
 {
+  GLuint fragment_shader;
   GLint success;
-  u32 vertex_shader;
+  GLuint vertex_shader;
   assert(camera);
   gl_camera_set_aspect_ratio(camera, w, h);
   camera->clip_z_far = 1000.0f;
@@ -63,12 +103,32 @@ s_gl_camera * gl_camera_init (s_gl_camera *camera, uw w, uw h)
     err_write_1("gl_camera_init: shader compilation failed: ");
     err_puts(info_log);
   }
+  fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
+  glShaderSource(fragment_shader, 1, &g_gl_camera_fragment_shader_src,
+                 NULL);
+  glCompileShader(fragment_shader);
+  glGetShaderiv(fragment_shader, GL_COMPILE_STATUS, &success);
+  if (! success) {
+    char info_log[512];
+    glGetShaderInfoLog(fragment_shader, sizeof(info_log), NULL, info_log);
+    err_write_1("gl_camera_init: shader compilation failed: ");
+    err_puts(info_log);
+  }
   camera->gl_shader_program = glCreateProgram();
   glAttachShader(camera->gl_shader_program, vertex_shader);
+  glAttachShader(camera->gl_shader_program, fragment_shader);
   glLinkProgram(camera->gl_shader_program);
   glDeleteShader(vertex_shader);
-  camera->gl_matrix_loc =
-    glGetUniformLocation(camera->gl_shader_program, "matrix");
+  glDeleteShader(fragment_shader);
+  camera->gl_projection_matrix_loc =
+    glGetUniformLocation(camera->gl_shader_program,
+                         "uProjectionMatrix");
+  camera->gl_view_matrix_loc =
+    glGetUniformLocation(camera->gl_shader_program,
+                         "uViewMatrix");
+  camera->gl_model_matrix_loc =
+    glGetUniformLocation(camera->gl_shader_program,
+                         "uModelMatrix");
   return camera;
 }
 
@@ -90,21 +150,27 @@ s_gl_camera * gl_camera_new (uw w, uw h)
 void gl_camera_render (s_gl_camera *camera)
 {
   assert(camera);
-  gl_matrix_4f_init_identity(&camera->matrix);
-  gl_matrix_4f_perspective(&camera->matrix, camera->fov_y,
+  gl_matrix_4f_init_identity(&camera->projection_matrix);
+  gl_matrix_4f_perspective(&camera->projection_matrix, camera->fov_y,
                            camera->aspect_ratio, camera->clip_z_near,
                            camera->clip_z_far);
-  gl_matrix_4f_translate(&camera->matrix, camera->position.x,
+  gl_matrix_4f_init_identity(&camera->view_matrix);
+  gl_matrix_4f_translate(&camera->view_matrix, camera->position.x,
                          camera->position.y, camera->position.z);
-  gl_matrix_4f_rotate_axis(&camera->matrix, camera->rotation.x,
+  gl_matrix_4f_rotate_axis(&camera->view_matrix, camera->rotation.x,
                            &(s_gl_point_3f) { 1.0f, 0.0f, 0.0f });
-  gl_matrix_4f_rotate_axis(&camera->matrix, camera->rotation.y,
+  gl_matrix_4f_rotate_axis(&camera->view_matrix, camera->rotation.y,
                            &(s_gl_point_3f) { 0.0f, 1.0f, 0.0f });
-  gl_matrix_4f_rotate_axis(&camera->matrix, camera->rotation.z,
+  gl_matrix_4f_rotate_axis(&camera->view_matrix, camera->rotation.z,
                            &(s_gl_point_3f) { 0.0f, 0.0f, 1.0f });
+  gl_matrix_4f_init_identity(&camera->model_matrix);
   glUseProgram(camera->gl_shader_program);
-  glUniformMatrix4fv(camera->gl_matrix_loc, 1, GL_FALSE,
-                     &camera->matrix.xx);
+  glUniformMatrix4fv(camera->gl_projection_matrix_loc, 1, GL_FALSE,
+                     &camera->projection_matrix.xx);
+  glUniformMatrix4fv(camera->gl_view_matrix_loc, 1, GL_FALSE,
+                     &camera->view_matrix.xx);
+  glUniformMatrix4fv(camera->gl_model_matrix_loc, 1, GL_FALSE,
+                     &camera->model_matrix.xx);
 }
 
 void gl_camera_render_end (s_gl_camera *camera)
diff --git a/libc3/window/sdl2/gl_camera.h b/libc3/window/sdl2/gl_camera.h
index e4e9307..7ccdc65 100644
--- a/libc3/window/sdl2/gl_camera.h
+++ b/libc3/window/sdl2/gl_camera.h
@@ -25,6 +25,8 @@ void          gl_camera_delete (s_gl_camera *camera);
 s_gl_camera * gl_camera_new (uw w, uw h);
 
 /* Operators. */
+void          gl_camera_bind_texture (s_gl_camera *camera,
+                                      GLuint texture);
 void          gl_camera_render (s_gl_camera *camera);
 s_gl_camera * gl_camera_set_aspect_ratio (s_gl_camera *camera, uw w,
                                           uw h);
diff --git a/libc3/window/sdl2/gl_font.c b/libc3/window/sdl2/gl_font.c
index 41ac14d..73e0309 100644
--- a/libc3/window/sdl2/gl_font.c
+++ b/libc3/window/sdl2/gl_font.c
@@ -23,32 +23,35 @@ void gl_font_clean (s_gl_font *font)
   str_clean(&font->real_path);
 }
 
-s_gl_font * gl_font_init (s_gl_font *font, const char *path)
+s_gl_font * gl_font_init (s_gl_font *font, const char *path,
+                          f32 point_per_pixel)
 {
+  s_gl_font tmp = {0};
   assert(font);
   assert(path);
-  str_init_copy_1(&font->path, path);
-  if (! file_search(&font->path, sym_1("r"), &font->real_path)) {
+  str_init_copy_1(&tmp.path, path);
+  if (! file_search(&tmp.path, sym_1("r"), &tmp.real_path)) {
     err_write_1("gl_font_init: file not found: ");
     err_puts(path);
-    str_clean(&font->path);
+    str_clean(&tmp.path);
     return NULL;
   }
   assert(glGetError() == GL_NO_ERROR);
-  if (FT_New_Face(g_ft, font->real_path.ptr.pchar, 0, &font->ft_face)) {
+  if (FT_New_Face(g_ft, tmp.real_path.ptr.pchar, 0, &tmp.ft_face)) {
     err_write_1("gl_font_init: error loading font: ");
-    err_puts(font->real_path.ptr.pchar);
-    str_clean(&font->path);
-    str_clean(&font->real_path);
+    err_puts(tmp.real_path.ptr.pchar);
+    str_clean(&tmp.path);
+    str_clean(&tmp.real_path);
     return NULL;
   }
+  tmp.point_per_pixel = point_per_pixel;
+  *font = tmp;
   return font;
 }
 
-void gl_font_set_size (s_gl_font *font, f64 point_size,
-                       f64 pixel_per_point)
+void gl_font_set_size (s_gl_font *font, f32 point_size)
 {
-  f64 size;
-  size = point_size * pixel_per_point;
+  f32 size;
+  size = point_size / font->point_per_pixel;
   FT_Set_Pixel_Sizes(font->ft_face, 0, size);
 }
diff --git a/libc3/window/sdl2/gl_font.h b/libc3/window/sdl2/gl_font.h
index 6841544..2b2faa8 100644
--- a/libc3/window/sdl2/gl_font.h
+++ b/libc3/window/sdl2/gl_font.h
@@ -20,9 +20,10 @@ extern FT_Library g_ft;
 /* Stack-allocation compatible functions, call gl_font_clean
    after use. */
 void        gl_font_clean (s_gl_font *font);
-s_gl_font * gl_font_init (s_gl_font *font, const char *path);
+s_gl_font * gl_font_init (s_gl_font *font, const char *path,
+                          f32 point_per_pixel);
 
 /* Operators. */
-void gl_font_set_size (s_gl_font *font, f64 size, f64 pixels_per_point);
+void gl_font_set_size (s_gl_font *font, f32 point_size);
 
 #endif /* GL_FONT_H */
diff --git a/libc3/window/sdl2/gl_ortho.c b/libc3/window/sdl2/gl_ortho.c
index e89d0be..7214c5e 100644
--- a/libc3/window/sdl2/gl_ortho.c
+++ b/libc3/window/sdl2/gl_ortho.c
@@ -19,37 +19,36 @@
 
 static const char * g_gl_ortho_vertex_shader_src =
   "#version 330 core\n"
-  "layout (location = 0) in vec3 aPos;\n"
-  "layout (location = 1) in vec3 aNorm;\n"
-  "layout (location = 2) in vec2 aTexCoord;\n"
-  "out vec3 FragNormal;\n"
-  "out vec2 TexCoord;\n"
-  "uniform mat4 projection_matrix;\n"
-  "uniform mat4 view_matrix;\n"
-  "uniform mat4 model_matrix;\n"
-  "\n"
+  "layout (location = 0) in vec3 iPos;\n"
+  "layout (location = 1) in vec3 iNormal;\n"
+  "layout (location = 2) in vec2 iTexCoord;\n"
+  "out vec3 oFragNormal;\n"
+  "out vec2 oTexCoord;\n"
+  "uniform mat4 uProjectionMatrix;\n"
+  "uniform mat4 uViewMatrix;\n"
+  "uniform mat4 uModelMatrix;\n"
   "void main() {\n"
-  "  gl_Position = vec4(projection_matrix * view_matrix * \n"
-  "                     model_matrix * vec4(aPos, 1.0));\n"
-  "  FragNormal = vec3(mat3(transpose(inverse(model_matrix))) *\n"
-  "                    aNorm);\n"
-  "  TexCoord = aTexCoord;\n"
+  "  gl_Position = vec4(uProjectionMatrix * uViewMatrix * \n"
+  "                     uModelMatrix * vec4(iPos, 1.0));\n"
+  "  oFragNormal = vec3(mat3(transpose(inverse(uModelMatrix))) *\n"
+  "                     iNormal);\n"
+  "  oTexCoord = iTexCoord;\n"
   "}\n";
 
 static const char * g_gl_ortho_fragment_shader_src =
   "#version 330 core\n"
-  "in vec3 FragNormal;\n"
-  "in vec2 TexCoord;\n"
-  "out vec4 FragColor;\n"
-  "uniform bool enable_texture;\n"
-  "uniform sampler2D tex;\n"
+  "in vec3 iFragNormal;\n"
+  "in vec2 iTexCoord;\n"
+  "out vec4 oFragColor;\n"
+  "uniform bool uEnableTex2D;\n"
+  "uniform sampler2D uTex2D;\n"
   "void main() {\n"
-  "  if (enable_texture) {\n"
-  "    vec4 textureColor = texture(tex, TexCoord);\n"
-  "    FragColor = textureColor;\n"
+  "  if (uEnableTex2D) {\n"
+  "    vec4 texColor = texture(uTex2D, iTexCoord);\n"
+  "    oFragColor = texColor;\n"
   "  }\n"
   "  else\n"
-  "    FragColor = vec4(1, 1, 1, 1);\n"
+  "    oFragColor = vec4(1, 1, 1, 1);\n"
   "}\n";
 
 void gl_ortho_bind_texture (s_gl_ortho *ortho, GLuint texture)
@@ -57,13 +56,13 @@ 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);
+    glUniform1i(ortho->gl_enable_tex2d_loc, 0);
     assert(glGetError() == GL_NO_ERROR);
     return;
   }
-  glUniform1i(ortho->gl_enable_texture_loc, 1);
+  glUniform1i(ortho->gl_enable_tex2d_loc, 1);
   assert(glGetError() == GL_NO_ERROR);
-  glUniform1i(ortho->gl_texture_loc, texture);  
+  glUniform1i(ortho->gl_tex2d_loc, texture);  
   assert(glGetError() == GL_NO_ERROR);
 }
 
@@ -136,19 +135,19 @@ s_gl_ortho * gl_ortho_init (s_gl_ortho *ortho)
   glDeleteShader(fragment_shader);
   assert(glGetError() == GL_NO_ERROR);
   ortho->gl_projection_matrix_loc =
-    glGetUniformLocation(ortho->gl_shader_program, "projection_matrix");
+    glGetUniformLocation(ortho->gl_shader_program, "uProjectionMatrix");
   assert(glGetError() == GL_NO_ERROR);
   ortho->gl_view_matrix_loc =
-    glGetUniformLocation(ortho->gl_shader_program, "view_matrix");
+    glGetUniformLocation(ortho->gl_shader_program, "uViewMatrix");
   assert(glGetError() == GL_NO_ERROR);
   ortho->gl_model_matrix_loc =
-    glGetUniformLocation(ortho->gl_shader_program, "model_matrix");
+    glGetUniformLocation(ortho->gl_shader_program, "uModelMatrix");
   assert(glGetError() == GL_NO_ERROR);
-  ortho->gl_enable_texture_loc =
-    glGetUniformLocation(ortho->gl_shader_program, "enable_texture");
+  ortho->gl_enable_tex2d_loc =
+    glGetUniformLocation(ortho->gl_shader_program, "uEnableTex2D");
   assert(glGetError() == GL_NO_ERROR);
-  ortho->gl_texture_loc =
-    glGetUniformLocation(ortho->gl_shader_program, "texture2D");
+  ortho->gl_tex2d_loc =
+    glGetUniformLocation(ortho->gl_shader_program, "uTex2D");
   assert(glGetError() == GL_NO_ERROR);
   return ortho;
 }
@@ -204,12 +203,13 @@ void gl_ortho_render (s_gl_ortho *ortho)
   glUniformMatrix4fv(ortho->gl_model_matrix_loc, 1, GL_FALSE,
                      &ortho->model_matrix.xx);
   assert(glGetError() == GL_NO_ERROR);
-  glUniform1i(ortho->gl_enable_texture_loc, 0);
+  glUniform1i(ortho->gl_enable_tex2d_loc, 0);
   assert(glGetError() == GL_NO_ERROR);
-  glUniform1i(ortho->gl_texture_loc, 0);
+  glUniform1i(ortho->gl_tex2d_loc, 0);
   assert(glGetError() == GL_NO_ERROR);
   glDepthRange(ortho->clip_z_near, ortho->clip_z_far);
   assert(glGetError() == GL_NO_ERROR);
+  /*
   err_puts("gl_ortho_render projection matrix");
   gl_matrix_4f_buf_inspect(&g_c3_env.err, &ortho->projection_matrix);
   err_puts("view matrix");
@@ -217,6 +217,7 @@ void gl_ortho_render (s_gl_ortho *ortho)
   err_puts("model matrix");
   gl_matrix_4f_buf_inspect(&g_c3_env.err, &ortho->model_matrix);
   buf_flush(&g_c3_env.err);
+  */
 }
 
 void gl_ortho_render_end (s_gl_ortho *ortho)
@@ -242,7 +243,7 @@ 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_rect(ortho, 0, 0, text->pt_w, text->pt_h);
   gl_ortho_bind_texture(ortho, 0);
 }
 
@@ -253,6 +254,7 @@ void gl_ortho_update_model_matrix (s_gl_ortho *ortho)
   glUniformMatrix4fv(ortho->gl_model_matrix_loc, 1, GL_FALSE,
                      &ortho->model_matrix.xx);
   assert(glGetError() == GL_NO_ERROR);
+  /*
   err_puts("gl_ortho_update_model_matrix projection matrix");
   gl_matrix_4f_buf_inspect(&g_c3_env.err, &ortho->projection_matrix);
   err_puts("view matrix");
@@ -260,6 +262,7 @@ void gl_ortho_update_model_matrix (s_gl_ortho *ortho)
   err_puts("model matrix");
   gl_matrix_4f_buf_inspect(&g_c3_env.err, &ortho->model_matrix);
   buf_flush(&g_c3_env.err);
+  */
 }
 
 void gl_ortho_update_view_matrix (s_gl_ortho *ortho)
diff --git a/libc3/window/sdl2/gl_sprite.c b/libc3/window/sdl2/gl_sprite.c
index d812be1..d28dd60 100644
--- a/libc3/window/sdl2/gl_sprite.c
+++ b/libc3/window/sdl2/gl_sprite.c
@@ -18,20 +18,9 @@
 #include "gl_sprite.h"
 #include "gl_triangle.h"
 
-void gl_sprite_bind (const s_gl_sprite *sprite, uw frame)
-{
-  assert(sprite);
-  assert(frame < sprite->frame_count);
-  frame %= sprite->frame_count;
-  assert(glGetError() == GL_NO_ERROR);
-  glBindTexture(GL_TEXTURE_2D, sprite->texture[frame]);
-  assert(glGetError() == GL_NO_ERROR);
-}
-
 void gl_sprite_clean (s_gl_sprite *sprite)
 {
   assert(sprite);
-  gl_object_clean(&sprite->object);
   str_clean(&sprite->path);
   str_clean(&sprite->real_path);
   glDeleteTextures(sprite->frame_count, sprite->texture);
@@ -97,7 +86,8 @@ static bool png_info_to_gl_info (s32 png_color_type,
 }
 
 s_gl_sprite * gl_sprite_init (s_gl_sprite *sprite, const char *path,
-                              uw dim_x, uw dim_y, uw frame_count)
+                              uw dim_x, uw dim_y, uw frame_count,
+                              f32 point_per_pixel)
 {
   u8 *data;
   FILE *fp;
@@ -122,8 +112,6 @@ s_gl_sprite * gl_sprite_init (s_gl_sprite *sprite, const char *path,
   uw y;
   uw v;
   s_gl_sprite tmp = {0};
-  s_gl_triangle *triangle;
-  s_gl_vertex *vertex;
   assert(sprite);
   assert(path);
   assert(dim_x);
@@ -246,8 +234,8 @@ s_gl_sprite * gl_sprite_init (s_gl_sprite *sprite, const char *path,
   tmp.total_h = png_h;
   tmp.dim_x = dim_x;
   tmp.dim_y = dim_y;
-  tmp.w = tmp.total_w / dim_x;
-  tmp.h = tmp.total_h / dim_y;
+  tmp.pix_w = tmp.total_w / dim_x;
+  tmp.pix_h = tmp.total_h / dim_y;
   tmp.texture = calloc(tmp.frame_count, sizeof(GLuint));
   if (! tmp.texture) {
     err_puts("gl_sprite_init: tmp.texture:"
@@ -269,8 +257,8 @@ s_gl_sprite * gl_sprite_init (s_gl_sprite *sprite, const char *path,
     str_clean(&tmp.real_path);
     return NULL;
   }
-  sprite_stride = tmp.w * png_pixel_size;
-  data = malloc(tmp.h * sprite_stride);
+  sprite_stride = tmp.pix_w * png_pixel_size;
+  data = malloc(tmp.pix_h * sprite_stride);
   if (! data) {
     err_write_1("gl_sprite_init: failed to allocate memory: ");
     err_puts(tmp.real_path.ptr.pchar);
@@ -284,12 +272,12 @@ s_gl_sprite * gl_sprite_init (s_gl_sprite *sprite, const char *path,
   while (i < tmp.frame_count && y < dim_y) {
     x = 0;
     while (i < tmp.frame_count && x < dim_x) {
-      sprite_data = data + sprite_stride * tmp.h;
+      sprite_data = data + sprite_stride * tmp.pix_h;
       v = 0;
-      while (v < tmp.h) {
+      while (v < tmp.pix_h) {
 	sprite_data -= sprite_stride;
 	memcpy(sprite_data,
-	       png_row[y * tmp.h + v] + x * sprite_stride,
+	       png_row[y * tmp.pix_h + v] + x * sprite_stride,
 	       sprite_stride);
 	v++;
       }
@@ -317,10 +305,8 @@ s_gl_sprite * gl_sprite_init (s_gl_sprite *sprite, const char *path,
         err_puts(gl_error_string(gl_error));
 	return NULL;
       }
-      glTexImage2D(GL_TEXTURE_2D, 0, gl_format, tmp.w, tmp.h,
+      glTexImage2D(GL_TEXTURE_2D, 0, gl_format, tmp.pix_w, tmp.pix_h,
                    0, gl_format, gl_type, data);
-      //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tmp.w, tmp.h,
-      //             0, GL_RGBA, GL_UNSIGNED_BYTE, data);
       gl_error = glGetError();
       if (gl_error != GL_NO_ERROR) {
 	err_write_1("gl_sprite_init: ");
@@ -337,42 +323,20 @@ s_gl_sprite * gl_sprite_init (s_gl_sprite *sprite, const char *path,
     y++;
   }
   glBindTexture(GL_TEXTURE_2D, 0);
+  assert(glGetError() == GL_NO_ERROR);
+  tmp.pt_w = tmp.pix_w * point_per_pixel;
+  tmp.pt_h = tmp.pix_h * point_per_pixel;
   free(data);
   free(png_data);
   free(png_row);
-  assert(glGetError() == GL_NO_ERROR);
-  gl_object_init(&tmp.object);
-  gl_object_allocate(&tmp.object, 4, 2);
-  vertex = tmp.object.vertex.data;
-  gl_point_3f_init(&vertex[0].position, 0.0, tmp.h, 0.0);
-  gl_point_3f_init(&vertex[0].normal, 0.0, 0.0, -1.0);
-  gl_point_2f_init(&vertex[0].tex_coord, 0.0, 1.0);
-  gl_point_3f_init(&vertex[1].position, 0.0, 0.0, 0.0);
-  gl_point_3f_init(&vertex[1].normal, 0.0, 0.0, -1.0);
-  gl_point_2f_init(&vertex[1].tex_coord, 0.0, 0.0);
-  gl_point_3f_init(&vertex[2].position, tmp.w, tmp.h, 0.0);
-  gl_point_3f_init(&vertex[2].normal, 0.0, 0.0, -1.0);
-  gl_point_2f_init(&vertex[2].tex_coord, 1.0, 1.0);
-  gl_point_3f_init(&vertex[3].position, tmp.w, 0.0, 0.0);
-  gl_point_3f_init(&vertex[3].normal, 0.0, 0.0, -1.0);
-  gl_point_2f_init(&vertex[3].tex_coord, 1.0, 0.0);
-  triangle = tmp.object.triangle.data;
-  gl_triangle_init(triangle + 0, 0, 1, 2);
-  gl_triangle_init(triangle + 1, 1, 3, 2);
-  gl_object_update(&tmp.object);
   *sprite = tmp;  
   return sprite;
 }
 
-void gl_sprite_render (const s_gl_sprite *sprite, uw frame)
+GLuint gl_sprite_texture (const s_gl_sprite *sprite, uw frame)
 {
   assert(sprite);
-  assert(glGetError() == GL_NO_ERROR);
-  gl_sprite_bind(sprite, frame);
-  assert(glGetError() == GL_NO_ERROR);
-  gl_object_render(&sprite->object);
-  assert(glGetError() == GL_NO_ERROR);
-  glBindTexture(GL_TEXTURE_2D, 0);
-  assert(glGetError() == GL_NO_ERROR);
-  gl_object_render_wireframe(&sprite->object);
+  assert(frame < sprite->frame_count);
+  frame %= sprite->frame_count;
+  return sprite->texture[frame];
 }
diff --git a/libc3/window/sdl2/gl_sprite.h b/libc3/window/sdl2/gl_sprite.h
index 07ff58e..9756dbf 100644
--- a/libc3/window/sdl2/gl_sprite.h
+++ b/libc3/window/sdl2/gl_sprite.h
@@ -19,10 +19,10 @@
    after use. */
 void          gl_sprite_clean (s_gl_sprite *sprite);
 s_gl_sprite * gl_sprite_init (s_gl_sprite *sprite, const char *path,
-                              uw dim_x, uw dim_y, uw frame_count);
+                              uw dim_x, uw dim_y, uw frame_count,
+                              f32 point_per_pixel);
 
 /* Observers. */
-void gl_sprite_bind (const s_gl_sprite *sprite, uw frame);
-void gl_sprite_render (const s_gl_sprite *sprite, uw frame);
+GLuint gl_sprite_texture (const s_gl_sprite *sprite, uw frame);
 
 #endif /* GL_SPRITE_H */
diff --git a/libc3/window/sdl2/gl_square.c b/libc3/window/sdl2/gl_square.c
index 8be5864..c709038 100644
--- a/libc3/window/sdl2/gl_square.c
+++ b/libc3/window/sdl2/gl_square.c
@@ -53,10 +53,10 @@ s_gl_square * gl_square_init (s_gl_square *square, uw seg_u, uw seg_v)
   vertex = tmp.object.vertex.data;
   i = 0;
   while (i < seg_v) {
-    y = (f32) i / seg_v;
+    y = (f32) i / (seg_v - 1);
     j = 0;
     while (j < seg_u) {
-      vertex->tex_coord.x = vertex->position.x = (f32) j / seg_u;
+      vertex->tex_coord.x = vertex->position.x = (f32) j / (seg_u - 1);
       vertex->tex_coord.y = vertex->position.y = y;
       vertex->position.z = 0.0;
       vertex->normal = normal;
diff --git a/libc3/window/sdl2/gl_text.c b/libc3/window/sdl2/gl_text.c
index 4b2b2b3..a04617b 100644
--- a/libc3/window/sdl2/gl_text.c
+++ b/libc3/window/sdl2/gl_text.c
@@ -19,7 +19,6 @@
 
 void gl_text_clean (s_gl_text *text)
 {
-  gl_object_clean(&text->object);
   str_clean(&text->str);
   glDeleteTextures(1, &text->texture);
 }
@@ -31,9 +30,6 @@ s_gl_text * gl_text_init (s_gl_text *text, const s_gl_font *font)
   tmp.font = font;
   glGenTextures(1, &tmp.texture);
   assert(glGetError() == GL_NO_ERROR);
-  gl_object_init(&tmp.object);
-  assert(glGetError() == GL_NO_ERROR);
-  gl_object_allocate(&tmp.object, 4, 2);
   *text = tmp;  
   return text;
 }
@@ -58,14 +54,6 @@ s_gl_text * gl_text_init_str (s_gl_text *text, const s_gl_font *font,
   return text;
 }
 
-void gl_text_render (const s_gl_text *text)
-{
-  assert(text);
-  assert(glGetError() == GL_NO_ERROR);
-  gl_object_render(&text->object);
-  assert(glGetError() == GL_NO_ERROR);
-}
-
 bool gl_text_render_to_texture (s_gl_text *text)
 {
   character c;
@@ -159,8 +147,10 @@ bool gl_text_render_to_texture (s_gl_text *text)
   assert(glGetError() == GL_NO_ERROR);
   free(data);
   glBindTexture(GL_TEXTURE_2D, 0);
-  text->w = data_w;
-  text->h = data_h;
+  text->pix_w = data_w;
+  text->pix_h = data_h;
+  text->pt_w = text->pix_w * text->font->point_per_pixel;
+  text->pt_h = text->pix_h * text->font->point_per_pixel;
   return true;
 }
 
@@ -210,28 +200,7 @@ bool gl_text_set_text_buf (s_gl_text *text, s_buf *buf)
 
 bool gl_text_update (s_gl_text *text)
 {
-  s_gl_vertex *vertex;
-  s_gl_triangle *triangle;
-  if (! gl_text_render_to_texture(text))
-    return false;
-  vertex = text->object.vertex.data;
-  gl_point_3f_init(&vertex[0].position,  0.0,     text->h, 0.0);
-  gl_point_3f_init(&vertex[0].normal,    0.0,     0.0,    -1.0);
-  gl_point_2f_init(&vertex[0].tex_coord, 0.0,     1.0);
-  gl_point_3f_init(&vertex[1].position,  0.0,     0.0,     0.0);
-  gl_point_3f_init(&vertex[1].normal,    0.0,     0.0,    -1.0);
-  gl_point_2f_init(&vertex[1].tex_coord, 0.0,     0.0);
-  gl_point_3f_init(&vertex[2].position,  text->w, text->h, 0.0);
-  gl_point_3f_init(&vertex[2].normal,    0.0,     0.0,    -1.0);
-  gl_point_2f_init(&vertex[2].tex_coord, 1.0,     1.0);
-  gl_point_3f_init(&vertex[3].position,  text->w, 0.0,     0.0);
-  gl_point_3f_init(&vertex[3].normal,    0.0,     0.0,    -1.0);
-  gl_point_2f_init(&vertex[3].tex_coord, 1.0,     0.0);
-  triangle = text->object.triangle.data;
-  gl_triangle_init(triangle + 0, 0, 1, 2);
-  gl_triangle_init(triangle + 1, 1, 3, 2);
-  gl_object_update(&text->object);
-  return true;
+  return gl_text_render_to_texture(text);
 }
 
 bool gl_text_update_1 (s_gl_text *text, const char *p)
diff --git a/libc3/window/sdl2/types.h b/libc3/window/sdl2/types.h
index 1c824ed..fef23ea 100644
--- a/libc3/window/sdl2/types.h
+++ b/libc3/window/sdl2/types.h
@@ -86,9 +86,9 @@ typedef void (*f_window_sdl2_unload) (s_window_sdl2 *window);
 
 struct gl_font {
   FT_Face ft_face;
-  f32 point_size;
-  f32 pixel_per_point;
   s_str path;
+  f32 point_size;
+  f32 point_per_pixel;
   s_str real_path;
 };
 
@@ -192,27 +192,27 @@ struct gl_point_3f {
 };
 
 struct gl_sprite {
-  s_str path;
-  s_str real_path;
-  uw total_w;
-  uw total_h;
   uw dim_x;
   uw dim_y;
   uw frame_count;
+  s_str path;
+  uw pix_w;
+  uw pix_h;
   f32 pt_w;
   f32 pt_h;
-  uw tex_w;
-  uw tex_h;
+  s_str real_path;
   GLuint *texture;
+  uw total_w;
+  uw total_h;
 };
 
 struct gl_text {
   const s_gl_font *font;
-  s_str str;
-  uw tex_w;
-  uw tex_h;
+  uw pix_w;
+  uw pix_h;
   f32 pt_w;
   f32 pt_h;
+  s_str str;
   GLuint texture;
 };
 
@@ -272,8 +272,15 @@ struct gl_camera {
   f32 fov_y;
   s_gl_point_3f position;
   s_gl_point_3f rotation;
-  s_gl_matrix_4f matrix;
-  u32 gl_matrix_loc;
+  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_enable_tex2d_loc;
+  u32 gl_tex2d_loc;
   u32 gl_shader_program;
 };
 
@@ -337,9 +344,8 @@ struct gl_ortho {
   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_enable_tex2d_loc;
+  u32 gl_tex2d_loc;
   u32 gl_shader_program;
   s_gl_square square;
 };