raylib bindings?

How to USE and/or how to CREATE Builder extentions!
Post Reply
xAction
Posts: 281
Joined: Thu Sep 16, 2021 1:40 pm
Contact:

raylib bindings?

Post by xAction »

raylib "is a simple and easy-to-use library to enjoy videogames programming."
From the homepage
no fancy interface, no visual helpers, no auto-debugging... just coding in the most pure spartan-programmers way. Are you ready to learn? Jump to raylib code examples!
No fancy interface? Well, we'll see about that!

From the homepage:-
  • NO external dependencies, all required libraries included with raylib
    - Multiplatform: Windows, Linux, MacOS, RPI, Android, HTML5... and more!
    - Written in plain C code (C99) in PascalCase/camelCase notation
    - Hardware accelerated with OpenGL (1.1, 2.1, 3.3, 4.3 or ES 2.0)
    - Unique OpenGL abstraction layer: rlgl
    - Powerful Fonts module (XNA SpriteFonts, BMfonts, TTF, SDF)
    - Outstanding texture formats support, including compressed formats (DXT, ETC, ASTC)
    - Full 3d support for 3d Shapes, Models, Billboards, Heightmaps and more!
    - Flexible Materials system, supporting classic maps and PBR maps
    - Animated 3d models supported (skeletal bones animation)
    - Shaders support, including Model shaders and Postprocessing shaders
    - Powerful math module for Vector, Matrix and Quaternion operations: raymath
    - Audio loading and playing with streaming support (WAV, OGG, MP3, FLAC, XM, MOD)
    - VR stereo rendering support with configurable HMD device parameters
    - Huge examples collection with +120 code examples!
    - Bindings to +50 programming languages!
    - Free and open source. Check [LICENSE].

And what's very important, I think, is that it has a sweet little raylib_parser.c that exposes all its enums, functions and structs very easily and through the JSON file it outputs I believe we can automate binding it for OpenXTalk.

So here is a stack where raylib_api.json has been imported into a custom property array and then placed into a Tree View so that we can view the data and get to producing Builder code.
RayLib_to_Array_preview.png
RayLib_to_Array_preview.png (25.26 KiB) Viewed 11035 times
Raylib_to_Array.zip
(40.14 KiB) Downloaded 296 times
I've disabled the buttons at the top of the stack window as the data has already been set into the stack, they are left there just in case the data gets mangled. I'm so tempted to lift all the 'name' array indexes up to the root...but i figured I better leave things intact just in case we figure out a way to automate the process we are after, then any future raylib update will be easily run through the same automation to achieve the desired result.

Oh A plain text file is availble from the parser
it might be easier to have an overview of the language through that text than through the stack or through the JSON.

Or maybe the big [url=https://www.raylib.com/cheatsheet/cheatsheet.html]cheat sheet PDF
is more your flavor.

This would be a perfect opportunity for a tutorial in making external libraries available to OpenXtalk through the Builder.

So where do we start?
User avatar
OpenXTalkPaul
Posts: 1485
Joined: Sat Sep 11, 2021 4:19 pm
Contact:

Re: raylib bindings?

Post by OpenXTalkPaul »

Well I'm working on the IDE right now, and honestly any game engine is not what I would call low hanging fruit to start out with, unless its maybe something like a very basic 2D engine.

There's already been two 2D drawing libraries that already included, https://www.cairographics.org and https://skia.org .

It's my opinion we should go after System APIs first a LOT of those basics things are not available. Like for example WebCam access from the Script Engine (unless you use the OLD 32bit-only revVideoCapture).

But if you REALLY want to jump right into the fire, I would say start with getting the ray lib binary for the platform you're using and put it in a "code" / subfolder for the architecture you're using,

https://github.com/raysan5/raylib/releases/tag/4.0.0
Screen Shot 2021-11-07 at 7.50.56 PM.png
Screen Shot 2021-11-07 at 7.50.56 PM.png (128.89 KiB) Viewed 11023 times
AND add all of the dependencies (which it DOES have dependencies) for your platform into that same folder.

https://github.com/raysan5/raylib/wiki/ ... dependency

https://github.com/glfw/glfw/releases/tag/3.3.5
Screen Shot 2021-11-07 at 8.02.11 PM.png
Screen Shot 2021-11-07 at 8.02.11 PM.png (114.07 KiB) Viewed 11020 times
Your going to want to rename the main lib to libraylib.dylib (or .dll or .so depending on the platform)
The binding string for a C/C++ library would then look something like:

Code: Select all

__safe foreign handler oxt_RayLib_SetTargetFPS( in pFPS as CUInt ) binds to "c:libraylib.dylib>settargetfps"

Then you need to start a lcb file and make some binding strings. I would just start with binding to what you need from the lib to Initialize the library from Builder.

Start with the first example code from their site, you want to translate this into Builder code:

Code: Select all

#include "raylib.h"
int main(void)
{
    const int screenWidth = 800;
    const int screenHeight = 450;
    InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
    SetTargetFPS(60); 
    while (!WindowShouldClose())    // Detect window close button or ESC key
    
        BeginDrawing();

            ClearBackground(RAYWHITE);

            DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);

        EndDrawing();
   
    CloseWindow(); 

    return 0;
}
https://www.raylib.com/examples.html
So you would need Binding strings for: InitWindow() , SetTargetFPS(), BeginDrawing(), ClearBackground(), DrawText(), EndDrawing(), CloseWindow() to translate this code.

If you make it a Library instead of a Widget then you will likely need binding strings for your System's APIs for creating a Windows (for macOS you would need to make an NSView and NSWindow objects) or bind to internal Engine functions to get a hold of a Stack's window and then use that window (that's how a few of the handlers in the macOS tools lib work) to render to.
xAction
Posts: 281
Joined: Thu Sep 16, 2021 1:40 pm
Contact:

Re: raylib bindings?

Post by xAction »

Ok lets see if I got this right so far
rayLib_To_BindStringsPrvw.png
rayLib_To_BindStringsPrvw.png (38.89 KiB) Viewed 11006 times
Raylib_to_BindStrings.zip
(41.88 KiB) Downloaded 295 times
Clicking the Tree View > Functions > Node
will put the available data into the appropriate fields and then combine them into a binding string
Once the kinks are worked out this can be automated.

How do we handle inputs/parameters not defined in the Builder docs like Matrix, Shader, AudioFile and const* void??
We define a Pointer somehere ahead of that in the builder code?
such as :
private type fs_SETTINGS is Pointer
and then stuff that into the 'as type' section?
Looks like it from libSyth code.
What's "fs_"?

How do we handle "returns void" or any other return values?
User avatar
OpenXTalkPaul
Posts: 1485
Joined: Sat Sep 11, 2021 4:19 pm
Contact:

Re: raylib bindings?

Post by OpenXTalkPaul »

xAction wrote: Mon Nov 08, 2021 4:59 am Ok lets see if I got this right so far
rayLib_To_BindStringsPrvw.png
Raylib_to_BindStrings.zip

Clicking the Tree View > Functions > Node
will put the available data into the appropriate fields and then combine them into a binding string
Once the kinks are worked out this can be automated.

How do we handle inputs/parameters not defined in the Builder docs like Matrix, Shader, AudioFile and const* void??
We define a Pointer somehere ahead of that in the builder code?
such as :
private type fs_SETTINGS is Pointer
Yes, once you have a pointer to a foreign type, you can use a foreign type string to parse it (if you know the structure that it's supposed to be), into a list type that Builder can iterate through. Defining a foreign type is a little bit like using the binaryEncode / binaryDecode in LCScript.

>> const* void??
So "optional" means it can be something or "nothing". Null or Void in Builder is called "nothing".
and so a void pointer in Builder is "as optional Pointer" then you can check if the returned data is nothing or, hopefully, it's a pointer to something!
>> How do we handle "returns void" or any other return values?
Do you mean how to return Void to the Script engine? You would just have a line that said "return"...
If your public handler is defined with

Code: Select all

returns optional any
then you can pass back any type of data that the Script engine understands, String, Number, Boolean, Data, or you could do just

Code: Select all

return
to pass back empty or

Code: Select all

return the empty string
, but if you define the return type like

Code: Select all

returns String
then your function should return a string or you'll get a compiling error.

>>What's "fs_"?
fs_ is just short for FluidSynth... that library was actually already started by other people, I just picked up on it and ran with it, so I followed the existing naming pattern, you could name the Builder handler anything you like.
xAction
Posts: 281
Joined: Thu Sep 16, 2021 1:40 pm
Contact:

Re: raylib bindings?

Post by xAction »

Okay, these are the non-common return types of rayLib, does this builder code set up look right?

Code: Select all

private type rl_AUDIOSTREAM is Pointer
private type rl_BOUNDINGBOX is Pointer
private type rl_CAMERA is Pointer
private type rl_CAMERA2D is Pointer
private type rl_CAMERA3D is Pointer
private type rl_CHARINFO is Pointer
private type rl_COLOR is Pointer
private type rl_FONT is Pointer
private type rl_IMAGE is Pointer
private type rl_LOADFILEDATACALLBACK is Pointer
private type rl_LOADFILETEXTCALLBACK is Pointer
private type rl_MATERIAL is Pointer
private type rl_MATRIX is Pointer
private type rl_MESH is Pointer
private type rl_MODEL is Pointer
private type rl_MODELANIMATION is Pointer
private type rl_MUSIC is Pointer
private type rl_NPATCHINFO is Pointer
private type rl_RAY is Pointer
private type rl_RECTANGLE is Pointer
private type rl_RENDERTEXTURE2D is Pointer
private type rl_SAVEFILEDATACALLBACK is Pointer
private type rl_SAVEFILETEXTCALLBACK is Pointer
private type rl_SHADER is Pointer
private type rl_SOUND is Pointer
private type rl_TEXTURE2D is Pointer
private type rl_TRACELOGCALLBACK is Pointer
private type rl_VECTOR2 is Pointer
private type rl_VECTOR3 is Pointer
private type rl_VECTOR4 is Pointer
private type rl_VRDEVICEINFO is Pointer
private type rl_VRSTEREOCONFIG is Pointer
private type rl_WAVE is Pointer
then I assume stuff like this

Code: Select all

private variable mSettings as optional fs_SETTINGS
private variable mSynth as optional fs_SYNTH
is declared so you can use the library's types in your builder handlers?

so my code should look like this?

Code: Select all

private variable mAudioStream as optional rl_AUDIOSTREAM
private variable mBoundingBox as optional rl_BOUNDINGBOX
private variable mCamera as optional rl_CAMERA
private variable mCamera2D as optional rl_CAMERA2D
private variable mCamera3D as optional rl_CAMERA3D
private variable mCharInfo as optional rl_CHARINFO
private variable mColor as optional rl_COLOR
private variable mFont as optional rl_FONT
private variable mImage as optional rl_IMAGE
private variable mLoadFileDataCallback as optional rl_LOADFILEDATACALLBACK
private variable mLoadFileTextCallback as optional rl_LOADFILETEXTCALLBACK
private variable mMaterial as optional rl_MATERIAL
private variable mMatrix as optional rl_MATRIX
private variable mMesh as optional rl_MESH
private variable mModel as optional rl_MODEL
private variable mModelAnimation as optional rl_MODELANIMATION
private variable mMusic as optional rl_MUSIC
private variable mNPatchInfo as optional rl_NPATCHINFO
private variable mRay as optional rl_RAY
private variable mRectangle as optional rl_RECTANGLE
private variable mRenderTexture2D as optional rl_RENDERTEXTURE2D
private variable mSaveFileDataCallback as optional rl_SAVEFILEDATACALLBACK
private variable mSaveFileTextCallback as optional rl_SAVEFILETEXTCALLBACK
private variable mShader as optional rl_SHADER
private variable mSound as optional rl_SOUND
private variable mTexture2D as optional rl_TEXTURE2D
private variable mTraceLogCallback as optional rl_TRACELOGCALLBACK
private variable mVector2 as optional rl_VECTOR2
private variable mVector3 as optional rl_VECTOR3
private variable mVector4 as optional rl_VECTOR4
private variable mvoid as optional rl_VOID
private variable mVrDeviceInfo as optional rl_VRDEVICEINFO
private variable mVrStereoConfig as optional rl_VRSTEREOCONFIG
private variable mWave as optional rl_WAVE
Also I assume this gets compiled to bytecode so "rl_" is a good enough identifcation prefix without worrying about it ever getting mixed up with anyone else's code if they make a "RickyLib" or something?

what's going on here with the "c:"

Code: Select all

 binds to "c:libfluidsynth>new_fluid_settings"
Is that a directory reference Pointing to the "c:"ode folder?
User avatar
OpenXTalkPaul
Posts: 1485
Joined: Sat Sep 11, 2021 4:19 pm
Contact:

Re: raylib bindings?

Post by OpenXTalkPaul »

Yup, you're getting it right so far!
You're basically just making "type aliases" for pointer variables to help you keep track of what type of data or object that Pointer points to, which will be important later when you go to retrieve or parse whatever the Pointer points to. But underneath the alias those are all Pointer type variables.
what's going on here with the "c:"
CODE:
binds to "c:libfluidsynth>new_fluid_settings"
Is that a directory reference Pointing to the "c:"ode folder?
No! I thought the same thing at first, the "c:" actually tells Builder what type of Foreign code that you want to binding to!

c: means C or C++ based library ( which usually comes with a .h header that can help a lot to learn constant values and such)

objc: means Objective C, so mostly used on Apple stuff macOS/iOS/tvOS/watchOS, although I'm tempted to try this with the GNUStep Libraries, which are the Open Source cross-platform version of NeXTstep/Apple Cocoa APIs.

and lastly

java: obviously used with JAVA VM, on any OS with JAVA installed... these days I think that mostly means Android!

Builder also supports JS, for Emscripten (HTML5 Web Assembly Engine), but I have never looked into using that. I think the only person who did may have been Hermann Hoch (HH) but unfortunately he died last year. Also unfortunate that he kept some of his code as private. He did some really neat things with Builder Image Transform Matrices and, I believe, with the JS version of the popular ImageMagick Library! Like his Image Flipper Widget thing, that may have been straight Builder Canvas Library, I don't know because he never released the source code.
xAction
Posts: 281
Joined: Thu Sep 16, 2021 1:40 pm
Contact:

Re: raylib bindings?

Post by xAction »

Okay my automation scripts need a bit of work but I got it to build and it installs the library.
And I got a window open. Yipee. And I can Close it with rayLib commands via a second handler, Woohoo!
But I can't get text on the screen and the escape key and close box don't respond.

How do I assign something like "RayWhite" to a color?

Code: Select all

#define RAYWHITE   CLITERAL(Color){ 245, 245, 245, 255 } 
Where do Pointers point to ? A private handler?

I tried to pass "{245, 245, 245, 255}" & "245, 245, 245, 255" and "RAYWHITE" through in variable tRAYWHITE as rl_Color (a Pointer) and got this:
Value is not of correct type for assignment to variable - expected type <type: __builtin__.pointer> for assigning to variable tRAYWHITE in com.community.library.oxt_raylib.RlExample
I change rl_Color to type of String, and at least got no errors when trying to pass anything to the library, didn't get any visible results either.

I changed rl_Color to a type of Color but then the script cried this:
Value is not of correct type for assignment to variable - expected type <type: com.livecode.canvas.Color> for assigning to variable tRAYWHITE in com.community.library.oxt_raylib.RlExample
User avatar
OpenXTalkPaul
Posts: 1485
Joined: Sat Sep 11, 2021 4:19 pm
Contact:

Re: raylib bindings?

Post by OpenXTalkPaul »

xAction wrote: Tue Nov 09, 2021 7:04 pm Okay my automation scripts need a bit of work but I got it to build and it installs the library.
And I got a window open. Yipee. And I can Close it with rayLib commands via a second handler, Woohoo!
But I can't get text on the screen and the escape key and close box don't respond.

How do I assign something like "RayWhite" to a color?

Code: Select all

#define RAYWHITE   CLITERAL(Color){ 245, 245, 245, 255 } 
Where do Pointers point to ? A private handler?

I tried to pass "{245, 245, 245, 255}" & "245, 245, 245, 255" and "RAYWHITE" through in variable tRAYWHITE as rl_Color (a Pointer) and got this:
Value is not of correct type for assignment to variable - expected type <type: __builtin__.pointer> for assigning to variable tRAYWHITE in com.community.library.oxt_raylib.RlExample
I change rl_Color to type of String, and at least got no errors when trying to pass anything to the library, didn't get any visible results either.

I changed rl_Color to a type of Color but then the script cried this:
Value is not of correct type for assignment to variable - expected type <type: com.livecode.canvas.Color> for assigning to variable tRAYWHITE in com.community.library.oxt_raylib.RlExample
Pointers point to a chunk of memory which can contain any type of data, you need to know what the library is expecting to be passed for putting into that chunk of memory, or what it's filling that chunk of memory with in order to be able to pass what it expects or parse what it's giving to you back.

That looks like definition for a constant, that's an array of four integers, probably R,G,B,A, which with those numbers is probably like an off-white color, likely why they named it RAYWHITE.
...looks like that was a good guess:
https://github.com/raysan5/raylib/wiki/ ... structures

So we'll make that first type in that data structures list:
// Basic data structures
struct Color; [ 4 bytes] - // RGBA values, 4 char, 32bit color
To make this 4-byte RGBA Structure in Builder you need to define a foreign type, which is basically a List type, each element of the list can be a different variable type, like a record in a database, but in this particular case each of the four elements are going to be 1-byte unsigned integers, CUInt (C/C++ Unsigned Integer).

https://github.com/livecode/livecode/bl ... ference.md

In this document you will find this example and chart of characters which represent common types for use in a Builder foreign type definition:
Foreign Aggregate Types

C-style aggregates (e.g. structs) can now be accessed from LCB via the new aggregate parameterized type. This allows calling foreign functions which has arguments taking aggregates by value, or has an aggregate return value.

Aggregate types are foreign types and can be used in C and Obj-C foreign handler definitions. They bridge to and from the List type, allowing an aggregate's contents to be viewed as a sequence of discrete values.

Aggregate types are defined using a foreign type clause and binding string. e.g.

public foreign type NSRect binds to "MCAggregateTypeInfo:qqqq"
The structure of the aggregate is defined by using a sequence of type codes after the ':', each type code represents a specific foreign (C) type:

Char Type
a CBool
b CChar
c CUChar
C CSChar
d CUShort
D CSShort
e CUInt
E CSInt
f CULong
F CSLong
g CULongLong
G CSLongLong
h UInt8
H SInt8
i UInt16
I SInt16
j UInt32
J SInt32
k UInt64
K SInt64
l UIntPtr
L SIntPtr
m UIntSize
M SIntSize
n Float
N Double
o LCUInt
O LCSInt
p NaturalUInt
P NaturalSInt
q NaturalFloat
r Pointer
When importing an aggregate to a List, each field in the aggregate is also bridged, except for Pointer types which are left as Pointer. When exporting an aggregate from a List, each element is bridged to the target field type.

Note: Any foreign type binding to an aggregate must be public otherwise the type will not work correctly.
So you'll want to make a record type name something like RayRGBAColor (or whatever name you think is best)

Code: Select all

public foreign type RayRGBAColor binds to "MCAggregateTypeInfo:eeee"
Now that the RayRGBColor type is defined you can put a list of four unsigned integers into any variable that you typed with your new variable type.

Code: Select all

variable tRAYWHITE as RayRGBAColor
put { 245, 245, 245, 255 } into tRAYWHITE
That should work, but I haven't tested it, and don't have time to right now.
Keep in mind that I'm no where near an expert on C language, and I'm not entirely sure about that #DEFINE, specifically that CLITERAL(Color) bit before the { 245, 245, 245, 255 }, that might be combining the numbers into a single 32bit value that the library expects to receive. If that is what it expects then you would combine those 4 individual bytes into a single 32bit number and pass that to the library wherever you would've passed tRAYWHITE. I have an example of doing that I worked out somewhere (it was something to do with Apple's CoreAudio, a 4 character value like APPL, where the API wanted a single 32bit value, what made that worse was that it was an PowerPC-ancient API so I had to flip the byte order, so LPPA, and then translate that to a number, sheesh!)
xAction
Posts: 281
Joined: Thu Sep 16, 2021 1:40 pm
Contact:

Re: raylib bindings?

Post by xAction »

I think you are right on that 32 bit conversion, it crashes hard when passed the 1-byte RGBA values.
User avatar
OpenXTalkPaul
Posts: 1485
Joined: Sat Sep 11, 2021 4:19 pm
Contact:

Re: raylib bindings?

Post by OpenXTalkPaul »

xAction wrote: Sun Nov 14, 2021 3:15 am I think you are right on that 32 bit conversion, it crashes hard when passed the 1-byte RGBA values.
If you post Builder code of what you have, maybe I can squeeze in some time to look at it.
xAction
Posts: 281
Joined: Thu Sep 16, 2021 1:40 pm
Contact:

Re: raylib bindings?

Post by xAction »

Ray said :"Where you use RAYWHITE, it's replaced by preprocesor by a compound literal, a Color object"

Which doesn't help much and neither does the documentation on compound literals.

Here's the Builder code I'm uploading, I've reduced it down to what I think are the bare essentials for the example to work
I've added a drawRectangle to the example because I feel like I'm probably not passing the string values correctly.
The C source for the functions asks for const char *something
and I have no idea how you turn const char *something into "This is some text"
If we can got a box on screen at least we know the color thing works.

Included in the upload is the parsing stack and raylib_test with two buttons to open and close the window once you have the library loaded. LCB and DLL are in the oxt_raylib folder
rayLib_Project_11152021.zip
(1.46 MiB) Downloaded 299 times

Code: Select all

library com.community.library.oxt_raylib

metadata version is "0.0.1"
metadata author is "xAction"
metadata title is "oxtrayLib"

use com.livecode.foreign
use com.livecode.canvas
use com.livecode.string
use com.livecode.char
use com.livecode.array
use com.livecode.list
use com.livecode.widget
use com.livecode.engine
use com.livecode.library.widgetutils
use com.livecode.system

--builder types for rayLib data types

-- NOTE -- experiementing with rl_COLOR
-- Tried ints, chars, floats in aggregate 
-- Tried UInt32, CUInt, CInt

public foreign type rl_COLOR binds to "MCAggregateTypeInfo:eeee"
--public  type rl_COLOR is UInt32
--private type rl_COLOR is Pointer

public  type rl_CHARS is CSChar

--Builder foreign handler strings for rayLib library functions

-- Initialize window and OpenGL context
__safe foreign handler oxt_RayLib_InitWindow(in pWidth as CInt, in pHeight as CInt, in pTitle as String) returns nothing binds to "c:libraylib.dll>InitWindow"

-- Check if KEY_ESCAPE pressed or Close icon pressed
__safe foreign handler oxt_RayLib_WindowShouldClose() returns CBool binds to "c:libraylib.dll>WindowShouldClose"

-- Close window and unload OpenGL context
__safe foreign handler oxt_RayLib_CloseWindow() returns nothing binds to "c:libraylib.dll>CloseWindow"

-- Set background color (framebuffer clear color)
__safe foreign handler oxt_RayLib_ClearBackground(in pColor as rl_Color) returns nothing binds to "c:libraylib.dll>ClearBackground"

-- Draw a color-filled rectangle
__safe foreign handler oxt_RayLib_DrawRectangle(in pPosY as CInt, in pHeight as CInt, in pPosX as CInt, in pWidth as CInt, in pColor as rl_Color) returns nothing binds to "c:libraylib.dll>DrawRectangle"

-- Set target FPS (maximum)
__safe foreign handler oxt_RayLib_SetTargetFPS(in pFps as CInt) returns nothing binds to "c:libraylib.dll>SetTargetFPS"

-- Setup canvas (framebuffer) to start drawing
__safe foreign handler oxt_RayLib_BeginDrawing() returns nothing binds to "c:libraylib.dll>BeginDrawing"
-- End canvas drawing and swap buffers (double buffering)
__safe foreign handler oxt_RayLib_EndDrawing() returns nothing binds to "c:libraylib.dll>EndDrawing"

-- Draw text (using default font)
__safe foreign handler oxt_RayLib_DrawText(in pText as rl_CHARS,  in pPosX as CInt, in pPosY as CInt, in pFontSize as CInt, in pColor as rl_COLOR) returns nothing binds to "c:libraylib.dll>DrawText"

--raylib example core basic window
public handler RlExample() 
	variable tScreenWidth as Integer
	variable tScreenHeight as Integer
	variable tTitle as String
    variable tCongrats as rl_CHARS
	variable tLIGHTGRAY as rl_COLOR
    variable tRAYWHITE as rl_COLOR
     put 800 into tScreenWidth
	put 450 into tScreenHeight
	put "oxt_raylib core example  basic window" into tTitle
	--put "Congrats! You created your first window!" into tCongrats
   -- text as char, instead of string -- just to see if it shows up
    put 65 into tCongrats

    -- aggregate as float
    --put [0.6,0.6,0.6,1.0] into tLIGHTGRAY
   -- put [0.9,0.9,0.9,1.0] into tRAYWHITE
   
    -- aggregate as Int 
	put [200, 200, 200, 255] into tLIGHTGRAY
	put [245, 245, 245, 255]  into tRAYWHITE
    
    -- UInt3D
  -- put 4291611903 into tRAYWHITE
  -- put 4286611711 into tLIGHTGRAY
    
    oxt_RayLib_InitWindow(tScreenWidth, tScreenHeight, tTitle)
    oxt_RayLib_SetTargetFPS(60)
	
	repeat while oxt_RayLib_WindowShouldClose() is true  -- << if this is false it crashes the IDE

	oxt_RayLib_BeginDrawing()

	oxt_RayLib_ClearBackground(tRAYWHITE)
    
        oxt_RayLib_DrawRectangle(tScreenwidth/4*2 - 60, 100, 120, 60, tLIGHTGRAY)
	oxt_RayLib_DrawText(tCongrats, 190, 200, 20,tLIGHTGRAY)
	end repeat
    
	-- the window closes automatically if these are uncommented
	--oxt_RayLib_EndDrawing()
   --oxt_RayLib_CloseWindow()
end handler

public handler ExitRayLib()
oxt_RayLib_EndDrawing()
 oxt_RayLib_CloseWindow()
end handler

--raylib as widget to test, lets open a window
public handler OnCreate()
	RlExample()
end handler

end library
User avatar
OpenXTalkPaul
Posts: 1485
Joined: Sat Sep 11, 2021 4:19 pm
Contact:

Re: raylib bindings?

Post by OpenXTalkPaul »

If all the elements of the compound literal are (made up of) simple constant expressions suitable for use in initializers of objects of static storage duration, then the compound literal can be coerced to a pointer to its first element
Just a guess but that sounds like you would need to make that into Foreign Type (4 byte struct) and then get a pointer to that struct and pass the pointer.

As for the string, a lot of times with C API you can just pass a string ( which gets passed as a reference), to the corresponding FFI binding definition, which would accept it if the parameter is defined like:

Code: Select all

in pMyString as ZStringNative
Note that if it's a Unicode String the receiver expects then you may have to define it as

Code: Select all

ZStringUTF8
or

Code: Select all

ZStringUTF16
xAction
Posts: 281
Joined: Thu Sep 16, 2021 1:40 pm
Contact:

Re: raylib bindings?

Post by xAction »

in pMyString as ZStringNative
Hoorah, after a week the window has a title!

ZStringNative isn't even in the documentation...
Just a guess but that sounds like you would need to make that into Foreign Type (4 byte struct) and then get a pointer to that struct and pass the pointer.
That's greek to me.
User avatar
OpenXTalkPaul
Posts: 1485
Joined: Sat Sep 11, 2021 4:19 pm
Contact:

Re: raylib bindings?

Post by OpenXTalkPaul »

xAction wrote: Tue Nov 16, 2021 1:12 am ZStringNative isn't even in the documentation...
That's a huge problem with Builder, it's not well documented.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest