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
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
|
#include "main.h"
#include "state.h"
#include "textures.h"
#include "text.h"
#include "lua_core.h"
static void checkImageRealloc( int i ) {
if ( i == state->imageCount ) {
state->imageCount++;
}
if ( state->imageCount == state->imageAlloc ) {
state->imageAlloc += ALLOC_PAGE_SIZE;
state->images = realloc( state->images, state->imageAlloc * sizeof( Image* ) );
for ( i = state->imageCount; i < state->imageAlloc; i++ ) {
state->images[i] = NULL;
}
}
}
static void checkTextureRealloc( int i ) {
if ( i == state->textureCount ) {
state->textureCount++;
}
if ( state->textureCount == state->textureAlloc ) {
state->textureAlloc += ALLOC_PAGE_SIZE;
state->textures = realloc( state->textures, state->textureAlloc * sizeof( Texture2D* ) );
for ( i = state->textureCount; i < state->textureAlloc; i++ ) {
state->textures[i] = NULL;
}
}
}
static void checkRenderTextureRealloc( int i ) {
if ( i == state->renderTextureCount ) {
state->renderTextureCount++;
}
if ( state->renderTextureCount == state->renderTextureAlloc ) {
state->renderTextureAlloc += ALLOC_PAGE_SIZE;
state->renderTextures = realloc( state->renderTextures, state->renderTextureAlloc * sizeof( RenderTexture2D* ) );
for ( i = state->renderTextureCount; i < state->renderTextureAlloc; i++ ) {
state->renderTextures[i] = NULL;
}
}
}
bool validImage( size_t id ) {
if ( id < 0 || state->imageCount < id || state->images[ id ] == NULL ) {
TraceLog( LOG_WARNING, "%s %d", "Invalid image", id );
return false;
}
else {
return true;
}
}
bool validTexture( size_t id ) {
if ( id < 0 || state->textureCount < id || state->textures[ id ] == NULL ) {
TraceLog( LOG_WARNING, "%s %d", "Invalid texture", id );
return false;
}
else {
return true;
}
}
bool validRenderTexture( size_t id ) {
if ( id < 0 || state->renderTextureCount < id || state->renderTextures[ id ] == NULL ) {
TraceLog( LOG_WARNING, "%s %d", "Invalid renderTexture", id );
return false;
}
else {
return true;
}
}
bool validSourceTexture( size_t id ) {
switch ( state->textureSource ) {
case TEXTURE_SOURCE_TEXTURE:
return validTexture( id );
case TEXTURE_SOURCE_RENDER_TEXTURE:
return validRenderTexture( id );
default:
return validTexture( id );
break;
}
}
Texture2D* texturesGetSourceTexture( size_t index ) {
switch ( state->textureSource ) {
case TEXTURE_SOURCE_TEXTURE:
return state->textures[ index ];
case TEXTURE_SOURCE_RENDER_TEXTURE:
return &state->renderTextures[ index ]->texture;
default:
return state->textures[ index ];
break;
}
}
/*
## Textures - Load
*/
/*
> image = RL_LoadImage( string fileName )
Load image from file into CPU memory ( RAM )
- Failure return -1
- Success return int
*/
int ltexturesLoadImage( lua_State *L ) {
if ( !lua_isstring( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_LoadImage( string fileName )" );
lua_pushinteger( L, -1 );
return 1;
}
if ( FileExists( lua_tostring( L, -1 ) ) ) {
int i = 0;
for ( i = 0; i < state->imageCount; i++ ) {
if ( state->images[i] == NULL ) {
break;
}
}
state->images[i] = malloc( sizeof( Image ) );
*state->images[i] = LoadImage( lua_tostring( L, -1 ) );
lua_pushinteger( L, i );
checkImageRealloc( i );
return 1;
}
else {
lua_pushinteger( L, -1 );
return 1;
}
}
/*
> image = RL_GenImageColor( int width, int height, Color color )
Generate image: plain color
- Failure return -1
- Success return int
*/
int ltexturesGenImageColor( lua_State *L ) {
if ( !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GenImageColor( int width, int height, Color color )" );
lua_pushinteger( L, -1 );
return 1;
}
Color color = uluaGetColor( L );
lua_pop( L, 1 );
int height = lua_tointeger( L, -1 );
lua_pop( L, 1 );
int width = lua_tointeger( L, -1 );
int i = 0;
for ( i = 0; i < state->imageCount; i++ ) {
if ( state->images[i] == NULL ) {
break;
}
}
state->images[i] = malloc( sizeof( Image ) );
*state->images[i] = GenImageColor( width, height, color );
lua_pushinteger( L, i );
checkImageRealloc( i );
return 1;
}
/*
> success = RL_UnloadImage( Image image )
Unload image from CPU memory ( RAM )
- Failure return false
- Success return true
*/
int ltexturesUnloadImage( lua_State *L ) {
if ( !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_UnloadImage( Image image )" );
lua_pushboolean( L, false );
return 1;
}
size_t id = lua_tointeger( L, -1 );
if ( !validImage( id ) ) {
lua_pushboolean( L, false );
return 1;
}
UnloadImage( *state->images[ id ] );
state->images[ id ] = NULL;
lua_pushboolean( L, true );
return 1;
}
/*
> texture = RL_LoadTexture( string fileName )
Load texture from file into GPU memory ( VRAM )
- Failure return -1
- Success return int
*/
int ltexturesLoadTexture( lua_State *L ) {
if ( !lua_isstring( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_LoadTexture( string fileName )" );
lua_pushinteger( L, -1 );
return 1;
}
if ( FileExists( lua_tostring( L, -1 ) ) ) {
int i = 0;
for ( i = 0; i < state->textureCount; i++ ) {
if ( state->textures[i] == NULL ) {
break;
}
}
state->textures[i] = malloc( sizeof( Texture2D ) );
*state->textures[i] = LoadTexture( lua_tostring( L, -1 ) );
lua_pushinteger( L, i );
checkTextureRealloc( i );
return 1;
}
else {
lua_pushinteger( L, -1 );
return 1;
}
}
/*
> texture = RL_LoadTextureFromImage( Image image )
Load texture from image data
- Failure return -1
- Success return int
*/
int ltexturesLoadTextureFromImage( lua_State *L ) {
if ( !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_LoadTextureFromImage( Image image )" );
lua_pushinteger( L, -1 );
return 1;
}
size_t imageId = lua_tointeger( L, -1 );
if ( !validImage( imageId ) ) {
lua_pushboolean( L, false );
return 1;
}
int i = 0;
for ( i = 0; i < state->textureCount; i++ ) {
if ( state->textures[i] == NULL ) {
break;
}
}
state->textures[i] = malloc( sizeof( Texture2D ) );
*state->textures[i] = LoadTextureFromImage( *state->images[ imageId ] );
lua_pushinteger( L, i );
checkTextureRealloc( i );
return 1;
}
/*
> success = RL_UnloadTexture( Texture2D texture )
Unload texture from GPU memory ( VRAM )
- Failure return false
- Success return true
*/
int ltexturesUnloadTexture( lua_State *L ) {
if ( !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_UnloadTexture( Texture2D texture )" );
lua_pushboolean( L, false );
return 1;
}
size_t id = lua_tointeger( L, -1 );
if ( !validTexture( id ) ) {
lua_pushboolean( L, false );
return 1;
}
UnloadTexture( *state->textures[ id ] );
state->textures[ id ] = NULL;
lua_pushboolean( L, true );
return 1;
}
/*
> renderTexture = RL_LoadRenderTexture( Vector2 size )
Load texture for rendering ( framebuffer )
- Failure return -1
- Success return int
*/
int ltexturesLoadRenderTexture( lua_State *L ) {
if ( !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_LoadRenderTexture( Vector2 size )" );
lua_pushinteger( L, -1 );
return 1;
}
Vector2 size = uluaGetVector2( L );
int i = 0;
for ( i = 0; i < state->renderTextureCount; i++ ) {
if ( state->renderTextures[i] == NULL ) {
break;
}
}
state->renderTextures[i] = malloc( sizeof( RenderTexture2D ) );
*state->renderTextures[i] = LoadRenderTexture( (int)size.x, (int)size.y );
lua_pushinteger( L, i );
checkRenderTextureRealloc( i );
return 1;
}
/*
> success = RL_UnloadRenderTexture( RenderTexture2D target )
Unload render texture from GPU memory ( VRAM )
- Failure return false
- Success return true
*/
int ltexturesUnloadRenderTexture( lua_State *L ) {
if ( !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_UnloadRenderTexture( RenderTexture2D target )" );
lua_pushboolean( L, false );
return 1;
}
size_t id = lua_tointeger( L, -1 );
if ( !validRenderTexture( id ) ) {
lua_pushboolean( L, false );
return 1;
}
UnloadRenderTexture( *state->renderTextures[ id ] );
state->renderTextures[ id ] = NULL;
lua_pushboolean( L, true );
return 1;
}
/*
## Textures - Image Drawing
*/
/*
> success = RL_ImageClearBackground( Image dst, Color color )
Clear image background with given color
- Failure return false
- Success return true
*/
int ltexturesImageClearBackground( lua_State *L ) {
if ( !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageClearBackground( Image dst, Color color )" );
lua_pushboolean( L, false );
return 1;
}
Color color = uluaGetColor( L );
lua_pop( L, 1 );
size_t imageId = lua_tointeger( L, -1 );
if ( !validImage( imageId ) ) {
lua_pushboolean( L, false );
return 1;
}
ImageClearBackground( state->images[ imageId ], color );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_ImageDrawPixel( Image dst, Vector2 position, Color color )
Draw pixel within an image
- Failure return false
- Success return true
*/
int ltexturesImageDrawPixel( lua_State *L ) {
if ( !lua_isnumber( L, -3 ) || !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageDrawPixel( Image dst, Vector2 position, Color color )" );
lua_pushboolean( L, false );
return 1;
}
Color color = uluaGetColor( L );
lua_pop( L, 1 );
Vector2 position = uluaGetVector2( L );
lua_pop( L, 1 );
size_t imageId = lua_tointeger( L, -1 );
if ( !validImage( imageId ) ) {
lua_pushboolean( L, false );
return 1;
}
ImageDrawPixelV( state->images[ imageId ], position, color );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_ImageDrawLine( Image dst, Vector2 start, Vector2 end, Color color )
Draw line within an image
- Failure return false
- Success return true
*/
int ltexturesImageDrawLine( lua_State *L ) {
if ( !lua_isnumber( L, -4 ) || !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageDrawLine( Image dst, Vector2 start, Vector2 end, Color color )" );
lua_pushboolean( L, false );
return 1;
}
Color color = uluaGetColor( L );
lua_pop( L, 1 );
Vector2 end = uluaGetVector2( L );
lua_pop( L, 1 );
Vector2 start = uluaGetVector2( L );
lua_pop( L, 1 );
size_t imageId = lua_tointeger( L, -1 );
if ( !validImage( imageId ) ) {
lua_pushboolean( L, false );
return 1;
}
ImageDrawLineV( state->images[ imageId ], start, end, color );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_ImageDrawCircle( Image dst, Vector2 center, int radius, Color color )
Draw circle within an image
- Failure return false
- Success return true
*/
int ltexturesImageDrawCircle( lua_State *L ) {
if ( !lua_isnumber( L, -4 ) || !lua_istable( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageDrawCircle( Image dst, Vector2 center, int radius, Color color )" );
lua_pushboolean( L, false );
return 1;
}
Color color = uluaGetColor( L );
lua_pop( L, 1 );
int radius = lua_tointeger( L, -1 );
lua_pop( L, 1 );
Vector2 center = uluaGetVector2( L );
lua_pop( L, 1 );
size_t imageId = lua_tointeger( L, -1 );
if ( !validImage( imageId ) ) {
lua_pushboolean( L, false );
return 1;
}
ImageDrawCircleV( state->images[ imageId ], center, radius, color );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_ImageDrawRectangle( Image dst, Rectangle rec, Color color )
Draw rectangle within an image
- Failure return false
- Success return true
*/
int ltexturesImageDrawRectangle( lua_State *L ) {
if ( !lua_isnumber( L, -3 ) || !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageDrawRectangle( Image dst, Rectangle rec, Color color )" );
lua_pushboolean( L, false );
return 1;
}
Color color = uluaGetColor( L );
lua_pop( L, 1 );
Rectangle rec = uluaGetRectangle( L );
lua_pop( L, 1 );
size_t imageId = lua_tointeger( L, -1 );
if ( !validImage( imageId ) ) {
lua_pushboolean( L, false );
return 1;
}
ImageDrawRectangleRec( state->images[ imageId ], rec, color );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_DrawRectangleLines( Image dst, Rectangle rec, int thick, Color color )
Draw rectangle lines within an image
- Failure return false
- Success return true
*/
int ltexturesImageDrawRectangleLines( lua_State *L ) {
if ( !lua_isnumber( L, -4 ) || !lua_istable( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_DrawRectangleLines( Image dst, Rectangle rec, int thick, Color color )" );
lua_pushboolean( L, false );
return 1;
}
Color color = uluaGetColor( L );
lua_pop( L, 1 );
int thick = lua_tointeger( L, -1 );
lua_pop( L, 1 );
Rectangle rec = uluaGetRectangle( L );
lua_pop( L, 1 );
size_t imageId = lua_tointeger( L, -1 );
if ( !validImage( imageId ) ) {
lua_pushboolean( L, false );
return 1;
}
ImageDrawRectangleLines( state->images[ imageId ], rec, thick, color );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_ImageDraw( Image dst, Image src, Rectangle srcRec, Rectangle dstRec, Color tint )
Draw a source image within a destination image ( Tint applied to source )
- Failure return false
- Success return true
*/
int ltexturesImageDraw( lua_State *L ) {
if ( !lua_isnumber( L, -5 ) || !lua_isnumber( L, -4 ) || !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageDraw( Image dst, Image src, Rectangle srcRec, Rectangle dstRec, Color tint )" );
lua_pushboolean( L, false );
return 1;
}
Color tint = uluaGetColor( L );
lua_pop( L, 1 );
Rectangle dstRec = uluaGetRectangle( L );
lua_pop( L, 1 );
Rectangle srcRec = uluaGetRectangle( L );
lua_pop( L, 1 );
size_t imageSrcId = lua_tointeger( L, -1 );
lua_pop( L, 1 );
size_t imageDstId = lua_tointeger( L, -1 );
if ( !validImage( imageDstId ) || !validImage( imageSrcId ) ) {
lua_pushboolean( L, false );
return 1;
}
ImageDraw( state->images[ imageDstId ], *state->images[ imageSrcId ], srcRec, dstRec, tint );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_ImageDrawTextEx( Image dst, Font font, string text, Vector2 position, float fontSize, float spacing, Color tint )
Draw text ( Custom sprite font ) within an image ( Destination )
- Failure return false
- Success return true
*/
int ltexturesImageDrawTextEx( lua_State *L ) {
if ( !lua_isnumber( L, -7 ) || !lua_isnumber( L, -6 ) || !lua_isstring( L, -5 ) || !lua_istable( L, -4 )
|| !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ImageDrawTextEx( Image dst, Font font, string text, Vector2 position, float fontSize, float spacing, Color tint )" );
lua_pushboolean( L, false );
return 1;
}
Color tint = uluaGetColor( L );
lua_pop( L, 1 );
float spacing = lua_tonumber( L, -1 );
lua_pop( L, 1 );
float fontSize = lua_tonumber( L, -1 );
lua_pop( L, 1 );
Vector2 position = uluaGetVector2( L );
lua_pop( L, 1 );
size_t fontId = lua_tointeger( L, -2 );
size_t imageId = lua_tointeger( L, -3 );
if ( !validImage( imageId ) || !validFont( fontId ) ) {
lua_pushboolean( L, false );
return 1;
}
ImageDrawTextEx( state->images[ imageId ], *state->fonts[ fontId ], lua_tostring( L, -1 ), position, fontSize, spacing, tint );
lua_pushboolean( L, true );
return 1;
}
/*
## Textures - Texture Drawing
*/
/*
> success = RL_DrawTexture( Texture2D texture, Vector2 position, Color tint )
Draw a Texture2D
- Failure return false
- Success return true
*/
int ltexturesDrawTexture( lua_State *L ) {
if ( !lua_isnumber( L, -3 ) || !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_DrawTexture( Texture2D texture, Vector2 position, Color tint )" );
lua_pushboolean( L, false );
return 1;
}
Color color = uluaGetColor( L );
lua_pop( L, 1 );
Vector2 pos = uluaGetVector2( L );
lua_pop( L, 1 );
size_t texId = lua_tointeger( L, -1 );
if ( !validSourceTexture( texId ) ) {
lua_pushboolean( L, false );
return 1;
}
DrawTexture( *texturesGetSourceTexture( texId ), pos.x, pos.y, color );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_DrawTextureRec( Texture2D texture, Rectangle source, Vector2 position, Color tint )
Draw a part of a texture defined by a rectangle
- Failure return false
- Success return true
*/
int ltexturesDrawTextureRec( lua_State *L ) {
if ( !lua_isnumber( L, -4 ) || !lua_istable( L, -3 ) || !lua_istable( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_DrawTextureRec( Texture2D texture, Rectangle source, Vector2 position, Color tint )" );
lua_pushboolean( L, false );
return 1;
}
Color color = uluaGetColor( L );
lua_pop( L, 1 );
Vector2 pos = uluaGetVector2( L );
lua_pop( L, 1 );
Rectangle srcRect = uluaGetRectangle( L );
lua_pop( L, 1 );
size_t texId = lua_tointeger( L, -1 );
if ( !validSourceTexture( texId ) ) {
lua_pushboolean( L, false );
return 1;
}
DrawTextureRec( *texturesGetSourceTexture( texId ), srcRect, pos, color );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_DrawTextureTiled( Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, float scale, Color tint )
Draw part of a texture ( defined by a rectangle ) with rotation and scale tiled into dest
- Failure return false
- Success return true
*/
int ltexturesDrawTextureTiled( lua_State *L ) {
if ( !lua_isnumber( L, -7 ) || !lua_istable( L, -6 ) || !lua_istable( L, -5 ) || !lua_istable( L, -4 )
|| !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_DrawTextureTiled( Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, float scale, Color tint )" );
lua_pushboolean( L, false );
return 1;
}
Color color = uluaGetColor( L );
lua_pop( L, 1 );
float scale = lua_tonumber( L, -1 );
lua_pop( L, 1 );
float rot = lua_tonumber( L, -1 );
lua_pop( L, 1 );
Vector2 origin = uluaGetVector2( L );
lua_pop( L, 1 );
Rectangle dstRect = uluaGetRectangle( L );
lua_pop( L, 1 );
Rectangle srcRect = uluaGetRectangle( L );
lua_pop( L, 1 );
size_t texId = lua_tointeger( L, -1 );
if ( !validSourceTexture( texId ) ) {
lua_pushboolean( L, false );
return 1;
}
DrawTextureTiled( *texturesGetSourceTexture( texId ), srcRect, dstRect, origin, rot, scale, color );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_DrawTexturePro( Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, Color tint )
Draw a part of a texture defined by a rectangle with "pro" parameters
- Failure return false
- Success return true
*/
int ltexturesDrawTexturePro( lua_State *L ) {
if ( !lua_isnumber( L, -6 ) || !lua_istable( L, -5 ) || !lua_istable( L, -4 )
|| !lua_istable( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_DrawTexturePro( Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, Color tint )" );
lua_pushboolean( L, false );
return 1;
}
Color color = uluaGetColor( L );
lua_pop( L, 1 );
float rot = lua_tonumber( L, -1 );
lua_pop( L, 1 );
Vector2 origin = uluaGetVector2( L );
lua_pop( L, 1 );
Rectangle dstRect = uluaGetRectangle( L );
lua_pop( L, 1 );
Rectangle srcRect = uluaGetRectangle( L );
lua_pop( L, 1 );
size_t texId = lua_tointeger( L, -1 );
if ( !validSourceTexture( texId ) ) {
lua_pushboolean( L, false );
return 1;
}
DrawTexturePro( *texturesGetSourceTexture( texId ), srcRect, dstRect, origin, rot, color );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_DrawTextureNPatch( Texture2D texture, NPatchInfo nPatchInfo, Rectangle dest, Vector2 origin, float rotation, Color tint )
Draws a texture ( or part of it ) that stretches or shrinks nicely
- Failure return false
- Success return true
*/
int ltexturesDrawTextureNPatch( lua_State *L ) {
if ( !lua_isnumber( L, -6 ) || !lua_istable( L, -5 ) || !lua_istable( L, -4 )
|| !lua_istable( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_DrawTextureNPatch( Texture2D texture, NPatchInfo nPatchInfo, Rectangle dest, Vector2 origin, float rotation, Color tint )" );
lua_pushboolean( L, false );
return 1;
}
Color tint = uluaGetColor( L );
lua_pop( L, 1 );
float rotation = lua_tonumber( L, -1 );
lua_pop( L, 1 );
Vector2 origin = uluaGetVector2( L );
lua_pop( L, 1 );
Rectangle dest = uluaGetRectangle( L );
lua_pop( L, 1 );
NPatchInfo nPatchInfo = uluaGetNPatchInfo( L );
lua_pop( L, 1 );
size_t texId = lua_tointeger( L, -1 );
if ( !validSourceTexture( texId ) ) {
lua_pushboolean( L, false );
return 1;
}
DrawTextureNPatch( *texturesGetSourceTexture( texId ), nPatchInfo, dest, origin, rotation, tint );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_DrawTexturePoly( Texture2D texture, Vector2 center, Vector2{} points, Vector2{} texcoords, int pointsCount, Color tint )
Draw a textured polygon ( Convex )
- Failure return false
- Success return true
*/
int ltexturesDrawTexturePoly( lua_State *L ) {
if ( !lua_isnumber( L, -6 ) || !lua_istable( L, -5 ) || !lua_istable( L, -4 )
|| !lua_istable( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_DrawTexturePoly( Texture2D texture, Vector2 center, Vector2 points{}, Vector2 texcoords{}, int pointsCount, Color tint )" );
lua_pushboolean( L, false );
return 1;
}
Color color = uluaGetColor( L );
lua_pop( L, 1 );
int pointsCount = lua_tointeger( L, -1 );
lua_pop( L, 1 );
Vector2 texCoords[ pointsCount ];
int t = lua_gettop( L ), i = 0;
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
texCoords[i] = uluaGetVector2( L );
i++;
lua_pop( L, 1 );
}
lua_pop( L, 1 );
Vector2 points[ pointsCount ];
t = lua_gettop( L );
i = 0;
lua_pushnil( L );
while ( lua_next( L, t ) != 0 ) {
points[i] = uluaGetVector2( L );
i++;
lua_pop( L, 1 );
}
lua_pop( L, 1 );
Vector2 center = uluaGetVector2( L );
lua_pop( L, 1 );
size_t texId = lua_tointeger( L, -1 );
if ( !validSourceTexture( texId ) ) {
lua_pushboolean( L, false );
return 1;
}
DrawTexturePoly( *texturesGetSourceTexture( texId ), center, points, texCoords, pointsCount, color );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_BeginTextureMode( RenderTexture2D target )
Begin drawing to render texture
- Failure return false
- Success return true
*/
int ltexturesBeginTextureMode( lua_State *L ) {
if ( !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_BeginTextureMode( RenderTexture2D target )" );
lua_pushboolean( L, false );
return 1;
}
size_t texId = lua_tointeger( L, -1 );
if ( !validRenderTexture( texId ) ) {
lua_pushboolean( L, false );
return 1;
}
BeginTextureMode( *state->renderTextures[ texId ] );
lua_pushboolean( L, true );
return 1;
}
/*
> RL_EndTextureMode()
Ends drawing to render texture
*/
int ltexturesEndTextureMode( lua_State *L ) {
EndTextureMode();
return 1;
}
/*
> success = RL_SetTextureSource( int textureSource )
Set what texture source to use ( TEXTURE_SOURCE_TEXTURE or TEXTURE_SOURCE_RENDER_TEXTURE )
- Failure return false
- Success return true
*/
int ltexturesSetTextureSource( lua_State *L ) {
if ( !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_SetTextureSource( int textureSource )" );
lua_pushboolean( L, false );
return 1;
}
int texSource = lua_tointeger( L, -1 );
if ( texSource != TEXTURE_SOURCE_TEXTURE && texSource != TEXTURE_SOURCE_RENDER_TEXTURE ) {
TraceLog( LOG_WARNING, "%s %d", "Invalid source texture", texSource );
lua_pushboolean( L, false );
return 1;
}
state->textureSource = texSource;
lua_pushboolean( L, true );
return 1;
}
/*
> textureSource = RL_GetTextureSource()
Get current texture source type ( TEXTURE_SOURCE_TEXTURE or TEXTURE_SOURCE_RENDER_TEXTURE )
- Success return int
*/
int ltexturesGetTextureSource( lua_State *L ) {
lua_pushinteger( L, state->textureSource );
return 1;
}
/*
## Textures - Configure
*/
/*
> success = RL_GenTextureMipmaps( Texture2D texture )
Generate GPU mipmaps for a texture
- Failure return false
- Success return true
*/
int ltexturesGenTextureMipmaps( lua_State *L ) {
if ( !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GenTextureMipmaps( Texture2D texture )" );
lua_pushboolean( L, false );
return 1;
}
size_t texId = lua_tointeger( L, -1 );
if ( !validTexture( texId ) ) {
lua_pushboolean( L, false );
return 1;
}
GenTextureMipmaps( texturesGetSourceTexture( texId ) );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_SetTextureFilter( Texture2D texture, int filter )
Set texture scaling filter mode ( TEXTURE_FILTER_POINT, TEXTURE_FILTER_BILINEAR... )
- Failure return false
- Success return true
*/
int ltexturesSetTextureFilter( lua_State *L ) {
if ( !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_SetTextureFilter( Texture2D texture, int filter )" );
lua_pushboolean( L, false );
return 1;
}
size_t texId = lua_tointeger( L, -2 );
if ( !validTexture( texId ) ) {
lua_pushboolean( L, false );
return 1;
}
SetTextureFilter( *texturesGetSourceTexture( texId ), lua_tointeger( L, -1 ) );
lua_pushboolean( L, true );
return 1;
}
/*
> success = RL_SetTextureWrap( Texture2D texture, int wrap )
Set texture wrapping mode ( TEXTURE_WRAP_REPEAT, TEXTURE_WRAP_CLAMP... )
- Failure return false
- Success return true
*/
int ltexturesSetTextureWrap( lua_State *L ) {
if ( !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_SetTextureWrap( Texture2D texture, int wrap )" );
lua_pushboolean( L, false );
return 1;
}
size_t texId = lua_tointeger( L, -2 );
if ( !validTexture( texId ) ) {
lua_pushboolean( L, false );
return 1;
}
SetTextureWrap( *state->textures[ texId ], lua_tointeger( L, -1 ) );
lua_pushboolean( L, true );
return 1;
}
/*
> size = RL_GetTextureSize( Texture2D texture )
Get texture size
- Failure return nil
- Success return Vector2
*/
int ltexturesGetTextureSize( lua_State *L ) {
if ( !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetTextureSize( Texture2D texture )" );
lua_pushnil( L );
return 1;
}
size_t texId = lua_tointeger( L, -1 );
if ( !validSourceTexture( texId ) ) {
lua_pushboolean( L, false );
return 1;
}
Texture2D texture = *texturesGetSourceTexture( texId );
uluaPushVector2( L, (Vector2){ texture.width, texture.height } );
return 1;
}
/*
## Textures - Color/pixel
*/
/*
> color = RL_Fade( Color color, float alpha )
Returns color with alpha applied, alpha goes from 0.0f to 1.0f
- Failure return false
- Success return Color
*/
int ltexturesFade( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_Fade( Color color, float alpha )" );
lua_pushboolean( L, false );
return 1;
}
float alpha = lua_tonumber( L, -1 );
lua_pop( L, 1 );
Color color = uluaGetColor( L );
uluaPushColor( L, Fade( color, alpha ) );
return 1;
}
/*
> value = RL_ColorToInt( Color color )
Returns hexadecimal value for a Color
- Failure return false
- Success return int
*/
int ltexturesColorToInt( lua_State *L ) {
if ( !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ColorToInt( Color color )" );
lua_pushboolean( L, false );
return 1;
}
Color color = uluaGetColor( L );
lua_pushinteger( L, ColorToInt( color ) );
return 1;
}
/*
> color = RL_ColorNormalize( Color color )
Returns Color normalized as float [0..1]
- Failure return false
- Success return Vector4
*/
int ltexturesColorNormalize( lua_State *L ) {
if ( !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ColorNormalize( Color color )" );
lua_pushboolean( L, false );
return 1;
}
Color color = uluaGetColor( L );
uluaPushVector4( L, ColorNormalize( color ) );
return 1;
}
/*
> color = RL_ColorFromNormalized( Vector4 normalized )
Color from normalized values [0..1]
- Failure return false
- Success return Color
*/
int ltexturesColorFromNormalized( lua_State *L ) {
if ( !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ColorFromNormalized( Vector4 normalized )" );
lua_pushboolean( L, false );
return 1;
}
Vector4 normalized = uluaGetVector4( L );
uluaPushColor( L, ColorFromNormalized( normalized ) );
return 1;
}
/*
> HSV = RL_ColorToHSV( Color color )
Returns HSV values for a Color, hue [0..360], saturation/value [0..1]
- Failure return false
- Success return Vector3
*/
int ltexturesColorToHSV( lua_State *L ) {
if ( !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ColorToHSV( Color color )" );
lua_pushboolean( L, false );
return 1;
}
Color color = uluaGetColor( L );
uluaPushVector3( L, ColorToHSV( color ) );
return 1;
}
/*
> color = RL_ColorFromHSV( float hue, float saturation, float value )
Returns a Color from HSV values, hue [0..360], saturation/value [0..1]
- Failure return false
- Success return Color
*/
int ltexturesColorFromHSV( lua_State *L ) {
if ( !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ColorFromHSV( float hue, float saturation, float value )" );
lua_pushboolean( L, false );
return 1;
}
uluaPushColor( L, ColorFromHSV( lua_tonumber( L, -3 ), lua_tonumber( L, -2 ), lua_tonumber( L, -1 ) ) );
return 1;
}
/*
> color = RL_ColorAlpha( Color color, float alpha )
Returns color with alpha applied, alpha goes from 0.0f to 1.0f
- Failure return false
- Success return Color
*/
int ltexturesColorAlpha( lua_State *L ) {
if ( !lua_istable( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ColorAlpha( Color color, float alpha )" );
lua_pushboolean( L, false );
return 1;
}
float alpha = lua_tonumber( L, -1 );
lua_pop( L, 1 );
Color color = uluaGetColor( L );
uluaPushColor( L, ColorAlpha( color, alpha ) );
return 1;
}
/*
> color = RL_ColorAlphaBlend( Color dst, Color src, Color tint )
Returns src alpha-blended into dst color with tint
- Failure return false
- Success return Color
*/
int ltexturesColorAlphaBlend( lua_State *L ) {
if ( !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ColorAlphaBlend( Color dst, Color src, Color tint )" );
lua_pushboolean( L, false );
return 1;
}
Color tint = uluaGetColor( L );
lua_pop( L, 1 );
Color src = uluaGetColor( L );
lua_pop( L, 1 );
Color dst = uluaGetColor( L );
uluaPushColor( L, ColorAlphaBlend( dst, src, tint ) );
return 1;
}
/*
> Color = RL_GetColor( unsigned int hexValue )
Get Color structure from hexadecimal value
- Failure return false
- Success return Color
*/
int ltexturesGetColor( lua_State *L ) {
if ( !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetColor( unsigned int hexValue )" );
lua_pushboolean( L, false );
return 1;
}
uluaPushColor( L, GetColor( (unsigned int)lua_tointeger( L, -1 ) ) );
return 1;
}
/*
> Color = RL_GetPixelColor( Texture2D texture, Vector2 position )
Get pixel color from source texture
- Failure return false
- Success return Color
*/
int ltexturesGetPixelColor( lua_State *L ) {
if ( !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetPixelColor( Texture2D texture, Vector2 position )" );
lua_pushboolean( L, false );
return 1;
}
Vector2 pos = uluaGetVector2( L );
lua_pop( L, 1 );
size_t texId = lua_tointeger( L, -2 );
if ( !validTexture( texId ) ) {
lua_pushboolean( L, false );
return 1;
}
Texture2D *texture = texturesGetSourceTexture( texId );
Image srcImage = LoadImageFromTexture( *texture );
uluaPushColor( L, GetImageColor( srcImage, pos.x, pos.y ) );
UnloadImage( srcImage );
return 1;
}
Color GetPixelColor(void *srcPtr, int format);
/*
> size = RL_GetPixelDataSize( int width, int height, int format )
Get pixel data size in bytes for certain format
- Failure return false
- Success return int
*/
int ltexturesGetPixelDataSize( lua_State *L ) {
if ( !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetPixelDataSize( int width, int height, int format )" );
lua_pushboolean( L, false );
return 1;
}
lua_pushinteger( L, GetPixelDataSize( lua_tointeger( L, -3 ), lua_tointeger( L, -2 ), lua_tointeger( L, -1 ) ) );
return 1;
}
|