-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.c
2940 lines (2728 loc) · 89.5 KB
/
main.c
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
#include "main.h"
#include "enums.h"
#include "classes.h"
/*!MD
## Table of content
| [Core](#Core) | Core module, provides basic config, window, drawing, color manipulating etc functions.
| :------------------------------------------------------------ | :-----------------------------------------------------------
| **Window-related functions** |
| [InitWindow](#InitWindow) | Initialize window and OpenGL context
| [WindowShouldClose](#WindowShouldClose) | Check if KEY_ESCAPE pressed or Close icon pressed
| [CloseWindow](#CloseWindow) | Close window and unload OpenGL context
| [IsWindowReady](#IsWindowReady) | Check if window has been initialized successfully
| [IsWindowMinimized](#IsWindowMinimized) | Check if window has been minimized (or lost focus)
| [IsWindowResized](#IsWindowResized) | Check if window has been resized
| [IsWindowHidden](#IsWindowHidden) | Check if window is currently hidden
| [ToggleFullscreen](#ToggleFullscreen) | oggle fullscreen mode (only PLATFORM_DESKTOP)
| [UnhideWindow](#UnhideWindow) | Show the window
| [HideWindow](#HideWindow) | Hide the window
| [SetWindowIcon](#SetWindowIcon) | Set icon for window (only PLATFORM_DESKTOP)
| [SetWindowTitle](#SetWindowTitle) | Set title for window (only PLATFORM_DESKTOP)
| [SetWindowPosition](#SetWindowPosition) | Set window position on screen (only PLATFORM_DESKTOP)
| [SetWindowMonitor](#SetWindowMonitor) | Set monitor for the current window (fullscreen mode)
| [SetWindowMinSize](#SetWindowMinSize) | Set window minimum dimensions (for FLAG_WINDOW_RESIZABLE)
| [SetWindowSize](#SetWindowSize) | Set window dimensions
| [GetWindowHandle](#GetWindowHandle) | Get native window handle
| [GetScreenWidth](#GetScreenWidth) | Get current screen width
| [GetScreenHeight](#GetScreenHeight) | Get current screen height
| [GetScreenDimensions](#GetScreenDimensions) | Get current screen dimensions
| [GetMonitorCount](#GetMonitorCount) | Get number of connected monitors
| [GetMonitorWidth](#GetMonitorWidth) | Get selected monitor width
| [GetMonitorHeight](#GetMonitorHeight) | Get selected monitor height
| [GetMonitorDimensions](#GetMonitorDimensions) | Get selected monitor dimensions
| [GetMonitorPhysicalWidth](#GetMonitorPhysicalWidth) | Get selected monitor physical width in millimetres
| [GetMonitorPhysicalHeight](#GetMonitorPhysicalHeight) | Get selected monitor physical height in millimetres
| [GetMonitorPhysicalDimensions](#GetMonitorPhysicalDimensions) | Get selected monitor physical dimensions in millimetres
| [GetMonitors](#GetMonitors) | Get all currently available monitor stats
| [GetWindowPosition](#GetWindowPosition) | Get window position XY on monitor
| [GetMonitorName](#GetMonitorName) | Get the human-readable, UTF-8 encoded name of the primary monitor
| [GetClipboardText](#GetClipboardText) | Get clipboard text content
| [SetClipboardText](#SetClipboardText) | Set clipboard text content
| **Cursor-related functions** |
| [ShowCursor](#ShowCursor) | Shows cursor
| [HideCursor](#HideCursor) | Hides cursor
| [IsCursorHidden](#IsCursorHidden) | Check if cursor is not visible
| [EnableCursor](#EnableCursor) | Enables cursor (unlock cursor)
| [DisableCursor](#DisableCursor) | Disables cursor (lock cursor)
| **Drawing-related functions** |
| [ClearBackground](#ClearBackground) | Set background color (framebuffer clear color)
| [BeginDrawing](#BeginDrawing) | Setup canvas (framebuffer) to start drawing
| [EndDrawing](#EndDrawing) | End canvas drawing and swap buffers (double buffering)
| [BeginMode2D](#BeginMode2D) | Initialize 2D mode with custom camera (2D)
| [EndMode2D](#EndMode2D) | Ends 2D mode with custom camera
| [BeginMode3D](#BeginMode3D) | Initializes 3D mode with custom camera (3D)
| [EndMode3D](#EndMode3D) | Ends 3D mode and returns to default 2D orthographic mode
| [BeginTextureMode](#BeginTextureMode) | Initializes render texture for drawing
| [EndTextureMode](#EndTextureMode) | Ends drawing to render texture
| [BeginScissorMode](#BeginScissorMode) | Begin scissor mode (define screen area for following drawing)
| [EndScissorMode](#EndScissorMode) | End scissor mode
| **Screen-space-related functions** |
| [GetMouseRay](#GetMouseRay) | Returns a ray trace from mouse position
| [GetCameraMatrix](#GetCameraMatrix) | Returns camera transform matrix (view matrix)
| [GetCameraMatrix2D](#GetCameraMatrix2D) | Returns camera 2d transform matrix
| [GetWorldToScreen](#GetWorldToScreen) | Returns the screen space position for a 3d world space position
| [GetWorldToScreenEx](#GetWorldToScreenEx) | Returns size position for a 3d world space position
| [GetWorldToScreen2D](#GetWorldToScreen2D) | Returns the screen space position for a 2d camera world space position
| [GetScreenToWorld2D](#GetScreenToWorld2D) | Returns the world space position for a 2d camera screen space position
| **Timing-related functions** |
| [SetTargetFPS](#SetTargetFPS) | Set target FPS (maximum)
| [GetFPS](#GetFPS) | Returns current FPS
| [GetFrameTime](#GetFrameTime) | Returns time in seconds for last frame drawn (delta time)
| [GetTime](#GetTime) | Returns elapsed time in seconds since InitWindow()
| **Color-related functions** |
| [ColorToInt](#ColorToInt) | Returns hexadecimal value for a Color
| [ColorNormalize](#ColorNormalize) | Returns color normalized as float [0..1]
| [ColorFromNormalized](#ColorFromNormalized) | Returns color from normalized values [0..1]
| [ColorToHSV](#ColorToHSV) | Returns HSV values for a Color
| [ColorFromHSV](#ColorFromHSV) | Returns a Color from HSV values
| [GetColor](#GetColor) | Returns a Color struct from hexadecimal value
| [Fade](#Fade) | Color fade-in or fade-out, alpha goes from 0.0f to 1.0f
| **Misc. functions** |
| [SetConfigFlags](#SetConfigFlags) | Setup window configuration flags
| [SetTraceLogLevel](#SetTraceLogLevel) | Set the current threshold (minimum) log level
| [SetTraceLogExit](#SetTraceLogExit) | Set the exit threshold (minimum) log level
| [SetTraceLogCallback](#SetTraceLogCallback) | Set a trace log callback to enable custom logging
| [TraceLog](#TraceLog) | Show trace log messages (DEBUG, INFO, WARNING, ERROR)
| [TakeScreenshot](#TakeScreenshot) | Takes a screenshot of current screen (saved a .png)
| [GetRandomValue](#GetRandomValue) | Returns a random value between min and max (both included)
| **Files management functions** |
| [FileExists](#FileExists) | Check if file exists
| [IsFileExtension](#IsFileExtension) | Check file extension
| [DirectoryExists](#DirectoryExists) | Check if a directory path exists
| [GetExtension](#GetExtension) | Get string extension for a filename string
| [GetFileName](#GetFileName) | Get string filename for a path string
| [GetFileNameWithoutExt](#GetFileNameWithoutExt) | Get filename string without extension
| [GetDirectoryPath](#GetDirectoryPath) | Get full path for a given fileName with path
| [GetPrevDirectoryPath](#GetPrevDirectoryPath) | Get previous directory path for a given path
| [GetWorkingDirectory](#GetWorkingDirectory) | Get current working directory
| [GetDirectoryFiles](#GetDirectoryFiles) | Get filenames in a directory path
| [ClearDirectoryFiles](#ClearDirectoryFiles) | Clear directory files paths buffers (deprecated)
| [ChangeDirectory](#ChangeDirectory) | Change working directory, returns true if success
| [IsFileDropped](#IsFileDropped) | Check if a file has been dropped into window
| [GetDroppedFiles](#GetDroppedFiles) | Get dropped files names
| [ClearDroppedFiles](#ClearDroppedFiles) | Clear dropped files paths buffer
| [GetFileModTime](#GetFileModTime) | Get file modification time (last write time)
| [GetFileInfo](#GetFileInfo) | Get info table for a given path
| [CompressData](#CompressData) | Compress data (DEFLATE algorythm)
| [DecompressData](#DecompressData) | Decompress data (DEFLATE algorythm)
| [OpenURL](#OpenURL) | Open URL with default system browser (if available)
| **Persistent storage management** |
| [StorageSaveValue](#StorageSaveValue) | Save integer value to storage file (to defined position)
| [StorageLoadValue](#StorageLoadValue) | Load integer value from storage file (from defined position)
| **Input-related functions: keyboard** |
| [IsKeyPressed](#IsKeyPressed) | Detect if a key has been pressed once
| [IsKeyDown](#IsKeyDown) | Detect if a key is being pressed
| [IsKeyReleased](#IsKeyReleased) | Detect if a key has been released once
| [IsKeyUp](#IsKeyUp) | Detect if a key is NOT being pressed
| [GetKeyPressed](#GetKeyPressed) | Get latest key pressed (scancode)
| [GetKeyPressedString](#GetKeyPressedString) | Get latest key pressed (UTF-8 encoded)
| [GetAllKeysPressedString](#GetAllKeysPressedString) | Get all latest keys pressed (UTF-8 encoded)
| [SetExitKey](#SetExitKey) | Set a custom key to exit program (default is ESC)
| **Input-related functions: gamepads** |
| [IsGamepadAvailable](#IsGamepadAvailable) | Detect if a gamepad is available
| [IsGamepadName](#IsGamepadName) | Check gamepad name (if available)
| [GetGamepadName](#GetGamepadName) | Return gamepad internal name id
| [IsGamepadButtonPressed](#IsGamepadButtonPressed) | Detect if a gamepad button has been pressed once
| [IsGamepadButtonDown](#IsGamepadButtonDown) | Detect if a gamepad button is being pressed
| [IsGamepadButtonReleased](#IsGamepadButtonReleased) | Detect if a gamepad button has been released once
| [IsGamepadButtonUp](#IsGamepadButtonUp) | Detect if a gamepad button is NOT being pressed
| [GetGamepadButtonPressed](#GetGamepadButtonPressed) | Get the last gamepad button pressed
| [GetGamepadAxisCount](#GetGamepadAxisCount) | Return gamepad axis count for a gamepad
| [GetGamepadAxisMovement](#GetGamepadAxisMovement) | Return axis movement value for a gamepad axis
| **Input-related functions: mouse** |
| [IsMouseButtonPressed](#IsMouseButtonPressed) | Detect if a mouse button has been pressed once
| [IsMouseButtonDown](#IsMouseButtonDown) | Detect if a mouse button is being pressed
| [IsMouseButtonReleased](#IsMouseButtonReleased) | Detect if a mouse button has been released once
| [IsMouseButtonUp](#IsMouseButtonUp) | Detect if a mouse button is NOT being pressed
| [GetMouseX](#GetMouseX) | Returns mouse position X
| [GetMouseY](#GetMouseY) | Returns mouse position Y
| [GetMousePosition](#GetMousePosition) | Returns mouse position XY
| [SetMousePosition](#SetMousePosition) | Set mouse position XY
| [SetMouseOffset](#SetMouseOffset) | Set mouse offset
| [SetMouseScale](#SetMouseScale) | Set mouse scaling
| [GetMouseWheelMove](#GetMouseWheelMove) | Returns mouse wheel movement Y
| **Input-related functions: touch** |
| [GetTouchX](#GetTouchX) | Returns touch position X for touch point 1 (relative to screen size)
| [GetTouchY](#GetTouchY) | Returns touch position Y for touch point 1 (relative to screen size)
| [GetTouch](#GetTouch) | Returns touch position XY for touch point 1 (relative to screen size)
| [GetTouchPosition](#GetTouchPosition) | Returns touch position XY for a touch point index (relative to screen size)
| [GetTouches](#GetTouches) | Returns all available touches positions XY (relative to screen size)
| [SetGesturesEnabled](#SetGesturesEnabled) | Enable a set of gestures using flags
| [IsGestureDetected](#IsGestureDetected) | Check if a gesture have been detected
| [GetGestureDetected](#GetGestureDetected) | Get latest detected gesture
| [GetTouchPointsCount](#GetTouchPointsCount) | Get touch points count
| [GetGestureHoldDuration](#GetGestureHoldDuration) | Get gesture hold time in milliseconds
| [GetGestureDragVector](#GetGestureDragVector) | Get gesture drag vector
| [GetGestureDragAngle](#GetGestureDragAngle) | Get gesture drag angle
| [GetGesturePinchVector](#GetGesturePinchVector) | Get gesture pinch delta
| [GetGesturePinchAngle](#GetGesturePinchAngle) | Get gesture pinch angle
| **Camera System Functions** |
| [SetCameraMode](#SetCameraMode) | Set camera mode (multiple camera modes available)
| [UpdateCamera](#UpdateCamera) | Update camera position for selected mode
| [SetCameraPanControl](#SetCameraPanControl) | Set camera pan key to combine with mouse movement (free camera)
| [SetCameraAltControl](#SetCameraAltControl) | Set camera alt key to combine with mouse movement (free camera)
| [SetCameraSmoothZoomControl](#SetCameraSmoothZoomControl) | Set camera smooth zoom key to combine with mouse (free camera)
| [SetCameraMoveControls](#SetCameraMoveControls) | Set camera move controls (1st person and 3rd person cameras)
| [Shapes](#Shapes) | Description
| :-------------------- | :------------
| -- | --
| [Textures](#Textures) | Description
| :-------------------- | :------------
| -- | --
| [Text](#Text) | Description
| :-------------------- | :------------
| -- | --
| [Models](#Models) | Description
| :-------------------- | :------------
| -- | --
| [Shaders](#Shaders) | Description
| :-------------------- | :------------
| -- | --
| [Audio](#Audio) | Description
| :-------------------- | :------------
| -- | --
| [Classes](#Classes) | Description
| :-------------------- | :------------
| [Vector2](#Vector2) | Vector2 type
| [Vector3](#Vector3) | Vector3 type
| [Vector4](#Vector4) | Vector4 (Quaternion) type
| [Matrix](#Matrix) | Matrix type (OpenGL style 4x4)
| [Color](#Color) | Color type, RGBA (32bit)
| [Rectangle](#Rectangle) | Rectangle type
| [Image](#Image) | Image type (multiple pixel formats supported), stored in CPU memory (RAM)
| [Texture](#Texture) | Texture type (multiple internal formats supported), stored in GPU memory (VRAM)
| [RenderTexture](#RenderTexture) | RenderTexture type, for texture rendering
| [NPatchInfo](#NPatchInfo) | N-Patch layout info
| [CharInfo](#CharInfo) | Font character info
| [Font](#Font) | Font type, includes texture and chars data
| [Camera](#Camera3D) | Camera3D type, defines 3d camera position/orientation
| [Camera2D](#Camera2D) | Camera2D type, defines a 2d camera
| [Mesh](#Mesh) | Vertex data definning a mesh
| [Shader](#Shader) | Shader type (generic shader)
| [MaterialMap](#MaterialMap) | Material texture map
| [Material](#Material) | Material type
| [Model](#Model) | Basic 3d Model type
| [Transform](#Transform) | Transformation (used for bones)
| [BoneInfo](#BoneInfo) | Bone information
| [ModelAnimation](#ModelAnimation) | Model animation data (bones and frames)
| [Ray](#Ray) | Ray type (useful for raycast)
| [RayHitInfo](#RayHitInfo) | Raycast hit information
| [BoundingBox](#BoundingBox) | Bounding box type for 3d mesh
| [Wave](#Wave) | Wave type, defines audio wave data
| [Sound](#Sound) | Basic Sound source and buffer
| [Music](#Music) | Music type (file streaming from memory)
| [AudioStream](#AudioStream) | Raw audio stream type
| [VrDeviceInfo](#VrDeviceInfo) | VR device parameters
*/
// Modules
/*!MD
## Core
### Core functions
#### Initialization
```lua
local rl = require("raylib_luamore")
```
*/
/*!MD
### Window-related functions:
#### InitWindow
```lua
rl.core.InitWindow(integer Width, integer Height, string Title)
```
Initialize window and OpenGL context
Should be called before any widnow stuff is used.
* Default Width is 800
* Default Height is 600
* Default Title is "Untitled"
*/
int lua_core_InitWindow(lua_State *L){
int w = luax_optnumber(L, 1, 800);
int h = luax_optnumber(L, 2, 600);
const char * title = luax_optstring(L, 3, "Untitled");
InitWindow(w, h, title);
return 0;
}
/*!MD
#### WindowShouldClose
```lua
boolean Status = rl.core.WindowShouldClose()
```
Check if ESCAPE-key pressed or Close icon pressed.
See [SetExitKey](#SetExitKey).
*/
int lua_core_WindowShouldClose(lua_State *L){
lua_pushboolean(L, WindowShouldClose());
return 1;
}
/*!MD
#### CloseWindow
```lua
rl.core.CloseWindow()
```
Close window and unload OpenGL context.
*/
int lua_core_CloseWindow(lua_State *L){
CloseWindow();
return 0;
}
/*!MD
#### IsWindowReady
```lua
boolean Status = rl.core.IsWindowReady()
```
Check if window has been initialized successfully.
*/
int lua_core_IsWindowReady(lua_State *L){
lua_pushboolean(L, IsWindowReady());
return 1;
}
/*!MD
#### IsWindowMinimized
```lua
boolean Status = rl.core.IsWindowMinimized()
```
Check if window has been minimized (or lost focus).
*/
int lua_core_IsWindowMinimized(lua_State *L){
lua_pushboolean(L, IsWindowMinimized());
return 1;
}
/*!MD
#### IsWindowResized
```lua
boolean Status = rl.core.IsWindowResized()
```
Check if window has been resized.
*/
int lua_core_IsWindowResized(lua_State *L){
lua_pushboolean(L, IsWindowResized());
return 1;
}
/*!MD
#### IsWindowHidden
```lua
boolean Status = rl.core.IsWindowHidden()
```
Check if window is currently hidden.
*/
int lua_core_IsWindowHidden(lua_State *L){
lua_pushboolean(L, IsWindowHidden());
return 1;
}
/*!MD
#### ToggleFullscreen
```lua
rl.core.ToggleFullscreen()
```
Toggle fullscreen mode (only PLATFORM_DESKTOP).
*/
int lua_core_ToggleFullscreen(lua_State *L){
ToggleFullscreen();
return 0;
}
/*!MD
#### UnhideWindow
```lua
rl.core.UnhideWindow()
```
Show the window.
*/
int lua_core_UnhideWindow(lua_State *L){
UnhideWindow();
return 0;
}
/*!MD
#### HideWindow
```lua
rl.core.HideWindow()
```
Hide the window.
*/
int lua_core_HideWindow(lua_State *L){
HideWindow();
return 0;
}
/*!MD
#### SetWindowIcon
```lua
rl.core.SetWindowIcon(Image Icon)
```
Set icon for window (only PLATFORM_DESKTOP).
See [Image](#Image).
*/
int lua_core_SetWindowIcon(lua_State *L){
Image* i = (Image*)luaL_checkudata(L, 1, "Image");
SetWindowIcon(*i);
return 0;
}
/*!MD
#### SetWindowTitle
```lua
rl.core.SetWindowTitle(string Title)
```
Set title for window (only PLATFORM_DESKTOP).
*/
int lua_core_SetWindowTitle(lua_State *L){
SetWindowTitle(luaL_checkstring(L, 1));
return 0;
}
/*!MD
#### SetWindowPosition
```lua
rl.core.SetWindowPosition(integer x, integer y)
```
Set window position on screen (only PLATFORM_DESKTOP).
*/
int lua_core_SetWindowPosition(lua_State *L){
SetWindowPosition(luaL_checkinteger(L, 1), luaL_checkinteger(L, 2));
return 0;
}
/*!MD
#### SetWindowMonitor
```lua
rl.core.SetWindowMonitor(integer Monitor)
```
Set monitor for the current window (fullscreen mode).
*/
int lua_core_SetWindowMonitor(lua_State *L){
SetWindowMonitor(luaL_checkinteger(L, 1) - 1);
return 0;
}
/*!MD
#### SetWindowMinSize
```lua
rl.core.SetWindowMinSize(integer Width, integer Height)
```
Set window minimum dimensions, for flag ["WINDOW_RESIZABLE"](#SetConfigFlags).
*/
int lua_core_SetWindowMinSize(lua_State *L){
SetWindowMinSize(luaL_checkinteger(L, 1), luaL_checkinteger(L, 2));
return 0;
}
/*!MD
#### SetWindowSize
```lua
rl.core.SetWindowSize(integer Width, integer Height)
```
Set window dimensions.
*/
int lua_core_SetWindowSize(lua_State *L){
SetWindowSize(luaL_checkinteger(L, 1), luaL_checkinteger(L, 2));
return 0;
}
/*!MD
#### GetWindowHandle
```lua
userdata Handle = rl.core.GetWindowHandle()
```
Get native window handle.
Use for FFI or something.
*/
int lua_core_GetWindowHandle(lua_State *L){
void* h = GetWindowHandle();
lua_pushlightuserdata(L, h);
return 1;
}
/*!MD
#### GetScreenWidth
```lua
integer Width = rl.core.GetScreenWidth()
```
Get current screen width.
*/
int lua_core_GetScreenWidth(lua_State *L){
lua_pushnumber(L, GetScreenWidth());
return 1;
}
/*!MD
#### GetScreenHeight
```lua
integer Height = rl.core.GetScreenHeight()
```
Get current screen height.
*/
int lua_core_GetScreenHeight(lua_State *L){
lua_pushnumber(L, GetScreenHeight());
return 1;
}
/*!MD
#### GetScreenDimensions
```lua
integer Width, integer Height = rl.core.GetScreenDimensions()
```
Get current screen dimensions.
*/
int lua_core_GetScreenDimensions(lua_State *L){
lua_pushnumber(L, GetScreenWidth());
lua_pushnumber(L, GetScreenHeight());
return 2;
}
/*!MD
#### GetMonitorCount
```lua
integer Count = rl.core.GetMonitorCount()
```
Get number of connected monitors.
*/
int lua_core_GetMonitorCount(lua_State *L){
lua_pushnumber(L, GetMonitorCount());
return 1;
}
/*!MD
#### GetMonitorWidth
```lua
integer Width = rl.core.GetMonitorWidth(integer Monitor)
```
Get selected monitor width.
*/
int lua_core_GetMonitorWidth(lua_State *L){
lua_pushnumber(L, GetMonitorWidth(luaL_checkinteger(L, 1) + 1));
return 1;
}
/*!MD
#### GetMonitorHeight
```lua
integer Height = rl.core.GetMonitorHeight(integer Monitor)
```
Get selected monitor height.
*/
int lua_core_GetMonitorHeight(lua_State *L){
lua_pushnumber(L, GetMonitorHeight(luaL_checkinteger(L, 1) + 1));
return 1;
}
/*!MD
#### GetMonitorDimensions
```lua
integer Width, integer Height = rl.core.GetMonitorDimensions(integer Monitor)
```
Get selected monitor dimensions.
*/
int lua_core_GetMonitorDimensions(lua_State *L){
lua_pushnumber(L, GetMonitorWidth(luaL_checkinteger(L, 1) + 1));
lua_pushnumber(L, GetMonitorHeight(luaL_checkinteger(L, 1) + 1));
return 2;
}
/*!MD
#### GetMonitorPhysicalWidth
```lua
integer Width = rl.core.GetMonitorPhysicalWidth(integer Monitor)
```
Get selected monitor physical width in millimetres.
*/
int lua_core_GetMonitorPhysicalWidth(lua_State *L){
lua_pushnumber(L, GetMonitorPhysicalWidth(luaL_checkinteger(L, 1) + 1));
return 1;
}
/*!MD
#### GetMonitorPhysicalHeight
```lua
integer Height = rl.core.GetMonitorPhysicalHeight(integer Monitor)
```
Get selected monitor physical height in millimetres.
*/
int lua_core_GetMonitorPhysicalHeight(lua_State *L){
lua_pushnumber(L, GetMonitorPhysicalHeight(luaL_checkinteger(L, 1) + 1));
return 1;
}
/*!MD
#### GetMonitorPhysicalDimensions
```lua
integer Width, integer Height = rl.core.GetMonitorPhysicalDimensions(integer Monitor)
```
Get selected monitor physical dimensions in millimetres.
*/
int lua_core_GetMonitorPhysicalDimensions(lua_State *L){
lua_pushnumber(L, GetMonitorPhysicalWidth(luaL_checkinteger(L, 1) + 1));
lua_pushnumber(L, GetMonitorPhysicalHeight(luaL_checkinteger(L, 1) + 1));
return 2;
}
/*!MD
#### GetMonitors
```lua
table Monitors = rl.core.GetMonitors()
```
Get all monitors and it's stats, using this layout:
```lua
Monitors = {
{ -- first monitor info
string name, -- human-readable monitor name
integer width, -- monitor width in pixels
integer height -- monitor height in pixels
integer pwidth, -- monitor physical width in millimetres
integer pheight, -- monitor physical height in millimetres
},
{ -- second monitor
}
}
```
*/
int lua_core_GetMonitors(lua_State *L){
lua_newtable(L);
for (int i = 0; i < GetMonitorCount(); i++) {
lua_pushinteger(L, i + 1);
lua_newtable(L);
luax_tsnumber(L, "width", GetMonitorWidth(i));
luax_tsnumber(L, "height", GetMonitorHeight(i));
luax_tsnumber(L, "pwidth", GetMonitorPhysicalWidth(i));
luax_tsnumber(L, "pheight", GetMonitorPhysicalHeight(i));
luax_tsstring(L, "name", GetMonitorName(i));
lua_rawset(L, -3);
}
return 1;
}
/*!MD
#### GetWindowPosition
```lua
Vector2 Position = rl.core.GetWindowPosition()
```
Get window position XY on monitor.
See [Vector2](#Vector2).
*/
int lua_core_GetWindowPosition(lua_State *L){
Vector2 * v = luax_newobject(L, "Vector2", sizeof(Vector2));
*v = GetWindowPosition();
return 1;
}
/*!MD
#### GetMonitorName
```lua
string Name = rl.core.GetMonitorName()
```
Get the human-readable, UTF-8 encoded name of the primary monitor.
*/
int lua_core_GetMonitorName(lua_State *L){
lua_pushstring(L, GetMonitorName(luaL_checkinteger(L, 1)));
return 1;
}
/*!MD
#### GetClipboardText
```lua
string Text = rl.core.GetClipboardText()
```
Get clipboard text content.
*/
int lua_core_GetClipboardText(lua_State *L){
lua_pushstring(L, GetClipboardText());
return 1;
}
/*!MD
#### SetClipboardText
```lua
rl.core.SetClipboardText(string Text)
```
Set clipboard text content.
*/
int lua_core_SetClipboardText(lua_State *L){
SetClipboardText(luaL_checkstring(L, 1));
return 0;
}
/*!MD
### Cursor-related functions
#### ShowCursor
```lua
rl.core.ShowCursor()
```
Shows cursor.
*/
int lua_core_ShowCursor(lua_State* L) {
ShowCursor();
return 0;
}
/*!MD
#### HideCursor
```lua
rl.core.HideCursor()
```
Hides cursor.
*/
int lua_core_HideCursor(lua_State* L) {
HideCursor();
return 0;
}
/*!MD
#### IsCursorHidden
```lua
boolean Status = rl.core.IsCursorHidden()
```
Check if cursor is not visible.
*/
int lua_core_IsCursorHidden(lua_State* L) {
lua_pushboolean(L, IsCursorHidden());
return 1;
}
/*!MD
#### EnableCursor
```lua
rl.core.EnableCursor()
```
Enables cursor (unlock cursor).
*/
int lua_core_EnableCursor(lua_State* L) {
EnableCursor();
return 0;
}
/*!MD
#### DisableCursor
```lua
rl.core.DisableCursor()
```
Disables cursor (lock cursor).
*/
int lua_core_DisableCursor(lua_State* L) {
DisableCursor();
return 0;
}
/*!MD
### Drawing-related functions
#### ClearBackground
```lua
rl.core.ClearBackground(Color Color)
```
Set background color (framebuffer clear color).
See [Color](#Color).
*/
int lua_core_ClearBackground(lua_State *L){
Color * c = luaL_checkudata(L, 1, "Color");
ClearBackground(*c);
return 0;
}
/*!MD
#### BeginDrawing
```lua
rl.core.BeginDrawing()
```
Setup canvas (framebuffer) to start drawing.
*/
int lua_core_BeginDrawing(lua_State *L){
BeginDrawing();
return 0;
}
/*!MD
#### EndDrawing
```lua
rl.core.EndDrawing()
```
End canvas drawing and swap buffers (double buffering).
*/
int lua_core_EndDrawing(lua_State *L){
EndDrawing();
return 0;
}
/*!MD
#### BeginMode2D
```lua
rl.core.BeginMode2D(Camera2D Camera)
```
Initialize 2D mode with custom camera (2D).
See [Camera2D](#Camera2D).
*/
int lua_core_BeginMode2D(lua_State *L){
Camera2D * c = luaL_checkudata(L, 1, "Camera2D");
BeginMode2D(*c);
return 0;
}
/*!MD
#### EndMode2D
```lua
rl.core.EndMode2D()
```
Ends 2D mode with custom camera.
*/
int lua_core_EndMode2D(lua_State *L){
EndMode2D();
return 0;
}
/*!MD
#### BeginMode3D
```lua
rl.core.BeginMode3D(Camera3D Camera)
```
Initializes 3D mode with custom camera (3D).
See [Camera3D](#Camera3D).
*/
int lua_core_BeginMode3D(lua_State *L){
Camera3D * c = luaL_checkudata(L, 1, "Camera3D");
BeginMode3D(*c);
return 0;
}
/*!MD
#### EndMode3D
```lua
rl.core.EndMode3D()
```
Ends 3D mode and returns to default 2D orthographic mode.
*/
int lua_core_EndMode3D(lua_State *L){
EndMode3D();
return 0;
}
/*!MD
#### BeginTextureMode
```lua
rl.core.BeginTextureMode(RenderTexture Texture)
```
Initializes render texture for drawing.
See [RenderTexture](#RenderTexture).
*/
int lua_core_BeginTextureMode(lua_State *L){
RenderTexture2D * t = luaL_checkudata(L, 1, "RenderTexture");
BeginTextureMode(*t);
return 0;
}
/*!MD
#### EndTextureMode
```lua
rl.core.EndTextureMode()
```
Ends drawing to render texture.
*/
int lua_core_EndTextureMode(lua_State *L){
EndTextureMode();
return 0;
}
/*!MD
#### BeginScissorMode
```lua
rl.core.BeginScissorMode(integer X, integer Y, integer Width, integer Height)
```
Begin scissor mode (define screen area for following drawing).
*/
int lua_core_BeginScissorMode(lua_State *L){
int x = luaL_checkinteger(L, 1);
int y = luaL_checkinteger(L, 2);
int w = luaL_checkinteger(L, 3);
int h = luaL_checkinteger(L, 4);
BeginScissorMode(x, y, w, h);
return 0;
}
/*!MD
#### EndScissorMode
```lua
rl.core.EndScissorMode()
```
End scissor mode.
*/
int lua_core_EndScissorMode(lua_State *L){
EndScissorMode();
return 0;
}
/*!MD
### Screen-space-related functions
#### GetMouseRay
```lua
-- variants
Ray Ray = rl.core.GetMouseRay(Vector2 Vector, Camera3D Camera)
Vector2 Position, Vector2 Direction = rl.core.GetMouseRay(Vector2 Vector, Camera3D Camera, "v")
```
Returns a ray trace from mouse position.
See [Ray](#Ray), [Vector2](#Vector2).
*/
int lua_core_GetMouseRay(lua_State *L){
Vector2 * v = luaL_checkudata(L, 1, "Vector2");
Camera3D * c = luaL_checkudata(L, 2, "Camera3D");
if (luax_optstring(L, 3, "\0")[0] == 'v') {
Ray r = GetMouseRay(*v, *c);
Vector3 * position = luax_newobject(L, "Vector3", sizeof(Vector3));
Vector3 * direction = luax_newobject(L, "Vector3", sizeof(Vector3));
*position = r.position;
*direction = r.direction;
return 2;
}
Ray * r = luax_newobject(L, "Ray", sizeof(Ray));
*r = GetMouseRay(*v, *c);
return 1;
}
/*!MD
#### GetCameraMatrix
```lua
Matrix View = rl.core.GetCameraMatrix(Camera3D Camera)
```
Returns camera transform matrix (view matrix).
See [Matrix](#Matrix).
*/
int lua_core_GetCameraMatrix(lua_State *L){
Camera3D * c = luaL_checkudata(L, 1, "Camera3D");
Matrix * m = luax_newobject(L, "Matrix", sizeof(Matrix));
*m = GetCameraMatrix(*c);
return 1;
}
/*!MD
#### GetCameraMatrix2D
```lua
Matrix View = rl.core.GetCameraMatrix2D(Camera2D Camera)
```
Returns camera 2d transform matrix.
See [Matrix](#Matrix), [Camera2D](#Camera2D).
*/
int lua_core_GetCameraMatrix2D(lua_State *L){
Camera2D * c = luaL_checkudata(L, 1, "Camera2D");
Matrix * m = luax_newobject(L, "Matrix", sizeof(Matrix));
*m = GetCameraMatrix2D(*c);
return 1;
}
/*!MD
#### GetWorldToScreen
```lua
Vector2 ScreenV = rl.core.GetWorldToScreen(Vector3 Vector, Camera3D Camera)
```
Returns the screen space position for a 3d world space position.
See [Vector2](#Vector2), [Vector3](#Vector3), [Camera3D](#Camera3D).
*/
int lua_core_GetWorldToScreen(lua_State *L){
Vector3 * v = luaL_checkudata(L, 1, "Vector3");
Camera3D * c = luaL_checkudata(L, 2, "Camera3D");
Vector2 * p = luax_newobject(L, "Vector2", sizeof(Vector2));
*p = GetWorldToScreen(*v, *c);
return 1;
}
/*!MD
#### GetWorldToScreenEx
```lua
Vector2 ScreenV = rl.core.GetWorldToScreenEx(Vector3 Vector, Camera3D Camera, integer Width, integer Height)
```
Returns size position for a 3d world space position.
See [Vector2](#Vector2), [Vector3](#Vector3), [Camera3D](#Camera3D).
*/
int lua_core_GetWorldToScreenEx(lua_State *L){
Vector3 * v = luaL_checkudata(L, 1, "Vector3");
Camera3D * c = luaL_checkudata(L, 2, "Camera3D");
int w = luaL_checkinteger(L, 3);
int h = luaL_checkinteger(L, 4);
Vector2 * p = luax_newobject(L, "Vector2", sizeof(Vector2));
*p = GetWorldToScreenEx(*v, *c, w, h);
return 1;
}
/*!MD
#### GetWorldToScreen2D
```lua
Vector2 ScreenV = rl.core.GetWorldToScreen2D(Vector2 Vector, Camera2D Camera)
```
Returns the screen space position for a 2d camera world space position.
See [Vector2](#Vector2), [Camera2D](#Camera2D).
*/
int lua_core_GetWorldToScreen2D(lua_State *L){
Vector2 * v = luaL_checkudata(L, 1, "Vector2");
Camera2D * c = luaL_checkudata(L, 2, "Camera2D");
Vector2 * p = luax_newobject(L, "Vector2", sizeof(Vector2));
*p = GetWorldToScreen2D(*v, *c);
return 1;
}
/*!MD
#### GetScreenToWorld2D
```lua
Vector2 ScreenV = rl.core.GetScreenToWorld2D(Vector2 Vector, Camera2D Camera)
```
Returns the world space position for a 2d camera screen space position.
See [Vector2](#Vector2), [Camera2D](#Camera2D).
*/
int lua_core_GetScreenToWorld2D(lua_State *L){
Vector2 * v = luaL_checkudata(L, 1, "Vector2");
Camera2D * c = luaL_checkudata(L, 2, "Camera2D");
Vector2 * p = luax_newobject(L, "Vector2", sizeof(Vector2));
*p = GetScreenToWorld2D(*v, *c);
return 1;
}
/*!MD
### Timing-related functions
#### SetTargetFPS
```lua
rl.core.SetTargetFPS(integer FPS)
```