-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathraylib3-helpers.fs
321 lines (218 loc) · 9.62 KB
/
raylib3-helpers.fs
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
require raylib3.fs
\ Example helpers for moving data from the stack to structures
\ or back. Will add more as I need them.
: Vector2> ( Vector2 -- f: -- x y )
dup dup sf@ Vector2-y sf@
free throw ;
: >Vector2 ( f: -- x y -- Vector2 )
Vector2 allocate throw
dup dup sf! Vector2-y sf! ;
: >Vector3 ( f: -- x y z -- Vector3 )
Vector3 allocate throw { Vec3 }
Vec3 Vector3-z sf!
Vec3 Vector3-y sf!
Vec3 sf! Vec3 ;
: Vector3> ( Vector3 -- f: -- x y z )
{ Vec3 }
Vec3 sf@
Vec3 Vector3-y sf@
Vec3 Vector3-z sf@ ;
\ -----------------------------------------------------------
\ raycall will allocate a structure of the type it is sent
\ and sends this empty structure along with the function call.
\ The function will "fill up" the structure and return a pointer
\ instead of the structure as it does in the original raylib.
\ This is because Gforth can't return structures.
\ Notice I do NOT call free at any point in these.
\ You have to handle the memory management on the Forth side
\ with this method. (Which is fine because you have the addr
\ to free.)
\ This is trying to be as unopinionated as possible
\ so you can implement your own way of doing things.
\ if you need to see the what the return type of the word is
\ simply call "see" on it. The word before "raycall" is the
\ structure type being returned as an address.
\ Any parameters prefixed with f- indicated a float value.
\ Everything else is either an int or the name of a structure
\ like color, vector2/vec2, etc
: raycall ( xt type -- addr )
allocate throw swap execute ;
: GetMonitorPosition ( #monitor -- vec2 )
['] iGetMonitorPosition Vector2 raycall ;
: GetWindowPosition ( -- vec2 )
['] iGetWindowPosition Vector2 raycall ;
: GetWindowScaleDPI ( -- vec2 )
['] iGetWindowScaleDPI Vector2 raycall ;
: GetMouseRay ( Vector2 Camera3d -- Ray )
['] iGetMouseRay Ray raycall ;
: GetCameraMatrix ( Camera3d -- Matrix )
['] iGetCameraMatrix Matrix raycall ;
: GetCameraMatrix2D ( Camera2d -- Matrix )
['] iGetCameraMatrix2D Matrix raycall ;
: GetWorldToScreen ( position camera -- vector2 )
['] iGetWorldToScreen Vector2 raycall ;
: GetWorldToScreenEx ( pos cam width height -- vector )
['] iGetWorldToScreenEx Vector2 raycall ;
: GetWorldToScreen2D ( pos camera2d -- vector2 )
['] iGetWorldToScreen2D Vector2 raycall ;
\ I'm not capitalizing anymore. Gforth is case insensitive anyway
: getscreentoworld2d ( pos camera2d -- vec2 )
['] igetscreentoworld2d vector2 raycall ;
: getmouseposition ( -- vec2 )
['] igetmouseposition vector2 raycall ;
: gettouchposition ( index -- vec2 )
['] igettouchposition vector2 raycall ;
: getgesturedragvector ( -- vec2 )
['] igetgesturedragvector vector2 raycall ;
: getgesturepinchvector ( -- vec2 )
['] igetgesturepinchvector vector2 raycall ;
: getcollisionrec ( rec1 rec2 -- rec3 )
['] igetcollisionrec rectangle raycall ;
: loadimage ( filename -- image )
['] iloadimage image raycall ;
: loadimageraw ( filename width height format headersize -- image )
['] iloadimageraw image raycall ;
: loadimageanim ( filename frames -- image )
['] iloadimageanim image raycall ;
: genimagecolor ( width height color -- image )
['] igenimagecolor image raycall ;
: genimagegradientv ( width height color-top color-bottom -- image )
['] igenimagegradientv image raycall ;
: genimagegradienth ( width height color-top color-bottom -- image )
['] igenimagegradienth image raycall ;
: genimagegradientradial ( width height f-density color-inner color-outer -- image )
['] igenimagegradientradial image raycall ;
: genimagechecked ( width height cheksX checksY color-1 color-2 -- image )
['] igenimagechecked image raycall ;
: genimagewhitenoise ( width height f-factor -- image )
['] igenimagewhitenoise image raycall ;
: genimageperlinnoise ( width height offsetX offsetY f-scale -- image )
['] igenimageperlinnoise image raycall ;
: genimagecellular ( width height tilesize -- image )
['] igenimagecellular image raycall ;
: imagecopy ( image -- image )
['] iimagecopy image raycall ;
: imagefromimage ( image rectangle -- image )
['] iimagefromimage image raycall ;
: imagetext ( text fontsize color -- image )
['] iimagetext image raycall ;
: imagetextex ( Font text f-fontsize f-spacing color-tint -- image )
['] iimagetextex image raycall ;
: getimagealphaborder ( image f-threshold -- rectangle )
['] igetimagealphaborder rectangle raycall ;
: loadtexture ( filename -- texture2d )
['] iloadtexture texture2d raycall ;
: loadtexturefromimage ( image -- texture2d )
['] iloadtexturefromimage texture2d raycall ;
: loadtexturecubemap ( image layoutType -- texturecubemap )
['] iloadtexturecubemap texturecubemap raycall ;
: loadrendertexture ( width height -- rendertexture2d )
['] iloadrendertexture rendertexture2d raycall ;
: gettexturedata ( texture2d -- image )
['] igettexturedata image raycall ;
: getscreendata ( -- image )
['] igetscreendata image raycall ;
: fade ( color f-alpha -- color )
['] ifade color raycall ;
: getcolor ( hex -- color )
['] igetcolor color raycall ;
: colornormalize ( color -- vector4 )
['] icolornormalize vector4 raycall ;
: colorfromnormalized ( vector4 -- color )
['] icolorfromnormalized color raycall ;
: colortohsv ( color -- vec3 )
['] icolortohsv vector3 raycall ;
: colorfromhsv ( f-hue f-saturation f-value -- color )
['] icolorfromhsv color raycall ;
: coloralpha ( color f-alpha -- color )
['] icoloralpha color raycall ;
: coloralphablend ( color-dst color-src color-tint -- color )
['] icoloralphablend color raycall ;
: getpixelcolor ( scrPtr format -- color )
['] igetpixelcolor color raycall ;
: getfontdefault ( -- Font )
['] igetfontdefault font raycall ;
: loadfont ( filename -- font )
['] iloadfont font raycall ;
: loadfontex ( filename fontsize *fontchars charscount -- font )
['] iloadfontex font raycall ;
: loadfontfromimage ( image color-key firstchar -- font )
['] iloadfontfromimage font raycall ;
: loadfontfrommemory ( fileData dataSize fontSize fontChars charCount )
['] iloadfontfrommemory font raycall ;
: genimagefontatlas ( CharInfo*chars Rectangle**recs charscount fontsize padding packmethod -- image )
['] igenimagefontatlas image raycall ;
: mesauretextex ( font text f-fontsize f-spacing -- vec2 )
['] imeasuretextex vector2 raycall ;
: loadmodel ( filename -- model )
['] iloadmodel model raycall ;
: loadmodelfrommesh ( mesh -- model )
['] iloadmodelfrommesh model raycall ;
: loadmaterialdefault ( -- material )
['] iloadmaterialdefault material raycall ;
: genmeshpoly ( sides f-radius -- mesh )
['] igenmeshpoly mesh raycall ;
: genmeshplane ( f-width f-length resx resz -- mesh )
['] igenmeshplane mesh raycall ;
: genmeshcube ( f-width f-height f-length -- mesh )
['] igenmeshcube mesh raycall ;
: genmeshsphere ( f-radius rings slices -- mesh )
['] igenmeshsphere mesh raycall ;
: genmeshhemisphere ( f-radius rings slices -- mesh )
['] igenmeshhemisphere mesh raycall ;
: genmeshcylinder ( f-radius f-height slices -- mesh )
['] igenmeshcylinder mesh raycall ;
: genmeshtorus ( f-radius f-size radSeg sides -- mesh )
['] igenmeshtorus mesh raycall ;
: genmeshknot ( f-radius f-size radSeg sides -- mesh )
['] igenmeshknot mesh raycall ;
: genmeshheightmap ( image-heightmap vector3-size -- mesh )
['] igenmeshheightmap mesh raycall ;
: genmeshcubicmap ( image-cubicmap vector3-cubesize -- mesh )
['] igenmeshcubicmap mesh raycall ;
: meshboundingbox ( mesh -- boundingbox )
['] imeshboundingbox boundingbox raycall ;
: getcollisionraymodel ( ray model -- rayinfo )
['] igetcollisionraymodel rayhitinfo raycall ;
: getcollisionraytriangle ( ray vec3-p1 vec3-p2 vec3-p3 -- rayinfo )
['] igetcollisionraytriangle rayhitinfo raycall ;
: getcollisionrayground ( ray f-groundheight -- rayinfo )
['] igetcollisionrayground rayhitinfo raycall ;
: loadshader ( vsfilename fsfilename -- shader )
['] iloadshader shader raycall ;
: loadshadercode ( vscode fscode -- shader )
['] iloadshadercode shader raycall ;
: getshaderdefault ( -- shader )
['] igetshaderdefault shader raycall ;
: gettexturedefault ( -- texture2d )
['] igettexturedefault texture2d raycall ;
: getshapestexture ( -- texture2d )
['] igetshapestexture texture2d raycall ;
: getshapestexturerec ( -- rectangle )
['] igetshapestexturerec rectangle raycall ;
: getmatrixmodelview ( -- matrix )
['] igetmatrixmodelview matrix raycall ;
: getmatrixprojection ( -- matrix )
['] igetmatrixprojection matrix raycall ;
: gentexturecubemap ( shader texture2d-map size format -- texture2d )
['] igentexturecubemap texture2d raycall ;
: gentextureirradiance ( shader texture2d-cubemap size -- texture2d )
['] igentextureirradiance texture2d raycall ;
: gentextureprefilter ( shader texture2d-cubemap size -- texture2d )
['] igentextureprefilter texture2d raycall ;
: gentexturebrdf ( shader size -- texture2d )
['] igentexturebrdf texture2d raycall ;
: loadwave ( filename -- wave )
['] iloadwave wave raycall ;
: loadsound ( filename -- sound )
['] iloadsound sound raycall ;
: loadsoundfromwave ( wave -- sound )
['] iloadsoundfromwave sound raycall ;
: wavecopy ( wave -- wave )
['] iwavecopy wave raycall ;
: loadmusicstream ( filename -- music )
['] iloadmusicstream music raycall ;
: initaudiostream ( u-samplerate u-samplesize u-channels -- audiostream )
['] iinitaudiostream audiostream raycall ;
: loadwavefrommemory ( filetype filedata datasize wave -- wave )
['] iloadwavefrommemory wave raycall ;