diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d33fa92 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +index/main.wasm diff --git a/codegen/extractFuncs.go b/codegen/extractFuncs.go deleted file mode 100644 index e92c25c..0000000 --- a/codegen/extractFuncs.go +++ /dev/null @@ -1,85 +0,0 @@ -// yes, it's Gippity -package main - -import ( - "bytes" - "go/ast" - "go/parser" - "go/printer" - "go/token" -) - -// Function holds the metadata for one top‐level function, including its doc comment. -type Function struct { - Name string - Description string // the text of the leading comment group, or "" if none - Params []Param - ReturnType string // "" if none, otherwise the first return’s type - ReturnsStruct bool -} - -// Param holds one parameter’s name and type. -type Param struct { - Name, Type string - isReference bool - isStruct bool -} - -// ExtractFuncs parses src and returns all top-level FuncDecls along with their comments. -func ExtractFuncs(src string) []Function { - fset := token.NewFileSet() - file, err := parser.ParseFile(fset, "", src, parser.ParseComments) - if err != nil { - panic(err) - } - - var funcs []Function - for _, decl := range file.Decls { - fd, ok := decl.(*ast.FuncDecl) - if !ok || fd.Name == nil { - continue - } - - f := Function{ - Name: fd.Name.Name, - Description: "", - Params: nil, - ReturnType: "", - } - - // --- extract the doc-comment text, if any --- - if fd.Doc != nil { - // Doc.Text() returns the comment text with line breaks - f.Description = fd.Doc.Text() - } - - // --- collect parameters --- - if fd.Type.Params != nil { - for _, field := range fd.Type.Params.List { - // render the type expression to a string - buf := new(bytes.Buffer) - printer.Fprint(buf, fset, field.Type) - typ := buf.String() - - for _, name := range field.Names { - f.Params = append(f.Params, Param{ - Name: name.Name, - Type: typ, - }) - } - // (could handle anonymous params here if needed) - } - } - - // --- collect a single return type, if any --- - if fd.Type.Results != nil && len(fd.Type.Results.List) > 0 { - buf := new(bytes.Buffer) - printer.Fprint(buf, fset, fd.Type.Results.List[0].Type) - f.ReturnType = buf.String() - } - - funcs = append(funcs, f) - } - - return funcs -} diff --git a/codegen/fn.go b/codegen/fn.go deleted file mode 100644 index 2a7a93b..0000000 --- a/codegen/fn.go +++ /dev/null @@ -1,30 +0,0 @@ -package main - -import "fmt" - - - -func (fn Function) RegisterSignature() string { - var out string - var ProcOrFunction = fmt.Sprintf("wasm.Func[%s](\"%s\")", fn.ReturnType, fn.Name) - if fn.ReturnType == "" { - ProcOrFunction = fmt.Sprintf("wasm.Proc(\"%s\")", fn.Name) - } - out += fmt.Sprintf("var %s = %s ", Uncapitalize(fn.Name), ProcOrFunction) - return out -} - -func (fn Function) Signature(code string) string { - var out string - out += fmt.Sprintf("func %s(%s) %s {\n%s}\n", fn.Name, fn.Expand(), fn.ReturnType, code) - return out -} - -func (fn Function) Expand() string { - var out string - for _, p := range fn.Params { - out += fmt.Sprintf("%s %s,", p.Name, p.Type) - } - return out -} - diff --git a/codegen/generateBind.go b/codegen/generateBind.go deleted file mode 100644 index 8c027ac..0000000 --- a/codegen/generateBind.go +++ /dev/null @@ -1,64 +0,0 @@ -package main - -import ( - "fmt" - "strings" -) - -func (fn Function) BindingCode() string { - if strings.Contains(fn.Description, "(only PLATFORM_DESKTOP)") || fn.ReturnType == "unsafe.Pointer" { - if fn.ReturnType == "" { - return "" - } else { - return fmt.Sprintf("var zero %s;return zero", fn.ReturnType) - } - } - if (len(fn.ReturnType) > 0) && (fn.ReturnType[:1] == "*" || fn.ReturnType[:1] == "[") { - return fmt.Sprintf("var zero %s;return zero", fn.ReturnType) - } - var out string - var param_names string - // generate reference binding code - // func CheckCollisionLines(startPos1 Vector2, endPos1 Vector2, startPos2 Vector2, endPos2 Vector2, collisionPoint *Vector2) bool { - // _collisionPoint := wasm.Struct(*collisionPoint) - // ret, fl := checkCollisionLines.Call(wasm.Struct(startPos1), wasm.Struct(endPos1), wasm.Struct(startPos2), wasm.Struct(endPos2), _collisionPoint) - // v := wasm.Boolean(ret) - // *collisionPoint = wasm.BytesToStruct[Vector2](wasm.ReadFromWASM(_collisionPoint.Mem, _collisionPoint.Size)) - // wasm.Free(fl...) - // return v - // } - var referenceBinding string - for _, p := range fn.Params { - if p.isReference { - referenceBinding += fmt.Sprintf("_%s := wasm.Struct(*%s)\n", p.Name, p.Name) - } - } - for _, p := range fn.Params { - if !p.isStruct && !p.isReference { - param_names += fmt.Sprintf("%s,", p.Name) - } else if p.isStruct && !p.isReference { - param_names += fmt.Sprintf("wasm.Struct(%s),", p.Name) - } else if p.isReference { - param_names += fmt.Sprintf("_%s", p.Name) - } - } - var returnV bool - if fn.ReturnType == "" { - out += fmt.Sprintf("_,fl :=%s.Call(%s)\n", Uncapitalize(fn.Name), param_names) - } else { - out += fmt.Sprintf("ret,fl :=%s.Call(%s)\n", Uncapitalize(fn.Name), param_names) - if fn.ReturnType == "bool" { - out += "v := wasm.Boolean(ret)\n" - } else if !fn.ReturnsStruct { - out += fmt.Sprintf("v := wasm.Numeric[%s](ret)\n", fn.ReturnType) - } else { - out += fmt.Sprintf("v := wasm.ReadStruct[%s](ret)\n", fn.ReturnType) - } - returnV = true - } - out += "wasm.Free(fl...)\n" - if returnV { - out += "return v" - } - return out -} diff --git a/codegen/genstubs.go b/codegen/genstubs.go deleted file mode 100644 index 137c1ed..0000000 --- a/codegen/genstubs.go +++ /dev/null @@ -1,53 +0,0 @@ -package main - -import ( - "fmt" - "go/format" - "slices" - "strings" -) - -// make empty definitions -func ModeStub(file string, structs []string) { - - funcs := ExtractFuncs(file) - // check which parameters are struct types - // and which functions return structs - for i := range funcs { - f := &funcs[i] - if slices.Contains(structs, f.ReturnType) { - f.ReturnsStruct = true - } - - for j := range f.Params { - p := &f.Params[j] - if slices.Contains(structs, p.Type) { - p.isStruct = true - } else if p.Type[0] == '*' { - // *Vector2 - p.isReference = true - } - } - } - - var out string = fmt.Sprintln("//go:build !js") + imports - for _, f := range funcs { - comments := strings.SplitSeq(f.Description, "\n") - for comment := range comments { - out += fmt.Sprintln("//", comment) - } - // func InitWindow(width int32, height int32, title string){//binding code} - var stub string = "//empty code to make gopls happy on non-web\n" - if f.ReturnType != "" { - stub += fmt.Sprintf("var zero %s ;return zero", f.ReturnType) - } - out += fmt.Sprintln(f.Signature(stub)) - } - - formatted, err := format.Source([]byte(out)) - if err != nil { - fmt.Println(out) - panic(fmt.Errorf("format error: %s ", err)) - } - fmt.Println(string(formatted)) -} diff --git a/codegen/main.go b/codegen/main.go deleted file mode 100644 index 65d8bdd..0000000 --- a/codegen/main.go +++ /dev/null @@ -1,79 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "os" - "slices" -) - -var help string = fmt.Sprintf("Supported libraries to generate bindings for are: %s\npassing a third argument 'stub' will generate stubs", supportedLibs) - -var mode int - -// files to bind for -var supportedLibs = []string{"rcore"} - -// go bindings for raylib dont have aliases for some structs -var additions = []string{"color.RGBA", "Texture2D", "RenderTexture2D"} - -var imports = ` -package rl -import ( - "image/color" - "unsafe" - wasm github.com/BrownNPC/wasm-ffi-go -) -` - -// get data codegen data for a supported lib -func CodegenDataFor(libname string) (defines string, structNames []string, err error) { - var DefinesPath = fmt.Sprintf("testdata/%s_defines.txt", libname) - var JsonPath = fmt.Sprintf("testdata/%s.json", libname) - var f []byte - f, err = os.ReadFile(DefinesPath) - if err != nil { - return - } - defines = string(f) - - // get struct names - type Value struct { - Name string `json:"name"` - } - var ApiJson map[string][]Value - var file *os.File - file, err = os.Open(JsonPath) - if err != nil { - return - } - err = json.NewDecoder(file).Decode(&ApiJson) - if err != nil { - panic(err) - } - for _, s := range ApiJson["structs"] { - structNames = append(structNames, s.Name) - } - structNames = append(structNames, additions...) - return -} - -func main() { - if len(os.Args) < 2 { - fmt.Println(help) - os.Exit(0) - } else if slices.Contains(supportedLibs, os.Args[1]) { - var LibraryToBind = os.Args[1] - defines, structNames, err := CodegenDataFor(LibraryToBind) - if err != nil { - os.Exit(1) - } - if len(os.Args) == 3 && os.Args[2] == "stub" { - ModeStub(defines, structNames) - } else { - ModeBind(defines, structNames) - } - } else { - fmt.Println(help) - } -} diff --git a/codegen/modeBind.go b/codegen/modeBind.go deleted file mode 100644 index 62491c4..0000000 --- a/codegen/modeBind.go +++ /dev/null @@ -1,54 +0,0 @@ -package main - -import ( - "fmt" - "go/format" - "slices" - "strings" -) - - -func ModeBind(file string, structs []string) { - - funcs := ExtractFuncs(file) - // check which parameters are struct types - // and which functions return structs - for i := range funcs { - f := &funcs[i] - if slices.Contains(structs, f.ReturnType) { - f.ReturnsStruct = true - } - - for j := range f.Params { - p := &f.Params[j] - if slices.Contains(structs, p.Type) { - p.isStruct = true - } - } - } - - var out string = imports - // - for _, f := range funcs { - if strings.Contains(f.Description, "(only PLATFORM_DESKTOP)") { - continue - } - // var initWindow = wasm.Proc("InitWindow") - out += fmt.Sprintln(f.RegisterSignature()) - } - for _, f := range funcs { - comments := strings.SplitSeq(f.Description, "\n") - for comment := range comments { - out += fmt.Sprintln("//", comment) - } - // func InitWindow(width int32, height int32, title string){//binding code} - out += fmt.Sprintln(f.Signature(f.BindingCode())) - } - - formatted, err := format.Source([]byte(out)) - if err != nil { - fmt.Println(out) - panic(fmt.Errorf("format error: %s ", err)) - } - fmt.Println(string(formatted)) -} diff --git a/codegen/strings.go b/codegen/strings.go deleted file mode 100644 index 45f0af4..0000000 --- a/codegen/strings.go +++ /dev/null @@ -1,23 +0,0 @@ -package main - -import "unicode" - - - -func Capitalize(s string) string { - if s == "" { - return s - } - runes := []rune(s) - runes[0] = unicode.ToUpper(runes[0]) - return string(runes) -} - -func Uncapitalize(s string) string { - if s == "" { - return s - } - runes := []rune(s) - runes[0] = unicode.ToLower(runes[0]) - return string(runes) -} diff --git a/examples/messingAround/go.mod b/examples/messingAround/go.mod new file mode 100644 index 0000000..d9ef7ee --- /dev/null +++ b/examples/messingAround/go.mod @@ -0,0 +1,7 @@ +module main + +replace github.com/gen2brain/raylib-go/raylib => ../../raylib + +go 1.25.6 + +require github.com/gen2brain/raylib-go/raylib v0.55.1 diff --git a/examples/messingAround/go.sum b/examples/messingAround/go.sum new file mode 100644 index 0000000..e69de29 diff --git a/examples/messingAround/main.go b/examples/messingAround/main.go new file mode 100644 index 0000000..59e966a --- /dev/null +++ b/examples/messingAround/main.go @@ -0,0 +1,15 @@ +//go:build js + +package main + +import ( + rl "github.com/gen2brain/raylib-go/raylib" +) + +func main() { + rl.InitWindow(300, 300, "We are on web bois") + rl.SetMain(func() { + rl.BeginDrawing() + rl.EndDrawing() + }) +} diff --git a/index/.gitignore b/index/.gitignore deleted file mode 100644 index f7aa9b7..0000000 --- a/index/.gitignore +++ /dev/null @@ -1 +0,0 @@ -main.wasm diff --git a/index/index.html b/index/index.html index 6a1d51c..a4c777f 100644 --- a/index/index.html +++ b/index/index.html @@ -1,64 +1,13 @@ - - -
-
-
-
Loading…
-
-
- - diff --git a/index/index.js b/index/index.js index d19f170..aa7996c 100644 --- a/index/index.js +++ b/index/index.js @@ -1,30 +1,45 @@ -const overlay = document.getElementById('loading-overlay'); -function hideOverlay() { overlay.style.display = 'none' } -function showOverlay() { overlay.style.display = 'flex' } - -// show loading overlay -showOverlay(); +// disable right click context menu +document.getElementById("canvas").addEventListener( + "contextmenu", + (e) => e.preventDefault(), +); +// INITIALIZE RAYLIB import Module from "./rl/raylib.js"; - const wasmBinary = await fetch("./rl/raylib.wasm") - .then(r => r.arrayBuffer()); - -// disable right click context menu -document.getElementById("canvas").addEventListener('contextmenu', e => e.preventDefault()) + .then((r) => r.arrayBuffer()); -let mod = await Module({ - canvas: document.getElementById('canvas'), +const raylib = await Module({ + canvas: document.getElementById("canvas"), wasmBinary: new Uint8Array(wasmBinary), }); -window.mod = mod +// INITIALIZE GO const go = new Go(); -WebAssembly.instantiateStreaming(fetch("main.wasm"), go.importObject) - .then(result => { - // hide loading overlay before running code - hideOverlay(); - go.run(result.instance); - }) - .catch(console.error); +// inject raylib +go.importObject.raylib = raylib; +go.importObject.globalThis = globalThis; +globalThis.raylib = raylib; + +import { Runtime } from "./runtime.js"; // helper funtions +//init +const runtime = new Runtime(); +// inject custom runtime methods +Object.assign(go.importObject.gojs, { + array: runtime.array.bind(runtime), + struct: runtime.struct.bind(runtime), + CStringFromGoString: runtime.CStringFromGoString.bind(runtime), + CStringGetLength: runtime.CStringGetLength.bind(runtime), + CopyToC: runtime.CopyToC.bind(runtime), + CopyToGo: runtime.CopyToGo.bind(runtime), + Alert: runtime.Alert.bind(runtime), +}); + +WebAssembly.instantiateStreaming(fetch("main.wasm"), go.importObject).then( + (result) => { + const instance = result.instance; + globalThis.goInstance = instance; + go.run(instance); + }, +); diff --git a/index/rl/raylib.js b/index/rl/raylib.js index 8f20ef6..f26bcd2 100644 --- a/index/rl/raylib.js +++ b/index/rl/raylib.js @@ -13,4 +13,4 @@ var Module=moduleArg;var readyPromiseResolve,readyPromiseReject;Module["ready"]= ); })(); ; -export default Module; \ No newline at end of file +export default Module; diff --git a/index/rl/raylib.wasm b/index/rl/raylib.wasm old mode 100755 new mode 100644 diff --git a/index/runtime.js b/index/runtime.js new file mode 100644 index 0000000..9c78be4 --- /dev/null +++ b/index/runtime.js @@ -0,0 +1,153 @@ +// Helper functions called from Go via go:wasmimport + +class Runtime { + constructor() { + } + get mem() { + return new DataView(globalThis.goInstance.exports.mem.buffer); + } + getmem(addr, len) { + return new Uint8Array(globalThis.goInstance.exports.mem.buffer, addr, len); + } + get Sp() { + return globalThis.goInstance.exports.getsp() >>> 0; + } + // ---- Helpers from wasm_exec.js ---- + setInt32 = (addr, v) => { + return this.mem.setUint32(addr + 0, v, true); + }; + getInt32 = (addr) => { + return this.mem.getUint32(addr + 0, true); + }; + + setInt64 = (addr, v) => { + this.mem.setUint32(addr + 0, v, true); + this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true); + }; + + getInt64 = (addr) => { + const low = this.mem.getUint32(addr + 0, true); + const high = this.mem.getInt32(addr + 4, true); + return low + high * 4294967296; + }; + + loadSlice = (addr) => { + const array = this.getInt64(addr + 0); + const len = this.getInt64(addr + 8); + return this.getmem(array, len); + }; + + // ---- Runtime helpers ---- + array = (sp) => { + // messing around with slice + sp >>>= 0; + console.log(sp); + // slice capacity + console.log(this.getInt64(sp + 8 + 8)); + console.log(sp + 8); + }; + // function messing around with struct + struct = (sp) => { + sp >>>= 0; + const ptr = this.getInt64(sp + 8); + // this.setInt32(ptr, 99); + // // 2nd field of struct + // this.setInt32(ptr + 4, 69); + // return + this.setInt64(sp + 16, ptr); + }; + + getRaylibU8Array(cptr, len) { + return new Uint8Array( // js slice + globalThis.raylib.HEAPU8.buffer, + cptr, + len, + ); + } + // func(cptr) cstr + // Scans for null terminator and returns the length + CStringGetLength = (sp) => { + sp >>>= 0; + const cStr = this.getInt32(sp + 8 * 1); + const view = raylib.HEAPU8.subarray(cStr); + let len = 0; + while (view[len] !== 0) { + len++; + } + this.setInt32(sp + 8 * 2, len); + }; + // func(string) cptr + // returns pointer to C string in raylib memory + CStringFromGoString = (sp) => { + sp >>>= 0; + // get string addr and length + const saddr = this.getInt64(sp + 8 * 1); // go string address + const len = this.getInt64(sp + 8 * 2); // go string length + + const goStrView = this.getmem(saddr, len); // js slice + + // malloc cstr with room for null terminator + const cstr = globalThis.raylib._malloc(len + 1); + const cStrView = this.getRaylibU8Array(cstr, len + 1); + + // copy Go string to C + cStrView.set(goStrView); + // // set last byte to null terminator + cStrView[len] = 0; + // return cstr + this.setInt32(sp + 8 * 3, cstr); + }; + // func(src unsafe.Pointer, srcSize, dstCptr cptr) + // copies Go memory to C memory. Useful for copying slices and structs. + // Destination C array must have enough space. + // src must be a type. cannot be a slice. To pass a slice, use unsafe.SliceData + CopyToC = (sp) => { + sp >>>= 0; + const srcGoPtr = this.getInt64(sp + 8 * 1); + const srcSize = this.getInt32(sp + 8 * 2); // size of the dstGoPtr + // size and pointer are packed into a single 64bit int by Go's compiler + const dstCptr = this.getInt32(sp + 8 * 2 + 4); + + const goBytes = this.getmem(srcGoPtr, srcSize); + this.getRaylibU8Array(dstCptr, srcSize).set(goBytes); + }; + // func(dstGoPtr unsafe.Pointer, size int32, src cptr) + // copies C memory to a Go pointer. Useful for copying C structs into Go structs + // + // example usage: + // type Person struct{ + // Age string + // } + // + // var cPtrToPersonInCHeap cptr = ... + // + // var p Person + // CopyToGo(unsafe.Pointer(&p),unsafe.SizeOf(p),cPtrToPersonInCHeap) + // + // p.Age == (whatever it was in C) + CopyToGo = (sp) => { + sp >>>= 0; + const dstGoPtr = this.getInt64(sp + 8 * 1); + const size = this.getInt32(sp + 8 * 2); // size of the dstGoPtr + // size and pointer are packed into a single 64bit int by Go's compiler + const srcCptr = this.getInt32(sp + 8 * 2 + 4); + + const srcCBytes = this.getRaylibU8Array(srcCptr, size); + const dstGoBytes = this.getmem(dstGoPtr, size); + // copy C bytes to Go + dstGoBytes.set(srcCBytes); + }; + // func alert(string) + Alert = (sp) => { + sp >>>= 0; + const saddr = this.getInt64(sp + 8 * 1); + const len = this.getInt64(sp + 8 * 2); + const strU8 = this.getmem(saddr, len); + + const decoder = new TextDecoder("utf-8"); // 'utf-8' is the default encoding + const str = decoder.decode(strU8); + alert(str); + }; +} + +export { Runtime }; diff --git a/raylib/go.mod b/raylib/go.mod index 3214f14..764c26a 100644 --- a/raylib/go.mod +++ b/raylib/go.mod @@ -1,5 +1,3 @@ module github.com/BrownNPC/Raylib-Go-Wasm/raylib -require github.com/BrownNPC/wasm-ffi-go v1.2.0 - go 1.24.1 diff --git a/raylib/go.sum b/raylib/go.sum index 808648e..e69de29 100644 --- a/raylib/go.sum +++ b/raylib/go.sum @@ -1,2 +0,0 @@ -github.com/BrownNPC/wasm-ffi-go v1.1.0 h1:oashfuQflpB+qx/xI71Gvim3YN/0iIny5TMIpzEFz0Y= -github.com/BrownNPC/wasm-ffi-go v1.1.0/go.mod h1:D5+RBMb672fgw6vPz4HOWYxpyrmPrIao8VqlXihOFFg= diff --git a/raylib/raylib.go b/raylib/raylib.go index 3aff8b1..59de771 100644 --- a/raylib/raylib.go +++ b/raylib/raylib.go @@ -1,3 +1,5 @@ +//go:build js + /* Package raylib - Go bindings for raylib, a simple and easy-to-use library to enjoy videogames programming. @@ -11,13 +13,12 @@ package rl import ( "image/color" "io" - - wasm "github.com/BrownNPC/wasm-ffi-go" + "structs" ) - // Wave type, defines audio wave data type Wave struct { + _ structs.HostLayout // Number of samples FrameCount uint32 // Frequency (samples per second) @@ -27,21 +28,27 @@ type Wave struct { // Number of channels (1-mono, 2-stereo) Channels uint32 // Buffer data pointer - Data wasm.Pointer + Data cptr } -// // NewWave - Returns new Wave -// func NewWave(sampleCount, sampleRate, sampleSize, channels uint32, data []byte) Wave { -// d := wasm.Pointer(&data[0]) - -// return Wave{sampleCount, sampleRate, sampleSize, channels, d} -// } +// NewWave - Returns new Wave +func NewWave(sampleCount, sampleRate, sampleSize, channels uint32, data []byte) Wave { + ptr, _ := copySliceToC(data) + return Wave{ + FrameCount: sampleCount, + SampleRate: sampleRate, + SampleSize: sampleSize, + Channels: channels, + Data: ptr, + } +} // AudioCallback function. type AudioCallback func(data []float32, frames int) // Sound source type type Sound struct { + _ structs.HostLayout Stream AudioStream FrameCount uint32 _ [4]byte @@ -50,16 +57,18 @@ type Sound struct { // Music type (file streaming from memory) // NOTE: Anything longer than ~10 seconds should be streamed type Music struct { + _ structs.HostLayout Stream AudioStream FrameCount uint32 Looping bool CtxType int32 - CtxData wasm.Pointer + CtxData cptr } // AudioStream type // NOTE: Useful to create custom audio streams not bound to a specific file type AudioStream struct { + _ structs.HostLayout // Buffer Buffer *AudioBuffer // Processor @@ -74,6 +83,7 @@ type AudioStream struct { } type maDataConverter struct { + _ structs.HostLayout FormatIn uint32 FormatOut uint32 ChannelsIn uint32 @@ -94,6 +104,7 @@ type maDataConverter struct { } type maChannelConverter struct { + _ structs.HostLayout Format uint32 ChannelsIn uint32 ChannelsOut uint32 @@ -109,6 +120,7 @@ type maChannelConverter struct { } type maResampler struct { + _ structs.HostLayout PBackend *byte PBackendVTable *maResamplingBackendVtable PBackendUserData *byte @@ -123,6 +135,7 @@ type maResampler struct { } type maResamplingBackendVtable struct { + _ structs.HostLayout OnGetHeapSize *[0]byte OnInit *[0]byte OnUninit *[0]byte @@ -136,6 +149,7 @@ type maResamplingBackendVtable struct { } type AudioBuffer struct { + _ structs.HostLayout Converter maDataConverter Callback *[0]byte Processor *AudioProcessor @@ -156,6 +170,7 @@ type AudioBuffer struct { } type AudioProcessor struct { + _ structs.HostLayout Process *[0]byte Next *AudioProcessor Prev *AudioProcessor @@ -163,6 +178,7 @@ type AudioProcessor struct { // AutomationEvent - Automation event type AutomationEvent struct { + _ structs.HostLayout Frame uint32 Type uint32 Params [4]int32 @@ -170,6 +186,7 @@ type AutomationEvent struct { // AutomationEventList - Automation event list type AutomationEventList struct { + _ structs.HostLayout Capacity uint32 Count uint32 // Events array (c array) @@ -490,17 +507,23 @@ var ( // Vector2 type type Vector2 struct { + _ structs.HostLayout X float32 Y float32 } // NewVector2 - Returns new Vector2 func NewVector2(x, y float32) Vector2 { - return Vector2{x, y} + return Vector2{ + X: x, + Y: y, + } } // Vector3 type type Vector3 struct { + _ structs.HostLayout + _ structs.HostLayout X float32 Y float32 Z float32 @@ -508,11 +531,17 @@ type Vector3 struct { // NewVector3 - Returns new Vector3 func NewVector3(x, y, z float32) Vector3 { - return Vector3{x, y, z} + return Vector3{ + X: x, + Y: y, + Z: z, + } } // Vector4 type type Vector4 struct { + _ structs.HostLayout + _ structs.HostLayout X float32 Y float32 Z float32 @@ -521,11 +550,17 @@ type Vector4 struct { // NewVector4 - Returns new Vector4 func NewVector4(x, y, z, w float32) Vector4 { - return Vector4{x, y, z, w} + return Vector4{ + X: x, + Y: y, + Z: z, + W: w, + } } // Matrix type (OpenGL style 4x4 - right handed, column major) type Matrix struct { + _ structs.HostLayout M0, M4, M8, M12 float32 M1, M5, M9, M13 float32 M2, M6, M10, M14 float32 @@ -534,11 +569,29 @@ type Matrix struct { // NewMatrix - Returns new Matrix func NewMatrix(m0, m4, m8, m12, m1, m5, m9, m13, m2, m6, m10, m14, m3, m7, m11, m15 float32) Matrix { - return Matrix{m0, m4, m8, m12, m1, m5, m9, m13, m2, m6, m10, m14, m3, m7, m11, m15} + return Matrix{ + M0: m0, + M4: m4, + M8: m8, + M12: m12, + M1: m1, + M5: m5, + M9: m9, + M13: m13, + M2: m2, + M6: m6, + M10: m10, + M14: m14, + M3: m3, + M7: m7, + M11: m11, + M15: m15, + } } // Mat2 type (used for polygon shape rotation matrix) type Mat2 struct { + _ structs.HostLayout M00 float32 M01 float32 M10 float32 @@ -547,7 +600,12 @@ type Mat2 struct { // NewMat2 - Returns new Mat2 func NewMat2(m0, m1, m10, m11 float32) Mat2 { - return Mat2{m0, m1, m10, m11} + return Mat2{ + M00: m0, + M01: m1, + M10: m10, + M11: m11, + } } // Quaternion, 4 components (Vector4 alias) @@ -555,7 +613,12 @@ type Quaternion = Vector4 // NewQuaternion - Returns new Quaternion func NewQuaternion(x, y, z, w float32) Quaternion { - return Quaternion{x, y, z, w} + return Quaternion{ + X: x, + Y: y, + Z: z, + W: w, + } } // Color type, RGBA (32bit) @@ -569,6 +632,7 @@ func NewColor(r, g, b, a uint8) color.RGBA { // Rectangle type type Rectangle struct { + _ structs.HostLayout X float32 Y float32 Width float32 @@ -577,7 +641,12 @@ type Rectangle struct { // NewRectangle - Returns new Rectangle func NewRectangle(x, y, width, height float32) Rectangle { - return Rectangle{x, y, width, height} + return Rectangle{ + X: x, + Y: y, + Width: width, + Height: height, + } } // ToInt32 converts rectangle to int32 variant @@ -593,6 +662,7 @@ func (r *Rectangle) ToInt32() RectangleInt32 { // RectangleInt32 type type RectangleInt32 struct { + _ structs.HostLayout X int32 Y int32 Width int32 @@ -612,6 +682,7 @@ func (r *RectangleInt32) ToFloat32() Rectangle { // Camera3D type, defines a camera position/orientation in 3d space type Camera3D struct { + _ structs.HostLayout // Camera position Position Vector3 // Camera target it looks-at @@ -629,11 +700,18 @@ type Camera = Camera3D // NewCamera3D - Returns new Camera3D func NewCamera3D(pos, target, up Vector3, fovy float32, ct CameraProjection) Camera3D { - return Camera3D{pos, target, up, fovy, ct} + return Camera3D{ + Position: pos, + Target: target, + Up: up, + Fovy: fovy, + Projection: ct, + } } // Camera2D type, defines a 2d camera type Camera2D struct { + _ structs.HostLayout // Camera offset (displacement from target) Offset Vector2 // Camera target (rotation and zoom origin) @@ -646,11 +724,17 @@ type Camera2D struct { // NewCamera2D - Returns new Camera2D func NewCamera2D(offset, target Vector2, rotation, zoom float32) Camera2D { - return Camera2D{offset, target, rotation, zoom} + return Camera2D{ + Offset: offset, + Target: target, + Rotation: rotation, + Zoom: zoom, + } } // BoundingBox type type BoundingBox struct { + _ structs.HostLayout // Minimum vertex box-corner Min Vector3 // Maximum vertex box-corner @@ -659,7 +743,10 @@ type BoundingBox struct { // NewBoundingBox - Returns new BoundingBox func NewBoundingBox(min, max Vector3) BoundingBox { - return BoundingBox{min, max} + return BoundingBox{ + Min: min, + Max: max, + } } // Asset file @@ -782,6 +869,7 @@ const ( // Mesh - Vertex data definning a mesh type Mesh struct { + _ structs.HostLayout // Number of vertices stored in arrays VertexCount int32 // Number of triangles stored (indexed or not) @@ -820,6 +908,7 @@ type Mesh struct { // Material type type Material struct { + _ structs.HostLayout // Shader Shader Shader // Maps @@ -830,11 +919,12 @@ type Material struct { // // GetMap - Get pointer to MaterialMap by map type // func (mt Material) GetMap(index int32) *MaterialMap { -// return (*MaterialMap)(wasm.Pointer(uintptr(wasm.Pointer(mt.Maps)) + uintptr(index)*wasm.Sizeof(MaterialMap{}))) +// return (*MaterialMap)(cptr(uintptr(cptr(mt.Maps)) + uintptr(index)*wasm.Sizeof(MaterialMap{}))) // } // MaterialMap type type MaterialMap struct { + _ structs.HostLayout // Texture Texture Texture2D // Color @@ -845,6 +935,7 @@ type MaterialMap struct { // Model is struct of model, meshes, materials and animation data type Model struct { + _ structs.HostLayout // Local transform matrix Transform Matrix // Number of meshes @@ -895,12 +986,14 @@ type Model struct { // BoneInfo type type BoneInfo struct { + _ structs.HostLayout Name [32]int8 Parent int32 } // Transform type type Transform struct { + _ structs.HostLayout Translation Vector3 Rotation Vector4 Scale Vector3 @@ -908,6 +1001,7 @@ type Transform struct { // Ray type (useful for raycast) type Ray struct { + _ structs.HostLayout // Ray position (origin) Position Vector3 // Ray direction @@ -916,11 +1010,15 @@ type Ray struct { // NewRay - Returns new Ray func NewRay(position, direction Vector3) Ray { - return Ray{position, direction} + return Ray{ + Position: position, + Direction: direction, + } } // ModelAnimation type type ModelAnimation struct { + _ structs.HostLayout BoneCount int32 FrameCount int32 Bones *BoneInfo @@ -952,6 +1050,7 @@ func (m ModelAnimation) GetName() string { // RayCollision type - ray hit information type RayCollision struct { + _ structs.HostLayout Hit bool Distance float32 Point Vector3 @@ -960,7 +1059,12 @@ type RayCollision struct { // NewRayCollision - Returns new RayCollision func NewRayCollision(hit bool, distance float32, point, normal Vector3) RayCollision { - return RayCollision{hit, distance, point, normal} + return RayCollision{ + Hit: hit, + Distance: distance, + Point: point, + Normal: normal, + } } // BlendMode type @@ -980,29 +1084,38 @@ const ( // Shader type (generic shader) type Shader struct { + _ structs.HostLayout // Shader program id ID uint32 // Shader locations array - Locs *int32 + Locs cptr } // NewShader - Returns new Shader func NewShader(id uint32, locs *int32) Shader { - return Shader{id, locs} + return Shader{ + ID: id, + Locs: cptr(*locs), + } } -// // GetLocation - Get shader value's location -// func (sh Shader) GetLocation(index int32) int32 { -// return *(*int32)(wasm.Pointer(uintptr(wasm.Pointer(sh.Locs)) + uintptr(index*4))) -// } +// GetLocation - Get shader value's location +func (sh Shader) GetLocation(index int32) int32 { + var v int32 + locAddr := sh.Locs + cptr(index)*4 + copyValueToGo(locAddr, &v) + return v +} -// // UpdateLocation - Update shader value's location -// func (sh Shader) UpdateLocation(index int32, loc int32) { -// *(*int32)(wasm.Pointer(uintptr(wasm.Pointer(sh.Locs)) + uintptr(index*4))) = loc -// } +// UpdateLocation - Update shader value's location +func (sh Shader) UpdateLocation(index int32, loc int32) { + locAddr := sh.Locs * cptr(index) * 4 + copyToC(&loc, locAddr) +} // GlyphInfo - Font character info type GlyphInfo struct { + _ structs.HostLayout // Character value (Unicode) Value int32 // Character offset X when drawing @@ -1017,11 +1130,18 @@ type GlyphInfo struct { // NewGlyphInfo - Returns new CharInfo func NewGlyphInfo(value int32, offsetX, offsetY, advanceX int32, image Image) GlyphInfo { - return GlyphInfo{value, offsetX, offsetY, advanceX, image} + return GlyphInfo{ + Value: value, + OffsetX: offsetX, + OffsetY: offsetY, + AdvanceX: advanceX, + Image: image, + } } // Font type, includes texture and charSet array data type Font struct { + _ structs.HostLayout // Base size (default chars height) BaseSize int32 // Number of characters @@ -1031,9 +1151,11 @@ type Font struct { // Characters texture atlas Texture Texture2D // Characters rectangles in texture - Recs *Rectangle + // Recs *Rectangle + Recs cptr // Characters info data - Chars *GlyphInfo + // Chars *GlyphInfo + Chars cptr } // Font type, defines generation method @@ -1137,8 +1259,9 @@ const ( // Image type, bpp always RGBA (32bit) // NOTE: Data stored in CPU memory (RAM) type Image struct { + _ structs.HostLayout // Image raw Data - Data wasm.Pointer + Data cptr // Image base width Width int32 // Image base height @@ -1151,7 +1274,7 @@ type Image struct { // // NewImage - Returns new Image // func NewImage(data []byte, width, height, mipmaps int32, format PixelFormat) *Image { -// d := wasm.Pointer(&data[0]) +// d := cptr(&data[0]) // return &Image{d, width, height, mipmaps, format} // } @@ -1159,6 +1282,7 @@ type Image struct { // Texture2D type, bpp always RGBA (32bit) // NOTE: Data stored in GPU memory type Texture2D struct { + _ structs.HostLayout // OpenGL texture id ID uint32 // Texture base width @@ -1173,11 +1297,18 @@ type Texture2D struct { // NewTexture2D - Returns new Texture2D func NewTexture2D(id uint32, width, height, mipmaps int32, format PixelFormat) Texture2D { - return Texture2D{id, width, height, mipmaps, format} + return Texture2D{ + ID: id, + Width: width, + Height: height, + Mipmaps: mipmaps, + Format: format, + } } // RenderTexture2D type, for texture rendering type RenderTexture2D struct { + _ structs.HostLayout // Render texture (fbo) id ID uint32 // Color buffer attachment texture @@ -1188,7 +1319,11 @@ type RenderTexture2D struct { // NewRenderTexture2D - Returns new RenderTexture2D func NewRenderTexture2D(id uint32, texture, depth Texture2D) RenderTexture2D { - return RenderTexture2D{id, texture, depth} + return RenderTexture2D{ + ID: id, + Texture: texture, + Depth: depth, + } } // TraceLogCallbackFun - function that will recive the trace log messages @@ -1229,6 +1364,7 @@ const ( // NPatchInfo type, n-patch layout info type NPatchInfo struct { + _ structs.HostLayout Source Rectangle // Texture source rectangle Left int32 // Left border offset Top int32 // Top border offset @@ -1239,6 +1375,7 @@ type NPatchInfo struct { // VrStereoConfig, VR stereo rendering configuration for simulator type VrStereoConfig struct { + _ structs.HostLayout Projection [2]Matrix // VR projection matrices (per eye) ViewOffset [2]Matrix // VR view offset matrices (per eye) LeftLensCenter [2]float32 // VR left lens center @@ -1251,6 +1388,7 @@ type VrStereoConfig struct { // VrDeviceInfo, Head-Mounted-Display device parameters type VrDeviceInfo struct { + _ structs.HostLayout HResolution int32 // Horizontal resolution in pixels VResolution int32 // Vertical resolution in pixels HScreenSize float32 // Horizontal size in meters diff --git a/raylib/raylib_wasm.go b/raylib/raylib_wasm.go deleted file mode 100644 index 096031f..0000000 --- a/raylib/raylib_wasm.go +++ /dev/null @@ -1,122 +0,0 @@ -//go:build js && wasm - -package rl - -// some functions need to be defined manually - -import ( - "image" - "image/color" - "io/fs" - "syscall/js" - - "github.com/BrownNPC/wasm-ffi-go" -) - -// DEPRECATED: use SetMain instead. -var SetMainLoop = SetMain - -// Use this instead of a for loop on web platform -func SetMain(UpdateAndDrawFrame func()) { - wasm.SetMainLoop(UpdateAndDrawFrame) - <-make(chan struct{}, 0) -} - -// Copy embed.FS to wasm memory. This must be called before loading assets -// pass it an embed.FS -func AddFileSystem(efs fs.FS) { - wasm.AddFileSystem(efs) -} - -// UNSUPPORTED: USE SetMainLoop -func WindowShouldClose() bool { - wasm.Panic("WindowShouldClose is unsupported on the web, use SetMainLoop") - return true -} - -var setTraceLogCallback = wasm.Proc("SetTraceLogCallback") - -// SetTraceLogCallback - Set custom trace log -func SetTraceLogCallback(fn TraceLogCallbackFun) { - _, fl := setTraceLogCallback.Call(js.FuncOf(func(this js.Value, args []js.Value) any { - fn(args[0].Int(), args[1].String()) - return nil - })) - wasm.Free(fl...) -} - -var initWindow = wasm.Proc("InitWindow") - -// InitWindow - Initialize window and OpenGL context -func InitWindow(width int32, height int32, title string) { - if width == 0 { - width = int32(js.Global().Get("innerWidth").Int()) - } - if height == 0 { - height = int32(js.Global().Get("innerHeight").Int()) - } - _, fl := initWindow.Call(width, height, title) - wasm.Free(fl...) -} - -var loadFontEx = wasm.Func[Font]("LoadFontEx") - -// LoadFontEx - Load font from file with extended parameters, use NULL for codepoints and 0 for codepointCount to load the default character setFont -func LoadFontEx(fileName string, fontSize int32, codepoints []rune, runesNumber ...int32) Font { - codepointCount := int32(len(codepoints)) - if len(runesNumber) > 0 { - codepointCount = int32(runesNumber[0]) - } - - // Handle empty codepoints slice by passing nil - var codepointsToPass any = codepoints - if len(codepoints) == 0 { - codepointsToPass = nil - } - - ret, fl := loadFontEx.Call(fileName, fontSize, codepointsToPass, codepointCount) - v := wasm.ReadStruct[Font](ret) - wasm.Free(fl...) - return v -} - -// NewImageFromImage - Returns new Image from Go image.Image - -// NewImageFromImage - Returns new Image from Go image.Image -func NewImageFromImage(img image.Image) *Image { - size := img.Bounds().Size() - - ret := GenImageColor(size.X, size.Y, White) - - for y := range size.Y { - for x := range size.X { - col := img.At(x, y) - r, g, b, a := col.RGBA() - rcolor := NewColor(uint8(r>>8), uint8(g>>8), uint8(b>>8), uint8(a>>8)) - ImageDrawPixel(ret, int32(x), int32(y), rcolor) - } - } - return ret -} - -// GenImageColor - Generate image: plain color -func GenImageColor(width int, height int, col color.RGBA) *Image { - ret, fl := genImageColor.Call(width, height, wasm.Struct(col)) - v := wasm.ReadStruct[Image](ret) - wasm.Free(fl...) - return &v -} - -// LoadTextureFromImage - Load texture from image data -func LoadTextureFromImage(image *Image) Texture2D { - ret, fl := loadTextureFromImage.Call(wasm.Struct(*image)) - v := wasm.ReadStruct[Texture2D](ret) - wasm.Free(fl...) - return v -} - -// ImageDrawPixel - Draw pixel within an image -func ImageDrawPixel(dst *Image, posX int32, posY int32, col color.RGBA) { - _, fl := imageDrawPixel.Call(wasm.Struct(*dst), posX, posY, wasm.Struct(col)) - wasm.Free(fl...) -} diff --git a/raylib/rcamera.go b/raylib/rcamera.go index d0df645..a772014 100644 --- a/raylib/rcamera.go +++ b/raylib/rcamera.go @@ -1,350 +1,350 @@ package rl -// GetCameraForward - Returns the cameras forward vector (normalized) -func GetCameraForward(camera *Camera) Vector3 { - return Vector3Normalize(Vector3Subtract(camera.Target, camera.Position)) -} - -// GetCameraUp - Returns the cameras up vector (normalized) -// Note: The up vector might not be perpendicular to the forward vector -func GetCameraUp(camera *Camera) Vector3 { - return Vector3Normalize(camera.Up) -} - -// GetCameraRight - Returns the cameras right vector (normalized) -func GetCameraRight(camera *Camera) Vector3 { - forward := GetCameraForward(camera) - up := GetCameraUp(camera) - - return Vector3CrossProduct(forward, up) -} - -// CameraMoveForward - Moves the camera in its forward direction -func CameraMoveForward(camera *Camera, distance float32, moveInWorldPlane uint8) { - forward := GetCameraForward(camera) - - if moveInWorldPlane != 0 { - // Project vector onto world plane - forward.Y = float32(0) - forward = Vector3Normalize(forward) - } - - // Scale by distance - forward = Vector3Scale(forward, distance) - - // Move position and target - camera.Position = Vector3Add(camera.Position, forward) - camera.Target = Vector3Add(camera.Target, forward) -} - -// CameraMoveUp - Moves the camera in its up direction -func CameraMoveUp(camera *Camera, distance float32) { - up := GetCameraUp(camera) - - // Scale by distance - up = Vector3Scale(up, distance) - - // Move position and target - camera.Position = Vector3Add(camera.Position, up) - camera.Target = Vector3Add(camera.Target, up) -} - -// CameraMoveRight - Moves the camera target in its current right direction -func CameraMoveRight(camera *Camera, distance float32, moveInWorldPlane uint8) { - right := GetCameraRight(camera) - - if moveInWorldPlane != 0 { - // Project vector onto world plane - right.Y = float32(0) - right = Vector3Normalize(right) - } - - // Scale by distance - right = Vector3Scale(right, distance) - - // Move position and target - camera.Position = Vector3Add(camera.Position, right) - camera.Target = Vector3Add(camera.Target, right) -} - -// CameraMoveToTarget - Moves the camera position closer/farther to/from the camera target -func CameraMoveToTarget(camera *Camera, delta float32) { - distance := Vector3Distance(camera.Position, camera.Target) - - // Apply delta - distance = distance + delta - - // Distance must be greater than 0 - if distance <= float32(0) { - distance = 0.001 - } - - // Set new distance by moving the position along the forward vector - forward := GetCameraForward(camera) - camera.Position = Vector3Add(camera.Target, Vector3Scale(forward, -distance)) -} - -// CameraYaw - Rotates the camera around its up vector -// Yaw is "looking left and right" -// If rotateAroundTarget is false, the camera rotates around its position -// Note: angle must be provided in radians -func CameraYaw(camera *Camera, angle float32, rotateAroundTarget uint8) { - // Rotation axis - var up = GetCameraUp(camera) - - // View vector - var targetPosition = Vector3Subtract(camera.Target, camera.Position) - - // Rotate view vector around up axis - targetPosition = Vector3RotateByAxisAngle(targetPosition, up, angle) - - if rotateAroundTarget != 0 { - // Move position relative to target - camera.Position = Vector3Subtract(camera.Target, targetPosition) - } else { - // Move target relative to position - camera.Target = Vector3Add(camera.Position, targetPosition) - } -} - -// CameraPitch - Rotates the camera around its right vector, pitch is "looking up and down" -// - lockView prevents camera overrotation (aka "somersaults") -// - rotateAroundTarget defines if rotation is around target or around its position -// - rotateUp rotates the up direction as well (typically only useful in CAMERA_FREE) -// -// NOTE: angle must be provided in radians -func CameraPitch(camera *Camera, angle float32, lockView uint8, rotateAroundTarget uint8, rotateUp uint8) { - // Up direction - var up = GetCameraUp(camera) - - // View vector - var targetPosition = Vector3Subtract(camera.Target, camera.Position) - - if lockView != 0 { - // In these camera modes we clamp the Pitch angle - // to allow only viewing straight up or down. - - // Clamp view up - maxAngleUp := Vector3Angle(up, targetPosition) - maxAngleUp = maxAngleUp - 0.001 // avoid numerical errors - if angle > maxAngleUp { - angle = maxAngleUp - } - - // Clamp view down - maxAngleDown := Vector3Angle(Vector3Negate(up), targetPosition) - maxAngleDown = maxAngleDown * -1.0 // downwards angle is negative - maxAngleDown = maxAngleDown + 0.001 // avoid numerical errors - if angle < maxAngleDown { - angle = maxAngleDown - } - } - - // Rotation axis - var right = GetCameraRight(camera) - - // Rotate view vector around right axis - targetPosition = Vector3RotateByAxisAngle(targetPosition, right, angle) - - if rotateAroundTarget != 0 { - // Move position relative to target - camera.Position = Vector3Subtract(camera.Target, targetPosition) - } else { - // Move target relative to position - camera.Target = Vector3Add(camera.Position, targetPosition) - } - - if rotateUp != 0 { - // Rotate up direction around right axis - camera.Up = Vector3RotateByAxisAngle(camera.Up, right, angle) - } -} - -// CameraRoll - Rotates the camera around its forward vector -// Roll is "turning your head sideways to the left or right" -// Note: angle must be provided in radians -func CameraRoll(camera *Camera, angle float32) { - // Rotation axis - var forward = GetCameraForward(camera) - - // Rotate up direction around forward axis - camera.Up = Vector3RotateByAxisAngle(camera.Up, forward, angle) -} - -// GetCameraViewMatrix - Returns the camera view matrix -func GetCameraViewMatrix(camera *Camera) Matrix { - return MatrixLookAt(camera.Position, camera.Target, camera.Up) -} - -// GetCameraProjectionMatrix - Returns the camera projection matrix -func GetCameraProjectionMatrix(camera *Camera, aspect float32) Matrix { - if camera.Projection == CameraPerspective { - return MatrixPerspective(camera.Fovy*(Pi/180.0), aspect, 0.01, 1000.0) - } else if camera.Projection == CameraOrthographic { - top := camera.Fovy / 2.0 - right := top * aspect - - return MatrixOrtho(-right, right, -top, top, 0.01, 1000.0) - } - - return MatrixIdentity() -} - -// UpdateCamera - Update camera position for selected mode -// Camera mode: CameraFree, CameraFirstPerson, CameraThirdPerson, CameraOrbital or Custom -func UpdateCamera(camera *Camera, mode CameraMode) { - var mousePositionDelta = GetMouseDelta() - - moveInWorldPlaneBool := mode == CameraFirstPerson || mode == CameraThirdPerson - var moveInWorldPlane uint8 - if moveInWorldPlaneBool { - moveInWorldPlane = 1 - } - - rotateAroundTargetBool := mode == CameraThirdPerson || mode == CameraOrbital - var rotateAroundTarget uint8 - if rotateAroundTargetBool { - rotateAroundTarget = 1 - } - - lockViewBool := mode == CameraFirstPerson || mode == CameraThirdPerson || mode == CameraOrbital - var lockView uint8 - if lockViewBool { - lockView = 1 - } - - var rotateUp uint8 - - if mode == CameraOrbital { - // Orbital can just orbit - var rotation = MatrixRotate(GetCameraUp(camera), 0.5*GetFrameTime()) - var view = Vector3Subtract(camera.Position, camera.Target) - view = Vector3Transform(view, rotation) - camera.Position = Vector3Add(camera.Target, view) - } else { - // Camera rotation - if IsKeyDown(KeyDown) { - CameraPitch(camera, -0.03, lockView, rotateAroundTarget, rotateUp) - } - if IsKeyDown(KeyUp) { - CameraPitch(camera, 0.03, lockView, rotateAroundTarget, rotateUp) - } - if IsKeyDown(KeyRight) { - CameraYaw(camera, -0.03, rotateAroundTarget) - } - if IsKeyDown(KeyLeft) { - CameraYaw(camera, 0.03, rotateAroundTarget) - } - if IsKeyDown(KeyQ) { - CameraRoll(camera, -0.03) - } - if IsKeyDown(KeyE) { - CameraRoll(camera, 0.03) - } - - // Camera movement - if !(IsGamepadAvailable(0)) { - // Camera pan (for CameraFree) - if mode == CameraFree && IsMouseButtonDown(MouseMiddleButton) { - var mouseDelta = GetMouseDelta() - if mouseDelta.X > 0.0 { - CameraMoveRight(camera, 0.2, moveInWorldPlane) - } - if mouseDelta.X < 0.0 { - CameraMoveRight(camera, -0.2, moveInWorldPlane) - } - if mouseDelta.Y > 0.0 { - CameraMoveUp(camera, -0.2) - } - if mouseDelta.Y < 0.0 { - CameraMoveUp(camera, 0.2) - } - } else { - // Mouse support - CameraYaw(camera, -mousePositionDelta.X*0.003, rotateAroundTarget) - CameraPitch(camera, -mousePositionDelta.Y*0.003, lockView, rotateAroundTarget, rotateUp) - } - - // Keyboard support - if IsKeyDown(KeyW) { - CameraMoveForward(camera, 0.09, moveInWorldPlane) - } - if IsKeyDown(KeyA) { - CameraMoveRight(camera, -0.09, moveInWorldPlane) - } - if IsKeyDown(KeyS) { - CameraMoveForward(camera, -0.09, moveInWorldPlane) - } - if IsKeyDown(KeyD) { - CameraMoveRight(camera, 0.09, moveInWorldPlane) - } - } else { - // Gamepad controller support - CameraYaw(camera, -(GetGamepadAxisMovement(0, GamepadAxisRightX)*float32(2))*0.003, rotateAroundTarget) - CameraPitch(camera, -(GetGamepadAxisMovement(0, GamepadAxisRightY)*float32(2))*0.003, lockView, rotateAroundTarget, rotateUp) - - if GetGamepadAxisMovement(0, GamepadAxisLeftY) <= -0.25 { - CameraMoveForward(camera, 0.09, moveInWorldPlane) - } - if GetGamepadAxisMovement(0, GamepadAxisLeftX) <= -0.25 { - CameraMoveRight(camera, -0.09, moveInWorldPlane) - } - if GetGamepadAxisMovement(0, GamepadAxisLeftY) >= 0.25 { - CameraMoveForward(camera, -0.09, moveInWorldPlane) - } - if GetGamepadAxisMovement(0, GamepadAxisLeftX) >= 0.25 { - CameraMoveRight(camera, 0.09, moveInWorldPlane) - } - } - - if mode == CameraFree { - if IsKeyDown(KeySpace) { - CameraMoveUp(camera, 0.09) - } - if IsKeyDown(KeyLeftControl) { - CameraMoveUp(camera, -0.09) - } - } - } - - if mode == CameraThirdPerson || mode == CameraOrbital || mode == CameraFree { - // Zoom target distance - CameraMoveToTarget(camera, -GetMouseWheelMove()) - if IsKeyPressed(KeyKpSubtract) { - CameraMoveToTarget(camera, 2.0) - } - if IsKeyPressed(KeyKpAdd) { - CameraMoveToTarget(camera, -2.0) - } - } -} - -// UpdateCameraPro - Update camera movement, movement/rotation values should be provided by user -func UpdateCameraPro(camera *Camera, movement Vector3, rotation Vector3, zoom float32) { - // Required values - // movement.X - Move forward/backward - // movement.Y - Move right/left - // movement.Z - Move up/down - // rotation.X - yaw - // rotation.Y - pitch - // rotation.Z - roll - // zoom - Move towards target - - lockView := uint8(1) - rotateAroundTarget := uint8(0) - rotateUp := uint8(0) - moveInWorldPlane := uint8(1) - - // Camera rotation - CameraPitch(camera, -rotation.Y*(Pi/180.0), lockView, rotateAroundTarget, rotateUp) - CameraYaw(camera, -rotation.X*(Pi/180.0), rotateAroundTarget) - CameraRoll(camera, rotation.Z*(Pi/180.0)) - - // Camera movement - CameraMoveForward(camera, movement.X, moveInWorldPlane) - CameraMoveRight(camera, movement.Y, moveInWorldPlane) - CameraMoveUp(camera, movement.Z) - - // Zoom target distance - CameraMoveToTarget(camera, zoom) -} +// // GetCameraForward - Returns the cameras forward vector (normalized) +// func GetCameraForward(camera *Camera) Vector3 { +// return Vector3Normalize(Vector3Subtract(camera.Target, camera.Position)) +// } + +// // GetCameraUp - Returns the cameras up vector (normalized) +// // Note: The up vector might not be perpendicular to the forward vector +// func GetCameraUp(camera *Camera) Vector3 { +// return Vector3Normalize(camera.Up) +// } + +// // GetCameraRight - Returns the cameras right vector (normalized) +// func GetCameraRight(camera *Camera) Vector3 { +// forward := GetCameraForward(camera) +// up := GetCameraUp(camera) + +// return Vector3CrossProduct(forward, up) +// } + +// // CameraMoveForward - Moves the camera in its forward direction +// func CameraMoveForward(camera *Camera, distance float32, moveInWorldPlane uint8) { +// forward := GetCameraForward(camera) + +// if moveInWorldPlane != 0 { +// // Project vector onto world plane +// forward.Y = float32(0) +// forward = Vector3Normalize(forward) +// } + +// // Scale by distance +// forward = Vector3Scale(forward, distance) + +// // Move position and target +// camera.Position = Vector3Add(camera.Position, forward) +// camera.Target = Vector3Add(camera.Target, forward) +// } + +// // CameraMoveUp - Moves the camera in its up direction +// func CameraMoveUp(camera *Camera, distance float32) { +// up := GetCameraUp(camera) + +// // Scale by distance +// up = Vector3Scale(up, distance) + +// // Move position and target +// camera.Position = Vector3Add(camera.Position, up) +// camera.Target = Vector3Add(camera.Target, up) +// } + +// // CameraMoveRight - Moves the camera target in its current right direction +// func CameraMoveRight(camera *Camera, distance float32, moveInWorldPlane uint8) { +// right := GetCameraRight(camera) + +// if moveInWorldPlane != 0 { +// // Project vector onto world plane +// right.Y = float32(0) +// right = Vector3Normalize(right) +// } + +// // Scale by distance +// right = Vector3Scale(right, distance) + +// // Move position and target +// camera.Position = Vector3Add(camera.Position, right) +// camera.Target = Vector3Add(camera.Target, right) +// } + +// // CameraMoveToTarget - Moves the camera position closer/farther to/from the camera target +// func CameraMoveToTarget(camera *Camera, delta float32) { +// distance := Vector3Distance(camera.Position, camera.Target) + +// // Apply delta +// distance = distance + delta + +// // Distance must be greater than 0 +// if distance <= float32(0) { +// distance = 0.001 +// } + +// // Set new distance by moving the position along the forward vector +// forward := GetCameraForward(camera) +// camera.Position = Vector3Add(camera.Target, Vector3Scale(forward, -distance)) +// } + +// // CameraYaw - Rotates the camera around its up vector +// // Yaw is "looking left and right" +// // If rotateAroundTarget is false, the camera rotates around its position +// // Note: angle must be provided in radians +// func CameraYaw(camera *Camera, angle float32, rotateAroundTarget uint8) { +// // Rotation axis +// var up = GetCameraUp(camera) + +// // View vector +// var targetPosition = Vector3Subtract(camera.Target, camera.Position) + +// // Rotate view vector around up axis +// targetPosition = Vector3RotateByAxisAngle(targetPosition, up, angle) + +// if rotateAroundTarget != 0 { +// // Move position relative to target +// camera.Position = Vector3Subtract(camera.Target, targetPosition) +// } else { +// // Move target relative to position +// camera.Target = Vector3Add(camera.Position, targetPosition) +// } +// } + +// // CameraPitch - Rotates the camera around its right vector, pitch is "looking up and down" +// // - lockView prevents camera overrotation (aka "somersaults") +// // - rotateAroundTarget defines if rotation is around target or around its position +// // - rotateUp rotates the up direction as well (typically only useful in CAMERA_FREE) +// // +// // NOTE: angle must be provided in radians +// func CameraPitch(camera *Camera, angle float32, lockView uint8, rotateAroundTarget uint8, rotateUp uint8) { +// // Up direction +// var up = GetCameraUp(camera) + +// // View vector +// var targetPosition = Vector3Subtract(camera.Target, camera.Position) + +// if lockView != 0 { +// // In these camera modes we clamp the Pitch angle +// // to allow only viewing straight up or down. + +// // Clamp view up +// maxAngleUp := Vector3Angle(up, targetPosition) +// maxAngleUp = maxAngleUp - 0.001 // avoid numerical errors +// if angle > maxAngleUp { +// angle = maxAngleUp +// } + +// // Clamp view down +// maxAngleDown := Vector3Angle(Vector3Negate(up), targetPosition) +// maxAngleDown = maxAngleDown * -1.0 // downwards angle is negative +// maxAngleDown = maxAngleDown + 0.001 // avoid numerical errors +// if angle < maxAngleDown { +// angle = maxAngleDown +// } +// } + +// // Rotation axis +// var right = GetCameraRight(camera) + +// // Rotate view vector around right axis +// targetPosition = Vector3RotateByAxisAngle(targetPosition, right, angle) + +// if rotateAroundTarget != 0 { +// // Move position relative to target +// camera.Position = Vector3Subtract(camera.Target, targetPosition) +// } else { +// // Move target relative to position +// camera.Target = Vector3Add(camera.Position, targetPosition) +// } + +// if rotateUp != 0 { +// // Rotate up direction around right axis +// camera.Up = Vector3RotateByAxisAngle(camera.Up, right, angle) +// } +// } + +// // CameraRoll - Rotates the camera around its forward vector +// // Roll is "turning your head sideways to the left or right" +// // Note: angle must be provided in radians +// func CameraRoll(camera *Camera, angle float32) { +// // Rotation axis +// var forward = GetCameraForward(camera) + +// // Rotate up direction around forward axis +// camera.Up = Vector3RotateByAxisAngle(camera.Up, forward, angle) +// } + +// // GetCameraViewMatrix - Returns the camera view matrix +// func GetCameraViewMatrix(camera *Camera) Matrix { +// return MatrixLookAt(camera.Position, camera.Target, camera.Up) +// } + +// // GetCameraProjectionMatrix - Returns the camera projection matrix +// func GetCameraProjectionMatrix(camera *Camera, aspect float32) Matrix { +// if camera.Projection == CameraPerspective { +// return MatrixPerspective(camera.Fovy*(Pi/180.0), aspect, 0.01, 1000.0) +// } else if camera.Projection == CameraOrthographic { +// top := camera.Fovy / 2.0 +// right := top * aspect + +// return MatrixOrtho(-right, right, -top, top, 0.01, 1000.0) +// } + +// return MatrixIdentity() +// } + +// // UpdateCamera - Update camera position for selected mode +// // Camera mode: CameraFree, CameraFirstPerson, CameraThirdPerson, CameraOrbital or Custom +// func UpdateCamera(camera *Camera, mode CameraMode) { +// var mousePositionDelta = GetMouseDelta() + +// moveInWorldPlaneBool := mode == CameraFirstPerson || mode == CameraThirdPerson +// var moveInWorldPlane uint8 +// if moveInWorldPlaneBool { +// moveInWorldPlane = 1 +// } + +// rotateAroundTargetBool := mode == CameraThirdPerson || mode == CameraOrbital +// var rotateAroundTarget uint8 +// if rotateAroundTargetBool { +// rotateAroundTarget = 1 +// } + +// lockViewBool := mode == CameraFirstPerson || mode == CameraThirdPerson || mode == CameraOrbital +// var lockView uint8 +// if lockViewBool { +// lockView = 1 +// } + +// var rotateUp uint8 + +// if mode == CameraOrbital { +// // Orbital can just orbit +// var rotation = MatrixRotate(GetCameraUp(camera), 0.5*GetFrameTime()) +// var view = Vector3Subtract(camera.Position, camera.Target) +// view = Vector3Transform(view, rotation) +// camera.Position = Vector3Add(camera.Target, view) +// } else { +// // Camera rotation +// if IsKeyDown(KeyDown) { +// CameraPitch(camera, -0.03, lockView, rotateAroundTarget, rotateUp) +// } +// if IsKeyDown(KeyUp) { +// CameraPitch(camera, 0.03, lockView, rotateAroundTarget, rotateUp) +// } +// if IsKeyDown(KeyRight) { +// CameraYaw(camera, -0.03, rotateAroundTarget) +// } +// if IsKeyDown(KeyLeft) { +// CameraYaw(camera, 0.03, rotateAroundTarget) +// } +// if IsKeyDown(KeyQ) { +// CameraRoll(camera, -0.03) +// } +// if IsKeyDown(KeyE) { +// CameraRoll(camera, 0.03) +// } + +// // Camera movement +// if !(IsGamepadAvailable(0)) { +// // Camera pan (for CameraFree) +// if mode == CameraFree && IsMouseButtonDown(MouseMiddleButton) { +// var mouseDelta = GetMouseDelta() +// if mouseDelta.X > 0.0 { +// CameraMoveRight(camera, 0.2, moveInWorldPlane) +// } +// if mouseDelta.X < 0.0 { +// CameraMoveRight(camera, -0.2, moveInWorldPlane) +// } +// if mouseDelta.Y > 0.0 { +// CameraMoveUp(camera, -0.2) +// } +// if mouseDelta.Y < 0.0 { +// CameraMoveUp(camera, 0.2) +// } +// } else { +// // Mouse support +// CameraYaw(camera, -mousePositionDelta.X*0.003, rotateAroundTarget) +// CameraPitch(camera, -mousePositionDelta.Y*0.003, lockView, rotateAroundTarget, rotateUp) +// } + +// // Keyboard support +// if IsKeyDown(KeyW) { +// CameraMoveForward(camera, 0.09, moveInWorldPlane) +// } +// if IsKeyDown(KeyA) { +// CameraMoveRight(camera, -0.09, moveInWorldPlane) +// } +// if IsKeyDown(KeyS) { +// CameraMoveForward(camera, -0.09, moveInWorldPlane) +// } +// if IsKeyDown(KeyD) { +// CameraMoveRight(camera, 0.09, moveInWorldPlane) +// } +// } else { +// // Gamepad controller support +// CameraYaw(camera, -(GetGamepadAxisMovement(0, GamepadAxisRightX)*float32(2))*0.003, rotateAroundTarget) +// CameraPitch(camera, -(GetGamepadAxisMovement(0, GamepadAxisRightY)*float32(2))*0.003, lockView, rotateAroundTarget, rotateUp) + +// if GetGamepadAxisMovement(0, GamepadAxisLeftY) <= -0.25 { +// CameraMoveForward(camera, 0.09, moveInWorldPlane) +// } +// if GetGamepadAxisMovement(0, GamepadAxisLeftX) <= -0.25 { +// CameraMoveRight(camera, -0.09, moveInWorldPlane) +// } +// if GetGamepadAxisMovement(0, GamepadAxisLeftY) >= 0.25 { +// CameraMoveForward(camera, -0.09, moveInWorldPlane) +// } +// if GetGamepadAxisMovement(0, GamepadAxisLeftX) >= 0.25 { +// CameraMoveRight(camera, 0.09, moveInWorldPlane) +// } +// } + +// if mode == CameraFree { +// if IsKeyDown(KeySpace) { +// CameraMoveUp(camera, 0.09) +// } +// if IsKeyDown(KeyLeftControl) { +// CameraMoveUp(camera, -0.09) +// } +// } +// } + +// if mode == CameraThirdPerson || mode == CameraOrbital || mode == CameraFree { +// // Zoom target distance +// CameraMoveToTarget(camera, -GetMouseWheelMove()) +// if IsKeyPressed(KeyKpSubtract) { +// CameraMoveToTarget(camera, 2.0) +// } +// if IsKeyPressed(KeyKpAdd) { +// CameraMoveToTarget(camera, -2.0) +// } +// } +// } + +// // UpdateCameraPro - Update camera movement, movement/rotation values should be provided by user +// func UpdateCameraPro(camera *Camera, movement Vector3, rotation Vector3, zoom float32) { +// // Required values +// // movement.X - Move forward/backward +// // movement.Y - Move right/left +// // movement.Z - Move up/down +// // rotation.X - yaw +// // rotation.Y - pitch +// // rotation.Z - roll +// // zoom - Move towards target + +// lockView := uint8(1) +// rotateAroundTarget := uint8(0) +// rotateUp := uint8(0) +// moveInWorldPlane := uint8(1) + +// // Camera rotation +// CameraPitch(camera, -rotation.Y*(Pi/180.0), lockView, rotateAroundTarget, rotateUp) +// CameraYaw(camera, -rotation.X*(Pi/180.0), rotateAroundTarget) +// CameraRoll(camera, rotation.Z*(Pi/180.0)) + +// // Camera movement +// CameraMoveForward(camera, movement.X, moveInWorldPlane) +// CameraMoveRight(camera, movement.Y, moveInWorldPlane) +// CameraMoveUp(camera, movement.Z) + +// // Zoom target distance +// CameraMoveToTarget(camera, zoom) +// } diff --git a/raylib/rcore_wasm.go b/raylib/rcore_wasm.go index 71b447e..9ef7f35 100644 --- a/raylib/rcore_wasm.go +++ b/raylib/rcore_wasm.go @@ -1,3951 +1,1484 @@ +//go:build js + package rl import ( - "image" "image/color" + "syscall/js" "unsafe" - - wasm "github.com/BrownNPC/wasm-ffi-go" ) -var closeWindow = wasm.Proc("CloseWindow") -var isWindowReady = wasm.Func[bool]("IsWindowReady") -var isWindowFullscreen = wasm.Func[bool]("IsWindowFullscreen") -var isWindowResized = wasm.Func[bool]("IsWindowResized") -var isWindowState = wasm.Func[bool]("IsWindowState") -var clearWindowState = wasm.Proc("ClearWindowState") -var setWindowIcon = wasm.Proc("SetWindowIcon") -var setWindowIcons = wasm.Proc("SetWindowIcons") -var setWindowTitle = wasm.Proc("SetWindowTitle") -var setWindowMonitor = wasm.Proc("SetWindowMonitor") -var setWindowMinSize = wasm.Proc("SetWindowMinSize") -var setWindowMaxSize = wasm.Proc("SetWindowMaxSize") -var setWindowSize = wasm.Proc("SetWindowSize") -var getWindowHandle = wasm.Func[unsafe.Pointer]("GetWindowHandle") -var getScreenWidth = wasm.Func[int]("GetScreenWidth") -var getScreenHeight = wasm.Func[int]("GetScreenHeight") -var getRenderWidth = wasm.Func[int]("GetRenderWidth") -var getRenderHeight = wasm.Func[int]("GetRenderHeight") -var getMonitorCount = wasm.Func[int]("GetMonitorCount") -var getCurrentMonitor = wasm.Func[int]("GetCurrentMonitor") -var getMonitorPosition = wasm.Func[Vector2]("GetMonitorPosition") -var getMonitorWidth = wasm.Func[int]("GetMonitorWidth") -var getMonitorHeight = wasm.Func[int]("GetMonitorHeight") -var getMonitorPhysicalWidth = wasm.Func[int]("GetMonitorPhysicalWidth") -var getMonitorPhysicalHeight = wasm.Func[int]("GetMonitorPhysicalHeight") -var getMonitorRefreshRate = wasm.Func[int]("GetMonitorRefreshRate") -var getWindowPosition = wasm.Func[Vector2]("GetWindowPosition") -var getWindowScaleDPI = wasm.Func[Vector2]("GetWindowScaleDPI") -var getMonitorName = wasm.Func[string]("GetMonitorName") -var setClipboardText = wasm.Proc("SetClipboardText") -var getClipboardText = wasm.Func[string]("GetClipboardText") -var getClipboardImage = wasm.Func[Image]("GetClipboardImage") -var enableEventWaiting = wasm.Proc("EnableEventWaiting") -var disableEventWaiting = wasm.Proc("DisableEventWaiting") -var showCursor = wasm.Proc("ShowCursor") -var hideCursor = wasm.Proc("HideCursor") -var isCursorHidden = wasm.Func[bool]("IsCursorHidden") -var enableCursor = wasm.Proc("EnableCursor") -var disableCursor = wasm.Proc("DisableCursor") -var isCursorOnScreen = wasm.Func[bool]("IsCursorOnScreen") -var clearBackground = wasm.Proc("ClearBackground") -var beginDrawing = wasm.Proc("BeginDrawing") -var endDrawing = wasm.Proc("EndDrawing") -var beginMode2D = wasm.Proc("BeginMode2D") -var endMode2D = wasm.Proc("EndMode2D") -var beginMode3D = wasm.Proc("BeginMode3D") -var endMode3D = wasm.Proc("EndMode3D") -var beginTextureMode = wasm.Proc("BeginTextureMode") -var endTextureMode = wasm.Proc("EndTextureMode") -var beginShaderMode = wasm.Proc("BeginShaderMode") -var endShaderMode = wasm.Proc("EndShaderMode") -var beginBlendMode = wasm.Proc("BeginBlendMode") -var endBlendMode = wasm.Proc("EndBlendMode") -var beginScissorMode = wasm.Proc("BeginScissorMode") -var endScissorMode = wasm.Proc("EndScissorMode") -var beginVrStereoMode = wasm.Proc("BeginVrStereoMode") -var endVrStereoMode = wasm.Proc("EndVrStereoMode") -var loadVrStereoConfig = wasm.Func[VrStereoConfig]("LoadVrStereoConfig") -var unloadVrStereoConfig = wasm.Proc("UnloadVrStereoConfig") -var loadShader = wasm.Func[Shader]("LoadShader") -var loadShaderFromMemory = wasm.Func[Shader]("LoadShaderFromMemory") -var isShaderValid = wasm.Func[bool]("IsShaderValid") -var getShaderLocation = wasm.Func[int32]("GetShaderLocation") -var getShaderLocationAttrib = wasm.Func[int32]("GetShaderLocationAttrib") -var setShaderValue = wasm.Proc("SetShaderValue") -var setShaderValueV = wasm.Proc("SetShaderValueV") -var setShaderValueMatrix = wasm.Proc("SetShaderValueMatrix") -var setShaderValueTexture = wasm.Proc("SetShaderValueTexture") -var unloadShader = wasm.Proc("UnloadShader") -var getMouseRay = wasm.Func[Ray]("GetMouseRay") -var getScreenToWorldRay = wasm.Func[Ray]("GetScreenToWorldRay") -var getScreenToWorldRayEx = wasm.Func[Ray]("GetScreenToWorldRayEx") -var getCameraMatrix = wasm.Func[Matrix]("GetCameraMatrix") -var getCameraMatrix2D = wasm.Func[Matrix]("GetCameraMatrix2D") -var getWorldToScreen = wasm.Func[Vector2]("GetWorldToScreen") -var getScreenToWorld2D = wasm.Func[Vector2]("GetScreenToWorld2D") -var getWorldToScreenEx = wasm.Func[Vector2]("GetWorldToScreenEx") -var getWorldToScreen2D = wasm.Func[Vector2]("GetWorldToScreen2D") -var setTargetFPS = wasm.Proc("SetTargetFPS") -var getFrameTime = wasm.Func[float32]("GetFrameTime") -var getTime = wasm.Func[float64]("GetTime") -var getFPS = wasm.Func[int32]("GetFPS") -var swapScreenBuffer = wasm.Proc("SwapScreenBuffer") -var pollInputEvents = wasm.Proc("PollInputEvents") -var waitTime = wasm.Proc("WaitTime") -var setRandomSeed = wasm.Proc("SetRandomSeed") -var getRandomValue = wasm.Func[int32]("GetRandomValue") -var loadRandomSequence = wasm.Func[[]int32]("LoadRandomSequence") -var unloadRandomSequence = wasm.Proc("UnloadRandomSequence") -var takeScreenshot = wasm.Proc("TakeScreenshot") -var setConfigFlags = wasm.Proc("SetConfigFlags") -var openURL = wasm.Proc("OpenURL") -var traceLog = wasm.Proc("TraceLog") -var setTraceLogLevel = wasm.Proc("SetTraceLogLevel") -var memAlloc = wasm.Func[unsafe.Pointer]("MemAlloc") -var memRealloc = wasm.Func[unsafe.Pointer]("MemRealloc") -var memFree = wasm.Proc("MemFree") -var isFileDropped = wasm.Func[bool]("IsFileDropped") -var loadDroppedFiles = wasm.Func[[]string]("LoadDroppedFiles") -var unloadDroppedFiles = wasm.Proc("UnloadDroppedFiles") -var loadAutomationEventList = wasm.Func[AutomationEventList]("LoadAutomationEventList") -var unloadAutomationEventList = wasm.Proc("UnloadAutomationEventList") -var exportAutomationEventList = wasm.Func[bool]("ExportAutomationEventList") -var setAutomationEventList = wasm.Proc("SetAutomationEventList") -var setAutomationEventBaseFrame = wasm.Proc("SetAutomationEventBaseFrame") -var startAutomationEventRecording = wasm.Proc("StartAutomationEventRecording") -var stopAutomationEventRecording = wasm.Proc("StopAutomationEventRecording") -var playAutomationEvent = wasm.Proc("PlayAutomationEvent") -var isKeyPressed = wasm.Func[bool]("IsKeyPressed") -var isKeyPressedRepeat = wasm.Func[bool]("IsKeyPressedRepeat") -var isKeyDown = wasm.Func[bool]("IsKeyDown") -var isKeyReleased = wasm.Func[bool]("IsKeyReleased") -var isKeyUp = wasm.Func[bool]("IsKeyUp") -var getKeyPressed = wasm.Func[int32]("GetKeyPressed") -var getCharPressed = wasm.Func[int32]("GetCharPressed") -var setExitKey = wasm.Proc("SetExitKey") -var isGamepadAvailable = wasm.Func[bool]("IsGamepadAvailable") -var getGamepadName = wasm.Func[string]("GetGamepadName") -var isGamepadButtonPressed = wasm.Func[bool]("IsGamepadButtonPressed") -var isGamepadButtonDown = wasm.Func[bool]("IsGamepadButtonDown") -var isGamepadButtonReleased = wasm.Func[bool]("IsGamepadButtonReleased") -var isGamepadButtonUp = wasm.Func[bool]("IsGamepadButtonUp") -var getGamepadButtonPressed = wasm.Func[int32]("GetGamepadButtonPressed") -var getGamepadAxisCount = wasm.Func[int32]("GetGamepadAxisCount") -var getGamepadAxisMovement = wasm.Func[float32]("GetGamepadAxisMovement") -var setGamepadMappings = wasm.Func[int32]("SetGamepadMappings") -var setGamepadVibration = wasm.Proc("SetGamepadVibration") -var isMouseButtonPressed = wasm.Func[bool]("IsMouseButtonPressed") -var isMouseButtonDown = wasm.Func[bool]("IsMouseButtonDown") -var isMouseButtonReleased = wasm.Func[bool]("IsMouseButtonReleased") -var isMouseButtonUp = wasm.Func[bool]("IsMouseButtonUp") -var getMouseX = wasm.Func[int32]("GetMouseX") -var getMouseY = wasm.Func[int32]("GetMouseY") -var getMousePosition = wasm.Func[Vector2]("GetMousePosition") -var getMouseDelta = wasm.Func[Vector2]("GetMouseDelta") -var setMousePosition = wasm.Proc("SetMousePosition") -var setMouseOffset = wasm.Proc("SetMouseOffset") -var setMouseScale = wasm.Proc("SetMouseScale") -var getMouseWheelMove = wasm.Func[float32]("GetMouseWheelMove") -var getMouseWheelMoveV = wasm.Func[Vector2]("GetMouseWheelMoveV") -var setMouseCursor = wasm.Proc("SetMouseCursor") -var getTouchX = wasm.Func[int32]("GetTouchX") -var getTouchY = wasm.Func[int32]("GetTouchY") -var getTouchPosition = wasm.Func[Vector2]("GetTouchPosition") -var getTouchPointId = wasm.Func[int32]("GetTouchPointId") -var getTouchPointCount = wasm.Func[int32]("GetTouchPointCount") -var setGesturesEnabled = wasm.Proc("SetGesturesEnabled") -var isGestureDetected = wasm.Func[bool]("IsGestureDetected") -var getGestureDetected = wasm.Func[Gestures]("GetGestureDetected") -var getGestureHoldDuration = wasm.Func[float32]("GetGestureHoldDuration") -var getGestureDragVector = wasm.Func[Vector2]("GetGestureDragVector") -var getGestureDragAngle = wasm.Func[float32]("GetGestureDragAngle") -var getGesturePinchVector = wasm.Func[Vector2]("GetGesturePinchVector") -var getGesturePinchAngle = wasm.Func[float32]("GetGesturePinchAngle") -var setShapesTexture = wasm.Proc("SetShapesTexture") -var getShapesTexture = wasm.Func[Texture2D]("GetShapesTexture") -var getShapesTextureRectangle = wasm.Func[Rectangle]("GetShapesTextureRectangle") -var drawPixel = wasm.Proc("DrawPixel") -var drawPixelV = wasm.Proc("DrawPixelV") -var drawLine = wasm.Proc("DrawLine") -var drawLineV = wasm.Proc("DrawLineV") -var drawLineEx = wasm.Proc("DrawLineEx") -var drawLineStrip = wasm.Proc("DrawLineStrip") -var drawLineBezier = wasm.Proc("DrawLineBezier") -var drawCircle = wasm.Proc("DrawCircle") -var drawCircleSector = wasm.Proc("DrawCircleSector") -var drawCircleSectorLines = wasm.Proc("DrawCircleSectorLines") -var drawCircleGradient = wasm.Proc("DrawCircleGradient") -var drawCircleV = wasm.Proc("DrawCircleV") -var drawCircleLines = wasm.Proc("DrawCircleLines") -var drawCircleLinesV = wasm.Proc("DrawCircleLinesV") -var drawEllipse = wasm.Proc("DrawEllipse") -var drawEllipseLines = wasm.Proc("DrawEllipseLines") -var drawRing = wasm.Proc("DrawRing") -var drawRingLines = wasm.Proc("DrawRingLines") -var drawRectangle = wasm.Proc("DrawRectangle") -var drawRectangleV = wasm.Proc("DrawRectangleV") -var drawRectangleRec = wasm.Proc("DrawRectangleRec") -var drawRectanglePro = wasm.Proc("DrawRectanglePro") -var drawRectangleGradientV = wasm.Proc("DrawRectangleGradientV") -var drawRectangleGradientH = wasm.Proc("DrawRectangleGradientH") -var drawRectangleGradientEx = wasm.Proc("DrawRectangleGradientEx") -var drawRectangleLines = wasm.Proc("DrawRectangleLines") -var drawRectangleLinesEx = wasm.Proc("DrawRectangleLinesEx") -var drawRectangleRounded = wasm.Proc("DrawRectangleRounded") -var drawRectangleRoundedLines = wasm.Proc("DrawRectangleRoundedLines") -var drawRectangleRoundedLinesEx = wasm.Proc("DrawRectangleRoundedLinesEx") -var drawTriangle = wasm.Proc("DrawTriangle") -var drawTriangleLines = wasm.Proc("DrawTriangleLines") -var drawTriangleFan = wasm.Proc("DrawTriangleFan") -var drawTriangleStrip = wasm.Proc("DrawTriangleStrip") -var drawPoly = wasm.Proc("DrawPoly") -var drawPolyLines = wasm.Proc("DrawPolyLines") -var drawPolyLinesEx = wasm.Proc("DrawPolyLinesEx") -var drawSplineLinear = wasm.Proc("DrawSplineLinear") -var drawSplineBasis = wasm.Proc("DrawSplineBasis") -var drawSplineCatmullRom = wasm.Proc("DrawSplineCatmullRom") -var drawSplineBezierQuadratic = wasm.Proc("DrawSplineBezierQuadratic") -var drawSplineBezierCubic = wasm.Proc("DrawSplineBezierCubic") -var drawSplineSegmentLinear = wasm.Proc("DrawSplineSegmentLinear") -var drawSplineSegmentBasis = wasm.Proc("DrawSplineSegmentBasis") -var drawSplineSegmentCatmullRom = wasm.Proc("DrawSplineSegmentCatmullRom") -var drawSplineSegmentBezierQuadratic = wasm.Proc("DrawSplineSegmentBezierQuadratic") -var drawSplineSegmentBezierCubic = wasm.Proc("DrawSplineSegmentBezierCubic") -var getSplinePointLinear = wasm.Func[Vector2]("GetSplinePointLinear") -var getSplinePointBasis = wasm.Func[Vector2]("GetSplinePointBasis") -var getSplinePointCatmullRom = wasm.Func[Vector2]("GetSplinePointCatmullRom") -var getSplinePointBezierQuad = wasm.Func[Vector2]("GetSplinePointBezierQuad") -var getSplinePointBezierCubic = wasm.Func[Vector2]("GetSplinePointBezierCubic") -var checkCollisionRecs = wasm.Func[bool]("CheckCollisionRecs") -var checkCollisionCircles = wasm.Func[bool]("CheckCollisionCircles") -var checkCollisionCircleRec = wasm.Func[bool]("CheckCollisionCircleRec") -var checkCollisionCircleLine = wasm.Func[bool]("CheckCollisionCircleLine") -var checkCollisionPointRec = wasm.Func[bool]("CheckCollisionPointRec") -var checkCollisionPointCircle = wasm.Func[bool]("CheckCollisionPointCircle") -var checkCollisionPointTriangle = wasm.Func[bool]("CheckCollisionPointTriangle") -var checkCollisionPointPoly = wasm.Func[bool]("CheckCollisionPointPoly") -var checkCollisionLines = wasm.Func[bool]("CheckCollisionLines") -var checkCollisionPointLine = wasm.Func[bool]("CheckCollisionPointLine") -var getCollisionRec = wasm.Func[Rectangle]("GetCollisionRec") -var loadImage = wasm.Func[*Image]("LoadImage") -var loadImageRaw = wasm.Func[*Image]("LoadImageRaw") -var loadImageAnim = wasm.Func[*Image]("LoadImageAnim") -var loadImageAnimFromMemory = wasm.Func[*Image]("LoadImageAnimFromMemory") -var loadImageFromMemory = wasm.Func[*Image]("LoadImageFromMemory") -var loadImageFromTexture = wasm.Func[*Image]("LoadImageFromTexture") -var loadImageFromScreen = wasm.Func[*Image]("LoadImageFromScreen") -var isImageValid = wasm.Func[bool]("IsImageValid") -var unloadImage = wasm.Proc("UnloadImage") -var exportImage = wasm.Func[bool]("ExportImage") -var exportImageToMemory = wasm.Func[[]byte]("ExportImageToMemory") -var genImageColor = wasm.Func[*Image]("GenImageColor") -var genImageGradientLinear = wasm.Func[*Image]("GenImageGradientLinear") -var genImageGradientRadial = wasm.Func[*Image]("GenImageGradientRadial") -var genImageGradientSquare = wasm.Func[*Image]("GenImageGradientSquare") -var genImageChecked = wasm.Func[*Image]("GenImageChecked") -var genImageWhiteNoise = wasm.Func[*Image]("GenImageWhiteNoise") -var genImagePerlinNoise = wasm.Func[*Image]("GenImagePerlinNoise") -var genImageCellular = wasm.Func[*Image]("GenImageCellular") -var genImageText = wasm.Func[Image]("GenImageText") -var imageCopy = wasm.Func[*Image]("ImageCopy") -var imageFromImage = wasm.Func[Image]("ImageFromImage") -var imageFromChannel = wasm.Func[Image]("ImageFromChannel") -var imageText = wasm.Func[Image]("ImageText") -var imageTextEx = wasm.Func[Image]("ImageTextEx") -var imageFormat = wasm.Proc("ImageFormat") -var imageToPOT = wasm.Proc("ImageToPOT") -var imageCrop = wasm.Proc("ImageCrop") -var imageAlphaCrop = wasm.Proc("ImageAlphaCrop") -var imageAlphaClear = wasm.Proc("ImageAlphaClear") -var imageAlphaMask = wasm.Proc("ImageAlphaMask") -var imageAlphaPremultiply = wasm.Proc("ImageAlphaPremultiply") -var imageBlurGaussian = wasm.Proc("ImageBlurGaussian") -var imageKernelConvolution = wasm.Proc("ImageKernelConvolution") -var imageResize = wasm.Proc("ImageResize") -var imageResizeNN = wasm.Proc("ImageResizeNN") -var imageResizeCanvas = wasm.Proc("ImageResizeCanvas") -var imageMipmaps = wasm.Proc("ImageMipmaps") -var imageDither = wasm.Proc("ImageDither") -var imageFlipVertical = wasm.Proc("ImageFlipVertical") -var imageFlipHorizontal = wasm.Proc("ImageFlipHorizontal") -var imageRotate = wasm.Proc("ImageRotate") -var imageRotateCW = wasm.Proc("ImageRotateCW") -var imageRotateCCW = wasm.Proc("ImageRotateCCW") -var imageColorTint = wasm.Proc("ImageColorTint") -var imageColorInvert = wasm.Proc("ImageColorInvert") -var imageColorGrayscale = wasm.Proc("ImageColorGrayscale") -var imageColorContrast = wasm.Proc("ImageColorContrast") -var imageColorBrightness = wasm.Proc("ImageColorBrightness") -var imageColorReplace = wasm.Proc("ImageColorReplace") -var loadImageColors = wasm.Func[[]color.RGBA]("LoadImageColors") -var loadImagePalette = wasm.Func[[]color.RGBA]("LoadImagePalette") -var unloadImageColors = wasm.Proc("UnloadImageColors") -var unloadImagePalette = wasm.Proc("UnloadImagePalette") -var getImageAlphaBorder = wasm.Func[Rectangle]("GetImageAlphaBorder") -var getImageColor = wasm.Func[color.RGBA]("GetImageColor") -var imageClearBackground = wasm.Proc("ImageClearBackground") -var imageDrawPixel = wasm.Proc("ImageDrawPixel") -var imageDrawPixelV = wasm.Proc("ImageDrawPixelV") -var imageDrawLine = wasm.Proc("ImageDrawLine") -var imageDrawLineV = wasm.Proc("ImageDrawLineV") -var imageDrawLineEx = wasm.Proc("ImageDrawLineEx") -var imageDrawCircle = wasm.Proc("ImageDrawCircle") -var imageDrawCircleV = wasm.Proc("ImageDrawCircleV") -var imageDrawCircleLines = wasm.Proc("ImageDrawCircleLines") -var imageDrawCircleLinesV = wasm.Proc("ImageDrawCircleLinesV") -var imageDrawRectangle = wasm.Proc("ImageDrawRectangle") -var imageDrawRectangleV = wasm.Proc("ImageDrawRectangleV") -var imageDrawRectangleRec = wasm.Proc("ImageDrawRectangleRec") -var imageDrawRectangleLines = wasm.Proc("ImageDrawRectangleLines") -var imageDrawTriangle = wasm.Proc("ImageDrawTriangle") -var imageDrawTriangleEx = wasm.Proc("ImageDrawTriangleEx") -var imageDrawTriangleLines = wasm.Proc("ImageDrawTriangleLines") -var imageDrawTriangleFan = wasm.Proc("ImageDrawTriangleFan") -var imageDrawTriangleStrip = wasm.Proc("ImageDrawTriangleStrip") -var imageDraw = wasm.Proc("ImageDraw") -var imageDrawText = wasm.Proc("ImageDrawText") -var imageDrawTextEx = wasm.Proc("ImageDrawTextEx") -var loadTexture = wasm.Func[Texture2D]("LoadTexture") -var loadTextureFromImage = wasm.Func[Texture2D]("LoadTextureFromImage") -var loadTextureCubemap = wasm.Func[Texture2D]("LoadTextureCubemap") -var loadRenderTexture = wasm.Func[RenderTexture2D]("LoadRenderTexture") -var isTextureValid = wasm.Func[bool]("IsTextureValid") -var unloadTexture = wasm.Proc("UnloadTexture") -var isRenderTextureValid = wasm.Func[bool]("IsRenderTextureValid") -var unloadRenderTexture = wasm.Proc("UnloadRenderTexture") -var updateTexture = wasm.Proc("UpdateTexture") -var updateTextureRec = wasm.Proc("UpdateTextureRec") -var genTextureMipmaps = wasm.Proc("GenTextureMipmaps") -var setTextureFilter = wasm.Proc("SetTextureFilter") -var setTextureWrap = wasm.Proc("SetTextureWrap") -var drawTexture = wasm.Proc("DrawTexture") -var drawTextureV = wasm.Proc("DrawTextureV") -var drawTextureEx = wasm.Proc("DrawTextureEx") -var drawTextureRec = wasm.Proc("DrawTextureRec") -var drawTexturePro = wasm.Proc("DrawTexturePro") -var drawTextureNPatch = wasm.Proc("DrawTextureNPatch") -var fade = wasm.Func[color.RGBA]("Fade") -var colorToInt = wasm.Func[int32]("ColorToInt") -var colorNormalize = wasm.Func[Vector4]("ColorNormalize") -var colorFromNormalized = wasm.Func[color.RGBA]("ColorFromNormalized") -var colorToHSV = wasm.Func[Vector3]("ColorToHSV") -var colorFromHSV = wasm.Func[color.RGBA]("ColorFromHSV") -var colorTint = wasm.Func[color.RGBA]("ColorTint") -var colorBrightness = wasm.Func[color.RGBA]("ColorBrightness") -var colorContrast = wasm.Func[color.RGBA]("ColorContrast") -var colorAlpha = wasm.Func[color.RGBA]("ColorAlpha") -var colorAlphaBlend = wasm.Func[color.RGBA]("ColorAlphaBlend") -var colorLerp = wasm.Func[color.RGBA]("ColorLerp") -var getColor = wasm.Func[color.RGBA]("GetColor") -var getPixelColor = wasm.Func[color.RGBA]("GetPixelColor") -var setPixelColor = wasm.Proc("SetPixelColor") -var getPixelDataSize = wasm.Func[int32]("GetPixelDataSize") -var getFontDefault = wasm.Func[Font]("GetFontDefault") -var loadFont = wasm.Func[Font]("LoadFont") -var loadFontFromImage = wasm.Func[Font]("LoadFontFromImage") -var loadFontFromMemory = wasm.Func[Font]("LoadFontFromMemory") -var isFontValid = wasm.Func[bool]("IsFontValid") -var loadFontData = wasm.Func[[]GlyphInfo]("LoadFontData") -var genImageFontAtlas = wasm.Func[Image]("GenImageFontAtlas") -var unloadFontData = wasm.Proc("UnloadFontData") -var unloadFont = wasm.Proc("UnloadFont") -var drawFPS = wasm.Proc("DrawFPS") -var drawText = wasm.Proc("DrawText") -var drawTextEx = wasm.Proc("DrawTextEx") -var drawTextPro = wasm.Proc("DrawTextPro") -var drawTextCodepoint = wasm.Proc("DrawTextCodepoint") -var drawTextCodepoints = wasm.Proc("DrawTextCodepoints") -var setTextLineSpacing = wasm.Proc("SetTextLineSpacing") -var measureText = wasm.Func[int32]("MeasureText") -var measureTextEx = wasm.Func[Vector2]("MeasureTextEx") -var getGlyphIndex = wasm.Func[int32]("GetGlyphIndex") -var getGlyphInfo = wasm.Func[GlyphInfo]("GetGlyphInfo") -var getGlyphAtlasRec = wasm.Func[Rectangle]("GetGlyphAtlasRec") -var drawLine3D = wasm.Proc("DrawLine3D") -var drawPoint3D = wasm.Proc("DrawPoint3D") -var drawCircle3D = wasm.Proc("DrawCircle3D") -var drawTriangle3D = wasm.Proc("DrawTriangle3D") -var drawTriangleStrip3D = wasm.Proc("DrawTriangleStrip3D") -var drawCube = wasm.Proc("DrawCube") -var drawCubeV = wasm.Proc("DrawCubeV") -var drawCubeWires = wasm.Proc("DrawCubeWires") -var drawCubeWiresV = wasm.Proc("DrawCubeWiresV") -var drawSphere = wasm.Proc("DrawSphere") -var drawSphereEx = wasm.Proc("DrawSphereEx") -var drawSphereWires = wasm.Proc("DrawSphereWires") -var drawCylinder = wasm.Proc("DrawCylinder") -var drawCylinderEx = wasm.Proc("DrawCylinderEx") -var drawCylinderWires = wasm.Proc("DrawCylinderWires") -var drawCylinderWiresEx = wasm.Proc("DrawCylinderWiresEx") -var drawCapsule = wasm.Proc("DrawCapsule") -var drawCapsuleWires = wasm.Proc("DrawCapsuleWires") -var drawPlane = wasm.Proc("DrawPlane") -var drawRay = wasm.Proc("DrawRay") -var drawGrid = wasm.Proc("DrawGrid") -var loadModel = wasm.Func[Model]("LoadModel") -var loadModelFromMesh = wasm.Func[Model]("LoadModelFromMesh") -var isModelValid = wasm.Func[bool]("IsModelValid") -var unloadModel = wasm.Proc("UnloadModel") -var getModelBoundingBox = wasm.Func[BoundingBox]("GetModelBoundingBox") -var drawModel = wasm.Proc("DrawModel") -var drawModelEx = wasm.Proc("DrawModelEx") -var drawModelWires = wasm.Proc("DrawModelWires") -var drawModelWiresEx = wasm.Proc("DrawModelWiresEx") -var drawModelPoints = wasm.Proc("DrawModelPoints") -var drawModelPointsEx = wasm.Proc("DrawModelPointsEx") -var drawBoundingBox = wasm.Proc("DrawBoundingBox") -var drawBillboard = wasm.Proc("DrawBillboard") -var drawBillboardRec = wasm.Proc("DrawBillboardRec") -var drawBillboardPro = wasm.Proc("DrawBillboardPro") -var uploadMesh = wasm.Proc("UploadMesh") -var updateMeshBuffer = wasm.Proc("UpdateMeshBuffer") -var unloadMesh = wasm.Proc("UnloadMesh") -var drawMesh = wasm.Proc("DrawMesh") -var drawMeshInstanced = wasm.Proc("DrawMeshInstanced") -var exportMesh = wasm.Func[bool]("ExportMesh") -var getMeshBoundingBox = wasm.Func[BoundingBox]("GetMeshBoundingBox") -var genMeshTangents = wasm.Proc("GenMeshTangents") -var genMeshPoly = wasm.Func[Mesh]("GenMeshPoly") -var genMeshPlane = wasm.Func[Mesh]("GenMeshPlane") -var genMeshCube = wasm.Func[Mesh]("GenMeshCube") -var genMeshSphere = wasm.Func[Mesh]("GenMeshSphere") -var genMeshHemiSphere = wasm.Func[Mesh]("GenMeshHemiSphere") -var genMeshCylinder = wasm.Func[Mesh]("GenMeshCylinder") -var genMeshCone = wasm.Func[Mesh]("GenMeshCone") -var genMeshTorus = wasm.Func[Mesh]("GenMeshTorus") -var genMeshKnot = wasm.Func[Mesh]("GenMeshKnot") -var genMeshHeightmap = wasm.Func[Mesh]("GenMeshHeightmap") -var genMeshCubicmap = wasm.Func[Mesh]("GenMeshCubicmap") -var loadMaterials = wasm.Func[[]Material]("LoadMaterials") -var loadMaterialDefault = wasm.Func[Material]("LoadMaterialDefault") -var isMaterialValid = wasm.Func[bool]("IsMaterialValid") -var unloadMaterial = wasm.Proc("UnloadMaterial") -var setMaterialTexture = wasm.Proc("SetMaterialTexture") -var setModelMeshMaterial = wasm.Proc("SetModelMeshMaterial") -var loadModelAnimations = wasm.Func[[]ModelAnimation]("LoadModelAnimations") -var updateModelAnimation = wasm.Proc("UpdateModelAnimation") -var updateModelAnimationBones = wasm.Proc("UpdateModelAnimationBones") -var unloadModelAnimation = wasm.Proc("UnloadModelAnimation") -var unloadModelAnimations = wasm.Proc("UnloadModelAnimations") -var isModelAnimationValid = wasm.Func[bool]("IsModelAnimationValid") -var checkCollisionSpheres = wasm.Func[bool]("CheckCollisionSpheres") -var checkCollisionBoxes = wasm.Func[bool]("CheckCollisionBoxes") -var checkCollisionBoxSphere = wasm.Func[bool]("CheckCollisionBoxSphere") -var getRayCollisionSphere = wasm.Func[RayCollision]("GetRayCollisionSphere") -var getRayCollisionBox = wasm.Func[RayCollision]("GetRayCollisionBox") -var getRayCollisionMesh = wasm.Func[RayCollision]("GetRayCollisionMesh") -var getRayCollisionTriangle = wasm.Func[RayCollision]("GetRayCollisionTriangle") -var getRayCollisionQuad = wasm.Func[RayCollision]("GetRayCollisionQuad") -var initAudioDevice = wasm.Proc("InitAudioDevice") -var closeAudioDevice = wasm.Proc("CloseAudioDevice") -var isAudioDeviceReady = wasm.Func[bool]("IsAudioDeviceReady") -var setMasterVolume = wasm.Proc("SetMasterVolume") -var getMasterVolume = wasm.Func[float32]("GetMasterVolume") -var loadWave = wasm.Func[Wave]("LoadWave") -var loadWaveFromMemory = wasm.Func[Wave]("LoadWaveFromMemory") -var isWaveValid = wasm.Func[bool]("IsWaveValid") -var loadSound = wasm.Func[Sound]("LoadSound") -var loadSoundFromWave = wasm.Func[Sound]("LoadSoundFromWave") -var loadSoundAlias = wasm.Func[Sound]("LoadSoundAlias") -var isSoundValid = wasm.Func[bool]("IsSoundValid") -var updateSound = wasm.Proc("UpdateSound") -var unloadWave = wasm.Proc("UnloadWave") -var unloadSound = wasm.Proc("UnloadSound") -var unloadSoundAlias = wasm.Proc("UnloadSoundAlias") -var exportWave = wasm.Func[bool]("ExportWave") -var playSound = wasm.Proc("PlaySound") -var stopSound = wasm.Proc("StopSound") -var pauseSound = wasm.Proc("PauseSound") -var resumeSound = wasm.Proc("ResumeSound") -var isSoundPlaying = wasm.Func[bool]("IsSoundPlaying") -var setSoundVolume = wasm.Proc("SetSoundVolume") -var setSoundPitch = wasm.Proc("SetSoundPitch") -var setSoundPan = wasm.Proc("SetSoundPan") -var waveCopy = wasm.Func[Wave]("WaveCopy") -var waveCrop = wasm.Proc("WaveCrop") -var waveFormat = wasm.Proc("WaveFormat") -var loadWaveSamples = wasm.Func[[]float32]("LoadWaveSamples") -var unloadWaveSamples = wasm.Proc("UnloadWaveSamples") -var loadMusicStream = wasm.Func[Music]("LoadMusicStream") -var loadMusicStreamFromMemory = wasm.Func[Music]("LoadMusicStreamFromMemory") -var isMusicValid = wasm.Func[bool]("IsMusicValid") -var unloadMusicStream = wasm.Proc("UnloadMusicStream") -var playMusicStream = wasm.Proc("PlayMusicStream") -var isMusicStreamPlaying = wasm.Func[bool]("IsMusicStreamPlaying") -var updateMusicStream = wasm.Proc("UpdateMusicStream") -var stopMusicStream = wasm.Proc("StopMusicStream") -var pauseMusicStream = wasm.Proc("PauseMusicStream") -var resumeMusicStream = wasm.Proc("ResumeMusicStream") -var seekMusicStream = wasm.Proc("SeekMusicStream") -var setMusicVolume = wasm.Proc("SetMusicVolume") -var setMusicPitch = wasm.Proc("SetMusicPitch") -var setMusicPan = wasm.Proc("SetMusicPan") -var getMusicTimeLength = wasm.Func[float32]("GetMusicTimeLength") -var getMusicTimePlayed = wasm.Func[float32]("GetMusicTimePlayed") -var loadAudioStream = wasm.Func[AudioStream]("LoadAudioStream") -var isAudioStreamValid = wasm.Func[bool]("IsAudioStreamValid") -var unloadAudioStream = wasm.Proc("UnloadAudioStream") -var updateAudioStream = wasm.Proc("UpdateAudioStream") -var isAudioStreamProcessed = wasm.Func[bool]("IsAudioStreamProcessed") -var playAudioStream = wasm.Proc("PlayAudioStream") -var pauseAudioStream = wasm.Proc("PauseAudioStream") -var resumeAudioStream = wasm.Proc("ResumeAudioStream") -var isAudioStreamPlaying = wasm.Func[bool]("IsAudioStreamPlaying") -var stopAudioStream = wasm.Proc("StopAudioStream") -var setAudioStreamVolume = wasm.Proc("SetAudioStreamVolume") -var setAudioStreamPitch = wasm.Proc("SetAudioStreamPitch") -var setAudioStreamPan = wasm.Proc("SetAudioStreamPan") -var setAudioStreamBufferSizeDefault = wasm.Proc("SetAudioStreamBufferSizeDefault") -var setAudioStreamCallback = wasm.Proc("SetAudioStreamCallback") -var attachAudioStreamProcessor = wasm.Proc("AttachAudioStreamProcessor") -var detachAudioStreamProcessor = wasm.Proc("DetachAudioStreamProcessor") -var attachAudioMixedProcessor = wasm.Proc("AttachAudioMixedProcessor") -var detachAudioMixedProcessor = wasm.Proc("DetachAudioMixedProcessor") -var setCallbackFunc = wasm.Proc("SetCallbackFunc") -var newImageFromImage = wasm.Func[*Image]("NewImageFromImage") -var toImage = wasm.Func[image.Image]("ToImage") -var openAsset = wasm.Func[Asset]("OpenAsset") -var homeDir = wasm.Func[string]("HomeDir") - -// CloseWindow - Close window and unload OpenGL context -func CloseWindow() { - _, fl := closeWindow.Call() - wasm.Free(fl...) +// WindowShouldClose - Check if KeyEscape pressed or Close icon pressed +func WindowShouldClose() bool { + const err = "WindowShouldClose is unsupported on the web, use SetMain" + alert(err) + panic(err) } -// IsWindowReady - Check if window has been initialized successfully -func IsWindowReady() bool { - ret, fl := isWindowReady.Call() - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v +//go:wasmimport raylib _InitWindow +func initWindow(width, height int32, cstr cptr) + +// InitWindow - Initialize Window and OpenGL Graphics +func InitWindow(width int32, height int32, title string) { + // prevents crash. + if width == 0 { + width = int32(js.Global().Get("innerWidth").Int()) + } + if height == 0 { + height = int32(js.Global().Get("innerHeight").Int()) + } + ctitle := cString(title) + defer free(ctitle) + initWindow(width, height, ctitle) } +// CloseWindow - Close Window and Terminate Context +// +//go:wasmimport raylib _CloseWindow +//go:noescape +func CloseWindow() + +// IsWindowReady - Check if window has been initialized successfully +// +//go:wasmimport raylib _IsWindowReady +//go:noescape +func IsWindowReady() bool + // IsWindowFullscreen - Check if window is currently fullscreen -func IsWindowFullscreen() bool { - ret, fl := isWindowFullscreen.Call() - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} +// +//go:wasmimport raylib _IsWindowFullscreen +//go:noescape +func IsWindowFullscreen() bool -// IsWindowHidden - Check if window is currently hidden (only PLATFORM_DESKTOP) -func IsWindowHidden() bool { - var zero bool - return zero -} +// IsWindowHidden - Check if window is currently hidden +// +//go:wasmimport raylib _IsWindowHidden +//go:noescape +func IsWindowHidden() bool -// IsWindowMinimized - Check if window is currently minimized (only PLATFORM_DESKTOP) -func IsWindowMinimized() bool { - var zero bool - return zero -} +// IsWindowMinimized - Check if window is currently minimized +// +//go:wasmimport raylib _IsWindowMinimized +//go:noescape +func IsWindowMinimized() bool -// IsWindowMaximized - Check if window is currently maximized (only PLATFORM_DESKTOP) -func IsWindowMaximized() bool { - var zero bool - return zero -} +// IsWindowMaximized - Check if window is currently maximized +// +//go:wasmimport raylib _IsWindowMaximized +//go:noescape +func IsWindowMaximized() bool -// IsWindowFocused - Check if window is currently focused (only PLATFORM_DESKTOP) -func IsWindowFocused() bool { - var zero bool - return zero -} +// IsWindowFocused - Check if window is currently focused +// +//go:wasmimport raylib _IsWindowFocused +//go:noescape +func IsWindowFocused() bool -// IsWindowResized - Check if window has been resized last frame -func IsWindowResized() bool { - ret, fl := isWindowResized.Call() - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} +// IsWindowResized - Check if window has been resized +// +//go:wasmimport raylib _IsWindowResized +//go:noescape +func IsWindowResized() bool // IsWindowState - Check if one specific window flag is enabled -func IsWindowState(flag uint32) bool { - ret, fl := isWindowState.Call(flag) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} +// +//go:wasmimport raylib _IsWindowState +//go:noescape +func IsWindowState(flag uint32) bool -// SetWindowState - Set window configuration state using flags (only PLATFORM_DESKTOP) -func SetWindowState(flags uint32) { -} +// SetWindowFocused - Sets the window to have focus +// +//go:wasmimport raylib _SetWindowFocused +//go:noescape +func SetWindowFocused() + +// SetWindowState - Set window configuration state using flags +// +//go:wasmimport raylib _SetWindowState +//go:noescape +func SetWindowState(flags uint32) // ClearWindowState - Clear window configuration state flags -func ClearWindowState(flags uint32) { - _, fl := clearWindowState.Call(flags) - wasm.Free(fl...) -} +// +//go:wasmimport raylib _ClearWindowState +//go:noescape +func ClearWindowState(flags uint32) -// ToggleFullscreen - Toggle window state: fullscreen/windowed (only PLATFORM_DESKTOP) -func ToggleFullscreen() { -} +// ToggleFullscreen - Fullscreen toggle (only PLATFORM_DESKTOP) +// +//go:wasmimport raylib _ToggleFullscreen +//go:noescape +func ToggleFullscreen() -// ToggleBorderlessWindowed - Toggle window state: borderless windowed (only PLATFORM_DESKTOP) -func ToggleBorderlessWindowed() { -} +// ToggleBorderlessWindowed - Borderless fullscreen toggle (only PLATFORM_DESKTOP) +// +//go:wasmimport raylib _ToggleBorderlessWindowed +//go:noescape +func ToggleBorderlessWindowed() -// MaximizeWindow - Set window state: maximized, if resizable (only PLATFORM_DESKTOP) -func MaximizeWindow() { -} +// MaximizeWindow - Set window state: maximized, if resizable +// +//go:wasmimport raylib _MaximizeWindow +//go:noescape +func MaximizeWindow() -// MinimizeWindow - Set window state: minimized, if resizable (only PLATFORM_DESKTOP) -func MinimizeWindow() { -} +// MinimizeWindow - Set window state: minimized, if resizable +// +//go:wasmimport raylib _MinimizeWindow +//go:noescape +func MinimizeWindow() -// RestoreWindow - Set window state: not minimized/maximized (only PLATFORM_DESKTOP) -func RestoreWindow() { -} +// RestoreWindow - Set window state: not minimized/maximized +// +//go:wasmimport raylib _RestoreWindow +//go:noescape +func RestoreWindow() // SetWindowIcon - Set icon for window (single image, RGBA 32bit, only PLATFORM_DESKTOP) -func SetWindowIcon(image Image) { - _, fl := setWindowIcon.Call(wasm.Struct(image)) - wasm.Free(fl...) -} +func SetWindowIcon(image Image) {} // SetWindowIcons - Set icon for window (multiple images, RGBA 32bit, only PLATFORM_DESKTOP) -func SetWindowIcons(images []Image, count int32) { - _, fl := setWindowIcons.Call(images, count) - wasm.Free(fl...) -} +func SetWindowIcons(images []Image, count int32) {} + +// SetWindowTitle - Set title for window +// +//go:wasmimport raylib _SetWindowTitle +//go:noescape +func setWindowTitle(title cptr) -// SetWindowTitle - Set title for window (only PLATFORM_DESKTOP and PLATFORM_WEB) +// SetWindowTitle - Set title for window (only PLATFORM_DESKTOP) func SetWindowTitle(title string) { - _, fl := setWindowTitle.Call(title) - wasm.Free(fl...) + ptr := cString(title) + defer free(ptr) + setWindowTitle(ptr) } // SetWindowPosition - Set window position on screen (only PLATFORM_DESKTOP) -func SetWindowPosition(x int, y int) { +// +//go:wasmimport raylib _SetWindowPosition +//go:noescape +func setWindowPosition(x, y int32) + +// SetWindowPosition - Set window position on screen (only PLATFORM_DESKTOP) +func SetWindowPosition(x, y int) { + cx := int32(x) + cy := int32(y) + setWindowPosition(cx, cy) } -// SetWindowMonitor - Set monitor for the current window +// SetWindowMonitor - Set monitor for the current window (fullscreen mode) +// +//go:wasmimport raylib _SetWindowMonitor +//go:noescape +func setWindowMonitor(monitor int32) + +// SetWindowMonitor - Set monitor for the current window (fullscreen mode) func SetWindowMonitor(monitor int) { - _, fl := setWindowMonitor.Call(monitor) - wasm.Free(fl...) + cmonitor := (int32)(monitor) + setWindowMonitor(cmonitor) } // SetWindowMinSize - Set window minimum dimensions (for FLAG_WINDOW_RESIZABLE) -func SetWindowMinSize(width int, height int) { - _, fl := setWindowMinSize.Call(width, height) - wasm.Free(fl...) +// +//go:wasmimport raylib _SetWindowMinSize +//go:noescape +func setWindowMinSize(w, h int32) + +// SetWindowMinSize - Set window minimum dimensions (for FLAG_WINDOW_RESIZABLE) +func SetWindowMinSize(w, h int) { + cw := (int32)(w) + ch := (int32)(h) + setWindowMinSize(cw, ch) } +//go:wasmimport raylib _SetWindowMaxSize +//go:noescape +func setWindowMaxSize(w, h int32) + // SetWindowMaxSize - Set window maximum dimensions (for FLAG_WINDOW_RESIZABLE) -func SetWindowMaxSize(width int, height int) { - _, fl := setWindowMaxSize.Call(width, height) - wasm.Free(fl...) +func SetWindowMaxSize(w, h int) { + cw := (int32)(w) + ch := (int32)(h) + setWindowMaxSize(cw, ch) } +//go:wasmimport raylib _SetWindowSize +//go:noescape +func setWindowSize(w, h int32) + // SetWindowSize - Set window dimensions -func SetWindowSize(width int, height int) { - _, fl := setWindowSize.Call(width, height) - wasm.Free(fl...) +func SetWindowSize(w, h int) { + cw := (int32)(w) + ch := (int32)(h) + setWindowSize(cw, ch) } // SetWindowOpacity - Set window opacity [0.0f..1.0f] (only PLATFORM_DESKTOP) -func SetWindowOpacity(opacity float32) { -} - -// SetWindowFocused - Set window focused (only PLATFORM_DESKTOP) -func SetWindowFocused() { -} +// +//go:wasmimport raylib _SetWindowOpacity +//go:noescape +func SetWindowOpacity(opacity float32) // GetWindowHandle - Get native window handle func GetWindowHandle() unsafe.Pointer { - var zero unsafe.Pointer - return zero + return nil } +//go:wasmimport raylib _GetScreenWidth +//go:noescape +func getScreenWidth() int32 + // GetScreenWidth - Get current screen width func GetScreenWidth() int { - ret, fl := getScreenWidth.Call() - v := wasm.Numeric[int](ret) - wasm.Free(fl...) + ret := getScreenWidth() + v := (int)(ret) return v } +//go:wasmimport raylib _GetScreenHeight +//go:noescape +func getScreenHeight() int32 + // GetScreenHeight - Get current screen height func GetScreenHeight() int { - ret, fl := getScreenHeight.Call() - v := wasm.Numeric[int](ret) - wasm.Free(fl...) + ret := getScreenHeight() + v := (int)(ret) return v } +//go:wasmimport raylib _GetRenderWidth +//go:noescape +func getRenderWidth() int32 + // GetRenderWidth - Get current render width (it considers HiDPI) func GetRenderWidth() int { - ret, fl := getRenderWidth.Call() - v := wasm.Numeric[int](ret) - wasm.Free(fl...) + ret := getRenderWidth() + v := (int)(ret) return v } // GetRenderHeight - Get current render height (it considers HiDPI) +// +//go:wasmimport raylib _GetRenderHeight +//go:noescape +func getRenderHeight() int32 func GetRenderHeight() int { - ret, fl := getRenderHeight.Call() - v := wasm.Numeric[int](ret) - wasm.Free(fl...) + ret := getRenderHeight() + v := (int)(ret) return v } +// GetMonitorCount - Get number of connected monitors +// +//go:wasmimport raylib _GetMonitorCount +//go:noescape +func getMonitorCount() int32 + // GetMonitorCount - Get number of connected monitors func GetMonitorCount() int { - ret, fl := getMonitorCount.Call() - v := wasm.Numeric[int](ret) - wasm.Free(fl...) + ret := getMonitorCount() + v := (int)(ret) return v } +//go:wasmimport raylib _GetCurrentMonitor +//go:noescape +func getCurrentMonitor() int32 + // GetCurrentMonitor - Get current monitor where window is placed func GetCurrentMonitor() int { - ret, fl := getCurrentMonitor.Call() - v := wasm.Numeric[int](ret) - wasm.Free(fl...) + ret := getCurrentMonitor() + v := (int)(ret) return v } +//go:wasmimport raylib _GetMonitorPosition +//go:noescape +func getMonitorPosition(vector2 cptr, monitor int32) + // GetMonitorPosition - Get specified monitor position func GetMonitorPosition(monitor int) Vector2 { - ret, fl := getMonitorPosition.Call(monitor) - v := wasm.ReadStruct[Vector2](ret) - wasm.Free(fl...) + var v Vector2 + cmonitor := (int32)(monitor) + + ret, f := mallocV(v) + defer f() + getMonitorPosition(ret, cmonitor) + copyValueToGo(ret, &v) return v } -// GetMonitorWidth - Get specified monitor width (current video mode used by monitor) +//go:wasmimport raylib _GetMonitorWidth +//go:noescape +func getMonitorWidth(monitor int32) int32 + +// GetMonitorWidth - Get primary monitor width func GetMonitorWidth(monitor int) int { - ret, fl := getMonitorWidth.Call(monitor) - v := wasm.Numeric[int](ret) - wasm.Free(fl...) + cmonitor := (int32)(monitor) + ret := getMonitorWidth(cmonitor) + v := (int)(ret) return v } -// GetMonitorHeight - Get specified monitor height (current video mode used by monitor) +//go:wasmimport raylib _GetMonitorHeight +//go:noescape +func getMonitorHeight(monitor int32) int32 + +// GetMonitorHeight - Get primary monitor height func GetMonitorHeight(monitor int) int { - ret, fl := getMonitorHeight.Call(monitor) - v := wasm.Numeric[int](ret) - wasm.Free(fl...) + cmonitor := (int32)(monitor) + ret := getMonitorHeight(cmonitor) + v := (int)(ret) return v } -// GetMonitorPhysicalWidth - Get specified monitor physical width in millimetres +// +//go:wasmimport raylib _GetMonitorPhysicalWidth +//go:noescape +func getMonitorPhysicalWidth(monitor int32) int32 + +// GetMonitorPhysicalWidth - Get primary monitor physical width in millimetres func GetMonitorPhysicalWidth(monitor int) int { - ret, fl := getMonitorPhysicalWidth.Call(monitor) - v := wasm.Numeric[int](ret) - wasm.Free(fl...) + cmonitor := (int32)(monitor) + ret := getMonitorPhysicalWidth(cmonitor) + v := (int)(ret) return v } -// GetMonitorPhysicalHeight - Get specified monitor physical height in millimetres +//go:wasmimport raylib _GetMonitorPhysicalHeight +//go:noescape +func getMonitorPhysicalHeight(monitor int32) int32 + +// GetMonitorPhysicalHeight - Get primary monitor physical height in millimetres func GetMonitorPhysicalHeight(monitor int) int { - ret, fl := getMonitorPhysicalHeight.Call(monitor) - v := wasm.Numeric[int](ret) - wasm.Free(fl...) + cmonitor := (int32)(monitor) + ret := getMonitorPhysicalHeight(cmonitor) + v := (int)(ret) return v } +//go:wasmimport raylib _GetMonitorRefreshRate +//go:noescape +func getMonitorRefreshRate(monitor int32) int32 + // GetMonitorRefreshRate - Get specified monitor refresh rate func GetMonitorRefreshRate(monitor int) int { - ret, fl := getMonitorRefreshRate.Call(monitor) - v := wasm.Numeric[int](ret) - wasm.Free(fl...) + cmonitor := (int32)(monitor) + ret := getMonitorRefreshRate(cmonitor) + v := (int)(ret) return v } +//go:wasmimport raylib _GetWindowPosition +//go:noescape +func getWindowPosition(vector2 cptr) + // GetWindowPosition - Get window position XY on monitor func GetWindowPosition() Vector2 { - ret, fl := getWindowPosition.Call() - v := wasm.ReadStruct[Vector2](ret) - wasm.Free(fl...) + var v Vector2 + ret, f := mallocV(v) + defer f() + getWindowPosition(ret) + copyValueToGo(ret, &v) return v } +//go:wasmimport raylib _GetWindowScaleDPI +//go:noescape +func getWindowScaleDPI(vector2 cptr) + // GetWindowScaleDPI - Get window scale DPI factor func GetWindowScaleDPI() Vector2 { - ret, fl := getWindowScaleDPI.Call() - v := wasm.ReadStruct[Vector2](ret) - wasm.Free(fl...) + var v Vector2 + ret, f := mallocV(v) + defer f() + getWindowScaleDPI(ret) + copyValueToGo(ret, &v) return v } -// GetMonitorName - Get the human-readable, UTF-8 encoded name of the specified monitor -func GetMonitorName(monitor int) string { - ret, fl := getMonitorName.Call(monitor) - v := wasm.Numeric[string](ret) - wasm.Free(fl...) - return v -} +// GetMonitorName - Get the human-readable, UTF-8 encoded name of the primary monitor +func GetMonitorName(monitor int) string { return "" } + +//go:wasmimport raylib _SetClipboardText +//go:noescape +func setClipboardText(data cptr) // SetClipboardText - Set clipboard text content -func SetClipboardText(text string) { - _, fl := setClipboardText.Call(text) - wasm.Free(fl...) +func SetClipboardText(data string) { + cdata := cString(data) + defer free(cdata) + setClipboardText(cdata) } +//go:wasmimport raylib _GetClipboardText +//go:noescape +func getClipboardText() cptr + // GetClipboardText - Get clipboard text content func GetClipboardText() string { - ret, fl := getClipboardText.Call() - v := wasm.Numeric[string](ret) - wasm.Free(fl...) + ret := getClipboardText() + defer free(ret) + v := goString(ret) return v } +//go:wasmimport raylib _GetClipboardImage +//go:noescape +func getClipboardImage(img cptr) + // GetClipboardImage - Get clipboard image content // -// Only works with SDL3 backend or Windows with RGFW/GLFW +// Only works with SDL3 backend or Windows with GLFW/RGFW func GetClipboardImage() Image { - ret, fl := getClipboardImage.Call() - v := wasm.ReadStruct[Image](ret) - wasm.Free(fl...) + var v Image + ret, f := mallocV(v) + defer f() + getClipboardImage(ret) + copyValueToGo(ret, &v) return v } // EnableEventWaiting - Enable waiting for events on EndDrawing(), no automatic event polling -func EnableEventWaiting() { - _, fl := enableEventWaiting.Call() - wasm.Free(fl...) -} +// +//go:wasmimport raylib _EnableEventWaiting +//go:noescape +func EnableEventWaiting() // DisableEventWaiting - Disable waiting for events on EndDrawing(), automatic events polling -func DisableEventWaiting() { - _, fl := disableEventWaiting.Call() - wasm.Free(fl...) -} - -// ShowCursor - Shows cursor -func ShowCursor() { - _, fl := showCursor.Call() - wasm.Free(fl...) -} - -// HideCursor - Hides cursor -func HideCursor() { - _, fl := hideCursor.Call() - wasm.Free(fl...) -} - -// IsCursorHidden - Check if cursor is not visible -func IsCursorHidden() bool { - ret, fl := isCursorHidden.Call() - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// EnableCursor - Enables cursor (unlock cursor) -func EnableCursor() { - _, fl := enableCursor.Call() - wasm.Free(fl...) -} - -// DisableCursor - Disables cursor (lock cursor) -func DisableCursor() { - _, fl := disableCursor.Call() - wasm.Free(fl...) -} +// +//go:wasmimport raylib _DisableEventWaiting +//go:noescape +func DisableEventWaiting() -// IsCursorOnScreen - Check if cursor is on the screen -func IsCursorOnScreen() bool { - ret, fl := isCursorOnScreen.Call() - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} +//go:wasmimport raylib _ClearBackground +//go:noescape +func clearBackground(col cptr) -// ClearBackground - Set background color (framebuffer clear color) +// ClearBackground - Sets Background Color func ClearBackground(col color.RGBA) { - _, fl := clearBackground.Call(wasm.Struct(col)) - wasm.Free(fl...) + ccolor, f := copyValueToC(col) + defer f() + clearBackground(ccolor) } -// BeginDrawing - Setup canvas (framebuffer) to start drawing -func BeginDrawing() { - _, fl := beginDrawing.Call() - wasm.Free(fl...) -} +// BeginDrawing - Setup drawing canvas to start drawing +// +//go:wasmimport raylib _BeginDrawing +//go:noescape +func BeginDrawing() -// EndDrawing - End canvas drawing and swap buffers (double buffering) -func EndDrawing() { - _, fl := endDrawing.Call() - wasm.Free(fl...) -} +// EndDrawing - End canvas drawing and Swap Buffers (Double Buffering) +// +//go:wasmimport raylib _EndDrawing +//go:noescape +func EndDrawing() -// BeginMode2D - Begin 2D mode with custom camera (2D) +//go:wasmimport raylib _BeginMode2D +//go:noescape +func beginMode2D(camera cptr) + +// BeginMode2D - Initialize 2D mode with custom camera func BeginMode2D(camera Camera2D) { - _, fl := beginMode2D.Call(wasm.Struct(camera)) - wasm.Free(fl...) + ccamera, f := copyValueToC(camera) + defer f() + beginMode2D(ccamera) } -// EndMode2D - Ends 2D mode with custom camera -func EndMode2D() { - _, fl := endMode2D.Call() - wasm.Free(fl...) -} +// EndMode2D - Ends 2D mode custom camera usage +// +//go:wasmimport raylib _EndMode2D +//go:noescape +func EndMode2D() + +//go:wasmimport raylib _BeginMode3D +//go:noescape +func beginMode3D(camera cptr) -// BeginMode3D - Begin 3D mode with custom camera (3D) -func BeginMode3D(camera Camera3D) { - _, fl := beginMode3D.Call(wasm.Struct(camera)) - wasm.Free(fl...) +// BeginMode3D - Initializes 3D mode for drawing (Camera setup) +func BeginMode3D(camera Camera) { + c, f := copyValueToC(camera) + defer f() + beginMode3D(c) } // EndMode3D - Ends 3D mode and returns to default 2D orthographic mode -func EndMode3D() { - _, fl := endMode3D.Call() - wasm.Free(fl...) -} +// +//go:wasmimport raylib _EndMode3D +//go:noescape +func EndMode3D() -// BeginTextureMode - Begin drawing to render texture +//go:wasmimport raylib _BeginTextureMode +//go:noescape +func beginTextureMode(target cptr) + +// BeginTextureMode - Initializes render texture for drawing func BeginTextureMode(target RenderTexture2D) { - _, fl := beginTextureMode.Call(wasm.Struct(target)) - wasm.Free(fl...) + c, f := copyValueToC(target) + defer f() + beginTextureMode(c) } // EndTextureMode - Ends drawing to render texture -func EndTextureMode() { - _, fl := endTextureMode.Call() - wasm.Free(fl...) -} - -// BeginShaderMode - Begin custom shader drawing -func BeginShaderMode(shader Shader) { - _, fl := beginShaderMode.Call(wasm.Struct(shader)) - wasm.Free(fl...) -} - -// EndShaderMode - End custom shader drawing (use default shader) -func EndShaderMode() { - _, fl := endShaderMode.Call() - wasm.Free(fl...) -} - -// BeginBlendMode - Begin blending mode (alpha, additive, multiplied, subtract, custom) -func BeginBlendMode(mode BlendMode) { - _, fl := beginBlendMode.Call(mode) - wasm.Free(fl...) -} +// +//go:wasmimport raylib _EndTextureMode +//go:noescape +func EndTextureMode() -// EndBlendMode - End blending mode (reset to default: alpha blending) -func EndBlendMode() { - _, fl := endBlendMode.Call() - wasm.Free(fl...) -} +// BeginScissorMode - Begins scissor mode (define screen area for following drawing) +// +//go:wasmimport raylib _BeginScissorMode +//go:noescape +func BeginScissorMode(x, y, width, height int32) -// BeginScissorMode - Begin scissor mode (define screen area for following drawing) -func BeginScissorMode(x int32, y int32, width int32, height int32) { - _, fl := beginScissorMode.Call(x, y, width, height) - wasm.Free(fl...) -} +// EndScissorMode - Ends scissor mode +// +//go:wasmimport raylib _EndScissorMode +//go:noescape +func EndScissorMode() -// EndScissorMode - End scissor mode -func EndScissorMode() { - _, fl := endScissorMode.Call() - wasm.Free(fl...) -} +// LoadShader - Load a custom shader and bind default locations +// +//go:wasmimport raylib _LoadShader +//go:noescape +func loadShader(shader, vsFileName cptr, fsFileName cptr) -// BeginVrStereoMode - Begin stereo rendering (requires VR simulator) -func BeginVrStereoMode(config VrStereoConfig) { - _, fl := beginVrStereoMode.Call(wasm.Struct(config)) - wasm.Free(fl...) -} +// LoadShader - Load a custom shader and bind default locations +func LoadShader(vsFileName string, fsFileName string) Shader { + cvsFileName := cString(vsFileName) + defer free(cvsFileName) -// EndVrStereoMode - End stereo rendering (requires VR simulator) -func EndVrStereoMode() { - _, fl := endVrStereoMode.Call() - wasm.Free(fl...) -} + cfsFileName := cString(fsFileName) + defer free(cfsFileName) -// LoadVrStereoConfig - Load VR stereo config for VR simulator device parameters -func LoadVrStereoConfig(device VrDeviceInfo) VrStereoConfig { - ret, fl := loadVrStereoConfig.Call(wasm.Struct(device)) - v := wasm.ReadStruct[VrStereoConfig](ret) - wasm.Free(fl...) + var v Shader + ret, f := mallocV(v) + defer f() + loadShader(ret, cvsFileName, cfsFileName) + copyValueToGo(ret, &v) return v } -// UnloadVrStereoConfig - Unload VR stereo config -func UnloadVrStereoConfig(config VrStereoConfig) { - _, fl := unloadVrStereoConfig.Call(wasm.Struct(config)) - wasm.Free(fl...) -} - -// LoadShader - Load shader from files and bind default locations -func LoadShader(vsFileName string, fsFileName string) Shader { - ret, fl := loadShader.Call(vsFileName, fsFileName) - v := wasm.ReadStruct[Shader](ret) - wasm.Free(fl...) - return v -} +// LoadShaderFromMemory - Load shader from code strings and bind default locations +// +//go:wasmimport raylib _LoadShaderFromMemory +//go:noescape +func loadShaderFromMemory(shader, vsCode cptr, fsCode cptr) // LoadShaderFromMemory - Load shader from code strings and bind default locations func LoadShaderFromMemory(vsCode string, fsCode string) Shader { - ret, fl := loadShaderFromMemory.Call(vsCode, fsCode) - v := wasm.ReadStruct[Shader](ret) - wasm.Free(fl...) + cvsCode := cString(vsCode) + defer free(cvsCode) + + cfsCode := cString(fsCode) + defer free(cfsCode) + + var v Shader + ret, f := mallocV(v) + defer f() + loadShaderFromMemory(ret, cvsCode, cfsCode) + copyValueToGo(ret, &v) return v } +// IsShaderValid - Check if a shader is valid (loaded on GPU) +// +//go:wasmimport raylib _IsShaderValid +//go:noescape +func isShaderValid(shader cptr) bool + // IsShaderValid - Check if a shader is valid (loaded on GPU) func IsShaderValid(shader Shader) bool { - ret, fl := isShaderValid.Call(wasm.Struct(shader)) - v := wasm.Boolean(ret) - wasm.Free(fl...) + c, f := copyValueToC(shader) + defer f() + v := isShaderValid(c) return v } +// GetShaderLocation - Get shader uniform location +// +//go:wasmimport raylib _GetShaderLocation +//go:noescape +func getShaderLocation(shader cptr, uniformName cptr) int32 + // GetShaderLocation - Get shader uniform location func GetShaderLocation(shader Shader, uniformName string) int32 { - ret, fl := getShaderLocation.Call(wasm.Struct(shader), uniformName) - v := wasm.Numeric[int32](ret) - wasm.Free(fl...) + cshader, f := copyValueToC(shader) + defer f() + + cuniformName := cString(uniformName) + defer free(cuniformName) + + v := getShaderLocation(cshader, cuniformName) return v } +// GetShaderLocationAttrib - Get shader attribute location +// +//go:wasmimport raylib _GetShaderLocationAttrib +//go:noescape +func getShaderLocationAttrib(shader cptr, attribName cptr) int32 + // GetShaderLocationAttrib - Get shader attribute location func GetShaderLocationAttrib(shader Shader, attribName string) int32 { - ret, fl := getShaderLocationAttrib.Call(wasm.Struct(shader), attribName) - v := wasm.Numeric[int32](ret) - wasm.Free(fl...) - return v + cshader, f := copyValueToC(shader) + defer f() + cuniformName := cString(attribName) + defer free(cuniformName) + return getShaderLocationAttrib(cshader, cuniformName) } -// SetShaderValue - Set shader uniform value +// SetShaderValue - Set shader uniform value (float) +// +//go:wasmimport raylib _SetShaderValue +//go:noescape +func setShaderValue(shader cptr, locIndex int32, value cptr, uniformType ShaderUniformDataType) + +// SetShaderValue - Set shader uniform value (float) func SetShaderValue(shader Shader, locIndex int32, value []float32, uniformType ShaderUniformDataType) { - _, fl := setShaderValue.Call(wasm.Struct(shader), locIndex, value, uniformType) - wasm.Free(fl...) + cshader, f := copyValueToC(shader) + defer f() + clocIndex := (int32)(locIndex) + cvalue, f := copySliceToC(value) + defer f() + cuniformType := (int32)(uniformType) + setShaderValue(cshader, clocIndex, cvalue, cuniformType) } -// SetShaderValueV - Set shader uniform value vector +// SetShaderValueV - Set shader uniform value (float) +// +//go:wasmimport raylib _SetShaderValueV +//go:noescape +func setShaderValueV(shader cptr, locIndex int32, value cptr, uniformType ShaderUniformDataType, count int32) + +// SetShaderValueV - Set shader uniform value (float) func SetShaderValueV(shader Shader, locIndex int32, value []float32, uniformType ShaderUniformDataType, count int32) { - _, fl := setShaderValueV.Call(wasm.Struct(shader), locIndex, value, uniformType, count) - wasm.Free(fl...) + cshader, f := copyValueToC(shader) + defer f() + clocIndex := (int32)(locIndex) + cvalue, f := copySliceToC(value) + defer f() + cuniformType := (int32)(uniformType) + ccount := (int32)(count) + setShaderValueV(cshader, clocIndex, cvalue, cuniformType, ccount) } +// SetShaderValueMatrix - Set shader uniform value (matrix 4x4) +// +//go:wasmimport raylib _SetShaderValueMatrix +//go:noescape +func setShaderValueMatrix(shader cptr, locIndex int32, mat cptr) + // SetShaderValueMatrix - Set shader uniform value (matrix 4x4) func SetShaderValueMatrix(shader Shader, locIndex int32, mat Matrix) { - _, fl := setShaderValueMatrix.Call(wasm.Struct(shader), locIndex, wasm.Struct(mat)) - wasm.Free(fl...) + cshader, f := copyValueToC(shader) + defer f() + clocIndex := (int32)(locIndex) + cmat, f := copyValueToC(mat) + defer f() + setShaderValueMatrix(cshader, clocIndex, cmat) } +// SetShaderValueTexture - Set shader uniform value for texture (sampler2d) +// +//go:wasmimport raylib _SetShaderValueTexture +//go:noescape +func setShaderValueTexture(shader cptr, locIndex int32, texture cptr) + // SetShaderValueTexture - Set shader uniform value for texture (sampler2d) func SetShaderValueTexture(shader Shader, locIndex int32, texture Texture2D) { - _, fl := setShaderValueTexture.Call(wasm.Struct(shader), locIndex, wasm.Struct(texture)) - wasm.Free(fl...) + cshader, f := copyValueToC(shader) + defer f() + clocIndex := (int32)(locIndex) + ctexture, f := copyValueToC(texture) + defer f() + setShaderValueTexture(cshader, clocIndex, ctexture) } -// UnloadShader - Unload shader from GPU memory (VRAM) +// UnloadShader - Unload a custom shader from memory +// +//go:wasmimport raylib _UnloadShader +//go:noescape +func unloadShader(shader cptr) + +// UnloadShader - Unload a custom shader from memory func UnloadShader(shader Shader) { - _, fl := unloadShader.Call(wasm.Struct(shader)) - wasm.Free(fl...) + + cshader, f := copyValueToC(shader) + defer f() + unloadShader(cshader) } // GetMouseRay - Get a ray trace from mouse position // // Deprecated: Use [GetScreenToWorldRay] instead. func GetMouseRay(mousePosition Vector2, camera Camera) Ray { - ret, fl := getMouseRay.Call(wasm.Struct(mousePosition), camera) - v := wasm.ReadStruct[Ray](ret) - wasm.Free(fl...) - return v + return GetScreenToWorldRay(mousePosition, camera) } +// GetScreenToWorldRay - Get a ray trace from screen position (i.e mouse) +// +//go:wasmimport raylib _GetScreenToWorldRay +//go:noescape +func getScreenToWorldRay(ray cptr, position cptr, camera cptr) + // GetScreenToWorldRay - Get a ray trace from screen position (i.e mouse) func GetScreenToWorldRay(position Vector2, camera Camera) Ray { - ret, fl := getScreenToWorldRay.Call(wasm.Struct(position), camera) - v := wasm.ReadStruct[Ray](ret) - wasm.Free(fl...) + cposition, f := copyValueToC(position) + defer f() + ccamera, f := copyValueToC(camera) + defer f() + var v Ray + ret, f := mallocV(v) + defer f() + getScreenToWorldRay(ret, cposition, ccamera) + copyValueToGo(ret, &v) return v } // GetScreenToWorldRayEx - Get a ray trace from screen position (i.e mouse) in a viewport -func GetScreenToWorldRayEx(position Vector2, camera Camera, width int32, height int32) Ray { - ret, fl := getScreenToWorldRayEx.Call(wasm.Struct(position), camera, width, height) - v := wasm.ReadStruct[Ray](ret) - wasm.Free(fl...) +// +//go:wasmimport raylib _GetScreenToWorldRayEx +//go:noescape +func getScreenToWorldRayEx(ray cptr, position cptr, camera cptr, width, height int32) + +// GetScreenToWorldRayEx - Get a ray trace from screen position (i.e mouse) in a viewport +func GetScreenToWorldRayEx(position Vector2, camera Camera, width, height int32) Ray { + cposition, f := copyValueToC(position) + defer f() + ccamera, f := copyValueToC(camera) + cwidth := (int32)(width) + cheight := (int32)(height) + var v Ray + ret, f := mallocV(v) + defer f() + getScreenToWorldRayEx(ret, cposition, ccamera, cwidth, cheight) + copyValueToGo(ret, &v) return v } -// GetCameraMatrix - Get camera transform matrix (view matrix) +// GetCameraMatrix - Returns camera transform matrix (view matrix) +// +//go:wasmimport raylib _GetCameraMatrix +//go:noescape +func getCameraMatrix(mat cptr, camera cptr) + +// GetCameraMatrix - Returns camera transform matrix (view matrix) func GetCameraMatrix(camera Camera) Matrix { - ret, fl := getCameraMatrix.Call(camera) - v := wasm.ReadStruct[Matrix](ret) - wasm.Free(fl...) + ccamera, f := copyValueToC(camera) + defer f() + var v Matrix + ret, f := mallocV(v) + defer f() + + getCameraMatrix(ret, ccamera) + copyValueToGo(ret, &v) return v } -// GetCameraMatrix2D - Get camera 2d transform matrix +// GetCameraMatrix2D - Returns camera 2d transform matrix +// +//go:wasmimport raylib _GetCameraMatrix2D +//go:noescape +func getCameraMatrix2D(mat, camera cptr) + +// GetCameraMatrix2D - Returns camera 2d transform matrix func GetCameraMatrix2D(camera Camera2D) Matrix { - ret, fl := getCameraMatrix2D.Call(wasm.Struct(camera)) - v := wasm.ReadStruct[Matrix](ret) - wasm.Free(fl...) + ccamera, f := copyValueToC(camera) + defer f() + var v Matrix + ret, f := mallocV(v) + defer f() + getCameraMatrix2D(ret, ccamera) + copyValueToGo(ret, &v) return v } -// GetWorldToScreen - Get the screen space position for a 3d world space position +// GetWorldToScreen - Returns the screen space position from a 3d world space position +// +//go:wasmimport raylib _GetWorldToScreen +//go:noescape +func getWorldToScreen(vector2, position, camera cptr) + +// GetWorldToScreen - Returns the screen space position from a 3d world space position func GetWorldToScreen(position Vector3, camera Camera) Vector2 { - ret, fl := getWorldToScreen.Call(wasm.Struct(position), camera) - v := wasm.ReadStruct[Vector2](ret) - wasm.Free(fl...) + cposition, f := copyValueToC(position) + defer f() + ccamera, f := copyValueToC(position) + defer f() + var v Vector2 + ret, f := mallocV(v) + defer f() + getWorldToScreen(ret, cposition, ccamera) + copyValueToGo(ret, &v) return v } -// GetScreenToWorld2D - Get the world space position for a 2d camera screen space position +// GetScreenToWorld2D - Returns the world space position for a 2d camera screen space position +// +//go:wasmimport raylib _GetScreenToWorld2D +//go:noescape +func getScreenToWorld2D(vector2, position cptr, camera cptr) + +// GetScreenToWorld2D - Returns the world space position for a 2d camera screen space position func GetScreenToWorld2D(position Vector2, camera Camera2D) Vector2 { - ret, fl := getScreenToWorld2D.Call(wasm.Struct(position), wasm.Struct(camera)) - v := wasm.ReadStruct[Vector2](ret) - wasm.Free(fl...) + cposition, f := copyValueToC(position) + defer f() + ccamera, f := copyValueToC(camera) + defer f() + var v Vector2 + ret, f := mallocV(v) + defer f() + getScreenToWorld2D(ret, cposition, ccamera) + copyValueToGo(ret, &v) return v } +// GetWorldToScreenEx - Get size position for a 3d world space position +// +//go:wasmimport raylib _GetWorldToScreenEx +//go:noescape +func getWorldToScreenEx(vector2, position, camera cptr, width int32, height int32) + // GetWorldToScreenEx - Get size position for a 3d world space position func GetWorldToScreenEx(position Vector3, camera Camera, width int32, height int32) Vector2 { - ret, fl := getWorldToScreenEx.Call(wasm.Struct(position), camera, width, height) - v := wasm.ReadStruct[Vector2](ret) - wasm.Free(fl...) + cposition, f := copyValueToC(position) + defer f() + ccamera, f := copyValueToC(camera) + defer f() + cwidth := (int32)(width) + cheight := (int32)(height) + var v Vector2 + ret, f := mallocV(v) + defer f() + + getWorldToScreenEx(ret, cposition, ccamera, cwidth, cheight) + copyValueToGo(ret, &v) return v } -// GetWorldToScreen2D - Get the screen space position for a 2d camera world space position +// GetWorldToScreen2D - Returns the screen space position for a 2d camera world space position +// +//go:wasmimport raylib _GetWorldToScreen2D +//go:noescape +func getWorldToScreen2D(vector2, position, camera cptr) + +// GetWorldToScreen2D - Returns the screen space position for a 2d camera world space position func GetWorldToScreen2D(position Vector2, camera Camera2D) Vector2 { - ret, fl := getWorldToScreen2D.Call(wasm.Struct(position), wasm.Struct(camera)) - v := wasm.ReadStruct[Vector2](ret) - wasm.Free(fl...) + cposition, f := copyValueToC(position) + defer f() + ccamera, f := copyValueToC(camera) + defer f() + var v Vector2 + ret, f := mallocV(v) + defer f() + + getWorldToScreen2D(ret, cposition, ccamera) + copyValueToGo(ret, &v) return v } // SetTargetFPS - Set target FPS (maximum) -func SetTargetFPS(fps int32) { - _, fl := setTargetFPS.Call(fps) - wasm.Free(fl...) -} +// +//go:wasmimport raylib _SetTargetFPS +//go:noescape +func SetTargetFPS(fps int32) -// GetFrameTime - Get time in seconds for last frame drawn (delta time) -func GetFrameTime() float32 { - ret, fl := getFrameTime.Call() - v := wasm.Numeric[float32](ret) - wasm.Free(fl...) - return v -} +// GetFPS - Returns current FPS +// +//go:wasmimport raylib _GetFPS +//go:noescape +func GetFPS() int32 -// GetTime - Get elapsed time in seconds since InitWindow() -func GetTime() float64 { - ret, fl := getTime.Call() - v := wasm.Numeric[float64](ret) - wasm.Free(fl...) - return v -} +// GetFrameTime - Returns time in seconds for one frame +// +//go:wasmimport raylib _GetFrameTime +//go:noescape +func GetFrameTime() float32 + +// GetTime - Return time in seconds +// +//go:wasmimport raylib _GetTime +//go:noescape +func GetTime() float64 + +// Custom frame control functions +// NOTE: SwapScreenBuffer and PollInputEvents are intended for advanced users that want full control over the frame processing +// By default EndDrawing() does this job: draws everything + SwapScreenBuffer() + manage frame timing + PollInputEvents() +// To avoid that behaviour and control frame processes manually you can either enable in config.h: SUPPORT_CUSTOM_FRAME_CONTROL +// or add CGO_CFLAGS="-DSUPPORT_CUSTOM_FRAME_CONTROL=1" to your build +// SwapScreenBuffer - Swap back buffer to front buffer +// +//go:wasmimport raylib _SwapScreenBuffer +//go:noescape +func SwapScreenBuffer() + +// Register all input events +// +//go:wasmimport raylib _PollInputEvents +//go:noescape +func PollInputEvents() -// GetFPS - Get current FPS -func GetFPS() int32 { - ret, fl := getFPS.Call() - v := wasm.Numeric[int32](ret) - wasm.Free(fl...) +// WaitTime - Wait for some time (halt program execution) +// +//go:wasmimport raylib _WaitTime +//go:noescape +func WaitTime(seconds float64) + +// Fade - Returns color with alpha applied, alpha goes from 0.0f to 1.0f +// +//go:wasmimport raylib _Fade +//go:noescape +func fade(color, col cptr, alpha float32) + +// Fade - Returns color with alpha applied, alpha goes from 0.0f to 1.0f +func Fade(col color.RGBA, alpha float32) color.RGBA { + ccolor, f := copyValueToC(col) + defer f() + var v Color + ret, f := mallocV(v) + defer f() + fade(ret, ccolor, alpha) + copyValueToGo(ret, &v) return v } -// SwapScreenBuffer - Swap back buffer with front buffer (screen drawing) -func SwapScreenBuffer() { - _, fl := swapScreenBuffer.Call() - wasm.Free(fl...) -} +// ColorToInt - Get hexadecimal value for a Color (0xRRGGBBAA) +// +//go:wasmimport raylib _ColorToInt +//go:noescape +func colorToInt(col cptr) int32 -// PollInputEvents - Register all input events -func PollInputEvents() { - _, fl := pollInputEvents.Call() - wasm.Free(fl...) +// ColorToInt - Get hexadecimal value for a Color (0xRRGGBBAA) +func ColorToInt(col color.RGBA) int32 { + ccolor, f := copyValueToC(col) + defer f() + return colorToInt(ccolor) } -// WaitTime - Wait for some time (halt program execution) -func WaitTime(seconds float64) { - _, fl := waitTime.Call(seconds) - wasm.Free(fl...) +// ColorNormalize - Returns color normalized as float [0..1] +func ColorNormalize(col color.RGBA) Vector4 { + result := Vector4{} + r, g, b, a := col.R, col.G, col.B, col.A + result.X = float32(r) / 255 + result.Y = float32(g) / 255 + result.Z = float32(b) / 255 + result.W = float32(a) / 255 + return result } -// SetRandomSeed - Set the seed for the random number generator +// ColorFromNormalized - Returns Color from normalized values [0..1] // -// Note: You can use go's math/rand package instead -func SetRandomSeed(seed uint32) { - _, fl := setRandomSeed.Call(seed) - wasm.Free(fl...) +//go:wasmimport raylib _ColorNormalized +//go:noescape +func colorFromNormalized(col, normalized cptr) + +// ColorFromNormalized - Returns Color from normalized values [0..1] +func ColorFromNormalized(normalized Vector4) color.RGBA { + cnormalized, f := copyValueToC(normalized) + defer f() + var v Color + ret, f := mallocV(v) + colorFromNormalized(ret, cnormalized) + copyValueToGo(ret, &v) + return v } -// GetRandomValue - Get a random value between min and max (both included) +// ColorToHSV - Returns HSV values for a Color, hue [0..360], saturation/value [0..1] // -// Note: You can use go's math/rand package instead -func GetRandomValue(minimum int32, maximum int32) int32 { - ret, fl := getRandomValue.Call(minimum, maximum) - v := wasm.Numeric[int32](ret) - wasm.Free(fl...) +//go:wasmimport raylib _ColorToHSV +//go:noescape +func colorToHSV(vector3, col cptr) + +// ColorToHSV - Returns HSV values for a Color, hue [0..360], saturation/value [0..1] +func ColorToHSV(col color.RGBA) Vector3 { + ccolor, f := copyValueToC(col) + defer f() + var v Vector3 + ret, f := mallocV(v) + defer f() + colorToHSV(ret, ccolor) + copyValueToGo(ret, &v) return v } -// LoadRandomSequence - Load random values sequence, no values repeated +// ColorFromHSV - Returns a Color from HSV values, hue [0..360], saturation/value [0..1] // -// Note: Use UnloadRandomSequence if you don't need the sequence any more. You can use go's math/rand.Perm function instead. -func LoadRandomSequence(count uint32, minimum int32, maximum int32) []int32 { - var zero []int32 - return zero -} +//go:wasmimport raylib _ColorFromHSV +//go:noescape +func colorFromHSV(col cptr, hue, saturation, value float32) -// UnloadRandomSequence - Unload random values sequence -func UnloadRandomSequence(sequence []int32) { - _, fl := unloadRandomSequence.Call(sequence) - wasm.Free(fl...) +// ColorFromHSV - Returns a Color from HSV values, hue [0..360], saturation/value [0..1] +func ColorFromHSV(hue, saturation, value float32) color.RGBA { + var v Color + ret, f := mallocV(v) + defer f() + colorFromHSV(ret, hue, saturation, value) + copyValueToGo(ret, &v) + return v } -// TakeScreenshot - Takes a screenshot of current screen (filename extension defines format) -func TakeScreenshot(fileName string) { - _, fl := takeScreenshot.Call(fileName) - wasm.Free(fl...) -} +// ColorTint - Get color multiplied with another color +// +//go:wasmimport raylib _ColorTint +//go:noescape +func colorTint(color, col, tint cptr) -// SetConfigFlags - Setup init configuration flags (view FLAGS) -func SetConfigFlags(flags uint32) { - _, fl := setConfigFlags.Call(flags) - wasm.Free(fl...) +// ColorTint - Get color multiplied with another color +func ColorTint(col color.RGBA, tint color.RGBA) color.RGBA { + ccolor, f := copyValueToC(col) + defer f() + + ctint, f := copyValueToC(tint) + defer f() + var v Color + ret, f := mallocV(v) + defer f() + colorTint(ret, ccolor, ctint) + return v } -// OpenURL - Open URL with default system browser (if available) -func OpenURL(url string) { - _, fl := openURL.Call(url) - wasm.Free(fl...) +/* + +// ColorContrast - Get color with contrast correction, contrast values between -1.0f and 1.0f +func ColorContrast(col color.RGBA, contrast float32) color.RGBA { + ccolor := colorCptr(col) + ccontrast := float(contrast) + ret := colorContrast(*ccolor, ccontrast) + v := newColorFromPointer(&ret) + return v } -// TraceLog - Show trace log messages (LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR...) -func TraceLog(logLevel TraceLogLevel, text string, args ...any) { - _, fl := traceLog.Call(logLevel, text, args) - wasm.Free(fl...) +// ColorAlpha - Returns color with alpha applied, alpha goes from 0.0f to 1.0f +func ColorAlpha(col color.RGBA, alpha float32) color.RGBA { + return Fade(col, alpha) } -// SetTraceLogLevel - Set the current threshold (minimum) log level -func SetTraceLogLevel(logLevel TraceLogLevel) { - _, fl := setTraceLogLevel.Call(logLevel) - wasm.Free(fl...) +// ColorAlphaBlend - Returns src alpha-blended into dst color with tint +func ColorAlphaBlend(src, dst, tint color.RGBA) color.RGBA { + csrc := colorCptr(src) + cdst := colorCptr(dst) + ctint := colorCptr(tint) + ret := colorAlphaBlend(*csrc, *cdst, *ctint) + v := newColorFromPointer(&ret) + return v } -// MemAlloc - Internal memory allocator -func MemAlloc(size uint32) unsafe.Pointer { - var zero unsafe.Pointer - return zero +// ColorLerp - Get color lerp interpolation between two colors, factor [0.0f..1.0f] +func ColorLerp(col1, col2 color.RGBA, factor float32) color.RGBA { + ccol1 := colorCptr(col1) + ccol2 := colorCptr(col2) + ret := colorLerp(*ccol1, *ccol2, float(factor)) + v := newColorFromPointer(&ret) + return v } -// MemRealloc - Internal memory reallocator -func MemRealloc(ptr unsafe.Pointer, size uint32) unsafe.Pointer { - var zero unsafe.Pointer - return zero +// GetColor - Returns a Color struct from hexadecimal value +func GetColor(hexValue uint) color.RGBA { + chexValue := (uint)(hexValue) + ret := getColor(chexValue) + v := newColorFromPointer(&ret) + return v } -// MemFree - Internal memory free -func MemFree(ptr unsafe.Pointer) { - _, fl := memFree.Call(ptr) - wasm.Free(fl...) +// GetPixelDataSize - Get pixel data size in bytes for certain format +func GetPixelDataSize(width, height, format int32) int32 { + cwidth := (int32)(width) + cheight := (int32)(height) + cformat := (int32)(format) + ret := getPixelDataSize(cwidth, cheight, cformat) + v := (int32)(ret) + return v } -// IsFileDropped - Check if a file has been dropped into window -func IsFileDropped() bool { - ret, fl := isFileDropped.Call() - v := wasm.Boolean(ret) - wasm.Free(fl...) +// GetRandomValue - Returns a random value between min and max (both included) +func GetRandomValue(min, max int32) int32 { + cmin := (int32)(min) + cmax := (int32)(max) + ret := getRandomValue(cmin, cmax) + v := (int32)(ret) return v } -// LoadDroppedFiles - Load dropped filepaths -func LoadDroppedFiles() []string { - var zero []string - return zero +// OpenURL - Open URL with default system browser (if available) +func OpenURL(url string) { + curl := cString(url) + defer free(curl) + openURL(curl) } -// UnloadDroppedFiles - Unload dropped filepaths -func UnloadDroppedFiles() { - _, fl := unloadDroppedFiles.Call() - wasm.Free(fl...) +// SetConfigFlags - Setup some window configuration flags +func SetConfigFlags(flags uint32) { + cflags := (uint)(flags) + setConfigFlags(cflags) } -// LoadAutomationEventList - Load automation events list from file, NULL for empty list, capacity = MAX_AUTOMATION_EVENTS -func LoadAutomationEventList(fileName string) AutomationEventList { - ret, fl := loadAutomationEventList.Call(fileName) - v := wasm.ReadStruct[AutomationEventList](ret) - wasm.Free(fl...) - return v +// TakeScreenshot - Takes a screenshot of current screen (saved a .png) +func TakeScreenshot(name string) { + cname := cString(name) + defer free(cname) + takeScreenshot(cname) +} + +// LoadAutomationEventList - Load automation events list from file, NULL for empty list, capacity = MAX_AUTOMATION_EVENTS +func LoadAutomationEventList(fileName string) AutomationEventList { + cfileName := cString(fileName) + defer free(cfileName) + + ret := loadAutomationEventList(cfileName) + v := newAutomationEventListFromPointer(&ret) + + return v } // UnloadAutomationEventList - Unload automation events list from file func UnloadAutomationEventList(list *AutomationEventList) { - _, fl := unloadAutomationEventList.Call(list) - wasm.Free(fl...) + unloadAutomationEventList(*list.cptr()) } // ExportAutomationEventList - Export automation events list as text file func ExportAutomationEventList(list AutomationEventList, fileName string) bool { - ret, fl := exportAutomationEventList.Call(wasm.Struct(list), fileName) - v := wasm.Boolean(ret) - wasm.Free(fl...) + cfileName := cString(fileName) + defer free(cfileName) + + ret := exportAutomationEventList(*list.cptr(), cfileName) + v := bool(ret) + return v } // SetAutomationEventList - Set automation event list to record to func SetAutomationEventList(list *AutomationEventList) { - _, fl := setAutomationEventList.Call(list) - wasm.Free(fl...) + setAutomationEventList(list.cptr()) } // SetAutomationEventBaseFrame - Set automation event internal base frame to start recording func SetAutomationEventBaseFrame(frame int) { - _, fl := setAutomationEventBaseFrame.Call(frame) - wasm.Free(fl...) + cframe := (int32)(frame) + setAutomationEventBaseFrame(cframe) } // StartAutomationEventRecording - Start recording automation events (AutomationEventList must be set) func StartAutomationEventRecording() { - _, fl := startAutomationEventRecording.Call() - wasm.Free(fl...) + startAutomationEventRecording() } // StopAutomationEventRecording - Stop recording automation events func StopAutomationEventRecording() { - _, fl := stopAutomationEventRecording.Call() - wasm.Free(fl...) + stopAutomationEventRecording() } // PlayAutomationEvent - Play a recorded automation event func PlayAutomationEvent(event AutomationEvent) { - _, fl := playAutomationEvent.Call(wasm.Struct(event)) - wasm.Free(fl...) + playAutomationEvent(*event.cptr()) } -// IsKeyPressed - Check if a key has been pressed once +// IsKeyPressed - Detect if a key has been pressed once func IsKeyPressed(key int32) bool { - ret, fl := isKeyPressed.Call(key) - v := wasm.Boolean(ret) - wasm.Free(fl...) + ckey := (int32)(key) + ret := isKeyPressed(ckey) + v := bool(ret) return v } -// IsKeyPressedRepeat - Check if a key has been pressed again (Only PLATFORM_DESKTOP) +// IsKeyPressedRepeat - Detect if a key has been pressed again (Only PLATFORM_DESKTOP) func IsKeyPressedRepeat(key int32) bool { - ret, fl := isKeyPressedRepeat.Call(key) - v := wasm.Boolean(ret) - wasm.Free(fl...) + ckey := (int32)(key) + ret := isKeyPressedRepeat(ckey) + v := bool(ret) return v } -// IsKeyDown - Check if a key is being pressed +// IsKeyDown - Detect if a key is being pressed func IsKeyDown(key int32) bool { - ret, fl := isKeyDown.Call(key) - v := wasm.Boolean(ret) - wasm.Free(fl...) + ckey := (int32)(key) + ret := isKeyDown(ckey) + v := bool(ret) return v } -// IsKeyReleased - Check if a key has been released once +// IsKeyReleased - Detect if a key has been released once func IsKeyReleased(key int32) bool { - ret, fl := isKeyReleased.Call(key) - v := wasm.Boolean(ret) - wasm.Free(fl...) + ckey := (int32)(key) + ret := isKeyReleased(ckey) + v := bool(ret) return v } -// IsKeyUp - Check if a key is NOT being pressed +// IsKeyUp - Detect if a key is NOT being pressed func IsKeyUp(key int32) bool { - ret, fl := isKeyUp.Call(key) - v := wasm.Boolean(ret) - wasm.Free(fl...) + ckey := (int32)(key) + ret := isKeyUp(ckey) + v := bool(ret) return v } -// GetKeyPressed - Get key pressed (keycode), call it multiple times for keys queued, returns 0 when the queue is empty +// GetKeyPressed - Get latest key pressed func GetKeyPressed() int32 { - ret, fl := getKeyPressed.Call() - v := wasm.Numeric[int32](ret) - wasm.Free(fl...) + ret := getKeyPressed() + v := (int32)(ret) return v } -// GetCharPressed - Get char pressed (unicode), call it multiple times for chars queued, returns 0 when the queue is empty +// GetCharPressed - Get the last char pressed func GetCharPressed() int32 { - ret, fl := getCharPressed.Call() - v := wasm.Numeric[int32](ret) - wasm.Free(fl...) + ret := getCharPressed() + v := (int32)(ret) return v } // SetExitKey - Set a custom key to exit program (default is ESC) func SetExitKey(key int32) { - _, fl := setExitKey.Call(key) - wasm.Free(fl...) + ckey := (int32)(key) + setExitKey(ckey) } -// IsGamepadAvailable - Check if a gamepad is available +// IsGamepadAvailable - Detect if a gamepad is available func IsGamepadAvailable(gamepad int32) bool { - ret, fl := isGamepadAvailable.Call(gamepad) - v := wasm.Boolean(ret) - wasm.Free(fl...) + cgamepad := (int32)(gamepad) + ret := isGamepadAvailable(cgamepad) + v := bool(ret) return v } -// GetGamepadName - Get gamepad internal name id +// GetGamepadName - Return gamepad internal name id func GetGamepadName(gamepad int32) string { - ret, fl := getGamepadName.Call(gamepad) - v := wasm.Numeric[string](ret) - wasm.Free(fl...) + cgamepad := (int32)(gamepad) + ret := getGamepadName(cgamepad) + v := goString(ret) return v } -// IsGamepadButtonPressed - Check if a gamepad button has been pressed once -func IsGamepadButtonPressed(gamepad int32, button int32) bool { - ret, fl := isGamepadButtonPressed.Call(gamepad, button) - v := wasm.Boolean(ret) - wasm.Free(fl...) +// IsGamepadButtonPressed - Detect if a gamepad button has been pressed once +func IsGamepadButtonPressed(gamepad, button int32) bool { + cgamepad := (int32)(gamepad) + cbutton := (int32)(button) + ret := isGamepadButtonPressed(cgamepad, cbutton) + v := bool(ret) return v } -// IsGamepadButtonDown - Check if a gamepad button is being pressed -func IsGamepadButtonDown(gamepad int32, button int32) bool { - ret, fl := isGamepadButtonDown.Call(gamepad, button) - v := wasm.Boolean(ret) - wasm.Free(fl...) +// IsGamepadButtonDown - Detect if a gamepad button is being pressed +func IsGamepadButtonDown(gamepad, button int32) bool { + cgamepad := (int32)(gamepad) + cbutton := (int32)(button) + ret := isGamepadButtonDown(cgamepad, cbutton) + v := bool(ret) return v } -// IsGamepadButtonReleased - Check if a gamepad button has been released once -func IsGamepadButtonReleased(gamepad int32, button int32) bool { - ret, fl := isGamepadButtonReleased.Call(gamepad, button) - v := wasm.Boolean(ret) - wasm.Free(fl...) +// IsGamepadButtonReleased - Detect if a gamepad button has been released once +func IsGamepadButtonReleased(gamepad, button int32) bool { + cgamepad := (int32)(gamepad) + cbutton := (int32)(button) + ret := isGamepadButtonReleased(cgamepad, cbutton) + v := bool(ret) return v } -// IsGamepadButtonUp - Check if a gamepad button is NOT being pressed -func IsGamepadButtonUp(gamepad int32, button int32) bool { - ret, fl := isGamepadButtonUp.Call(gamepad, button) - v := wasm.Boolean(ret) - wasm.Free(fl...) +// IsGamepadButtonUp - Detect if a gamepad button is NOT being pressed +func IsGamepadButtonUp(gamepad, button int32) bool { + cgamepad := (int32)(gamepad) + cbutton := (int32)(button) + ret := isGamepadButtonUp(cgamepad, cbutton) + v := bool(ret) return v } // GetGamepadButtonPressed - Get the last gamepad button pressed func GetGamepadButtonPressed() int32 { - ret, fl := getGamepadButtonPressed.Call() - v := wasm.Numeric[int32](ret) - wasm.Free(fl...) + ret := getGamepadButtonPressed() + v := (int32)(ret) return v } -// GetGamepadAxisCount - Get gamepad axis count for a gamepad +// GetGamepadAxisCount - Return gamepad axis count for a gamepad func GetGamepadAxisCount(gamepad int32) int32 { - ret, fl := getGamepadAxisCount.Call(gamepad) - v := wasm.Numeric[int32](ret) - wasm.Free(fl...) + cgamepad := (int32)(gamepad) + ret := getGamepadAxisCount(cgamepad) + v := (int32)(ret) return v } -// GetGamepadAxisMovement - Get axis movement value for a gamepad axis -func GetGamepadAxisMovement(gamepad int32, axis int32) float32 { - ret, fl := getGamepadAxisMovement.Call(gamepad, axis) - v := wasm.Numeric[float32](ret) - wasm.Free(fl...) +// GetGamepadAxisMovement - Return axis movement value for a gamepad axis +func GetGamepadAxisMovement(gamepad, axis int32) float32 { + cgamepad := (int32)(gamepad) + caxis := (int32)(axis) + ret := getGamepadAxisMovement(cgamepad, caxis) + v := (float32)(ret) return v } // SetGamepadMappings - Set internal gamepad mappings (SDL_GameControllerDB) func SetGamepadMappings(mappings string) int32 { - ret, fl := setGamepadMappings.Call(mappings) - v := wasm.Numeric[int32](ret) - wasm.Free(fl...) + cmappings := cString(mappings) + defer free(cmappings) + ret := setGamepadMappings(cmappings) + v := (int32)(ret) return v } // SetGamepadVibration - Set gamepad vibration for both motors (duration in seconds) -func SetGamepadVibration(gamepad int32, leftMotor float32, rightMotor float32, duration float32) { - _, fl := setGamepadVibration.Call(gamepad, leftMotor, rightMotor, duration) - wasm.Free(fl...) +func SetGamepadVibration(gamepad int32, leftMotor, rightMotor, duration float32) { + setGamepadVibration(int32(gamepad), float(leftMotor), float(rightMotor), float(duration)) } -// IsMouseButtonPressed - Check if a mouse button has been pressed once +// IsMouseButtonPressed - Detect if a mouse button has been pressed once func IsMouseButtonPressed(button MouseButton) bool { - ret, fl := isMouseButtonPressed.Call(button) - v := wasm.Boolean(ret) - wasm.Free(fl...) + cbutton := (int32)(button) + ret := isMouseButtonPressed(cbutton) + v := bool(ret) return v } -// IsMouseButtonDown - Check if a mouse button is being pressed +// IsMouseButtonDown - Detect if a mouse button is being pressed func IsMouseButtonDown(button MouseButton) bool { - ret, fl := isMouseButtonDown.Call(button) - v := wasm.Boolean(ret) - wasm.Free(fl...) + cbutton := (int32)(button) + ret := isMouseButtonDown(cbutton) + v := bool(ret) return v } -// IsMouseButtonReleased - Check if a mouse button has been released once +// IsMouseButtonReleased - Detect if a mouse button has been released once func IsMouseButtonReleased(button MouseButton) bool { - ret, fl := isMouseButtonReleased.Call(button) - v := wasm.Boolean(ret) - wasm.Free(fl...) + cbutton := (int32)(button) + ret := isMouseButtonReleased(cbutton) + v := bool(ret) return v } -// IsMouseButtonUp - Check if a mouse button is NOT being pressed +// IsMouseButtonUp - Detect if a mouse button is NOT being pressed func IsMouseButtonUp(button MouseButton) bool { - ret, fl := isMouseButtonUp.Call(button) - v := wasm.Boolean(ret) - wasm.Free(fl...) + cbutton := (int32)(button) + ret := isMouseButtonUp(cbutton) + v := bool(ret) return v } -// GetMouseX - Get mouse position X +// GetMouseX - Returns mouse position X func GetMouseX() int32 { - ret, fl := getMouseX.Call() - v := wasm.Numeric[int32](ret) - wasm.Free(fl...) + ret := getMouseX() + v := (int32)(ret) return v } -// GetMouseY - Get mouse position Y +// GetMouseY - Returns mouse position Y func GetMouseY() int32 { - ret, fl := getMouseY.Call() - v := wasm.Numeric[int32](ret) - wasm.Free(fl...) + ret := getMouseY() + v := (int32)(ret) return v } -// GetMousePosition - Get mouse position XY +// GetMousePosition - Returns mouse position XY func GetMousePosition() Vector2 { - ret, fl := getMousePosition.Call() - v := wasm.ReadStruct[Vector2](ret) - wasm.Free(fl...) + ret := getMousePosition() + v := newVector2FromPointer(&ret) return v } // GetMouseDelta - Get mouse delta between frames func GetMouseDelta() Vector2 { - ret, fl := getMouseDelta.Call() - v := wasm.ReadStruct[Vector2](ret) - wasm.Free(fl...) + ret := getMouseDelta() + v := newVector2FromPointer(&ret) return v } // SetMousePosition - Set mouse position XY -func SetMousePosition(x int32, y int32) { - _, fl := setMousePosition.Call(x, y) - wasm.Free(fl...) +func SetMousePosition(x, y int) { + cx := (int32)(x) + cy := (int32)(y) + setMousePosition(cx, cy) } // SetMouseOffset - Set mouse offset -func SetMouseOffset(offsetX int32, offsetY int32) { - _, fl := setMouseOffset.Call(offsetX, offsetY) - wasm.Free(fl...) +func SetMouseOffset(offsetX, offsetY int) { + ox := (int32)(offsetX) + oy := (int32)(offsetY) + setMouseOffset(ox, oy) } // SetMouseScale - Set mouse scaling -func SetMouseScale(scaleX float32, scaleY float32) { - _, fl := setMouseScale.Call(scaleX, scaleY) - wasm.Free(fl...) +func SetMouseScale(scaleX, scaleY float32) { + cscaleX := (float)(scaleX) + cscaleY := (float)(scaleY) + setMouseScale(cscaleX, cscaleY) } // GetMouseWheelMove - Get mouse wheel movement for X or Y, whichever is larger func GetMouseWheelMove() float32 { - ret, fl := getMouseWheelMove.Call() - v := wasm.Numeric[float32](ret) - wasm.Free(fl...) + ret := getMouseWheelMove() + v := (float32)(ret) return v } // GetMouseWheelMoveV - Get mouse wheel movement for both X and Y func GetMouseWheelMoveV() Vector2 { - ret, fl := getMouseWheelMoveV.Call() - v := wasm.ReadStruct[Vector2](ret) - wasm.Free(fl...) + ret := getMouseWheelMoveV() + v := newVector2FromPointer(&ret) return v } // SetMouseCursor - Set mouse cursor func SetMouseCursor(cursor int32) { - _, fl := setMouseCursor.Call(cursor) - wasm.Free(fl...) + ccursor := (int32)(cursor) + setMouseCursor(ccursor) } -// GetTouchX - Get touch position X for touch point 0 (relative to screen size) +// GetTouchX - Returns touch position X for touch point 0 (relative to screen size) func GetTouchX() int32 { - ret, fl := getTouchX.Call() - v := wasm.Numeric[int32](ret) - wasm.Free(fl...) + ret := getTouchX() + v := (int32)(ret) return v } -// GetTouchY - Get touch position Y for touch point 0 (relative to screen size) +// GetTouchY - Returns touch position Y for touch point 0 (relative to screen size) func GetTouchY() int32 { - ret, fl := getTouchY.Call() - v := wasm.Numeric[int32](ret) - wasm.Free(fl...) + ret := getTouchY() + v := (int32)(ret) return v } -// GetTouchPosition - Get touch position XY for a touch point index (relative to screen size) +// GetTouchPosition - Returns touch position XY for a touch point index (relative to screen size) func GetTouchPosition(index int32) Vector2 { - ret, fl := getTouchPosition.Call(index) - v := wasm.ReadStruct[Vector2](ret) - wasm.Free(fl...) + cindex := (int32)(index) + ret := getTouchPosition(cindex) + v := newVector2FromPointer(&ret) return v } // GetTouchPointId - Get touch point identifier for given index func GetTouchPointId(index int32) int32 { - ret, fl := getTouchPointId.Call(index) - v := wasm.Numeric[int32](ret) - wasm.Free(fl...) + cindex := (int32)(index) + ret := getTouchPointId(cindex) + v := (int32)(ret) return v } // GetTouchPointCount - Get number of touch points func GetTouchPointCount() int32 { - ret, fl := getTouchPointCount.Call() - v := wasm.Numeric[int32](ret) - wasm.Free(fl...) - return v -} - -// SetGesturesEnabled - Enable a set of gestures using flags -func SetGesturesEnabled(flags uint32) { - _, fl := setGesturesEnabled.Call(flags) - wasm.Free(fl...) -} - -// IsGestureDetected - Check if a gesture have been detected -func IsGestureDetected(gesture Gestures) bool { - ret, fl := isGestureDetected.Call(gesture) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// GetGestureDetected - Get latest detected gesture -func GetGestureDetected() Gestures { - ret, fl := getGestureDetected.Call() - v := wasm.Numeric[Gestures](ret) - wasm.Free(fl...) - return v -} - -// GetGestureHoldDuration - Get gesture hold time in milliseconds -func GetGestureHoldDuration() float32 { - ret, fl := getGestureHoldDuration.Call() - v := wasm.Numeric[float32](ret) - wasm.Free(fl...) - return v -} - -// GetGestureDragVector - Get gesture drag vector -func GetGestureDragVector() Vector2 { - ret, fl := getGestureDragVector.Call() - v := wasm.ReadStruct[Vector2](ret) - wasm.Free(fl...) - return v -} - -// GetGestureDragAngle - Get gesture drag angle -func GetGestureDragAngle() float32 { - ret, fl := getGestureDragAngle.Call() - v := wasm.Numeric[float32](ret) - wasm.Free(fl...) - return v -} - -// GetGesturePinchVector - Get gesture pinch delta -func GetGesturePinchVector() Vector2 { - ret, fl := getGesturePinchVector.Call() - v := wasm.ReadStruct[Vector2](ret) - wasm.Free(fl...) - return v -} - -// GetGesturePinchAngle - Get gesture pinch angle -func GetGesturePinchAngle() float32 { - ret, fl := getGesturePinchAngle.Call() - v := wasm.Numeric[float32](ret) - wasm.Free(fl...) - return v -} - -// SetShapesTexture - Set texture and rectangle to be used on shapes drawing -func SetShapesTexture(texture Texture2D, source Rectangle) { - _, fl := setShapesTexture.Call(wasm.Struct(texture), wasm.Struct(source)) - wasm.Free(fl...) -} - -// GetShapesTexture - Get texture that is used for shapes drawing -func GetShapesTexture() Texture2D { - ret, fl := getShapesTexture.Call() - v := wasm.ReadStruct[Texture2D](ret) - wasm.Free(fl...) - return v -} - -// GetShapesTextureRectangle - Get texture source rectangle that is used for shapes drawing -func GetShapesTextureRectangle() Rectangle { - ret, fl := getShapesTextureRectangle.Call() - v := wasm.ReadStruct[Rectangle](ret) - wasm.Free(fl...) - return v -} - -// DrawPixel - Draw a pixel -func DrawPixel(posX int32, posY int32, col color.RGBA) { - _, fl := drawPixel.Call(posX, posY, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawPixelV - Draw a pixel (Vector version) -func DrawPixelV(position Vector2, col color.RGBA) { - _, fl := drawPixelV.Call(wasm.Struct(position), wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawLine - Draw a line -func DrawLine(startPosX int32, startPosY int32, endPosX int32, endPosY int32, col color.RGBA) { - _, fl := drawLine.Call(startPosX, startPosY, endPosX, endPosY, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawLineV - Draw a line (using gl lines) -func DrawLineV(startPos Vector2, endPos Vector2, col color.RGBA) { - _, fl := drawLineV.Call(wasm.Struct(startPos), wasm.Struct(endPos), wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawLineEx - Draw a line (using triangles/quads) -func DrawLineEx(startPos Vector2, endPos Vector2, thick float32, col color.RGBA) { - _, fl := drawLineEx.Call(wasm.Struct(startPos), wasm.Struct(endPos), thick, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawLineStrip - Draw lines sequence (using gl lines) -func DrawLineStrip(points []Vector2, col color.RGBA) { - _, fl := drawLineStrip.Call(points, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawLineBezier - Draw line segment cubic-bezier in-out interpolation -func DrawLineBezier(startPos Vector2, endPos Vector2, thick float32, col color.RGBA) { - _, fl := drawLineBezier.Call(wasm.Struct(startPos), wasm.Struct(endPos), thick, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawCircle - Draw a color-filled circle -func DrawCircle(centerX int32, centerY int32, radius float32, col color.RGBA) { - _, fl := drawCircle.Call(centerX, centerY, radius, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawCircleSector - Draw a piece of a circle -func DrawCircleSector(center Vector2, radius float32, startAngle float32, endAngle float32, segments int32, col color.RGBA) { - _, fl := drawCircleSector.Call(wasm.Struct(center), radius, startAngle, endAngle, segments, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawCircleSectorLines - Draw circle sector outline -func DrawCircleSectorLines(center Vector2, radius float32, startAngle float32, endAngle float32, segments int32, col color.RGBA) { - _, fl := drawCircleSectorLines.Call(wasm.Struct(center), radius, startAngle, endAngle, segments, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawCircleGradient - Draw a gradient-filled circle -func DrawCircleGradient(centerX int32, centerY int32, radius float32, inner color.RGBA, outer color.RGBA) { - _, fl := drawCircleGradient.Call(centerX, centerY, radius, wasm.Struct(inner), wasm.Struct(outer)) - wasm.Free(fl...) -} - -// DrawCircleV - Draw a color-filled circle (Vector version) -func DrawCircleV(center Vector2, radius float32, col color.RGBA) { - _, fl := drawCircleV.Call(wasm.Struct(center), radius, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawCircleLines - Draw circle outline -func DrawCircleLines(centerX int32, centerY int32, radius float32, col color.RGBA) { - _, fl := drawCircleLines.Call(centerX, centerY, radius, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawCircleLinesV - Draw circle outline (Vector version) -func DrawCircleLinesV(center Vector2, radius float32, col color.RGBA) { - _, fl := drawCircleLinesV.Call(wasm.Struct(center), radius, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawEllipse - Draw ellipse -func DrawEllipse(centerX int32, centerY int32, radiusH float32, radiusV float32, col color.RGBA) { - _, fl := drawEllipse.Call(centerX, centerY, radiusH, radiusV, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawEllipseLines - Draw ellipse outline -func DrawEllipseLines(centerX int32, centerY int32, radiusH float32, radiusV float32, col color.RGBA) { - _, fl := drawEllipseLines.Call(centerX, centerY, radiusH, radiusV, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawRing - Draw ring -func DrawRing(center Vector2, innerRadius float32, outerRadius float32, startAngle float32, endAngle float32, segments int32, col color.RGBA) { - _, fl := drawRing.Call(wasm.Struct(center), innerRadius, outerRadius, startAngle, endAngle, segments, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawRingLines - Draw ring outline -func DrawRingLines(center Vector2, innerRadius float32, outerRadius float32, startAngle float32, endAngle float32, segments int32, col color.RGBA) { - _, fl := drawRingLines.Call(wasm.Struct(center), innerRadius, outerRadius, startAngle, endAngle, segments, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawRectangle - Draw a color-filled rectangle -func DrawRectangle(posX int32, posY int32, width int32, height int32, col color.RGBA) { - _, fl := drawRectangle.Call(posX, posY, width, height, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawRectangleV - Draw a color-filled rectangle (Vector version) -func DrawRectangleV(position Vector2, size Vector2, col color.RGBA) { - _, fl := drawRectangleV.Call(wasm.Struct(position), wasm.Struct(size), wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawRectangleRec - Draw a color-filled rectangle -func DrawRectangleRec(rec Rectangle, col color.RGBA) { - _, fl := drawRectangleRec.Call(wasm.Struct(rec), wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawRectanglePro - Draw a color-filled rectangle with pro parameters -func DrawRectanglePro(rec Rectangle, origin Vector2, rotation float32, col color.RGBA) { - _, fl := drawRectanglePro.Call(wasm.Struct(rec), wasm.Struct(origin), rotation, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawRectangleGradientV - Draw a vertical-gradient-filled rectangle -func DrawRectangleGradientV(posX int32, posY int32, width int32, height int32, top color.RGBA, bottom color.RGBA) { - _, fl := drawRectangleGradientV.Call(posX, posY, width, height, wasm.Struct(top), wasm.Struct(bottom)) - wasm.Free(fl...) -} - -// DrawRectangleGradientH - Draw a horizontal-gradient-filled rectangle -func DrawRectangleGradientH(posX int32, posY int32, width int32, height int32, left color.RGBA, right color.RGBA) { - _, fl := drawRectangleGradientH.Call(posX, posY, width, height, wasm.Struct(left), wasm.Struct(right)) - wasm.Free(fl...) -} - -// DrawRectangleGradientEx - Draw a gradient-filled rectangle with custom vertex colors -func DrawRectangleGradientEx(rec Rectangle, topLeft color.RGBA, bottomLeft color.RGBA, topRight color.RGBA, bottomRight color.RGBA) { - _, fl := drawRectangleGradientEx.Call(wasm.Struct(rec), wasm.Struct(topLeft), wasm.Struct(bottomLeft), wasm.Struct(topRight), wasm.Struct(bottomRight)) - wasm.Free(fl...) -} - -// DrawRectangleLines - Draw rectangle outline -func DrawRectangleLines(posX int32, posY int32, width int32, height int32, col color.RGBA) { - _, fl := drawRectangleLines.Call(posX, posY, width, height, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawRectangleLinesEx - Draw rectangle outline with extended parameters -func DrawRectangleLinesEx(rec Rectangle, lineThick float32, col color.RGBA) { - _, fl := drawRectangleLinesEx.Call(wasm.Struct(rec), lineThick, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawRectangleRounded - Draw rectangle with rounded edges -func DrawRectangleRounded(rec Rectangle, roundness float32, segments int32, col color.RGBA) { - _, fl := drawRectangleRounded.Call(wasm.Struct(rec), roundness, segments, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawRectangleRoundedLines - Draw rectangle lines with rounded edges -func DrawRectangleRoundedLines(rec Rectangle, roundness float32, segments int32, col color.RGBA) { - _, fl := drawRectangleRoundedLines.Call(wasm.Struct(rec), roundness, segments, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawRectangleRoundedLinesEx - Draw rectangle with rounded edges outline -func DrawRectangleRoundedLinesEx(rec Rectangle, roundness float32, segments int32, lineThick float32, col color.RGBA) { - _, fl := drawRectangleRoundedLinesEx.Call(wasm.Struct(rec), roundness, segments, lineThick, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawTriangle - Draw a color-filled triangle (vertex in counter-clockwise order!) -func DrawTriangle(v1 Vector2, v2 Vector2, v3 Vector2, col color.RGBA) { - _, fl := drawTriangle.Call(wasm.Struct(v1), wasm.Struct(v2), wasm.Struct(v3), wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawTriangleLines - Draw triangle outline (vertex in counter-clockwise order!) -func DrawTriangleLines(v1 Vector2, v2 Vector2, v3 Vector2, col color.RGBA) { - _, fl := drawTriangleLines.Call(wasm.Struct(v1), wasm.Struct(v2), wasm.Struct(v3), wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawTriangleFan - Draw a triangle fan defined by points (first vertex is the center) -func DrawTriangleFan(points []Vector2, col color.RGBA) { - _, fl := drawTriangleFan.Call(points, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawTriangleStrip - Draw a triangle strip defined by points -func DrawTriangleStrip(points []Vector2, col color.RGBA) { - _, fl := drawTriangleStrip.Call(points, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawPoly - Draw a regular polygon (Vector version) -func DrawPoly(center Vector2, sides int32, radius float32, rotation float32, col color.RGBA) { - _, fl := drawPoly.Call(wasm.Struct(center), sides, radius, rotation, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawPolyLines - Draw a polygon outline of n sides -func DrawPolyLines(center Vector2, sides int32, radius float32, rotation float32, col color.RGBA) { - _, fl := drawPolyLines.Call(wasm.Struct(center), sides, radius, rotation, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawPolyLinesEx - Draw a polygon outline of n sides with extended parameters -func DrawPolyLinesEx(center Vector2, sides int32, radius float32, rotation float32, lineThick float32, col color.RGBA) { - _, fl := drawPolyLinesEx.Call(wasm.Struct(center), sides, radius, rotation, lineThick, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawSplineLinear - Draw spline: Linear, minimum 2 points -func DrawSplineLinear(points []Vector2, thick float32, col color.RGBA) { - _, fl := drawSplineLinear.Call(points, thick, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawSplineBasis - Draw spline: B-Spline, minimum 4 points -func DrawSplineBasis(points []Vector2, thick float32, col color.RGBA) { - _, fl := drawSplineBasis.Call(points, thick, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawSplineCatmullRom - Draw spline: Catmull-Rom, minimum 4 points -func DrawSplineCatmullRom(points []Vector2, thick float32, col color.RGBA) { - _, fl := drawSplineCatmullRom.Call(points, thick, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawSplineBezierQuadratic - Draw spline: Quadratic Bezier, minimum 3 points (1 control point): [p1, c2, p3, c4...] -func DrawSplineBezierQuadratic(points []Vector2, thick float32, col color.RGBA) { - _, fl := drawSplineBezierQuadratic.Call(points, thick, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawSplineBezierCubic - Draw spline: Cubic Bezier, minimum 4 points (2 control points): [p1, c2, c3, p4, c5, c6...] -func DrawSplineBezierCubic(points []Vector2, thick float32, col color.RGBA) { - _, fl := drawSplineBezierCubic.Call(points, thick, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawSplineSegmentLinear - Draw spline segment: Linear, 2 points -func DrawSplineSegmentLinear(p1 Vector2, p2 Vector2, thick float32, col color.RGBA) { - _, fl := drawSplineSegmentLinear.Call(wasm.Struct(p1), wasm.Struct(p2), thick, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawSplineSegmentBasis - Draw spline segment: B-Spline, 4 points -func DrawSplineSegmentBasis(p1 Vector2, p2 Vector2, p3 Vector2, p4 Vector2, thick float32, col color.RGBA) { - _, fl := drawSplineSegmentBasis.Call(wasm.Struct(p1), wasm.Struct(p2), wasm.Struct(p3), wasm.Struct(p4), thick, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawSplineSegmentCatmullRom - Draw spline segment: Catmull-Rom, 4 points -func DrawSplineSegmentCatmullRom(p1 Vector2, p2 Vector2, p3 Vector2, p4 Vector2, thick float32, col color.RGBA) { - _, fl := drawSplineSegmentCatmullRom.Call(wasm.Struct(p1), wasm.Struct(p2), wasm.Struct(p3), wasm.Struct(p4), thick, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawSplineSegmentBezierQuadratic - Draw spline segment: Quadratic Bezier, 2 points, 1 control point -func DrawSplineSegmentBezierQuadratic(p1 Vector2, c2 Vector2, p3 Vector2, thick float32, col color.RGBA) { - _, fl := drawSplineSegmentBezierQuadratic.Call(wasm.Struct(p1), wasm.Struct(c2), wasm.Struct(p3), thick, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawSplineSegmentBezierCubic - Draw spline segment: Cubic Bezier, 2 points, 2 control points -func DrawSplineSegmentBezierCubic(p1 Vector2, c2 Vector2, c3 Vector2, p4 Vector2, thick float32, col color.RGBA) { - _, fl := drawSplineSegmentBezierCubic.Call(wasm.Struct(p1), wasm.Struct(c2), wasm.Struct(c3), wasm.Struct(p4), thick, wasm.Struct(col)) - wasm.Free(fl...) -} - -// GetSplinePointLinear - Get (evaluate) spline point: Linear -func GetSplinePointLinear(startPos Vector2, endPos Vector2, t float32) Vector2 { - ret, fl := getSplinePointLinear.Call(wasm.Struct(startPos), wasm.Struct(endPos), t) - v := wasm.ReadStruct[Vector2](ret) - wasm.Free(fl...) - return v -} - -// GetSplinePointBasis - Get (evaluate) spline point: B-Spline -func GetSplinePointBasis(p1 Vector2, p2 Vector2, p3 Vector2, p4 Vector2, t float32) Vector2 { - ret, fl := getSplinePointBasis.Call(wasm.Struct(p1), wasm.Struct(p2), wasm.Struct(p3), wasm.Struct(p4), t) - v := wasm.ReadStruct[Vector2](ret) - wasm.Free(fl...) - return v -} - -// GetSplinePointCatmullRom - Get (evaluate) spline point: Catmull-Rom -func GetSplinePointCatmullRom(p1 Vector2, p2 Vector2, p3 Vector2, p4 Vector2, t float32) Vector2 { - ret, fl := getSplinePointCatmullRom.Call(wasm.Struct(p1), wasm.Struct(p2), wasm.Struct(p3), wasm.Struct(p4), t) - v := wasm.ReadStruct[Vector2](ret) - wasm.Free(fl...) - return v -} - -// GetSplinePointBezierQuad - Get (evaluate) spline point: Quadratic Bezier -func GetSplinePointBezierQuad(p1 Vector2, c2 Vector2, p3 Vector2, t float32) Vector2 { - ret, fl := getSplinePointBezierQuad.Call(wasm.Struct(p1), wasm.Struct(c2), wasm.Struct(p3), t) - v := wasm.ReadStruct[Vector2](ret) - wasm.Free(fl...) - return v -} - -// GetSplinePointBezierCubic - Get (evaluate) spline point: Cubic Bezier -func GetSplinePointBezierCubic(p1 Vector2, c2 Vector2, c3 Vector2, p4 Vector2, t float32) Vector2 { - ret, fl := getSplinePointBezierCubic.Call(wasm.Struct(p1), wasm.Struct(c2), wasm.Struct(c3), wasm.Struct(p4), t) - v := wasm.ReadStruct[Vector2](ret) - wasm.Free(fl...) - return v -} - -// CheckCollisionRecs - Check collision between two rectangles -func CheckCollisionRecs(rec1 Rectangle, rec2 Rectangle) bool { - ret, fl := checkCollisionRecs.Call(wasm.Struct(rec1), wasm.Struct(rec2)) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// CheckCollisionCircles - Check collision between two circles -func CheckCollisionCircles(center1 Vector2, radius1 float32, center2 Vector2, radius2 float32) bool { - ret, fl := checkCollisionCircles.Call(wasm.Struct(center1), radius1, wasm.Struct(center2), radius2) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// CheckCollisionCircleRec - Check collision between circle and rectangle -func CheckCollisionCircleRec(center Vector2, radius float32, rec Rectangle) bool { - ret, fl := checkCollisionCircleRec.Call(wasm.Struct(center), radius, wasm.Struct(rec)) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// CheckCollisionCircleLine - Check if circle collides with a line created betweeen two points [p1] and [p2] -func CheckCollisionCircleLine(center Vector2, radius float32, p1 Vector2, p2 Vector2) bool { - ret, fl := checkCollisionCircleLine.Call(wasm.Struct(center), radius, wasm.Struct(p1), wasm.Struct(p2)) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// CheckCollisionPointRec - Check if point is inside rectangle -func CheckCollisionPointRec(point Vector2, rec Rectangle) bool { - ret, fl := checkCollisionPointRec.Call(wasm.Struct(point), wasm.Struct(rec)) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// CheckCollisionPointCircle - Check if point is inside circle -func CheckCollisionPointCircle(point Vector2, center Vector2, radius float32) bool { - ret, fl := checkCollisionPointCircle.Call(wasm.Struct(point), wasm.Struct(center), radius) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// CheckCollisionPointTriangle - Check if point is inside a triangle -func CheckCollisionPointTriangle(point Vector2, p1 Vector2, p2 Vector2, p3 Vector2) bool { - ret, fl := checkCollisionPointTriangle.Call(wasm.Struct(point), wasm.Struct(p1), wasm.Struct(p2), wasm.Struct(p3)) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// CheckCollisionPointPoly - Check if point is within a polygon described by array of vertices -func CheckCollisionPointPoly(point Vector2, points []Vector2) bool { - ret, fl := checkCollisionPointPoly.Call(wasm.Struct(point), points) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// CheckCollisionLines - Check the collision between two lines defined by two points each, returns collision point by reference -func CheckCollisionLines(startPos1 Vector2, endPos1 Vector2, startPos2 Vector2, endPos2 Vector2, collisionPoint *Vector2) bool { - _collisionPoint := wasm.Struct(*collisionPoint) - ret, fl := checkCollisionLines.Call(wasm.Struct(startPos1), wasm.Struct(endPos1), wasm.Struct(startPos2), wasm.Struct(endPos2), _collisionPoint) - v := wasm.Boolean(ret) - *collisionPoint = wasm.BytesToStruct[Vector2](wasm.ReadFromWASM(_collisionPoint.Mem, _collisionPoint.Size)) - wasm.Free(fl...) - return v -} - -// CheckCollisionPointLine - Check if point belongs to line created between two points [p1] and [p2] with defined margin in pixels [threshold] -func CheckCollisionPointLine(point Vector2, p1 Vector2, p2 Vector2, threshold int32) bool { - ret, fl := checkCollisionPointLine.Call(wasm.Struct(point), wasm.Struct(p1), wasm.Struct(p2), threshold) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// GetCollisionRec - Get collision rectangle for two rectangles collision -func GetCollisionRec(rec1 Rectangle, rec2 Rectangle) Rectangle { - ret, fl := getCollisionRec.Call(wasm.Struct(rec1), wasm.Struct(rec2)) - v := wasm.ReadStruct[Rectangle](ret) - wasm.Free(fl...) - return v -} - -// LoadImage - Load image from file into CPU memory (RAM) -func LoadImage(fileName string) *Image { - var zero *Image - return zero -} - -// LoadImageRaw - Load image from RAW file data -func LoadImageRaw(fileName string, width int32, height int32, format PixelFormat, headerSize int32) *Image { - var zero *Image - return zero -} - -// LoadImageAnim - Load image sequence from file (frames appended to image.data) -func LoadImageAnim(fileName string, frames *int32) *Image { - var zero *Image - return zero -} - -// LoadImageAnimFromMemory - Load image sequence from memory buffer -func LoadImageAnimFromMemory(fileType string, fileData []byte, dataSize int32, frames *int32) *Image { - var zero *Image - return zero -} - -// LoadImageFromMemory - Load image from memory buffer, fileType refers to extension: i.e. '.png' -func LoadImageFromMemory(fileType string, fileData []byte, dataSize int32) *Image { - var zero *Image - return zero -} - -// LoadImageFromTexture - Load image from GPU texture data -func LoadImageFromTexture(texture Texture2D) *Image { - var zero *Image - return zero -} - -// LoadImageFromScreen - Load image from screen buffer and (screenshot) -func LoadImageFromScreen() *Image { - var zero *Image - return zero -} - -// IsImageValid - Check if an image is valid (data and parameters) -func IsImageValid(image *Image) bool { - ret, fl := isImageValid.Call(image) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// UnloadImage - Unload image from CPU memory (RAM) -func UnloadImage(image *Image) { - _, fl := unloadImage.Call(image) - wasm.Free(fl...) -} - -// ExportImage - Export image data to file, returns true on success -func ExportImage(image Image, fileName string) bool { - ret, fl := exportImage.Call(wasm.Struct(image), fileName) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// ExportImageToMemory - Export image to memory buffer -func ExportImageToMemory(image Image, fileType string) []byte { - var zero []byte - return zero -} - - -// GenImageGradientLinear - Generate image: linear gradient, direction in degrees [0..360], 0=Vertical gradient -func GenImageGradientLinear(width int, height int, direction int, start color.RGBA, end color.RGBA) *Image { - var zero *Image - return zero -} - -// GenImageGradientRadial - Generate image: radial gradient -func GenImageGradientRadial(width int, height int, density float32, inner color.RGBA, outer color.RGBA) *Image { - var zero *Image - return zero -} - -// GenImageGradientSquare - Generate image: square gradient -func GenImageGradientSquare(width int, height int, density float32, inner color.RGBA, outer color.RGBA) *Image { - var zero *Image - return zero -} - -// GenImageChecked - Generate image: checked -func GenImageChecked(width int, height int, checksX int, checksY int, col1 color.RGBA, col2 color.RGBA) *Image { - var zero *Image - return zero -} - -// GenImageWhiteNoise - Generate image: white noise -func GenImageWhiteNoise(width int, height int, factor float32) *Image { - var zero *Image - return zero -} - -// GenImagePerlinNoise - Generate image: perlin noise -func GenImagePerlinNoise(width int, height int, offsetX int32, offsetY int32, scale float32) *Image { - var zero *Image - return zero -} - -// GenImageCellular - Generate image: cellular algorithm, bigger tileSize means bigger cells -func GenImageCellular(width int, height int, tileSize int) *Image { - var zero *Image - return zero -} - -// GenImageText - Generate image: grayscale image from text data -func GenImageText(width int, height int, text string) Image { - ret, fl := genImageText.Call(width, height, text) - v := wasm.ReadStruct[Image](ret) - wasm.Free(fl...) + ret := getTouchPointCount() + v := (int32)(ret) return v } -// ImageCopy - Create an image duplicate (useful for transformations) -func ImageCopy(image *Image) *Image { - var zero *Image - return zero -} - -// ImageFromImage - Create an image from another image piece -func ImageFromImage(image Image, rec Rectangle) Image { - ret, fl := imageFromImage.Call(wasm.Struct(image), wasm.Struct(rec)) - v := wasm.ReadStruct[Image](ret) - wasm.Free(fl...) - return v -} - -// ImageFromChannel - Create an image from a selected channel of another image (GRAYSCALE) -func ImageFromChannel(image Image, selectedChannel int32) Image { - ret, fl := imageFromChannel.Call(wasm.Struct(image), selectedChannel) - v := wasm.ReadStruct[Image](ret) - wasm.Free(fl...) - return v -} - -// ImageText - Create an image from text (default font) -func ImageText(text string, fontSize int32, col color.RGBA) Image { - ret, fl := imageText.Call(text, fontSize, wasm.Struct(col)) - v := wasm.ReadStruct[Image](ret) - wasm.Free(fl...) - return v -} - -// ImageTextEx - Create an image from text (custom sprite font) -func ImageTextEx(font Font, text string, fontSize float32, spacing float32, tint color.RGBA) Image { - ret, fl := imageTextEx.Call(wasm.Struct(font), text, fontSize, spacing, wasm.Struct(tint)) - v := wasm.ReadStruct[Image](ret) - wasm.Free(fl...) - return v -} - -// ImageFormat - Convert image data to desired format -func ImageFormat(image *Image, newFormat PixelFormat) { - _, fl := imageFormat.Call(image, newFormat) - wasm.Free(fl...) -} - -// ImageToPOT - Convert image to POT (power-of-two) -func ImageToPOT(image *Image, fill color.RGBA) { - _, fl := imageToPOT.Call(image, wasm.Struct(fill)) - wasm.Free(fl...) -} - -// ImageCrop - Crop an image to a defined rectangle -func ImageCrop(image *Image, crop Rectangle) { - _, fl := imageCrop.Call(image, wasm.Struct(crop)) - wasm.Free(fl...) -} - -// ImageAlphaCrop - Crop image depending on alpha value -func ImageAlphaCrop(image *Image, threshold float32) { - _, fl := imageAlphaCrop.Call(image, threshold) - wasm.Free(fl...) -} - -// ImageAlphaClear - Clear alpha channel to desired color -func ImageAlphaClear(image *Image, col color.RGBA, threshold float32) { - _, fl := imageAlphaClear.Call(image, wasm.Struct(col), threshold) - wasm.Free(fl...) -} - -// ImageAlphaMask - Apply alpha mask to image -func ImageAlphaMask(image *Image, alphaMask *Image) { - _, fl := imageAlphaMask.Call(image, alphaMask) - wasm.Free(fl...) -} - -// ImageAlphaPremultiply - Premultiply alpha channel -func ImageAlphaPremultiply(image *Image) { - _, fl := imageAlphaPremultiply.Call(image) - wasm.Free(fl...) +// BeginVrStereoMode - Begin stereo rendering (requires VR simulator) +func BeginVrStereoMode(config VrStereoConfig) { + beginVrStereoMode(*(*vrStereoConfig)(&config)) } -// ImageBlurGaussian - Apply Gaussian blur using a box blur approximation -func ImageBlurGaussian(image *Image, blurSize int32) { - _, fl := imageBlurGaussian.Call(image, blurSize) - wasm.Free(fl...) +// EndVrStereoMode - End stereo rendering (requires VR simulator) +func EndVrStereoMode() { + endVrStereoMode() } -// ImageKernelConvolution - Apply custom square convolution kernel to image -func ImageKernelConvolution(image *Image, kernel []float32) { - _, fl := imageKernelConvolution.Call(image, kernel) - wasm.Free(fl...) +// LoadVrStereoConfig - Load VR stereo config for VR simulator device parameters +func LoadVrStereoConfig(device VrDeviceInfo) VrStereoConfig { + ret := loadVrStereoConfig(*(*vrDeviceInfo)(&device)) + return *(*VrStereoConfig)(&ret) } -// ImageResize - Resize image (Bicubic scaling algorithm) -func ImageResize(image *Image, newWidth int32, newHeight int32) { - _, fl := imageResize.Call(image, newWidth, newHeight) - wasm.Free(fl...) -} - -// ImageResizeNN - Resize image (Nearest-Neighbor scaling algorithm) -func ImageResizeNN(image *Image, newWidth int32, newHeight int32) { - _, fl := imageResizeNN.Call(image, newWidth, newHeight) - wasm.Free(fl...) -} - -// ImageResizeCanvas - Resize canvas and fill with color -func ImageResizeCanvas(image *Image, newWidth int32, newHeight int32, offsetX int32, offsetY int32, fill color.RGBA) { - _, fl := imageResizeCanvas.Call(image, newWidth, newHeight, offsetX, offsetY, wasm.Struct(fill)) - wasm.Free(fl...) -} - -// ImageMipmaps - Compute all mipmap levels for a provided image -func ImageMipmaps(image *Image) { - _, fl := imageMipmaps.Call(image) - wasm.Free(fl...) -} - -// ImageDither - Dither image data to 16bpp or lower (Floyd-Steinberg dithering) -func ImageDither(image *Image, rBpp int32, gBpp int32, bBpp int32, aBpp int32) { - _, fl := imageDither.Call(image, rBpp, gBpp, bBpp, aBpp) - wasm.Free(fl...) -} - -// ImageFlipVertical - Flip image vertically -func ImageFlipVertical(image *Image) { - _, fl := imageFlipVertical.Call(image) - wasm.Free(fl...) -} - -// ImageFlipHorizontal - Flip image horizontally -func ImageFlipHorizontal(image *Image) { - _, fl := imageFlipHorizontal.Call(image) - wasm.Free(fl...) -} - -// ImageRotate - Rotate image by input angle in degrees (-359 to 359) -func ImageRotate(image *Image, degrees int32) { - _, fl := imageRotate.Call(image, degrees) - wasm.Free(fl...) -} - -// ImageRotateCW - Rotate image clockwise 90deg -func ImageRotateCW(image *Image) { - _, fl := imageRotateCW.Call(image) - wasm.Free(fl...) -} - -// ImageRotateCCW - Rotate image counter-clockwise 90deg -func ImageRotateCCW(image *Image) { - _, fl := imageRotateCCW.Call(image) - wasm.Free(fl...) -} - -// ImageColorTint - Modify image color: tint -func ImageColorTint(image *Image, col color.RGBA) { - _, fl := imageColorTint.Call(image, wasm.Struct(col)) - wasm.Free(fl...) -} - -// ImageColorInvert - Modify image color: invert -func ImageColorInvert(image *Image) { - _, fl := imageColorInvert.Call(image) - wasm.Free(fl...) -} - -// ImageColorGrayscale - Modify image color: grayscale -func ImageColorGrayscale(image *Image) { - _, fl := imageColorGrayscale.Call(image) - wasm.Free(fl...) -} - -// ImageColorContrast - Modify image color: contrast (-100 to 100) -func ImageColorContrast(image *Image, contrast float32) { - _, fl := imageColorContrast.Call(image, contrast) - wasm.Free(fl...) -} - -// ImageColorBrightness - Modify image color: brightness (-255 to 255) -func ImageColorBrightness(image *Image, brightness int32) { - _, fl := imageColorBrightness.Call(image, brightness) - wasm.Free(fl...) -} - -// ImageColorReplace - Modify image color: replace color -func ImageColorReplace(image *Image, col color.RGBA, replace color.RGBA) { - _, fl := imageColorReplace.Call(image, wasm.Struct(col), wasm.Struct(replace)) - wasm.Free(fl...) -} - -// LoadImageColors - Load color data from image as a Color array (RGBA - 32bit) -// -// NOTE: Memory allocated should be freed using UnloadImageColors() -func LoadImageColors(image *Image) []color.RGBA { - var zero []color.RGBA - return zero -} - -// LoadImagePalette - Load colors palette from image as a Color array (RGBA - 32bit) -// -// NOTE: Memory allocated should be freed using UnloadImagePalette() -func LoadImagePalette(image Image, maxPaletteSize int32) []color.RGBA { - var zero []color.RGBA - return zero -} - -// UnloadImageColors - Unload color data loaded with LoadImageColors() -func UnloadImageColors(colors []color.RGBA) { - _, fl := unloadImageColors.Call(colors) - wasm.Free(fl...) -} - -// UnloadImagePalette - Unload colors palette loaded with LoadImagePalette() -func UnloadImagePalette(colors []color.RGBA) { - _, fl := unloadImagePalette.Call(colors) - wasm.Free(fl...) -} - -// GetImageAlphaBorder - Get image alpha border rectangle -func GetImageAlphaBorder(image Image, threshold float32) Rectangle { - ret, fl := getImageAlphaBorder.Call(wasm.Struct(image), threshold) - v := wasm.ReadStruct[Rectangle](ret) - wasm.Free(fl...) - return v -} - -// GetImageColor - Get image pixel color at (x, y) position -func GetImageColor(image Image, x int32, y int32) color.RGBA { - ret, fl := getImageColor.Call(wasm.Struct(image), x, y) - v := wasm.ReadStruct[color.RGBA](ret) - wasm.Free(fl...) - return v -} - -// ImageClearBackground - Clear image background with given color -func ImageClearBackground(dst *Image, col color.RGBA) { - _, fl := imageClearBackground.Call(dst, wasm.Struct(col)) - wasm.Free(fl...) -} - -// ImageDrawPixelV - Draw pixel within an image (Vector version) -func ImageDrawPixelV(dst *Image, position Vector2, col color.RGBA) { - _, fl := imageDrawPixelV.Call(dst, wasm.Struct(position), wasm.Struct(col)) - wasm.Free(fl...) -} - -// ImageDrawLine - Draw line within an image -func ImageDrawLine(dst *Image, startPosX int32, startPosY int32, endPosX int32, endPosY int32, col color.RGBA) { - _, fl := imageDrawLine.Call(dst, startPosX, startPosY, endPosX, endPosY, wasm.Struct(col)) - wasm.Free(fl...) -} - -// ImageDrawLineV - Draw line within an image (Vector version) -func ImageDrawLineV(dst *Image, start Vector2, end Vector2, col color.RGBA) { - _, fl := imageDrawLineV.Call(dst, wasm.Struct(start), wasm.Struct(end), wasm.Struct(col)) - wasm.Free(fl...) -} - -// ImageDrawLineEx - Draw a line defining thickness within an image -func ImageDrawLineEx(dst *Image, start Vector2, end Vector2, thick int32, col color.RGBA) { - _, fl := imageDrawLineEx.Call(dst, wasm.Struct(start), wasm.Struct(end), thick, wasm.Struct(col)) - wasm.Free(fl...) -} - -// ImageDrawCircle - Draw a filled circle within an image -func ImageDrawCircle(dst *Image, centerX int32, centerY int32, radius int32, col color.RGBA) { - _, fl := imageDrawCircle.Call(dst, centerX, centerY, radius, wasm.Struct(col)) - wasm.Free(fl...) -} - -// ImageDrawCircleV - Draw a filled circle within an image (Vector version) -func ImageDrawCircleV(dst *Image, center Vector2, radius int32, col color.RGBA) { - _, fl := imageDrawCircleV.Call(dst, wasm.Struct(center), radius, wasm.Struct(col)) - wasm.Free(fl...) -} - -// ImageDrawCircleLines - Draw circle outline within an image -func ImageDrawCircleLines(dst *Image, centerX int32, centerY int32, radius int32, col color.RGBA) { - _, fl := imageDrawCircleLines.Call(dst, centerX, centerY, radius, wasm.Struct(col)) - wasm.Free(fl...) -} - -// ImageDrawCircleLinesV - Draw circle outline within an image (Vector version) -func ImageDrawCircleLinesV(dst *Image, center Vector2, radius int32, col color.RGBA) { - _, fl := imageDrawCircleLinesV.Call(dst, wasm.Struct(center), radius, wasm.Struct(col)) - wasm.Free(fl...) -} - -// ImageDrawRectangle - Draw rectangle within an image -func ImageDrawRectangle(dst *Image, posX int32, posY int32, width int32, height int32, col color.RGBA) { - _, fl := imageDrawRectangle.Call(dst, posX, posY, width, height, wasm.Struct(col)) - wasm.Free(fl...) -} - -// ImageDrawRectangleV - Draw rectangle within an image (Vector version) -func ImageDrawRectangleV(dst *Image, position Vector2, size Vector2, col color.RGBA) { - _, fl := imageDrawRectangleV.Call(dst, wasm.Struct(position), wasm.Struct(size), wasm.Struct(col)) - wasm.Free(fl...) -} - -// ImageDrawRectangleRec - Draw rectangle within an image -func ImageDrawRectangleRec(dst *Image, rec Rectangle, col color.RGBA) { - _, fl := imageDrawRectangleRec.Call(dst, wasm.Struct(rec), wasm.Struct(col)) - wasm.Free(fl...) -} - -// ImageDrawRectangleLines - Draw rectangle lines within an image -func ImageDrawRectangleLines(dst *Image, rec Rectangle, thick int, col color.RGBA) { - _, fl := imageDrawRectangleLines.Call(dst, wasm.Struct(rec), thick, wasm.Struct(col)) - wasm.Free(fl...) -} - -// ImageDrawTriangle - Draw triangle within an image -func ImageDrawTriangle(dst *Image, v1 Vector2, v2 Vector2, v3 Vector2, col color.RGBA) { - _, fl := imageDrawTriangle.Call(dst, wasm.Struct(v1), wasm.Struct(v2), wasm.Struct(v3), wasm.Struct(col)) - wasm.Free(fl...) -} - -// ImageDrawTriangleEx - Draw triangle with interpolated colors within an image -func ImageDrawTriangleEx(dst *Image, v1 Vector2, v2 Vector2, v3 Vector2, c1 color.RGBA, c2 color.RGBA, c3 color.RGBA) { - _, fl := imageDrawTriangleEx.Call(dst, wasm.Struct(v1), wasm.Struct(v2), wasm.Struct(v3), wasm.Struct(c1), wasm.Struct(c2), wasm.Struct(c3)) - wasm.Free(fl...) -} - -// ImageDrawTriangleLines - Draw triangle outline within an image -func ImageDrawTriangleLines(dst *Image, v1 Vector2, v2 Vector2, v3 Vector2, col color.RGBA) { - _, fl := imageDrawTriangleLines.Call(dst, wasm.Struct(v1), wasm.Struct(v2), wasm.Struct(v3), wasm.Struct(col)) - wasm.Free(fl...) -} - -// ImageDrawTriangleFan - Draw a triangle fan defined by points within an image (first vertex is the center) -func ImageDrawTriangleFan(dst *Image, points []Vector2, col color.RGBA) { - _, fl := imageDrawTriangleFan.Call(dst, points, wasm.Struct(col)) - wasm.Free(fl...) -} - -// ImageDrawTriangleStrip - Draw a triangle strip defined by points within an image -func ImageDrawTriangleStrip(dst *Image, points []Vector2, col color.RGBA) { - _, fl := imageDrawTriangleStrip.Call(dst, points, wasm.Struct(col)) - wasm.Free(fl...) -} - -// ImageDraw - Draw a source image within a destination image (tint applied to source) -func ImageDraw(dst *Image, src *Image, srcRec Rectangle, dstRec Rectangle, tint color.RGBA) { - _, fl := imageDraw.Call(dst, src, wasm.Struct(srcRec), wasm.Struct(dstRec), wasm.Struct(tint)) - wasm.Free(fl...) -} - -// ImageDrawText - Draw text (using default font) within an image (destination) -func ImageDrawText(dst *Image, posX int32, posY int32, text string, fontSize int32, col color.RGBA) { - _, fl := imageDrawText.Call(dst, posX, posY, text, fontSize, wasm.Struct(col)) - wasm.Free(fl...) -} - -// ImageDrawTextEx - Draw text (custom sprite font) within an image (destination) -func ImageDrawTextEx(dst *Image, position Vector2, font Font, text string, fontSize float32, spacing float32, tint color.RGBA) { - _, fl := imageDrawTextEx.Call(dst, wasm.Struct(position), wasm.Struct(font), text, fontSize, spacing, wasm.Struct(tint)) - wasm.Free(fl...) -} - -// LoadTexture - Load texture from file into GPU memory (VRAM) -func LoadTexture(fileName string) Texture2D { - ret, fl := loadTexture.Call(fileName) - v := wasm.ReadStruct[Texture2D](ret) - wasm.Free(fl...) - return v -} - - -// LoadTextureCubemap - Load cubemap from image, multiple image cubemap layouts supported -func LoadTextureCubemap(image *Image, layout int32) Texture2D { - ret, fl := loadTextureCubemap.Call(image, layout) - v := wasm.ReadStruct[Texture2D](ret) - wasm.Free(fl...) - return v -} - -// LoadRenderTexture - Load texture for rendering (framebuffer) -func LoadRenderTexture(width int32, height int32) RenderTexture2D { - ret, fl := loadRenderTexture.Call(width, height) - v := wasm.ReadStruct[RenderTexture2D](ret) - wasm.Free(fl...) - return v -} - -// IsTextureValid - Check if a texture is valid (loaded in GPU) -func IsTextureValid(texture Texture2D) bool { - ret, fl := isTextureValid.Call(wasm.Struct(texture)) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// UnloadTexture - Unload texture from GPU memory (VRAM) -func UnloadTexture(texture Texture2D) { - _, fl := unloadTexture.Call(wasm.Struct(texture)) - wasm.Free(fl...) -} - -// IsRenderTextureValid - Check if a render texture is valid (loaded in GPU) -func IsRenderTextureValid(target RenderTexture2D) bool { - ret, fl := isRenderTextureValid.Call(wasm.Struct(target)) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// UnloadRenderTexture - Unload render texture from GPU memory (VRAM) -func UnloadRenderTexture(target RenderTexture2D) { - _, fl := unloadRenderTexture.Call(wasm.Struct(target)) - wasm.Free(fl...) -} - -// UpdateTexture - Update GPU texture with new data -func UpdateTexture(texture Texture2D, pixels []color.RGBA) { - _, fl := updateTexture.Call(wasm.Struct(texture), pixels) - wasm.Free(fl...) -} - -// UpdateTextureRec - Update GPU texture rectangle with new data -func UpdateTextureRec(texture Texture2D, rec Rectangle, pixels []color.RGBA) { - _, fl := updateTextureRec.Call(wasm.Struct(texture), wasm.Struct(rec), pixels) - wasm.Free(fl...) -} - -// GenTextureMipmaps - Generate GPU mipmaps for a texture -func GenTextureMipmaps(texture *Texture2D) { - _, fl := genTextureMipmaps.Call(texture) - wasm.Free(fl...) -} - -// SetTextureFilter - Set texture scaling filter mode -func SetTextureFilter(texture Texture2D, filter TextureFilterMode) { - _, fl := setTextureFilter.Call(wasm.Struct(texture), filter) - wasm.Free(fl...) -} - -// SetTextureWrap - Set texture wrapping mode -func SetTextureWrap(texture Texture2D, wrap TextureWrapMode) { - _, fl := setTextureWrap.Call(wasm.Struct(texture), wrap) - wasm.Free(fl...) -} - -// DrawTexture - Draw a Texture2D -func DrawTexture(texture Texture2D, posX int32, posY int32, tint color.RGBA) { - _, fl := drawTexture.Call(wasm.Struct(texture), posX, posY, wasm.Struct(tint)) - wasm.Free(fl...) -} - -// DrawTextureV - Draw a Texture2D with position defined as Vector2 -func DrawTextureV(texture Texture2D, position Vector2, tint color.RGBA) { - _, fl := drawTextureV.Call(wasm.Struct(texture), wasm.Struct(position), wasm.Struct(tint)) - wasm.Free(fl...) -} - -// DrawTextureEx - Draw a Texture2D with extended parameters -func DrawTextureEx(texture Texture2D, position Vector2, rotation float32, scale float32, tint color.RGBA) { - _, fl := drawTextureEx.Call(wasm.Struct(texture), wasm.Struct(position), rotation, scale, wasm.Struct(tint)) - wasm.Free(fl...) -} - -// DrawTextureRec - Draw a part of a texture defined by a rectangle -func DrawTextureRec(texture Texture2D, source Rectangle, position Vector2, tint color.RGBA) { - _, fl := drawTextureRec.Call(wasm.Struct(texture), wasm.Struct(source), wasm.Struct(position), wasm.Struct(tint)) - wasm.Free(fl...) -} - -// DrawTexturePro - Draw a part of a texture defined by a rectangle with 'pro' parameters -func DrawTexturePro(texture Texture2D, source Rectangle, dest Rectangle, origin Vector2, rotation float32, tint color.RGBA) { - _, fl := drawTexturePro.Call(wasm.Struct(texture), wasm.Struct(source), wasm.Struct(dest), wasm.Struct(origin), rotation, wasm.Struct(tint)) - wasm.Free(fl...) -} - -// DrawTextureNPatch - Draws a texture (or part of it) that stretches or shrinks nicely -func DrawTextureNPatch(texture Texture2D, nPatchInfo NPatchInfo, dest Rectangle, origin Vector2, rotation float32, tint color.RGBA) { - _, fl := drawTextureNPatch.Call(wasm.Struct(texture), wasm.Struct(nPatchInfo), wasm.Struct(dest), wasm.Struct(origin), rotation, wasm.Struct(tint)) - wasm.Free(fl...) -} - -// Fade - Get color with alpha applied, alpha goes from 0.0f to 1.0f -func Fade(col color.RGBA, alpha float32) color.RGBA { - ret, fl := fade.Call(wasm.Struct(col), alpha) - v := wasm.ReadStruct[color.RGBA](ret) - wasm.Free(fl...) - return v -} - -// ColorToInt - Get hexadecimal value for a Color (0xRRGGBBAA) -func ColorToInt(col color.RGBA) int32 { - ret, fl := colorToInt.Call(wasm.Struct(col)) - v := wasm.Numeric[int32](ret) - wasm.Free(fl...) - return v -} - -// ColorNormalize - Get Color normalized as float [0..1] -func ColorNormalize(col color.RGBA) Vector4 { - ret, fl := colorNormalize.Call(wasm.Struct(col)) - v := wasm.ReadStruct[Vector4](ret) - wasm.Free(fl...) - return v -} - -// ColorFromNormalized - Get Color from normalized values [0..1] -func ColorFromNormalized(normalized Vector4) color.RGBA { - ret, fl := colorFromNormalized.Call(wasm.Struct(normalized)) - v := wasm.ReadStruct[color.RGBA](ret) - wasm.Free(fl...) - return v -} - -// ColorToHSV - Get HSV values for a Color, hue [0..360], saturation/value [0..1] -func ColorToHSV(col color.RGBA) Vector3 { - ret, fl := colorToHSV.Call(wasm.Struct(col)) - v := wasm.ReadStruct[Vector3](ret) - wasm.Free(fl...) - return v -} - -// ColorFromHSV - Get a Color from HSV values, hue [0..360], saturation/value [0..1] -func ColorFromHSV(hue float32, saturation float32, value float32) color.RGBA { - ret, fl := colorFromHSV.Call(hue, saturation, value) - v := wasm.ReadStruct[color.RGBA](ret) - wasm.Free(fl...) - return v -} - -// ColorTint - Get color multiplied with another color -func ColorTint(col color.RGBA, tint color.RGBA) color.RGBA { - ret, fl := colorTint.Call(wasm.Struct(col), wasm.Struct(tint)) - v := wasm.ReadStruct[color.RGBA](ret) - wasm.Free(fl...) - return v -} - -// ColorBrightness - Get color with brightness correction, brightness factor goes from -1.0f to 1.0f -func ColorBrightness(col color.RGBA, factor float32) color.RGBA { - ret, fl := colorBrightness.Call(wasm.Struct(col), factor) - v := wasm.ReadStruct[color.RGBA](ret) - wasm.Free(fl...) - return v -} - -// ColorContrast - Get color with contrast correction, contrast values between -1.0f and 1.0f -func ColorContrast(col color.RGBA, contrast float32) color.RGBA { - ret, fl := colorContrast.Call(wasm.Struct(col), contrast) - v := wasm.ReadStruct[color.RGBA](ret) - wasm.Free(fl...) - return v -} - -// ColorAlpha - Get color with alpha applied, alpha goes from 0.0f to 1.0f -func ColorAlpha(col color.RGBA, alpha float32) color.RGBA { - ret, fl := colorAlpha.Call(wasm.Struct(col), alpha) - v := wasm.ReadStruct[color.RGBA](ret) - wasm.Free(fl...) - return v -} - -// ColorAlphaBlend - Get src alpha-blended into dst color with tint -func ColorAlphaBlend(dst color.RGBA, src color.RGBA, tint color.RGBA) color.RGBA { - ret, fl := colorAlphaBlend.Call(wasm.Struct(dst), wasm.Struct(src), wasm.Struct(tint)) - v := wasm.ReadStruct[color.RGBA](ret) - wasm.Free(fl...) - return v -} - -// ColorLerp - Get color lerp interpolation between two colors, factor [0.0f..1.0f] -func ColorLerp(col1 color.RGBA, col2 color.RGBA, factor float32) color.RGBA { - ret, fl := colorLerp.Call(wasm.Struct(col1), wasm.Struct(col2), factor) - v := wasm.ReadStruct[color.RGBA](ret) - wasm.Free(fl...) - return v -} - -// GetColor - Get Color structure from hexadecimal value -func GetColor(hexValue uint) color.RGBA { - ret, fl := getColor.Call(hexValue) - v := wasm.ReadStruct[color.RGBA](ret) - wasm.Free(fl...) - return v -} - -// GetPixelColor - Get Color from a source pixel pointer of certain format -func GetPixelColor(srcPtr unsafe.Pointer, format int32) color.RGBA { - ret, fl := getPixelColor.Call(srcPtr, format) - v := wasm.ReadStruct[color.RGBA](ret) - wasm.Free(fl...) - return v -} - -// SetPixelColor - Set color formatted into destination pixel pointer -func SetPixelColor(dstPtr unsafe.Pointer, col color.RGBA, format int32) { - _, fl := setPixelColor.Call(dstPtr, wasm.Struct(col), format) - wasm.Free(fl...) -} - -// GetPixelDataSize - Get pixel data size in bytes for certain format -func GetPixelDataSize(width int32, height int32, format int32) int32 { - ret, fl := getPixelDataSize.Call(width, height, format) - v := wasm.Numeric[int32](ret) - wasm.Free(fl...) - return v -} - -// GetFontDefault - Get the default Font -func GetFontDefault() Font { - ret, fl := getFontDefault.Call() - v := wasm.ReadStruct[Font](ret) - wasm.Free(fl...) - return v -} - -// LoadFont - Load font from file into GPU memory (VRAM) -func LoadFont(fileName string) Font { - ret, fl := loadFont.Call(fileName) - v := wasm.ReadStruct[Font](ret) - wasm.Free(fl...) - return v -} - -// LoadFontFromImage - Load font from Image (XNA style) -func LoadFontFromImage(image Image, key color.RGBA, firstChar rune) Font { - ret, fl := loadFontFromImage.Call(wasm.Struct(image), wasm.Struct(key), firstChar) - v := wasm.ReadStruct[Font](ret) - wasm.Free(fl...) - return v -} - -// LoadFontFromMemory - Load font from memory buffer, fileType refers to extension: i.e. '.ttf' -func LoadFontFromMemory(fileType string, fileData []byte, fontSize int32, codepoints []rune) Font { - ret, fl := loadFontFromMemory.Call(fileType, fileData, fontSize, codepoints) - v := wasm.ReadStruct[Font](ret) - wasm.Free(fl...) - return v -} - -// IsFontValid - Check if a font is valid (font data loaded, WARNING: GPU texture not checked) -func IsFontValid(font Font) bool { - ret, fl := isFontValid.Call(wasm.Struct(font)) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// LoadFontData - Load font data for further use -func LoadFontData(fileData []byte, fontSize int32, codepoints []rune, codepointCount int32, typ int32) []GlyphInfo { - var zero []GlyphInfo - return zero -} - -// GenImageFontAtlas - Generate image font atlas using chars info -func GenImageFontAtlas(glyphs []GlyphInfo, glyphRecs []*Rectangle, fontSize int32, padding int32, packMethod int32) Image { - ret, fl := genImageFontAtlas.Call(glyphs, glyphRecs, fontSize, padding, packMethod) - v := wasm.ReadStruct[Image](ret) - wasm.Free(fl...) - return v -} - -// UnloadFontData - Unload font chars info data (RAM) -func UnloadFontData(glyphs []GlyphInfo) { - _, fl := unloadFontData.Call(glyphs) - wasm.Free(fl...) -} - -// UnloadFont - Unload font from GPU memory (VRAM) -func UnloadFont(font Font) { - _, fl := unloadFont.Call(wasm.Struct(font)) - wasm.Free(fl...) -} - -// DrawFPS - Draw current FPS -func DrawFPS(posX int32, posY int32) { - _, fl := drawFPS.Call(posX, posY) - wasm.Free(fl...) -} - -// DrawText - Draw text (using default font) -func DrawText(text string, posX int32, posY int32, fontSize int32, col color.RGBA) { - _, fl := drawText.Call(text, posX, posY, fontSize, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawTextEx - Draw text using font and additional parameters -func DrawTextEx(font Font, text string, position Vector2, fontSize float32, spacing float32, tint color.RGBA) { - _, fl := drawTextEx.Call(wasm.Struct(font), text, wasm.Struct(position), fontSize, spacing, wasm.Struct(tint)) - wasm.Free(fl...) -} - -// DrawTextPro - Draw text using Font and pro parameters (rotation) -func DrawTextPro(font Font, text string, position Vector2, origin Vector2, rotation float32, fontSize float32, spacing float32, tint color.RGBA) { - _, fl := drawTextPro.Call(wasm.Struct(font), text, wasm.Struct(position), wasm.Struct(origin), rotation, fontSize, spacing, wasm.Struct(tint)) - wasm.Free(fl...) -} - -// DrawTextCodepoint - Draw one character (codepoint) -func DrawTextCodepoint(font Font, codepoint rune, position Vector2, fontSize float32, tint color.RGBA) { - _, fl := drawTextCodepoint.Call(wasm.Struct(font), codepoint, wasm.Struct(position), fontSize, wasm.Struct(tint)) - wasm.Free(fl...) -} - -// DrawTextCodepoints - Draw multiple character (codepoint) -func DrawTextCodepoints(font Font, codepoints []rune, position Vector2, fontSize float32, spacing float32, tint color.RGBA) { - _, fl := drawTextCodepoints.Call(wasm.Struct(font), codepoints, wasm.Struct(position), fontSize, spacing, wasm.Struct(tint)) - wasm.Free(fl...) -} - -// SetTextLineSpacing - Set vertical line spacing when drawing with line-breaks -func SetTextLineSpacing(spacing int) { - _, fl := setTextLineSpacing.Call(spacing) - wasm.Free(fl...) -} - -// MeasureText - Measure string width for default font -func MeasureText(text string, fontSize int32) int32 { - ret, fl := measureText.Call(text, fontSize) - v := wasm.Numeric[int32](ret) - wasm.Free(fl...) - return v -} - -// MeasureTextEx - Measure string size for Font -func MeasureTextEx(font Font, text string, fontSize float32, spacing float32) Vector2 { - ret, fl := measureTextEx.Call(wasm.Struct(font), text, fontSize, spacing) - v := wasm.ReadStruct[Vector2](ret) - wasm.Free(fl...) - return v -} - -// GetGlyphIndex - Get glyph index position in font for a codepoint (unicode character), fallback to '?' if not found -func GetGlyphIndex(font Font, codepoint rune) int32 { - ret, fl := getGlyphIndex.Call(wasm.Struct(font), codepoint) - v := wasm.Numeric[int32](ret) - wasm.Free(fl...) - return v -} - -// GetGlyphInfo - Get glyph font info data for a codepoint (unicode character), fallback to '?' if not found -func GetGlyphInfo(font Font, codepoint rune) GlyphInfo { - ret, fl := getGlyphInfo.Call(wasm.Struct(font), codepoint) - v := wasm.ReadStruct[GlyphInfo](ret) - wasm.Free(fl...) - return v -} - -// GetGlyphAtlasRec - Get glyph rectangle in font atlas for a codepoint (unicode character), fallback to '?' if not found -func GetGlyphAtlasRec(font Font, codepoint rune) Rectangle { - ret, fl := getGlyphAtlasRec.Call(wasm.Struct(font), codepoint) - v := wasm.ReadStruct[Rectangle](ret) - wasm.Free(fl...) - return v -} - -// DrawLine3D - Draw a line in 3D world space -func DrawLine3D(startPos Vector3, endPos Vector3, col color.RGBA) { - _, fl := drawLine3D.Call(wasm.Struct(startPos), wasm.Struct(endPos), wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawPoint3D - Draw a point in 3D space, actually a small line -func DrawPoint3D(position Vector3, col color.RGBA) { - _, fl := drawPoint3D.Call(wasm.Struct(position), wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawCircle3D - Draw a circle in 3D world space -func DrawCircle3D(center Vector3, radius float32, rotationAxis Vector3, rotationAngle float32, col color.RGBA) { - _, fl := drawCircle3D.Call(wasm.Struct(center), radius, wasm.Struct(rotationAxis), rotationAngle, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawTriangle3D - Draw a color-filled triangle (vertex in counter-clockwise order!) -func DrawTriangle3D(v1 Vector3, v2 Vector3, v3 Vector3, col color.RGBA) { - _, fl := drawTriangle3D.Call(wasm.Struct(v1), wasm.Struct(v2), wasm.Struct(v3), wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawTriangleStrip3D - Draw a triangle strip defined by points -func DrawTriangleStrip3D(points []Vector3, col color.RGBA) { - _, fl := drawTriangleStrip3D.Call(points, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawCube - Draw cube -func DrawCube(position Vector3, width float32, height float32, length float32, col color.RGBA) { - _, fl := drawCube.Call(wasm.Struct(position), width, height, length, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawCubeV - Draw cube (Vector version) -func DrawCubeV(position Vector3, size Vector3, col color.RGBA) { - _, fl := drawCubeV.Call(wasm.Struct(position), wasm.Struct(size), wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawCubeWires - Draw cube wires -func DrawCubeWires(position Vector3, width float32, height float32, length float32, col color.RGBA) { - _, fl := drawCubeWires.Call(wasm.Struct(position), width, height, length, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawCubeWiresV - Draw cube wires (Vector version) -func DrawCubeWiresV(position Vector3, size Vector3, col color.RGBA) { - _, fl := drawCubeWiresV.Call(wasm.Struct(position), wasm.Struct(size), wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawSphere - Draw sphere -func DrawSphere(centerPos Vector3, radius float32, col color.RGBA) { - _, fl := drawSphere.Call(wasm.Struct(centerPos), radius, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawSphereEx - Draw sphere with extended parameters -func DrawSphereEx(centerPos Vector3, radius float32, rings int32, slices int32, col color.RGBA) { - _, fl := drawSphereEx.Call(wasm.Struct(centerPos), radius, rings, slices, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawSphereWires - Draw sphere wires -func DrawSphereWires(centerPos Vector3, radius float32, rings int32, slices int32, col color.RGBA) { - _, fl := drawSphereWires.Call(wasm.Struct(centerPos), radius, rings, slices, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawCylinder - Draw a cylinder/cone -func DrawCylinder(position Vector3, radiusTop float32, radiusBottom float32, height float32, slices int32, col color.RGBA) { - _, fl := drawCylinder.Call(wasm.Struct(position), radiusTop, radiusBottom, height, slices, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawCylinderEx - Draw a cylinder with base at startPos and top at endPos -func DrawCylinderEx(startPos Vector3, endPos Vector3, startRadius float32, endRadius float32, sides int32, col color.RGBA) { - _, fl := drawCylinderEx.Call(wasm.Struct(startPos), wasm.Struct(endPos), startRadius, endRadius, sides, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawCylinderWires - Draw a cylinder/cone wires -func DrawCylinderWires(position Vector3, radiusTop float32, radiusBottom float32, height float32, slices int32, col color.RGBA) { - _, fl := drawCylinderWires.Call(wasm.Struct(position), radiusTop, radiusBottom, height, slices, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawCylinderWiresEx - Draw a cylinder wires with base at startPos and top at endPos -func DrawCylinderWiresEx(startPos Vector3, endPos Vector3, startRadius float32, endRadius float32, sides int32, col color.RGBA) { - _, fl := drawCylinderWiresEx.Call(wasm.Struct(startPos), wasm.Struct(endPos), startRadius, endRadius, sides, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawCapsule - Draw a capsule with the center of its sphere caps at startPos and endPos -func DrawCapsule(startPos Vector3, endPos Vector3, radius float32, slices int32, rings int32, col color.RGBA) { - _, fl := drawCapsule.Call(wasm.Struct(startPos), wasm.Struct(endPos), radius, slices, rings, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawCapsuleWires - Draw capsule wireframe with the center of its sphere caps at startPos and endPos -func DrawCapsuleWires(startPos Vector3, endPos Vector3, radius float32, slices int32, rings int32, col color.RGBA) { - _, fl := drawCapsuleWires.Call(wasm.Struct(startPos), wasm.Struct(endPos), radius, slices, rings, wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawPlane - Draw a plane XZ -func DrawPlane(centerPos Vector3, size Vector2, col color.RGBA) { - _, fl := drawPlane.Call(wasm.Struct(centerPos), wasm.Struct(size), wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawRay - Draw a ray line -func DrawRay(ray Ray, col color.RGBA) { - _, fl := drawRay.Call(wasm.Struct(ray), wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawGrid - Draw a grid (centered at (0, 0, 0)) -func DrawGrid(slices int32, spacing float32) { - _, fl := drawGrid.Call(slices, spacing) - wasm.Free(fl...) -} - -// LoadModel - Load model from files (meshes and materials) -func LoadModel(fileName string) Model { - ret, fl := loadModel.Call(fileName) - v := wasm.ReadStruct[Model](ret) - wasm.Free(fl...) - return v -} - -// LoadModelFromMesh - Load model from generated mesh (default material) -func LoadModelFromMesh(mesh Mesh) Model { - ret, fl := loadModelFromMesh.Call(wasm.Struct(mesh)) - v := wasm.ReadStruct[Model](ret) - wasm.Free(fl...) - return v -} - -// IsModelValid - Check if a model is valid (loaded in GPU, VAO/VBOs) -func IsModelValid(model Model) bool { - ret, fl := isModelValid.Call(wasm.Struct(model)) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// UnloadModel - Unload model (including meshes) from memory (RAM and/or VRAM) -func UnloadModel(model Model) { - _, fl := unloadModel.Call(wasm.Struct(model)) - wasm.Free(fl...) -} - -// GetModelBoundingBox - Compute model bounding box limits (considers all meshes) -func GetModelBoundingBox(model Model) BoundingBox { - ret, fl := getModelBoundingBox.Call(wasm.Struct(model)) - v := wasm.ReadStruct[BoundingBox](ret) - wasm.Free(fl...) - return v -} - -// DrawModel - Draw a model (with texture if set) -func DrawModel(model Model, position Vector3, scale float32, tint color.RGBA) { - _, fl := drawModel.Call(wasm.Struct(model), wasm.Struct(position), scale, wasm.Struct(tint)) - wasm.Free(fl...) -} - -// DrawModelEx - Draw a model with extended parameters -func DrawModelEx(model Model, position Vector3, rotationAxis Vector3, rotationAngle float32, scale Vector3, tint color.RGBA) { - _, fl := drawModelEx.Call(wasm.Struct(model), wasm.Struct(position), wasm.Struct(rotationAxis), rotationAngle, wasm.Struct(scale), wasm.Struct(tint)) - wasm.Free(fl...) -} - -// DrawModelWires - Draw a model wires (with texture if set) -func DrawModelWires(model Model, position Vector3, scale float32, tint color.RGBA) { - _, fl := drawModelWires.Call(wasm.Struct(model), wasm.Struct(position), scale, wasm.Struct(tint)) - wasm.Free(fl...) -} - -// DrawModelWiresEx - Draw a model wires (with texture if set) with extended parameters -func DrawModelWiresEx(model Model, position Vector3, rotationAxis Vector3, rotationAngle float32, scale Vector3, tint color.RGBA) { - _, fl := drawModelWiresEx.Call(wasm.Struct(model), wasm.Struct(position), wasm.Struct(rotationAxis), rotationAngle, wasm.Struct(scale), wasm.Struct(tint)) - wasm.Free(fl...) -} - -// DrawModelPoints - Draw a model as points -func DrawModelPoints(model Model, position Vector3, scale float32, tint color.RGBA) { - _, fl := drawModelPoints.Call(wasm.Struct(model), wasm.Struct(position), scale, wasm.Struct(tint)) - wasm.Free(fl...) -} - -// DrawModelPointsEx - Draw a model as points with extended parameters -func DrawModelPointsEx(model Model, position Vector3, rotationAxis Vector3, rotationAngle float32, scale Vector3, tint color.RGBA) { - _, fl := drawModelPointsEx.Call(wasm.Struct(model), wasm.Struct(position), wasm.Struct(rotationAxis), rotationAngle, wasm.Struct(scale), wasm.Struct(tint)) - wasm.Free(fl...) -} - -// DrawBoundingBox - Draw bounding box (wires) -func DrawBoundingBox(box BoundingBox, col color.RGBA) { - _, fl := drawBoundingBox.Call(wasm.Struct(box), wasm.Struct(col)) - wasm.Free(fl...) -} - -// DrawBillboard - Draw a billboard texture -func DrawBillboard(camera Camera, texture Texture2D, position Vector3, scale float32, tint color.RGBA) { - _, fl := drawBillboard.Call(camera, wasm.Struct(texture), wasm.Struct(position), scale, wasm.Struct(tint)) - wasm.Free(fl...) -} - -// DrawBillboardRec - Draw a billboard texture defined by source -func DrawBillboardRec(camera Camera, texture Texture2D, source Rectangle, position Vector3, size Vector2, tint color.RGBA) { - _, fl := drawBillboardRec.Call(camera, wasm.Struct(texture), wasm.Struct(source), wasm.Struct(position), wasm.Struct(size), wasm.Struct(tint)) - wasm.Free(fl...) -} - -// DrawBillboardPro - Draw a billboard texture defined by source and rotation -func DrawBillboardPro(camera Camera, texture Texture2D, source Rectangle, position Vector3, up Vector3, size Vector2, origin Vector2, rotation float32, tint color.RGBA) { - _, fl := drawBillboardPro.Call(camera, wasm.Struct(texture), wasm.Struct(source), wasm.Struct(position), wasm.Struct(up), wasm.Struct(size), wasm.Struct(origin), rotation, wasm.Struct(tint)) - wasm.Free(fl...) -} - -// UploadMesh - Upload mesh vertex data in GPU and provide VAO/VBO ids -func UploadMesh(mesh *Mesh, dynamic bool) { - _, fl := uploadMesh.Call(mesh, dynamic) - wasm.Free(fl...) -} - -// UpdateMeshBuffer - Update mesh vertex data in GPU for a specific buffer index -func UpdateMeshBuffer(mesh Mesh, index int32, data []byte, offset int) { - _, fl := updateMeshBuffer.Call(wasm.Struct(mesh), index, data, offset) - wasm.Free(fl...) -} - -// UnloadMesh - Unload mesh data from CPU and GPU -func UnloadMesh(mesh *Mesh) { - _, fl := unloadMesh.Call(mesh) - wasm.Free(fl...) -} - -// DrawMesh - Draw a 3d mesh with material and transform -func DrawMesh(mesh Mesh, material Material, transform Matrix) { - _, fl := drawMesh.Call(wasm.Struct(mesh), wasm.Struct(material), wasm.Struct(transform)) - wasm.Free(fl...) -} - -// DrawMeshInstanced - Draw multiple mesh instances with material and different transforms -func DrawMeshInstanced(mesh Mesh, material Material, transforms []Matrix, instances int32) { - _, fl := drawMeshInstanced.Call(wasm.Struct(mesh), wasm.Struct(material), transforms, instances) - wasm.Free(fl...) -} - -// ExportMesh - Export mesh data to file, returns true on success -func ExportMesh(mesh Mesh, fileName string) bool { - ret, fl := exportMesh.Call(wasm.Struct(mesh), fileName) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// GetMeshBoundingBox - Compute mesh bounding box limits -func GetMeshBoundingBox(mesh Mesh) BoundingBox { - ret, fl := getMeshBoundingBox.Call(wasm.Struct(mesh)) - v := wasm.ReadStruct[BoundingBox](ret) - wasm.Free(fl...) - return v -} - -// GenMeshTangents - Compute mesh tangents -func GenMeshTangents(mesh *Mesh) { - _, fl := genMeshTangents.Call(mesh) - wasm.Free(fl...) -} - -// GenMeshPoly - Generate polygonal mesh -func GenMeshPoly(sides int, radius float32) Mesh { - ret, fl := genMeshPoly.Call(sides, radius) - v := wasm.ReadStruct[Mesh](ret) - wasm.Free(fl...) - return v -} - -// GenMeshPlane - Generate plane mesh (with subdivisions) -func GenMeshPlane(width float32, length float32, resX int, resZ int) Mesh { - ret, fl := genMeshPlane.Call(width, length, resX, resZ) - v := wasm.ReadStruct[Mesh](ret) - wasm.Free(fl...) - return v -} - -// GenMeshCube - Generate cuboid mesh -func GenMeshCube(width float32, height float32, length float32) Mesh { - ret, fl := genMeshCube.Call(width, height, length) - v := wasm.ReadStruct[Mesh](ret) - wasm.Free(fl...) - return v -} - -// GenMeshSphere - Generate sphere mesh (standard sphere) -func GenMeshSphere(radius float32, rings int, slices int) Mesh { - ret, fl := genMeshSphere.Call(radius, rings, slices) - v := wasm.ReadStruct[Mesh](ret) - wasm.Free(fl...) - return v -} - -// GenMeshHemiSphere - Generate half-sphere mesh (no bottom cap) -func GenMeshHemiSphere(radius float32, rings int, slices int) Mesh { - ret, fl := genMeshHemiSphere.Call(radius, rings, slices) - v := wasm.ReadStruct[Mesh](ret) - wasm.Free(fl...) - return v -} - -// GenMeshCylinder - Generate cylinder mesh -func GenMeshCylinder(radius float32, height float32, slices int) Mesh { - ret, fl := genMeshCylinder.Call(radius, height, slices) - v := wasm.ReadStruct[Mesh](ret) - wasm.Free(fl...) - return v -} - -// GenMeshCone - Generate cone/pyramid mesh -func GenMeshCone(radius float32, height float32, slices int) Mesh { - ret, fl := genMeshCone.Call(radius, height, slices) - v := wasm.ReadStruct[Mesh](ret) - wasm.Free(fl...) - return v -} - -// GenMeshTorus - Generate torus mesh -func GenMeshTorus(radius float32, size float32, radSeg int, sides int) Mesh { - ret, fl := genMeshTorus.Call(radius, size, radSeg, sides) - v := wasm.ReadStruct[Mesh](ret) - wasm.Free(fl...) - return v -} - -// GenMeshKnot - Generate trefoil knot mesh -func GenMeshKnot(radius float32, size float32, radSeg int, sides int) Mesh { - ret, fl := genMeshKnot.Call(radius, size, radSeg, sides) - v := wasm.ReadStruct[Mesh](ret) - wasm.Free(fl...) - return v -} - -// GenMeshHeightmap - Generate heightmap mesh from image data -func GenMeshHeightmap(heightmap Image, size Vector3) Mesh { - ret, fl := genMeshHeightmap.Call(wasm.Struct(heightmap), wasm.Struct(size)) - v := wasm.ReadStruct[Mesh](ret) - wasm.Free(fl...) - return v -} - -// GenMeshCubicmap - Generate cubes-based map mesh from image data -func GenMeshCubicmap(cubicmap Image, cubeSize Vector3) Mesh { - ret, fl := genMeshCubicmap.Call(wasm.Struct(cubicmap), wasm.Struct(cubeSize)) - v := wasm.ReadStruct[Mesh](ret) - wasm.Free(fl...) - return v -} - -// LoadMaterials - Load materials from model file -func LoadMaterials(fileName string) []Material { - var zero []Material - return zero -} - -// LoadMaterialDefault - Load default material (Supports: DIFFUSE, SPECULAR, NORMAL maps) -func LoadMaterialDefault() Material { - ret, fl := loadMaterialDefault.Call() - v := wasm.ReadStruct[Material](ret) - wasm.Free(fl...) - return v -} - -// IsMaterialValid - Check if a material is valid (shader assigned, map textures loaded in GPU) -func IsMaterialValid(material Material) bool { - ret, fl := isMaterialValid.Call(wasm.Struct(material)) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// UnloadMaterial - Unload material from GPU memory (VRAM) -func UnloadMaterial(material Material) { - _, fl := unloadMaterial.Call(wasm.Struct(material)) - wasm.Free(fl...) -} - -// SetMaterialTexture - Set texture for a material map type (MATERIAL_MAP_DIFFUSE, MATERIAL_MAP_SPECULAR...) -func SetMaterialTexture(material *Material, mapType int32, texture Texture2D) { - _, fl := setMaterialTexture.Call(material, mapType, wasm.Struct(texture)) - wasm.Free(fl...) -} - -// SetModelMeshMaterial - Set material for a mesh -func SetModelMeshMaterial(model *Model, meshId int32, materialId int32) { - _, fl := setModelMeshMaterial.Call(model, meshId, materialId) - wasm.Free(fl...) -} - -// LoadModelAnimations - Load model animations from file -func LoadModelAnimations(fileName string) []ModelAnimation { - var zero []ModelAnimation - return zero -} - -// UpdateModelAnimation - Update model animation pose (CPU) -func UpdateModelAnimation(model Model, anim ModelAnimation, frame int32) { - _, fl := updateModelAnimation.Call(wasm.Struct(model), wasm.Struct(anim), frame) - wasm.Free(fl...) -} - -// UpdateModelAnimationBones - Update model animation mesh bone matrices (GPU skinning) -func UpdateModelAnimationBones(model Model, anim ModelAnimation, frame int32) { - _, fl := updateModelAnimationBones.Call(wasm.Struct(model), wasm.Struct(anim), frame) - wasm.Free(fl...) -} - -// UnloadModelAnimation - Unload animation data -func UnloadModelAnimation(anim ModelAnimation) { - _, fl := unloadModelAnimation.Call(wasm.Struct(anim)) - wasm.Free(fl...) -} - -// UnloadModelAnimations - Unload animation array data -func UnloadModelAnimations(animations []ModelAnimation) { - _, fl := unloadModelAnimations.Call(animations) - wasm.Free(fl...) -} - -// IsModelAnimationValid - Check model animation skeleton match -func IsModelAnimationValid(model Model, anim ModelAnimation) bool { - ret, fl := isModelAnimationValid.Call(wasm.Struct(model), wasm.Struct(anim)) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// CheckCollisionSpheres - Check collision between two spheres -func CheckCollisionSpheres(center1 Vector3, radius1 float32, center2 Vector3, radius2 float32) bool { - ret, fl := checkCollisionSpheres.Call(wasm.Struct(center1), radius1, wasm.Struct(center2), radius2) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// CheckCollisionBoxes - Check collision between two bounding boxes -func CheckCollisionBoxes(box1 BoundingBox, box2 BoundingBox) bool { - ret, fl := checkCollisionBoxes.Call(wasm.Struct(box1), wasm.Struct(box2)) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// CheckCollisionBoxSphere - Check collision between box and sphere -func CheckCollisionBoxSphere(box BoundingBox, center Vector3, radius float32) bool { - ret, fl := checkCollisionBoxSphere.Call(wasm.Struct(box), wasm.Struct(center), radius) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// GetRayCollisionSphere - Get collision info between ray and sphere -func GetRayCollisionSphere(ray Ray, center Vector3, radius float32) RayCollision { - ret, fl := getRayCollisionSphere.Call(wasm.Struct(ray), wasm.Struct(center), radius) - v := wasm.ReadStruct[RayCollision](ret) - wasm.Free(fl...) - return v -} - -// GetRayCollisionBox - Get collision info between ray and box -func GetRayCollisionBox(ray Ray, box BoundingBox) RayCollision { - ret, fl := getRayCollisionBox.Call(wasm.Struct(ray), wasm.Struct(box)) - v := wasm.ReadStruct[RayCollision](ret) - wasm.Free(fl...) - return v -} - -// GetRayCollisionMesh - Get collision info between ray and mesh -func GetRayCollisionMesh(ray Ray, mesh Mesh, transform Matrix) RayCollision { - ret, fl := getRayCollisionMesh.Call(wasm.Struct(ray), wasm.Struct(mesh), wasm.Struct(transform)) - v := wasm.ReadStruct[RayCollision](ret) - wasm.Free(fl...) - return v -} - -// GetRayCollisionTriangle - Get collision info between ray and triangle -func GetRayCollisionTriangle(ray Ray, p1 Vector3, p2 Vector3, p3 Vector3) RayCollision { - ret, fl := getRayCollisionTriangle.Call(wasm.Struct(ray), wasm.Struct(p1), wasm.Struct(p2), wasm.Struct(p3)) - v := wasm.ReadStruct[RayCollision](ret) - wasm.Free(fl...) - return v -} - -// GetRayCollisionQuad - Get collision info between ray and quad -func GetRayCollisionQuad(ray Ray, p1 Vector3, p2 Vector3, p3 Vector3, p4 Vector3) RayCollision { - ret, fl := getRayCollisionQuad.Call(wasm.Struct(ray), wasm.Struct(p1), wasm.Struct(p2), wasm.Struct(p3), wasm.Struct(p4)) - v := wasm.ReadStruct[RayCollision](ret) - wasm.Free(fl...) - return v -} - -// InitAudioDevice - Initialize audio device and context -func InitAudioDevice() { - _, fl := initAudioDevice.Call() - wasm.Free(fl...) -} - -// CloseAudioDevice - Close the audio device and context -func CloseAudioDevice() { - _, fl := closeAudioDevice.Call() - wasm.Free(fl...) -} - -// IsAudioDeviceReady - Check if audio device has been initialized successfully -func IsAudioDeviceReady() bool { - ret, fl := isAudioDeviceReady.Call() - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// SetMasterVolume - Set master volume (listener) -func SetMasterVolume(volume float32) { - _, fl := setMasterVolume.Call(volume) - wasm.Free(fl...) -} - -// GetMasterVolume - Get master volume (listener) -func GetMasterVolume() float32 { - ret, fl := getMasterVolume.Call() - v := wasm.Numeric[float32](ret) - wasm.Free(fl...) - return v -} - -// LoadWave - Load wave data from file -func LoadWave(fileName string) Wave { - ret, fl := loadWave.Call(fileName) - v := wasm.ReadStruct[Wave](ret) - wasm.Free(fl...) - return v -} - -// LoadWaveFromMemory - Load wave from memory buffer, fileType refers to extension: i.e. '.wav' -func LoadWaveFromMemory(fileType string, fileData []byte, dataSize int32) Wave { - ret, fl := loadWaveFromMemory.Call(fileType, fileData, dataSize) - v := wasm.ReadStruct[Wave](ret) - wasm.Free(fl...) - return v -} - -// IsWaveValid - Checks if wave data is valid (data loaded and parameters) -func IsWaveValid(wave Wave) bool { - ret, fl := isWaveValid.Call(wasm.Struct(wave)) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// LoadSound - Load sound from file -func LoadSound(fileName string) Sound { - ret, fl := loadSound.Call(fileName) - v := wasm.ReadStruct[Sound](ret) - wasm.Free(fl...) - return v -} - -// LoadSoundFromWave - Load sound from wave data -func LoadSoundFromWave(wave Wave) Sound { - ret, fl := loadSoundFromWave.Call(wasm.Struct(wave)) - v := wasm.ReadStruct[Sound](ret) - wasm.Free(fl...) - return v -} - -// LoadSoundAlias - Create a new sound that shares the same sample data as the source sound, does not own the sound data -func LoadSoundAlias(source Sound) Sound { - ret, fl := loadSoundAlias.Call(wasm.Struct(source)) - v := wasm.ReadStruct[Sound](ret) - wasm.Free(fl...) - return v -} - -// IsSoundValid - Checks if a sound is valid (data loaded and buffers initialized) -func IsSoundValid(sound Sound) bool { - ret, fl := isSoundValid.Call(wasm.Struct(sound)) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// UpdateSound - Update sound buffer with new data -func UpdateSound(sound Sound, data []byte, sampleCount int32) { - _, fl := updateSound.Call(wasm.Struct(sound), data, sampleCount) - wasm.Free(fl...) -} - -// UnloadWave - Unload wave data -func UnloadWave(wave Wave) { - _, fl := unloadWave.Call(wasm.Struct(wave)) - wasm.Free(fl...) -} - -// UnloadSound - Unload sound -func UnloadSound(sound Sound) { - _, fl := unloadSound.Call(wasm.Struct(sound)) - wasm.Free(fl...) -} - -// UnloadSoundAlias - Unload a sound alias (does not deallocate sample data) -func UnloadSoundAlias(alias Sound) { - _, fl := unloadSoundAlias.Call(wasm.Struct(alias)) - wasm.Free(fl...) -} - -// ExportWave - Export wave data to file, returns true on success -func ExportWave(wave Wave, fileName string) bool { - ret, fl := exportWave.Call(wasm.Struct(wave), fileName) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// PlaySound - Play a sound -func PlaySound(sound Sound) { - _, fl := playSound.Call(wasm.Struct(sound)) - wasm.Free(fl...) -} - -// StopSound - Stop playing a sound -func StopSound(sound Sound) { - _, fl := stopSound.Call(wasm.Struct(sound)) - wasm.Free(fl...) -} - -// PauseSound - Pause a sound -func PauseSound(sound Sound) { - _, fl := pauseSound.Call(wasm.Struct(sound)) - wasm.Free(fl...) -} - -// ResumeSound - Resume a paused sound -func ResumeSound(sound Sound) { - _, fl := resumeSound.Call(wasm.Struct(sound)) - wasm.Free(fl...) -} - -// IsSoundPlaying - Check if a sound is currently playing -func IsSoundPlaying(sound Sound) bool { - ret, fl := isSoundPlaying.Call(wasm.Struct(sound)) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// SetSoundVolume - Set volume for a sound (1.0 is max level) -func SetSoundVolume(sound Sound, volume float32) { - _, fl := setSoundVolume.Call(wasm.Struct(sound), volume) - wasm.Free(fl...) -} - -// SetSoundPitch - Set pitch for a sound (1.0 is base level) -func SetSoundPitch(sound Sound, pitch float32) { - _, fl := setSoundPitch.Call(wasm.Struct(sound), pitch) - wasm.Free(fl...) -} - -// SetSoundPan - Set pan for a sound (0.5 is center) -func SetSoundPan(sound Sound, pan float32) { - _, fl := setSoundPan.Call(wasm.Struct(sound), pan) - wasm.Free(fl...) -} - -// WaveCopy - Copy a wave to a new wave -func WaveCopy(wave Wave) Wave { - ret, fl := waveCopy.Call(wasm.Struct(wave)) - v := wasm.ReadStruct[Wave](ret) - wasm.Free(fl...) - return v -} - -// WaveCrop - Crop a wave to defined frames range -func WaveCrop(wave *Wave, initFrame int32, finalFrame int32) { - _, fl := waveCrop.Call(wave, initFrame, finalFrame) - wasm.Free(fl...) -} - -// WaveFormat - Convert wave data to desired format -func WaveFormat(wave *Wave, sampleRate int32, sampleSize int32, channels int32) { - _, fl := waveFormat.Call(wave, sampleRate, sampleSize, channels) - wasm.Free(fl...) -} - -// LoadWaveSamples - Load samples data from wave as a 32bit float data array -func LoadWaveSamples(wave Wave) []float32 { - var zero []float32 - return zero -} - -// UnloadWaveSamples - Unload samples data loaded with LoadWaveSamples() -func UnloadWaveSamples(samples []float32) { - _, fl := unloadWaveSamples.Call(samples) - wasm.Free(fl...) -} - -// LoadMusicStream - Load music stream from file -func LoadMusicStream(fileName string) Music { - ret, fl := loadMusicStream.Call(fileName) - v := wasm.ReadStruct[Music](ret) - wasm.Free(fl...) - return v -} - -// LoadMusicStreamFromMemory - Load music stream from data -func LoadMusicStreamFromMemory(fileType string, data []byte, dataSize int32) Music { - ret, fl := loadMusicStreamFromMemory.Call(fileType, data, dataSize) - v := wasm.ReadStruct[Music](ret) - wasm.Free(fl...) - return v -} - -// IsMusicValid - Checks if a music stream is valid (context and buffers initialized) -func IsMusicValid(music Music) bool { - ret, fl := isMusicValid.Call(wasm.Struct(music)) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// UnloadMusicStream - Unload music stream -func UnloadMusicStream(music Music) { - _, fl := unloadMusicStream.Call(wasm.Struct(music)) - wasm.Free(fl...) -} - -// PlayMusicStream - Start music playing -func PlayMusicStream(music Music) { - _, fl := playMusicStream.Call(wasm.Struct(music)) - wasm.Free(fl...) -} - -// IsMusicStreamPlaying - Check if music is playing -func IsMusicStreamPlaying(music Music) bool { - ret, fl := isMusicStreamPlaying.Call(wasm.Struct(music)) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// UpdateMusicStream - Updates buffers for music streaming -func UpdateMusicStream(music Music) { - _, fl := updateMusicStream.Call(wasm.Struct(music)) - wasm.Free(fl...) -} - -// StopMusicStream - Stop music playing -func StopMusicStream(music Music) { - _, fl := stopMusicStream.Call(wasm.Struct(music)) - wasm.Free(fl...) -} - -// PauseMusicStream - Pause music playing -func PauseMusicStream(music Music) { - _, fl := pauseMusicStream.Call(wasm.Struct(music)) - wasm.Free(fl...) -} - -// ResumeMusicStream - Resume playing paused music -func ResumeMusicStream(music Music) { - _, fl := resumeMusicStream.Call(wasm.Struct(music)) - wasm.Free(fl...) -} - -// SeekMusicStream - Seek music to a position (in seconds) -func SeekMusicStream(music Music, position float32) { - _, fl := seekMusicStream.Call(wasm.Struct(music), position) - wasm.Free(fl...) -} - -// SetMusicVolume - Set volume for music (1.0 is max level) -func SetMusicVolume(music Music, volume float32) { - _, fl := setMusicVolume.Call(wasm.Struct(music), volume) - wasm.Free(fl...) -} - -// SetMusicPitch - Set pitch for a music (1.0 is base level) -func SetMusicPitch(music Music, pitch float32) { - _, fl := setMusicPitch.Call(wasm.Struct(music), pitch) - wasm.Free(fl...) -} - -// SetMusicPan - Set pan for a music (0.5 is center) -func SetMusicPan(music Music, pan float32) { - _, fl := setMusicPan.Call(wasm.Struct(music), pan) - wasm.Free(fl...) -} - -// GetMusicTimeLength - Get music time length (in seconds) -func GetMusicTimeLength(music Music) float32 { - ret, fl := getMusicTimeLength.Call(wasm.Struct(music)) - v := wasm.Numeric[float32](ret) - wasm.Free(fl...) - return v -} - -// GetMusicTimePlayed - Get current music time played (in seconds) -func GetMusicTimePlayed(music Music) float32 { - ret, fl := getMusicTimePlayed.Call(wasm.Struct(music)) - v := wasm.Numeric[float32](ret) - wasm.Free(fl...) - return v -} - -// LoadAudioStream - Load audio stream (to stream raw audio pcm data) -func LoadAudioStream(sampleRate uint32, sampleSize uint32, channels uint32) AudioStream { - ret, fl := loadAudioStream.Call(sampleRate, sampleSize, channels) - v := wasm.ReadStruct[AudioStream](ret) - wasm.Free(fl...) - return v -} - -// IsAudioStreamValid - Checks if an audio stream is valid (buffers initialized) -func IsAudioStreamValid(stream AudioStream) bool { - ret, fl := isAudioStreamValid.Call(wasm.Struct(stream)) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// UnloadAudioStream - Unload audio stream and free memory -func UnloadAudioStream(stream AudioStream) { - _, fl := unloadAudioStream.Call(wasm.Struct(stream)) - wasm.Free(fl...) -} - -// UpdateAudioStream - Update audio stream buffers with data -func UpdateAudioStream(stream AudioStream, data []float32) { - _, fl := updateAudioStream.Call(wasm.Struct(stream), data) - wasm.Free(fl...) -} - -// IsAudioStreamProcessed - Check if any audio stream buffers requires refill -func IsAudioStreamProcessed(stream AudioStream) bool { - ret, fl := isAudioStreamProcessed.Call(wasm.Struct(stream)) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// PlayAudioStream - Play audio stream -func PlayAudioStream(stream AudioStream) { - _, fl := playAudioStream.Call(wasm.Struct(stream)) - wasm.Free(fl...) -} - -// PauseAudioStream - Pause audio stream -func PauseAudioStream(stream AudioStream) { - _, fl := pauseAudioStream.Call(wasm.Struct(stream)) - wasm.Free(fl...) -} - -// ResumeAudioStream - Resume audio stream -func ResumeAudioStream(stream AudioStream) { - _, fl := resumeAudioStream.Call(wasm.Struct(stream)) - wasm.Free(fl...) -} - -// IsAudioStreamPlaying - Check if audio stream is playing -func IsAudioStreamPlaying(stream AudioStream) bool { - ret, fl := isAudioStreamPlaying.Call(wasm.Struct(stream)) - v := wasm.Boolean(ret) - wasm.Free(fl...) - return v -} - -// StopAudioStream - Stop audio stream -func StopAudioStream(stream AudioStream) { - _, fl := stopAudioStream.Call(wasm.Struct(stream)) - wasm.Free(fl...) -} - -// SetAudioStreamVolume - Set volume for audio stream (1.0 is max level) -func SetAudioStreamVolume(stream AudioStream, volume float32) { - _, fl := setAudioStreamVolume.Call(wasm.Struct(stream), volume) - wasm.Free(fl...) -} - -// SetAudioStreamPitch - Set pitch for audio stream (1.0 is base level) -func SetAudioStreamPitch(stream AudioStream, pitch float32) { - _, fl := setAudioStreamPitch.Call(wasm.Struct(stream), pitch) - wasm.Free(fl...) -} - -// SetAudioStreamPan - Set pan for audio stream (0.5 is centered) -func SetAudioStreamPan(stream AudioStream, pan float32) { - _, fl := setAudioStreamPan.Call(wasm.Struct(stream), pan) - wasm.Free(fl...) -} - -// SetAudioStreamBufferSizeDefault - Default size for new audio streams -func SetAudioStreamBufferSizeDefault(size int32) { - _, fl := setAudioStreamBufferSizeDefault.Call(size) - wasm.Free(fl...) -} - -// SetAudioStreamCallback - Audio thread callback to request new data -func SetAudioStreamCallback(stream AudioStream, callback AudioCallback) { - _, fl := setAudioStreamCallback.Call(wasm.Struct(stream), callback) - wasm.Free(fl...) -} - -// AttachAudioStreamProcessor - Attach audio stream processor to stream, receives the samples as s -func AttachAudioStreamProcessor(stream AudioStream, processor AudioCallback) { - _, fl := attachAudioStreamProcessor.Call(wasm.Struct(stream), processor) - wasm.Free(fl...) -} - -// DetachAudioStreamProcessor - Detach audio stream processor from stream -func DetachAudioStreamProcessor(stream AudioStream, processor AudioCallback) { - _, fl := detachAudioStreamProcessor.Call(wasm.Struct(stream), processor) - wasm.Free(fl...) -} - -// AttachAudioMixedProcessor - Attach audio stream processor to the entire audio pipeline, receives the samples as s -func AttachAudioMixedProcessor(processor AudioCallback) { - _, fl := attachAudioMixedProcessor.Call(processor) - wasm.Free(fl...) -} - -// DetachAudioMixedProcessor - Detach audio stream processor from the entire audio pipeline -func DetachAudioMixedProcessor(processor AudioCallback) { - _, fl := detachAudioMixedProcessor.Call(processor) - wasm.Free(fl...) -} - -// SetCallbackFunc - Sets callback function -func SetCallbackFunc() { - _, fl := setCallbackFunc.Call() - wasm.Free(fl...) -} - - -// ToImage converts a Image to Go image.Image -func ToImage() image.Image { - // ret, fl := toImage.Call() - // // v := wasm.Numeric[image.Image](ret) - // wasm.Free(fl...) - // return v - return nil -} - -// OpenAsset - Open asset -func OpenAsset(name string) Asset { - // ret, fl := openAsset.Call(name) - // v := wasm.Numeric[Asset](ret) - // wasm.Free(fl...) - // return v - return nil -} - -// HomeDir - Returns user home directory -// NOTE: On Android this returns internal data path and must be called after InitWindow -func HomeDir() string { - ret, fl := homeDir.Call() - v := wasm.Numeric[string](ret) - wasm.Free(fl...) - return v +// UnloadVrStereoConfig - Unload VR stereo config +func UnloadVrStereoConfig(config VrStereoConfig) { + unloadVrStereoConfig(*(*vrStereoConfig)(&config)) } +*/ diff --git a/raylib/wasm.go b/raylib/wasm.go new file mode 100644 index 0000000..2a43f3d --- /dev/null +++ b/raylib/wasm.go @@ -0,0 +1,151 @@ +//go:build js + +package rl + +import ( + "syscall/js" + "unsafe" +) + +// cptr is a pointer to raylib wasm memory +type cptr = uint32 + +// Allocates memory on raylib heap +// +//go:wasmimport raylib _malloc +//go:noescape +func malloc(size cptr) cptr + +// malloc the size of V +func mallocV[T any](V T) (cptr, func()) { + ptr := malloc(sizeof(V)) + return ptr, func() { free(ptr) } +} + +// free memory allocated on raylib heap +// +//go:wasmimport raylib _free +//go:noescape +func free(cptr) + +// _copyToC copies a Go type/struct to C memory. Useful for copying slices and structs. +// +// Destination C array must have enough space. +// +// NOTE: Value must be a type, it cannot be a slice. +// To pass a slice, use [unsafe.SliceData] +// +//go:wasmimport gojs CopyToC +//go:noescape +func _copyToC(Value unsafe.Pointer, srcSize, dstCptr cptr) + +// copies C memory to a Go pointer. Useful for copying C structs into Go structs +// +// example usage: +// +// type Person struct{ +// Age int32 +// } +// +// var cPtrToPersonInCHeap cptr = ... +// +// var p Person +// CopyToGo(unsafe.Pointer(&p),unsafe.SizeOf(p),cPtrToPersonInCHeap) +// +// p.Age == (whatever it was in C) +// +//go:wasmimport gojs CopyToGo +//go:noescape +func _copyToGo(dstGoPtr unsafe.Pointer, size cptr, src cptr) + +// Copies the src value to the dst cptr +func copyToC[T any](src *T, dst cptr) { + size := sizeof(src) + _copyToC(unsafe.Pointer(src), size, dst) +} + +// The alocated C string lives on the raylib heap and must be free()'d +// +//go:wasmimport gojs CStringFromGoString +//go:noescape +func cString(string) cptr + +// Scan for null terminator and return length excluding the null terminator. +// +//go:wasmimport gojs CStringGetLength +//go:noescape +func _cStringGetLength(cstr cptr) cptr + +// Copies a C string to Go memory without freeing the C string. +func goString(cstr cptr) string { + size := _cStringGetLength(cstr) + dstStr := make([]byte, size) + copySliceToGo(cstr, dstStr) + return string(dstStr) +} + +// copyValueToC copies a value to C and returns a pointer to it. +// +// NOTE: Value cannot be a slice. For a slice, use [copySliceToC] +func copyValueToC[T any](srcValue T) (cptr, func()) { + size := sizeof(srcValue) + dst := malloc(size) + copyToC(&srcValue, dst) + return dst, func() { free(dst) } +} + +// copySliceToC allocates a copy of a slice in C memory and returns a cptr to it. +// +// NOTE: Value MUST be a slice +func copySliceToC[Slice ~[]E, E any](s Slice) (cptr, func()) { + // size of the slice's underlying array in bytes + sliceSize := cptr(unsafe.Sizeof(s[0])) * cptr(len(s)) + // allocate C array to hold Value + dstCptr := malloc(sliceSize) + // copy underlying array memory to C + _copyToC(unsafe.Pointer(unsafe.SliceData(s)), sliceSize, dstCptr) + return dstCptr, func() { free(dstCptr) } +} + +// copyValueToGo copies a value from C memory to Go memory. +// Useful for copying structs +// +// NOTE: Slices are not supported. Use [copySliceToGo] +func copyValueToGo[T any](src cptr, dst *T) { + size := sizeof(*dst) + _copyToGo(unsafe.Pointer(dst), size, src) +} + +// copySliceToGo copies a C array into a Go Slice. +// +// It copies bytes to the underlying array of the slice. +func copySliceToGo[Slice ~[]E, E any](src cptr, dst Slice) { + // size of underlying array + var occupiedSize = len(dst) + if occupiedSize == 0 { + occupiedSize = cap(dst) + } + size := cptr(unsafe.Sizeof(dst[0])) * cptr(occupiedSize) + dstPtr := unsafe.SliceData(dst) + _copyToGo(unsafe.Pointer(dstPtr), size, src) +} + +//go:wasmimport gojs Alert +//go:noescape +func alert(string) + +// Use this instead of a for loop on web platform +// Everything that you would do inside the for-loop must be done inside UpdateAndDrawFrame +func SetMain(UpdateAndDrawFrame func()) { + var updateLoop js.Func + updateLoop = js.FuncOf(func(this js.Value, args []js.Value) any { + UpdateAndDrawFrame() + js.Global().Call("requestAnimationFrame", updateLoop) + return nil + }) + js.Global().Call("requestAnimationFrame", updateLoop) + select {} +} + +// return sizeof of v in bytes +func sizeof[T any](v T) cptr { return cptr(unsafe.Sizeof(v)) } diff --git a/raylib/wasm_test.go b/raylib/wasm_test.go new file mode 100644 index 0000000..3fefffb --- /dev/null +++ b/raylib/wasm_test.go @@ -0,0 +1,117 @@ +//go:build js + +package rl + +import ( + "reflect" + "testing" +) + +// Test copyValueToC + copyValueToGo round-trip for a struct and for a primitive. +func TestCopyValueToCAndBack(t *testing.T) { + type Person struct { + Age int32 + Score float32 + } + + original := Person{Age: 42, Score: 3.14} + // copy struct to C + cptr := copyValueToC(original) + if cptr == 0 { + t.Fatalf("copyValueToC returned null pointer") + } + // ensure we free at the end + defer free(cptr) + + var got Person + copyValueToGo(cptr, &got) + + if !reflect.DeepEqual(original, got) { + t.Fatalf("person round-trip mismatch: want %+v, got %+v", original, got) + } + + // test primitive type (int64) + var originalInt int64 = -1234567890 + cptr2 := copyValueToC(originalInt) + if cptr2 == 0 { + t.Fatalf("copyValueToC returned null pointer for primitive") + } + defer free(cptr2) + + var gotInt int64 + copyValueToGo(cptr2, &gotInt) + if originalInt != gotInt { + t.Fatalf("primitive round-trip mismatch: want %d, got %d", originalInt, gotInt) + } +} + +// Test copySliceToC + copySliceToGo round-trip for a byte slice and for an int slice. +func TestCopySliceToCAndBack(t *testing.T) { + // byte slice + origBytes := []byte("hello, raylib wasm") + cptr := copySliceToC(origBytes) + if cptr == 0 { + t.Fatalf("copySliceToC returned null pointer for bytes") + } + defer free(cptr) + + dstBytes := make([]byte, len(origBytes)) + copySliceToGo(cptr, dstBytes) + if !reflect.DeepEqual(origBytes, dstBytes) { + t.Fatalf("byte slice round-trip mismatch: want %v, got %v", origBytes, dstBytes) + } + + // int slice + origInts := []int32{1, 2, 3, 4, 5} + cptrInts := copySliceToC(origInts) + if cptrInts == 0 { + t.Fatalf("copySliceToC returned null pointer for ints") + } + defer free(cptrInts) + + dstInts := make([]int32, len(origInts)) + copySliceToGo(cptrInts, dstInts) + if !reflect.DeepEqual(origInts, dstInts) { + t.Fatalf("int slice round-trip mismatch: want %v, got %v", origInts, dstInts) + } +} + +// Test copySliceToGo behavior when dst has len==0 but cap>0. +// The function should copy into the underlying array (up to cap). +func TestCopySliceToGoCopiesToUnderlyingArrayWhenLenZero(t *testing.T) { + orig := []int32{10, 20, 30} + cptr := copySliceToC(orig) + if cptr == 0 { + t.Fatalf("copySliceToC returned null pointer") + } + defer free(cptr) + + // dst has length 0 but capacity 3 + dst := make([]int32, 0, 3) + // perform copy; after this the content should be in dst[:cap(dst)] + copySliceToGo(cptr, dst) + + // inspect underlying array by slicing up to capacity + gotUnderlying := dst[:cap(dst)] + if !reflect.DeepEqual(orig, gotUnderlying) { + t.Fatalf("underlying array mismatch: want %v, got %v", orig, gotUnderlying) + } +} + +// Test goString - constructs a C string via cString (wasm import) and reads it back via goString. +// Note: this test relies on cString and _cStringGetLength being available in the environment. +func TestGoString(t *testing.T) { + const s = "testing goString 🚀" + cstr := cString(s) + if cstr == 0 { + t.Fatalf("cString returned null pointer") + } + // cString allocates on raylib heap; free after test + defer free(cstr) + + got := goString(cstr) + if got != s { + t.Fatalf("goString returned %q, want %q", got, s) + } +} + diff --git a/testdata/api/rlapi.go b/testdata/api/rlapi.go new file mode 100644 index 0000000..be1fefd --- /dev/null +++ b/testdata/api/rlapi.go @@ -0,0 +1,76 @@ +package api + +import ( + _ "embed" + "encoding/json" +) + +var Api RlApi + +//go:embed rlapi.json +var rlApiJson []byte + +func init() { + err := json.Unmarshal(rlApiJson, &Api) + if err != nil { + panic(err) + } +} + +type RlDefine struct { + Name string `json:"name"` + Type string `json:"type"` + Value StringyValue `json:"value"` + Description string `json:"description"` +} + + +type RlField struct { + Type string `json:"type"` + Name string `json:"name"` + Description string `json:"description"` +} +type RlStruct struct { + Name string `json:"name"` + Description string `json:"description"` + Fields []RlField `json:"fields"` +} +type RlAlias struct { + Type string `json:"type"` + Name string `json:"name"` + Description string `json:"description"` +} +type RlValue struct { + Name string `json:"name"` + Value int `json:"value"` + Description string `json:"description"` +} +type RlEnum struct { + Name string `json:"name"` + Description string `json:"description"` + Values []RlValue `json:"values"` +} +type RlParam struct { + Type string `json:"type"` + Name string `json:"name"` +} +type RlCallback struct { + Name string `json:"name"` + Description string `json:"description"` + ReturnType string `json:"returnType"` + Params []RlParam `json:"params"` +} +type RlFunction struct { + Name string `json:"name"` + Description string `json:"description"` + ReturnType string `json:"returnType"` + Params []RlParam `json:"params,omitempty"` +} +type RlApi struct { + Defines []RlDefine `json:"defines"` + Structs []RlStruct `json:"structs"` + Aliases []RlAlias `json:"aliases"` + Enums []RlEnum `json:"enums"` + Callbacks []RlCallback `json:"callbacks"` + Functions []RlFunction `json:"functions"` +} diff --git a/testdata/rcore.json b/testdata/api/rlapi.json similarity index 96% rename from testdata/rcore.json rename to testdata/api/rlapi.json index 1e330c6..d4c059c 100644 --- a/testdata/rcore.json +++ b/testdata/api/rlapi.json @@ -40,7 +40,7 @@ "name": "RLAPI", "type": "UNKNOWN", "value": "__declspec(dllexport)", - "description": "We are building the library as a Win32 shared library (.dll)" + "description": "Building the library as a Win32 shared library (.dll)" }, { "name": "PI", @@ -753,7 +753,7 @@ { "type": "float", "name": "fovy", - "description": "Camera field-of-view aperture in Y (degrees) in perspective, used as near plane width in orthographic" + "description": "Camera field-of-view aperture in Y (degrees) in perspective, used as near plane height in world units in orthographic" }, { "type": "int", @@ -769,22 +769,22 @@ { "type": "Vector2", "name": "offset", - "description": "Camera offset (displacement from target)" + "description": "Camera offset (screen space offset from window origin)" }, { "type": "Vector2", "name": "target", - "description": "Camera target (rotation and zoom origin)" + "description": "Camera target (world space target point that is mapped to screen space offset)" }, { "type": "float", "name": "rotation", - "description": "Camera rotation in degrees" + "description": "Camera rotation in degrees (pivots around target)" }, { "type": "float", "name": "zoom", - "description": "Camera zoom (scaling), should be 1.0f by default" + "description": "Camera zoom (scaling around target), must not be set to 0, set to 1.0f for no scale" } ] }, @@ -1324,11 +1324,6 @@ "name": "FilePathList", "description": "File path list", "fields": [ - { - "type": "unsigned int", - "name": "capacity", - "description": "Filepaths max entries" - }, { "type": "unsigned int", "name": "count", @@ -2300,7 +2295,7 @@ }, { "name": "GamepadAxis", - "description": "Gamepad axis", + "description": "Gamepad axes", "values": [ { "name": "GAMEPAD_AXIS_LEFT_X", @@ -3139,7 +3134,7 @@ "name": "fileName" }, { - "type": "char *", + "type": "const char *", "name": "text" } ] @@ -3161,6 +3156,25 @@ } ], "functions": [ + { + "name": "InitWindow", + "description": "Initialize window and OpenGL context", + "returnType": "void", + "params": [ + { + "type": "int", + "name": "width" + }, + { + "type": "int", + "name": "height" + }, + { + "type": "const char *", + "name": "title" + } + ] + }, { "name": "CloseWindow", "description": "Close window and unload OpenGL context", @@ -4172,6 +4186,17 @@ } ] }, + { + "name": "SetTraceLogLevel", + "description": "Set the current threshold (minimum) log level", + "returnType": "void", + "params": [ + { + "type": "int", + "name": "logLevel" + } + ] + }, { "name": "TraceLog", "description": "Show trace log messages (LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR...)", @@ -4192,13 +4217,13 @@ ] }, { - "name": "SetTraceLogLevel", - "description": "Set the current threshold (minimum) log level", + "name": "SetTraceLogCallback", + "description": "Set custom trace log", "returnType": "void", "params": [ { - "type": "int", - "name": "logLevel" + "type": "TraceLogCallback", + "name": "callback" } ] }, @@ -4240,13 +4265,103 @@ ] }, { - "name": "SetTraceLogCallback", - "description": "Set custom trace log", + "name": "LoadFileData", + "description": "Load file data as byte array (read)", + "returnType": "unsigned char *", + "params": [ + { + "type": "const char *", + "name": "fileName" + }, + { + "type": "int *", + "name": "dataSize" + } + ] + }, + { + "name": "UnloadFileData", + "description": "Unload file data allocated by LoadFileData()", "returnType": "void", "params": [ { - "type": "TraceLogCallback", - "name": "callback" + "type": "unsigned char *", + "name": "data" + } + ] + }, + { + "name": "SaveFileData", + "description": "Save data to file from byte array (write), returns true on success", + "returnType": "bool", + "params": [ + { + "type": "const char *", + "name": "fileName" + }, + { + "type": "void *", + "name": "data" + }, + { + "type": "int", + "name": "dataSize" + } + ] + }, + { + "name": "ExportDataAsCode", + "description": "Export data to code (.h), returns true on success", + "returnType": "bool", + "params": [ + { + "type": "const unsigned char *", + "name": "data" + }, + { + "type": "int", + "name": "dataSize" + }, + { + "type": "const char *", + "name": "fileName" + } + ] + }, + { + "name": "LoadFileText", + "description": "Load text data from file (read), returns a '\\0' terminated string", + "returnType": "char *", + "params": [ + { + "type": "const char *", + "name": "fileName" + } + ] + }, + { + "name": "UnloadFileText", + "description": "Unload file text data allocated by LoadFileText()", + "returnType": "void", + "params": [ + { + "type": "char *", + "name": "text" + } + ] + }, + { + "name": "SaveFileText", + "description": "Save text data to file (write), string must be '\\0' terminated, returns true on success", + "returnType": "bool", + "params": [ + { + "type": "const char *", + "name": "fileName" + }, + { + "type": "const char *", + "name": "text" } ] }, @@ -4295,103 +4410,92 @@ ] }, { - "name": "LoadFileData", - "description": "Load file data as byte array (read)", - "returnType": "unsigned char *", + "name": "FileRename", + "description": "Rename file (if exists)", + "returnType": "int", "params": [ { "type": "const char *", "name": "fileName" }, { - "type": "int *", - "name": "dataSize" + "type": "const char *", + "name": "fileRename" } ] }, { - "name": "UnloadFileData", - "description": "Unload file data allocated by LoadFileData()", - "returnType": "void", + "name": "FileRemove", + "description": "Remove file (if exists)", + "returnType": "int", "params": [ { - "type": "unsigned char *", - "name": "data" + "type": "const char *", + "name": "fileName" } ] }, { - "name": "SaveFileData", - "description": "Save data to file from byte array (write), returns true on success", - "returnType": "bool", + "name": "FileCopy", + "description": "Copy file from one path to another, dstPath created if it doesn't exist", + "returnType": "int", "params": [ { "type": "const char *", - "name": "fileName" + "name": "srcPath" }, { - "type": "void *", - "name": "data" - }, - { - "type": "int", - "name": "dataSize" + "type": "const char *", + "name": "dstPath" } ] }, { - "name": "ExportDataAsCode", - "description": "Export data to code (.h), returns true on success", - "returnType": "bool", + "name": "FileMove", + "description": "Move file from one directory to another, dstPath created if it doesn't exist", + "returnType": "int", "params": [ { - "type": "const unsigned char *", - "name": "data" - }, - { - "type": "int", - "name": "dataSize" + "type": "const char *", + "name": "srcPath" }, { "type": "const char *", - "name": "fileName" + "name": "dstPath" } ] }, { - "name": "LoadFileText", - "description": "Load text data from file (read), returns a '\\0' terminated string", - "returnType": "char *", + "name": "FileTextReplace", + "description": "Replace text in an existing file", + "returnType": "int", "params": [ { "type": "const char *", "name": "fileName" - } - ] - }, - { - "name": "UnloadFileText", - "description": "Unload file text data allocated by LoadFileText()", - "returnType": "void", - "params": [ + }, { - "type": "char *", - "name": "text" + "type": "const char *", + "name": "search" + }, + { + "type": "const char *", + "name": "replacement" } ] }, { - "name": "SaveFileText", - "description": "Save text data to file (write), string must be '\\0' terminated, returns true on success", - "returnType": "bool", + "name": "FileTextFindIndex", + "description": "Find text in existing file", + "returnType": "int", "params": [ { "type": "const char *", "name": "fileName" }, { - "type": "char *", - "name": "text" + "type": "const char *", + "name": "search" } ] }, @@ -4419,7 +4523,7 @@ }, { "name": "IsFileExtension", - "description": "Check file extension (including point: .png, .wav)", + "description": "Check file extension (recommended include point: .png, .wav)", "returnType": "bool", "params": [ { @@ -4443,6 +4547,17 @@ } ] }, + { + "name": "GetFileModTime", + "description": "Get file modification time (last write time)", + "returnType": "long", + "params": [ + { + "type": "const char *", + "name": "fileName" + } + ] + }, { "name": "GetFileExtension", "description": "Get pointer to extension for a filename string (includes dot: '.png')", @@ -4526,7 +4641,7 @@ "params": [ { "type": "const char *", - "name": "dir" + "name": "dirPath" } ] }, @@ -4615,13 +4730,32 @@ ] }, { - "name": "GetFileModTime", - "description": "Get file modification time (last write time)", - "returnType": "long", + "name": "GetDirectoryFileCount", + "description": "Get the file count in a directory", + "returnType": "unsigned int", "params": [ { "type": "const char *", - "name": "fileName" + "name": "dirPath" + } + ] + }, + { + "name": "GetDirectoryFileCountEx", + "description": "Get the file count in a directory with extension filtering and recursive directory scan. Use 'DIR' in the filter string to include directories in the result", + "returnType": "unsigned int", + "params": [ + { + "type": "const char *", + "name": "basePath" + }, + { + "type": "const char *", + "name": "filter" + }, + { + "type": "bool", + "name": "scanSubdirs" } ] }, @@ -4665,7 +4799,7 @@ }, { "name": "EncodeDataBase64", - "description": "Encode data to Base64 string, memory must be MemFree()", + "description": "Encode data to Base64 string (includes NULL terminator), memory must be MemFree()", "returnType": "char *", "params": [ { @@ -4684,12 +4818,12 @@ }, { "name": "DecodeDataBase64", - "description": "Decode Base64 string data, memory must be MemFree()", + "description": "Decode Base64 string (expected NULL terminated), memory must be MemFree()", "returnType": "unsigned char *", "params": [ { - "type": "const unsigned char *", - "name": "data" + "type": "const char *", + "name": "text" }, { "type": "int *", @@ -4742,6 +4876,21 @@ } ] }, + { + "name": "ComputeSHA256", + "description": "Compute SHA256 hash code, returns static int[8] (32 bytes)", + "returnType": "unsigned int *", + "params": [ + { + "type": "unsigned char *", + "name": "data" + }, + { + "type": "int", + "name": "dataSize" + } + ] + }, { "name": "LoadAutomationEventList", "description": "Load automation events list from file, NULL for empty list, capacity = MAX_AUTOMATION_EVENTS", @@ -4998,7 +5147,7 @@ }, { "name": "GetGamepadAxisCount", - "description": "Get gamepad axis count for a gamepad", + "description": "Get axis count for a gamepad", "returnType": "int", "params": [ { @@ -5009,7 +5158,7 @@ }, { "name": "GetGamepadAxisMovement", - "description": "Get axis movement value for a gamepad axis", + "description": "Get movement value for a gamepad axis", "returnType": "float", "params": [ { @@ -5483,6 +5632,33 @@ } ] }, + { + "name": "DrawLineDashed", + "description": "Draw a dashed line", + "returnType": "void", + "params": [ + { + "type": "Vector2", + "name": "startPos" + }, + { + "type": "Vector2", + "name": "endPos" + }, + { + "type": "int", + "name": "dashSize" + }, + { + "type": "int", + "name": "spaceSize" + }, + { + "type": "Color", + "name": "color" + } + ] + }, { "name": "DrawCircle", "description": "Draw a color-filled circle", @@ -5683,6 +5859,29 @@ } ] }, + { + "name": "DrawEllipseV", + "description": "Draw ellipse (Vector version)", + "returnType": "void", + "params": [ + { + "type": "Vector2", + "name": "center" + }, + { + "type": "float", + "name": "radiusH" + }, + { + "type": "float", + "name": "radiusV" + }, + { + "type": "Color", + "name": "color" + } + ] + }, { "name": "DrawEllipseLines", "description": "Draw ellipse outline", @@ -5710,6 +5909,29 @@ } ] }, + { + "name": "DrawEllipseLinesV", + "description": "Draw ellipse outline (Vector version)", + "returnType": "void", + "params": [ + { + "type": "Vector2", + "name": "center" + }, + { + "type": "float", + "name": "radiusH" + }, + { + "type": "float", + "name": "radiusV" + }, + { + "type": "Color", + "name": "color" + } + ] + }, { "name": "DrawRing", "description": "Draw ring", @@ -5945,11 +6167,11 @@ }, { "type": "Color", - "name": "topRight" + "name": "bottomRight" }, { "type": "Color", - "name": "bottomRight" + "name": "topRight" } ] }, @@ -8237,7 +8459,7 @@ "name": "dst" }, { - "type": "Vector2 *", + "type": "const Vector2 *", "name": "points" }, { @@ -8260,7 +8482,7 @@ "name": "dst" }, { - "type": "Vector2 *", + "type": "const Vector2 *", "name": "points" }, { @@ -8464,7 +8686,7 @@ }, { "name": "UpdateTexture", - "description": "Update GPU texture with new data", + "description": "Update GPU texture with new data (pixels should be able to fill texture)", "returnType": "void", "params": [ { @@ -8479,7 +8701,7 @@ }, { "name": "UpdateTextureRec", - "description": "Update GPU texture rectangle with new data", + "description": "Update GPU texture rectangle with new data (pixels and rec should fit in texture)", "returnType": "void", "params": [ { @@ -8976,7 +9198,7 @@ "name": "fontSize" }, { - "type": "int *", + "type": "const int *", "name": "codepoints" }, { @@ -9026,7 +9248,7 @@ "name": "fontSize" }, { - "type": "int *", + "type": "const int *", "name": "codepoints" }, { @@ -9064,7 +9286,7 @@ "name": "fontSize" }, { - "type": "int *", + "type": "const int *", "name": "codepoints" }, { @@ -9074,6 +9296,10 @@ { "type": "int", "name": "type" + }, + { + "type": "int *", + "name": "glyphCount" } ] }, @@ -9540,6 +9766,36 @@ } ] }, + { + "name": "LoadTextLines", + "description": "Load text as separate lines ('\\n')", + "returnType": "char **", + "params": [ + { + "type": "const char *", + "name": "text" + }, + { + "type": "int *", + "name": "count" + } + ] + }, + { + "name": "UnloadTextLines", + "description": "Unload text lines", + "returnType": "void", + "params": [ + { + "type": "char **", + "name": "text" + }, + { + "type": "int", + "name": "lineCount" + } + ] + }, { "name": "TextCopy", "description": "Copy one string to another, returns bytes copied", @@ -9615,6 +9871,36 @@ } ] }, + { + "name": "TextRemoveSpaces", + "description": "Remove text spaces, concat words", + "returnType": "const char *", + "params": [ + { + "type": "const char *", + "name": "text" + } + ] + }, + { + "name": "GetTextBetween", + "description": "Get text between two strings", + "returnType": "char *", + "params": [ + { + "type": "const char *", + "name": "text" + }, + { + "type": "const char *", + "name": "begin" + }, + { + "type": "const char *", + "name": "end" + } + ] + }, { "name": "TextReplace", "description": "Replace text string (WARNING: memory must be freed!)", @@ -9626,11 +9912,34 @@ }, { "type": "const char *", - "name": "replace" + "name": "search" + }, + { + "type": "const char *", + "name": "replacement" + } + ] + }, + { + "name": "TextReplaceBetween", + "description": "Replace text between two specific strings (WARNING: memory must be freed!)", + "returnType": "char *", + "params": [ + { + "type": "const char *", + "name": "text" + }, + { + "type": "const char *", + "name": "begin" + }, + { + "type": "const char *", + "name": "end" }, { "type": "const char *", - "name": "by" + "name": "replacement" } ] }, @@ -9674,7 +9983,7 @@ }, { "name": "TextSplit", - "description": "Split text into multiple strings", + "description": "Split text into multiple strings, using MAX_TEXTSPLIT_COUNT static strings", "returnType": "char **", "params": [ { @@ -9693,7 +10002,7 @@ }, { "name": "TextAppend", - "description": "Append text at specific position and move cursor!", + "description": "Append text at specific position and move cursor", "returnType": "void", "params": [ { @@ -9712,7 +10021,7 @@ }, { "name": "TextFindIndex", - "description": "Find first text occurrence within a string", + "description": "Find first text occurrence within a string, -1 if not found", "returnType": "int", "params": [ { @@ -9721,7 +10030,7 @@ }, { "type": "const char *", - "name": "find" + "name": "search" } ] }, @@ -11446,7 +11755,7 @@ }, { "name": "UpdateSound", - "description": "Update sound buffer with new data", + "description": "Update sound buffer with new data (default data format: 32 bit float, stereo)", "returnType": "void", "params": [ { @@ -11613,7 +11922,7 @@ }, { "name": "SetSoundPan", - "description": "Set pan for a sound (0.5 is center)", + "description": "Set pan for a sound (-1.0 left, 0.0 center, 1.0 right)", "returnType": "void", "params": [ { @@ -11866,7 +12175,7 @@ }, { "name": "SetMusicPan", - "description": "Set pan for a music (0.5 is center)", + "description": "Set pan for a music (-1.0 left, 0.0 center, 1.0 right)", "returnType": "void", "params": [ { diff --git a/testdata/api/stringyvalue.go b/testdata/api/stringyvalue.go new file mode 100644 index 0000000..4176fec --- /dev/null +++ b/testdata/api/stringyvalue.go @@ -0,0 +1,28 @@ +package api + +import "encoding/json" + +type StringyValue string + +// convert the json type to a string. +func (s *StringyValue) UnmarshalJSON(b []byte) error { + // null + if string(b) == "null" { + *s = "" + return nil + } + + // quoted string + if len(b) > 0 && b[0] == '"' { + var v string + if err := json.Unmarshal(b, &v); err != nil { + return err + } + *s = StringyValue(v) + return nil + } + + // number / bare token → keep textual form + *s = StringyValue(b) + return nil +} diff --git a/testdata/codegen.go b/testdata/codegen.go new file mode 100644 index 0000000..1fe6a80 --- /dev/null +++ b/testdata/codegen.go @@ -0,0 +1,56 @@ +package main + +import ( + "codegen/api" + "codegen/templates" + _ "embed" + "slices" + "text/template" +) + +//go:embed templates/structs.go.gotmpl +var structsTempl string + +//go:embed templates/defines.go.gotmpl +var definesTempl string + +//go:embed templates/enums.go.gotmpl +var enumsTempl string + +//go:embed templates/aliases.go.gotmpl +var aliasesTempl string + +type Model struct { + BuildTags string + Imports []string + Structs []api.RlStruct + Defines []api.RlDefine + Enums []api.RlEnum + Aliases []api.RlAlias +} + +func main() { + m := Model{ + BuildTags: "js", + Imports: []string{}, + Structs: slices.Clone(api.Api.Structs), + // C #define macros need special parsing. And Names need to be PascalCase. + Defines: ParseDefines(api.Api.Defines), + Enums: slices.Clone(api.Api.Enums), + Aliases: slices.Clone(api.Api.Aliases), + } + // convert C types to Go and use PascalCase for field names. + for _, s := range m.Structs { + ProcessStructFields(s.Fields) + } + // Use PascalCase for enum names. + PascalCaseEnums(m.Enums) + funcs := template.FuncMap{ + "eq": func(a, b any) bool { return a == b }, + "contains": func(a any, b ...any) bool { return slices.Contains(b, a) }, + } + templates.GenerateCodeFormatted(m, structsTempl, "structs", nil) + templates.GenerateCodeFormatted(m, enumsTempl, "enums", nil) + templates.GenerateCodeFormatted(m, definesTempl, "defines", funcs) + templates.GenerateCodeFormatted(m, aliasesTempl, "aliases", funcs) +} diff --git a/testdata/go.mod b/testdata/go.mod new file mode 100644 index 0000000..ce211ca --- /dev/null +++ b/testdata/go.mod @@ -0,0 +1,5 @@ +module codegen + +go 1.25.6 + +require github.com/iancoleman/strcase v0.3.0 // indirect diff --git a/testdata/go.sum b/testdata/go.sum new file mode 100644 index 0000000..6261b6a --- /dev/null +++ b/testdata/go.sum @@ -0,0 +1,2 @@ +github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI= +github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= diff --git a/testdata/rcore_defines.txt b/testdata/rcore_defines.txt deleted file mode 100644 index e032786..0000000 --- a/testdata/rcore_defines.txt +++ /dev/null @@ -1,2920 +0,0 @@ -package fake - -import ( - "fmt" - "image" - "image/color" - "os" - "reflect" - "unsafe" - - "github.com/ebitengine/purego" - "golang.org/x/sys/windows" -) - - -// CloseWindow - Close window and unload OpenGL context -func CloseWindow() { - closeWindow() -} - -// IsWindowReady - Check if window has been initialized successfully -func IsWindowReady() bool { - return isWindowReady() -} - -// IsWindowFullscreen - Check if window is currently fullscreen -func IsWindowFullscreen() bool { - return isWindowFullscreen() -} - -// IsWindowHidden - Check if window is currently hidden (only PLATFORM_DESKTOP) -func IsWindowHidden() bool { - return isWindowHidden() -} - -// IsWindowMinimized - Check if window is currently minimized (only PLATFORM_DESKTOP) -func IsWindowMinimized() bool { - return isWindowMinimized() -} - -// IsWindowMaximized - Check if window is currently maximized (only PLATFORM_DESKTOP) -func IsWindowMaximized() bool { - return isWindowMaximized() -} - -// IsWindowFocused - Check if window is currently focused (only PLATFORM_DESKTOP) -func IsWindowFocused() bool { - return isWindowFocused() -} - -// IsWindowResized - Check if window has been resized last frame -func IsWindowResized() bool { - return isWindowResized() -} - -// IsWindowState - Check if one specific window flag is enabled -func IsWindowState(flag uint32) bool { - return isWindowState(flag) -} - -// SetWindowState - Set window configuration state using flags (only PLATFORM_DESKTOP) -func SetWindowState(flags uint32) { - setWindowState(flags) -} - -// ClearWindowState - Clear window configuration state flags -func ClearWindowState(flags uint32) { - clearWindowState(flags) -} - -// ToggleFullscreen - Toggle window state: fullscreen/windowed (only PLATFORM_DESKTOP) -func ToggleFullscreen() { - toggleFullscreen() -} - -// ToggleBorderlessWindowed - Toggle window state: borderless windowed (only PLATFORM_DESKTOP) -func ToggleBorderlessWindowed() { - toggleBorderlessWindowed() -} - -// MaximizeWindow - Set window state: maximized, if resizable (only PLATFORM_DESKTOP) -func MaximizeWindow() { - maximizeWindow() -} - -// MinimizeWindow - Set window state: minimized, if resizable (only PLATFORM_DESKTOP) -func MinimizeWindow() { - minimizeWindow() -} - -// RestoreWindow - Set window state: not minimized/maximized (only PLATFORM_DESKTOP) -func RestoreWindow() { - restoreWindow() -} - -// SetWindowIcon - Set icon for window (single image, RGBA 32bit, only PLATFORM_DESKTOP) -func SetWindowIcon(image Image) { - setWindowIcon(uintptr(unsafe.Pointer(&image))) -} - -// SetWindowIcons - Set icon for window (multiple images, RGBA 32bit, only PLATFORM_DESKTOP) -func SetWindowIcons(images []Image, count int32) { - setWindowIcons(uintptr(unsafe.Pointer(&images[0])), int32(len(images))) -} - -// SetWindowTitle - Set title for window (only PLATFORM_DESKTOP and PLATFORM_WEB) -func SetWindowTitle(title string) { - setWindowTitle(title) -} - -// SetWindowPosition - Set window position on screen (only PLATFORM_DESKTOP) -func SetWindowPosition(x int, y int) { - setWindowPosition(int32(x), int32(y)) -} - -// SetWindowMonitor - Set monitor for the current window -func SetWindowMonitor(monitor int) { - setWindowMonitor(int32(monitor)) -} - -// SetWindowMinSize - Set window minimum dimensions (for FLAG_WINDOW_RESIZABLE) -func SetWindowMinSize(width int, height int) { - setWindowMinSize(int32(width), int32(height)) -} - -// SetWindowMaxSize - Set window maximum dimensions (for FLAG_WINDOW_RESIZABLE) -func SetWindowMaxSize(width int, height int) { - setWindowMaxSize(int32(width), int32(height)) -} - -// SetWindowSize - Set window dimensions -func SetWindowSize(width int, height int) { - setWindowSize(int32(width), int32(height)) -} - -// SetWindowOpacity - Set window opacity [0.0f..1.0f] (only PLATFORM_DESKTOP) -func SetWindowOpacity(opacity float32) { - setWindowOpacity(opacity) -} - -// SetWindowFocused - Set window focused (only PLATFORM_DESKTOP) -func SetWindowFocused() { - setWindowFocused() -} - -// GetWindowHandle - Get native window handle -func GetWindowHandle() unsafe.Pointer { - return getWindowHandle() -} - -// GetScreenWidth - Get current screen width -func GetScreenWidth() int { - return int(getScreenWidth()) -} - -// GetScreenHeight - Get current screen height -func GetScreenHeight() int { - return int(getScreenHeight()) -} - -// GetRenderWidth - Get current render width (it considers HiDPI) -func GetRenderWidth() int { - return int(getRenderWidth()) -} - -// GetRenderHeight - Get current render height (it considers HiDPI) -func GetRenderHeight() int { - return int(getRenderHeight()) -} - -// GetMonitorCount - Get number of connected monitors -func GetMonitorCount() int { - return int(getMonitorCount()) -} - -// GetCurrentMonitor - Get current monitor where window is placed -func GetCurrentMonitor() int { - return int(getCurrentMonitor()) -} - -// GetMonitorPosition - Get specified monitor position -func GetMonitorPosition(monitor int) Vector2 { - ret := getMonitorPosition(int32(monitor)) - return *(*Vector2)(unsafe.Pointer(&ret)) -} - -// GetMonitorWidth - Get specified monitor width (current video mode used by monitor) -func GetMonitorWidth(monitor int) int { - return int(getMonitorWidth(int32(monitor))) -} - -// GetMonitorHeight - Get specified monitor height (current video mode used by monitor) -func GetMonitorHeight(monitor int) int { - return int(getMonitorHeight(int32(monitor))) -} - -// GetMonitorPhysicalWidth - Get specified monitor physical width in millimetres -func GetMonitorPhysicalWidth(monitor int) int { - return int(getMonitorPhysicalWidth(int32(monitor))) -} - -// GetMonitorPhysicalHeight - Get specified monitor physical height in millimetres -func GetMonitorPhysicalHeight(monitor int) int { - return int(getMonitorPhysicalHeight(int32(monitor))) -} - -// GetMonitorRefreshRate - Get specified monitor refresh rate -func GetMonitorRefreshRate(monitor int) int { - return int(getMonitorRefreshRate(int32(monitor))) -} - -// GetWindowPosition - Get window position XY on monitor -func GetWindowPosition() Vector2 { - ret := getWindowPosition() - return *(*Vector2)(unsafe.Pointer(&ret)) -} - -// GetWindowScaleDPI - Get window scale DPI factor -func GetWindowScaleDPI() Vector2 { - ret := getWindowScaleDPI() - return *(*Vector2)(unsafe.Pointer(&ret)) -} - -// GetMonitorName - Get the human-readable, UTF-8 encoded name of the specified monitor -func GetMonitorName(monitor int) string { - return getMonitorName(int32(monitor)) -} - -// SetClipboardText - Set clipboard text content -func SetClipboardText(text string) { - setClipboardText(text) -} - -// GetClipboardText - Get clipboard text content -func GetClipboardText() string { - return getClipboardText() -} - -// GetClipboardImage - Get clipboard image content -// -// Only works with SDL3 backend or Windows with RGFW/GLFW -func GetClipboardImage() Image { - var img Image - getClipboardImage(uintptr(unsafe.Pointer(&img))) - return img -} - -// EnableEventWaiting - Enable waiting for events on EndDrawing(), no automatic event polling -func EnableEventWaiting() { - enableEventWaiting() -} - -// DisableEventWaiting - Disable waiting for events on EndDrawing(), automatic events polling -func DisableEventWaiting() { - disableEventWaiting() -} - -// ShowCursor - Shows cursor -func ShowCursor() { - showCursor() -} - -// HideCursor - Hides cursor -func HideCursor() { - hideCursor() -} - -// IsCursorHidden - Check if cursor is not visible -func IsCursorHidden() bool { - return isCursorHidden() -} - -// EnableCursor - Enables cursor (unlock cursor) -func EnableCursor() { - enableCursor() -} - -// DisableCursor - Disables cursor (lock cursor) -func DisableCursor() { - disableCursor() -} - -// IsCursorOnScreen - Check if cursor is on the screen -func IsCursorOnScreen() bool { - return isCursorOnScreen() -} - -// ClearBackground - Set background color (framebuffer clear color) -func ClearBackground(col color.RGBA) { - clearBackground(*(*uintptr)(unsafe.Pointer(&col))) -} - -// BeginDrawing - Setup canvas (framebuffer) to start drawing -func BeginDrawing() { - beginDrawing() -} - -// EndDrawing - End canvas drawing and swap buffers (double buffering) -func EndDrawing() { - endDrawing() -} - -// BeginMode2D - Begin 2D mode with custom camera (2D) -func BeginMode2D(camera Camera2D) { - beginMode2D(uintptr(unsafe.Pointer(&camera))) -} - -// EndMode2D - Ends 2D mode with custom camera -func EndMode2D() { - endMode2D() -} - -// BeginMode3D - Begin 3D mode with custom camera (3D) -func BeginMode3D(camera Camera3D) { - beginMode3D(uintptr(unsafe.Pointer(&camera))) -} - -// EndMode3D - Ends 3D mode and returns to default 2D orthographic mode -func EndMode3D() { - endMode3D() -} - -// BeginTextureMode - Begin drawing to render texture -func BeginTextureMode(target RenderTexture2D) { - beginTextureMode(uintptr(unsafe.Pointer(&target))) -} - -// EndTextureMode - Ends drawing to render texture -func EndTextureMode() { - endTextureMode() -} - -// BeginShaderMode - Begin custom shader drawing -func BeginShaderMode(shader Shader) { - beginShaderMode(uintptr(unsafe.Pointer(&shader))) -} - -// EndShaderMode - End custom shader drawing (use default shader) -func EndShaderMode() { - endShaderMode() -} - -// BeginBlendMode - Begin blending mode (alpha, additive, multiplied, subtract, custom) -func BeginBlendMode(mode BlendMode) { - beginBlendMode(int32(mode)) -} - -// EndBlendMode - End blending mode (reset to default: alpha blending) -func EndBlendMode() { - endBlendMode() -} - -// BeginScissorMode - Begin scissor mode (define screen area for following drawing) -func BeginScissorMode(x int32, y int32, width int32, height int32) { - beginScissorMode(x, y, width, height) -} - -// EndScissorMode - End scissor mode -func EndScissorMode() { - endScissorMode() -} - -// BeginVrStereoMode - Begin stereo rendering (requires VR simulator) -func BeginVrStereoMode(config VrStereoConfig) { - beginVrStereoMode(uintptr(unsafe.Pointer(&config))) -} - -// EndVrStereoMode - End stereo rendering (requires VR simulator) -func EndVrStereoMode() { - endVrStereoMode() -} - -// LoadVrStereoConfig - Load VR stereo config for VR simulator device parameters -func LoadVrStereoConfig(device VrDeviceInfo) VrStereoConfig { - var config VrStereoConfig - loadVrStereoConfig(uintptr(unsafe.Pointer(&config)), uintptr(unsafe.Pointer(&device))) - return config -} - -// UnloadVrStereoConfig - Unload VR stereo config -func UnloadVrStereoConfig(config VrStereoConfig) { - unloadVrStereoConfig(uintptr(unsafe.Pointer(&config))) -} - -// LoadShader - Load shader from files and bind default locations -func LoadShader(vsFileName string, fsFileName string) Shader { - var shader Shader - var cvsFileName, cfsFileName *byte - if vsFileName != "" { - var err error - cvsFileName, err = windows.BytePtrFromString(vsFileName) - if err != nil { - panic(err) - } - } - if fsFileName != "" { - var err error - cfsFileName, err = windows.BytePtrFromString(fsFileName) - if err != nil { - panic(err) - } - } - loadShader(uintptr(unsafe.Pointer(&shader)), uintptr(unsafe.Pointer(cvsFileName)), uintptr(unsafe.Pointer(cfsFileName))) - return shader -} - -// LoadShaderFromMemory - Load shader from code strings and bind default locations -func LoadShaderFromMemory(vsCode string, fsCode string) Shader { - var shader Shader - var cvsCode, cfsCode *byte - if vsCode != "" { - var err error - cvsCode, err = windows.BytePtrFromString(vsCode) - if err != nil { - panic(err) - } - } - if fsCode != "" { - var err error - cfsCode, err = windows.BytePtrFromString(fsCode) - if err != nil { - panic(err) - } - } - loadShaderFromMemory(uintptr(unsafe.Pointer(&shader)), uintptr(unsafe.Pointer(cvsCode)), uintptr(unsafe.Pointer(cfsCode))) - return shader -} - -// IsShaderValid - Check if a shader is valid (loaded on GPU) -func IsShaderValid(shader Shader) bool { - return isShaderValid(uintptr(unsafe.Pointer(&shader))) -} - -// GetShaderLocation - Get shader uniform location -func GetShaderLocation(shader Shader, uniformName string) int32 { - return getShaderLocation(uintptr(unsafe.Pointer(&shader)), uniformName) -} - -// GetShaderLocationAttrib - Get shader attribute location -func GetShaderLocationAttrib(shader Shader, attribName string) int32 { - return getShaderLocationAttrib(uintptr(unsafe.Pointer(&shader)), attribName) -} - -// SetShaderValue - Set shader uniform value -func SetShaderValue(shader Shader, locIndex int32, value []float32, uniformType ShaderUniformDataType) { - setShaderValue(uintptr(unsafe.Pointer(&shader)), locIndex, value, int32(uniformType)) -} - -// SetShaderValueV - Set shader uniform value vector -func SetShaderValueV(shader Shader, locIndex int32, value []float32, uniformType ShaderUniformDataType, count int32) { - setShaderValueV(uintptr(unsafe.Pointer(&shader)), locIndex, value, int32(uniformType), count) -} - -// SetShaderValueMatrix - Set shader uniform value (matrix 4x4) -func SetShaderValueMatrix(shader Shader, locIndex int32, mat Matrix) { - setShaderValueMatrix(uintptr(unsafe.Pointer(&shader)), locIndex, uintptr(unsafe.Pointer(&mat))) -} - -// SetShaderValueTexture - Set shader uniform value for texture (sampler2d) -func SetShaderValueTexture(shader Shader, locIndex int32, texture Texture2D) { - setShaderValueTexture(uintptr(unsafe.Pointer(&shader)), locIndex, uintptr(unsafe.Pointer(&texture))) -} - -// UnloadShader - Unload shader from GPU memory (VRAM) -func UnloadShader(shader Shader) { - unloadShader(uintptr(unsafe.Pointer(&shader))) -} - -// GetMouseRay - Get a ray trace from mouse position -// -// Deprecated: Use [GetScreenToWorldRay] instead. -func GetMouseRay(mousePosition Vector2, camera Camera) Ray { - return GetScreenToWorldRay(mousePosition, camera) -} - -// GetScreenToWorldRay - Get a ray trace from screen position (i.e mouse) -func GetScreenToWorldRay(position Vector2, camera Camera) Ray { - var ray Ray - getScreenToWorldRay(uintptr(unsafe.Pointer(&ray)), *(*uintptr)(unsafe.Pointer(&position)), uintptr(unsafe.Pointer(&camera))) - return ray -} - -// GetScreenToWorldRayEx - Get a ray trace from screen position (i.e mouse) in a viewport -func GetScreenToWorldRayEx(position Vector2, camera Camera, width, height int32) Ray { - var ray Ray - getScreenToWorldRayEx(uintptr(unsafe.Pointer(&ray)), *(*uintptr)(unsafe.Pointer(&position)), uintptr(unsafe.Pointer(&camera)), width, height) - return ray -} - -// GetCameraMatrix - Get camera transform matrix (view matrix) -func GetCameraMatrix(camera Camera) Matrix { - var mat Matrix - getCameraMatrix(uintptr(unsafe.Pointer(&mat)), uintptr(unsafe.Pointer(&camera))) - return mat -} - -// GetCameraMatrix2D - Get camera 2d transform matrix -func GetCameraMatrix2D(camera Camera2D) Matrix { - var mat Matrix - getCameraMatrix2D(uintptr(unsafe.Pointer(&mat)), uintptr(unsafe.Pointer(&camera))) - return mat -} - -// GetWorldToScreen - Get the screen space position for a 3d world space position -func GetWorldToScreen(position Vector3, camera Camera) Vector2 { - ret := getWorldToScreen(uintptr(unsafe.Pointer(&position)), uintptr(unsafe.Pointer(&camera))) - return *(*Vector2)(unsafe.Pointer(&ret)) -} - -// GetScreenToWorld2D - Get the world space position for a 2d camera screen space position -func GetScreenToWorld2D(position Vector2, camera Camera2D) Vector2 { - ret := getScreenToWorld2D(*(*uintptr)(unsafe.Pointer(&position)), uintptr(unsafe.Pointer(&camera))) - return *(*Vector2)(unsafe.Pointer(&ret)) -} - -// GetWorldToScreenEx - Get size position for a 3d world space position -func GetWorldToScreenEx(position Vector3, camera Camera, width int32, height int32) Vector2 { - ret := getWorldToScreenEx(uintptr(unsafe.Pointer(&position)), uintptr(unsafe.Pointer(&camera)), width, height) - return *(*Vector2)(unsafe.Pointer(&ret)) -} - -// GetWorldToScreen2D - Get the screen space position for a 2d camera world space position -func GetWorldToScreen2D(position Vector2, camera Camera2D) Vector2 { - ret := getWorldToScreen2D(*(*uintptr)(unsafe.Pointer(&position)), uintptr(unsafe.Pointer(&camera))) - return *(*Vector2)(unsafe.Pointer(&ret)) -} - -// SetTargetFPS - Set target FPS (maximum) -func SetTargetFPS(fps int32) { - setTargetFPS(fps) -} - -// GetFrameTime - Get time in seconds for last frame drawn (delta time) -func GetFrameTime() float32 { - return getFrameTime() -} - -// GetTime - Get elapsed time in seconds since InitWindow() -func GetTime() float64 { - return getTime() -} - -// GetFPS - Get current FPS -func GetFPS() int32 { - return getFPS() -} - -// Custom frame control functions -// NOTE: SwapScreenBuffer and PollInputEvents are intended for advanced users that want full control over the frame processing -// By default EndDrawing() does this job: draws everything + SwapScreenBuffer() + manage frame timing + PollInputEvents() -// To avoid that behaviour and control frame processes manually you must recompile raylib with SUPPORT_CUSTOM_FRAME_CONTROL enabled in config.h - -// SwapScreenBuffer - Swap back buffer with front buffer (screen drawing) -func SwapScreenBuffer() { - swapScreenBuffer() -} - -// PollInputEvents - Register all input events -func PollInputEvents() { - pollInputEvents() -} - -// WaitTime - Wait for some time (halt program execution) -func WaitTime(seconds float64) { - waitTime(seconds) -} - -// SetRandomSeed - Set the seed for the random number generator -// -// Note: You can use go's math/rand package instead -func SetRandomSeed(seed uint32) { - setRandomSeed(seed) -} - -// GetRandomValue - Get a random value between min and max (both included) -// -// Note: You can use go's math/rand package instead -func GetRandomValue(minimum int32, maximum int32) int32 { - return getRandomValue(minimum, maximum) -} - -// LoadRandomSequence - Load random values sequence, no values repeated -// -// Note: Use UnloadRandomSequence if you don't need the sequence any more. You can use go's math/rand.Perm function instead. -func LoadRandomSequence(count uint32, minimum int32, maximum int32) []int32 { - ret := loadRandomSequence(count, minimum, maximum) - return unsafe.Slice(ret, 10) -} - -// UnloadRandomSequence - Unload random values sequence -func UnloadRandomSequence(sequence []int32) { - unloadRandomSequence(unsafe.SliceData(sequence)) -} - -// TakeScreenshot - Takes a screenshot of current screen (filename extension defines format) -func TakeScreenshot(fileName string) { - takeScreenshot(fileName) -} - -// SetConfigFlags - Setup init configuration flags (view FLAGS) -func SetConfigFlags(flags uint32) { - setConfigFlags(flags) -} - -// OpenURL - Open URL with default system browser (if available) -func OpenURL(url string) { - openURL(url) -} - -// TraceLog - Show trace log messages (LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR...) -func TraceLog(logLevel TraceLogLevel, text string, args ...any) { - traceLog(int32(logLevel), fmt.Sprintf(text, args...)) -} - -// SetTraceLogLevel - Set the current threshold (minimum) log level -func SetTraceLogLevel(logLevel TraceLogLevel) { - setTraceLogLevel(int32(logLevel)) -} - -// MemAlloc - Internal memory allocator -func MemAlloc(size uint32) unsafe.Pointer { - return memAlloc(size) -} - -// MemRealloc - Internal memory reallocator -func MemRealloc(ptr unsafe.Pointer, size uint32) unsafe.Pointer { - return memRealloc(ptr, size) -} - -// MemFree - Internal memory free -func MemFree(ptr unsafe.Pointer) { - memFree(ptr) -} - - -// IsFileDropped - Check if a file has been dropped into window -func IsFileDropped() bool { - return isFileDropped() -} - -// LoadDroppedFiles - Load dropped filepaths -func LoadDroppedFiles() []string { - var filePathList = struct { - capacity uint32 - count uint32 - paths **byte - }{} - loadDroppedFiles(uintptr(unsafe.Pointer(&filePathList))) - defer unloadDroppedFiles(uintptr(unsafe.Pointer(&filePathList))) - - tmpslice := (*[1 << 24]*byte)(unsafe.Pointer(filePathList.paths))[:filePathList.count:filePathList.count] - - gostrings := make([]string, filePathList.count) - for i, s := range tmpslice { - gostrings[i] = func(p *byte) string { - if p == nil || *p == 0 { - return "" - } - - n := 0 - for ptr := unsafe.Pointer(p); *(*byte)(ptr) != 0; n++ { - ptr = unsafe.Pointer(uintptr(ptr) + 1) - } - - return string(unsafe.Slice(p, n)) - }(s) - } - - return gostrings -} - -// UnloadDroppedFiles - Unload dropped filepaths -func UnloadDroppedFiles() {} - -// LoadAutomationEventList - Load automation events list from file, NULL for empty list, capacity = MAX_AUTOMATION_EVENTS -func LoadAutomationEventList(fileName string) AutomationEventList { - var automationEventList AutomationEventList - loadAutomationEventList(uintptr(unsafe.Pointer(&automationEventList)), fileName) - return automationEventList -} - -// UnloadAutomationEventList - Unload automation events list from file -func UnloadAutomationEventList(list *AutomationEventList) { - unloadAutomationEventList(uintptr(unsafe.Pointer(&list))) -} - -// ExportAutomationEventList - Export automation events list as text file -func ExportAutomationEventList(list AutomationEventList, fileName string) bool { - return exportAutomationEventList(uintptr(unsafe.Pointer(&list)), fileName) -} - -// SetAutomationEventList - Set automation event list to record to -func SetAutomationEventList(list *AutomationEventList) { - setAutomationEventList(uintptr(unsafe.Pointer(&list))) -} - -// SetAutomationEventBaseFrame - Set automation event internal base frame to start recording -func SetAutomationEventBaseFrame(frame int) { - setAutomationEventBaseFrame(int32(frame)) -} - -// StartAutomationEventRecording - Start recording automation events (AutomationEventList must be set) -func StartAutomationEventRecording() { - startAutomationEventRecording() -} - -// StopAutomationEventRecording - Stop recording automation events -func StopAutomationEventRecording() { - stopAutomationEventRecording() -} - -// PlayAutomationEvent - Play a recorded automation event -func PlayAutomationEvent(event AutomationEvent) { - playAutomationEvent(uintptr(unsafe.Pointer(&event))) -} - -// IsKeyPressed - Check if a key has been pressed once -func IsKeyPressed(key int32) bool { - return isKeyPressed(key) -} - -// IsKeyPressedRepeat - Check if a key has been pressed again (Only PLATFORM_DESKTOP) -func IsKeyPressedRepeat(key int32) bool { - return isKeyPressedRepeat(key) -} - -// IsKeyDown - Check if a key is being pressed -func IsKeyDown(key int32) bool { - return isKeyDown(key) -} - -// IsKeyReleased - Check if a key has been released once -func IsKeyReleased(key int32) bool { - return isKeyReleased(key) -} - -// IsKeyUp - Check if a key is NOT being pressed -func IsKeyUp(key int32) bool { - return isKeyUp(key) -} - -// GetKeyPressed - Get key pressed (keycode), call it multiple times for keys queued, returns 0 when the queue is empty -func GetKeyPressed() int32 { - return getKeyPressed() -} - -// GetCharPressed - Get char pressed (unicode), call it multiple times for chars queued, returns 0 when the queue is empty -func GetCharPressed() int32 { - return getCharPressed() -} - -// SetExitKey - Set a custom key to exit program (default is ESC) -func SetExitKey(key int32) { - setExitKey(key) -} - -// IsGamepadAvailable - Check if a gamepad is available -func IsGamepadAvailable(gamepad int32) bool { - return isGamepadAvailable(gamepad) -} - -// GetGamepadName - Get gamepad internal name id -func GetGamepadName(gamepad int32) string { - return getGamepadName(gamepad) -} - -// IsGamepadButtonPressed - Check if a gamepad button has been pressed once -func IsGamepadButtonPressed(gamepad int32, button int32) bool { - return isGamepadButtonPressed(gamepad, button) -} - -// IsGamepadButtonDown - Check if a gamepad button is being pressed -func IsGamepadButtonDown(gamepad int32, button int32) bool { - return isGamepadButtonDown(gamepad, button) -} - -// IsGamepadButtonReleased - Check if a gamepad button has been released once -func IsGamepadButtonReleased(gamepad int32, button int32) bool { - return isGamepadButtonReleased(gamepad, button) -} - -// IsGamepadButtonUp - Check if a gamepad button is NOT being pressed -func IsGamepadButtonUp(gamepad int32, button int32) bool { - return isGamepadButtonUp(gamepad, button) -} - -// GetGamepadButtonPressed - Get the last gamepad button pressed -func GetGamepadButtonPressed() int32 { - return getGamepadButtonPressed() -} - -// GetGamepadAxisCount - Get gamepad axis count for a gamepad -func GetGamepadAxisCount(gamepad int32) int32 { - return getGamepadAxisCount(gamepad) -} - -// GetGamepadAxisMovement - Get axis movement value for a gamepad axis -func GetGamepadAxisMovement(gamepad int32, axis int32) float32 { - return getGamepadAxisMovement(gamepad, axis) -} - -// SetGamepadMappings - Set internal gamepad mappings (SDL_GameControllerDB) -func SetGamepadMappings(mappings string) int32 { - return setGamepadMappings(mappings) -} - -// SetGamepadVibration - Set gamepad vibration for both motors (duration in seconds) -func SetGamepadVibration(gamepad int32, leftMotor, rightMotor, duration float32) { - setGamepadVibration(gamepad, leftMotor, rightMotor, duration) -} - -// IsMouseButtonPressed - Check if a mouse button has been pressed once -func IsMouseButtonPressed(button MouseButton) bool { - return isMouseButtonPressed(int32(button)) -} - -// IsMouseButtonDown - Check if a mouse button is being pressed -func IsMouseButtonDown(button MouseButton) bool { - return isMouseButtonDown(int32(button)) -} - -// IsMouseButtonReleased - Check if a mouse button has been released once -func IsMouseButtonReleased(button MouseButton) bool { - return isMouseButtonReleased(int32(button)) -} - -// IsMouseButtonUp - Check if a mouse button is NOT being pressed -func IsMouseButtonUp(button MouseButton) bool { - return isMouseButtonUp(int32(button)) -} - -// GetMouseX - Get mouse position X -func GetMouseX() int32 { - return getMouseX() -} - -// GetMouseY - Get mouse position Y -func GetMouseY() int32 { - return getMouseY() -} - -// GetMousePosition - Get mouse position XY -func GetMousePosition() Vector2 { - ret := getMousePosition() - return *(*Vector2)(unsafe.Pointer(&ret)) -} - -// GetMouseDelta - Get mouse delta between frames -func GetMouseDelta() Vector2 { - ret := getMouseDelta() - return *(*Vector2)(unsafe.Pointer(&ret)) -} - -// SetMousePosition - Set mouse position XY -func SetMousePosition(x int32, y int32) { - setMousePosition(x, y) -} - -// SetMouseOffset - Set mouse offset -func SetMouseOffset(offsetX int32, offsetY int32) { - setMouseOffset(offsetX, offsetY) -} - -// SetMouseScale - Set mouse scaling -func SetMouseScale(scaleX float32, scaleY float32) { - setMouseScale(scaleX, scaleY) -} - -// GetMouseWheelMove - Get mouse wheel movement for X or Y, whichever is larger -func GetMouseWheelMove() float32 { - return getMouseWheelMove() -} - -// GetMouseWheelMoveV - Get mouse wheel movement for both X and Y -func GetMouseWheelMoveV() Vector2 { - ret := getMouseWheelMoveV() - return *(*Vector2)(unsafe.Pointer(&ret)) -} - -// SetMouseCursor - Set mouse cursor -func SetMouseCursor(cursor int32) { - setMouseCursor(cursor) -} - -// GetTouchX - Get touch position X for touch point 0 (relative to screen size) -func GetTouchX() int32 { - return getTouchX() -} - -// GetTouchY - Get touch position Y for touch point 0 (relative to screen size) -func GetTouchY() int32 { - return getTouchY() -} - -// GetTouchPosition - Get touch position XY for a touch point index (relative to screen size) -func GetTouchPosition(index int32) Vector2 { - ret := getTouchPosition(index) - return *(*Vector2)(unsafe.Pointer(&ret)) -} - -// GetTouchPointId - Get touch point identifier for given index -func GetTouchPointId(index int32) int32 { - return getTouchPointId(index) -} - -// GetTouchPointCount - Get number of touch points -func GetTouchPointCount() int32 { - return getTouchPointCount() -} - -// SetGesturesEnabled - Enable a set of gestures using flags -func SetGesturesEnabled(flags uint32) { - setGesturesEnabled(flags) -} - -// IsGestureDetected - Check if a gesture have been detected -func IsGestureDetected(gesture Gestures) bool { - return isGestureDetected(uint32(gesture)) -} - -// GetGestureDetected - Get latest detected gesture -func GetGestureDetected() Gestures { - return Gestures(getGestureDetected()) -} - -// GetGestureHoldDuration - Get gesture hold time in milliseconds -func GetGestureHoldDuration() float32 { - return getGestureHoldDuration() -} - -// GetGestureDragVector - Get gesture drag vector -func GetGestureDragVector() Vector2 { - ret := getGestureDragVector() - return *(*Vector2)(unsafe.Pointer(&ret)) -} - -// GetGestureDragAngle - Get gesture drag angle -func GetGestureDragAngle() float32 { - return getGestureDragAngle() -} - -// GetGesturePinchVector - Get gesture pinch delta -func GetGesturePinchVector() Vector2 { - ret := getGesturePinchVector() - return *(*Vector2)(unsafe.Pointer(&ret)) -} - -// GetGesturePinchAngle - Get gesture pinch angle -func GetGesturePinchAngle() float32 { - return getGesturePinchAngle() -} - -// SetShapesTexture - Set texture and rectangle to be used on shapes drawing -func SetShapesTexture(texture Texture2D, source Rectangle) { - setShapesTexture(uintptr(unsafe.Pointer(&texture)), uintptr(unsafe.Pointer(&source))) -} - -// GetShapesTexture - Get texture that is used for shapes drawing -func GetShapesTexture() Texture2D { - var texture Texture2D - getShapesTexture(uintptr(unsafe.Pointer(&texture))) - return texture -} - -// GetShapesTextureRectangle - Get texture source rectangle that is used for shapes drawing -func GetShapesTextureRectangle() Rectangle { - var rec Rectangle - getShapesTextureRectangle(uintptr(unsafe.Pointer(&rec))) - return rec -} - -// DrawPixel - Draw a pixel -func DrawPixel(posX int32, posY int32, col color.RGBA) { - drawPixel(posX, posY, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawPixelV - Draw a pixel (Vector version) -func DrawPixelV(position Vector2, col color.RGBA) { - drawPixelV(*(*uintptr)(unsafe.Pointer(&position)), *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawLine - Draw a line -func DrawLine(startPosX int32, startPosY int32, endPosX int32, endPosY int32, col color.RGBA) { - drawLine(startPosX, startPosY, endPosX, endPosY, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawLineV - Draw a line (using gl lines) -func DrawLineV(startPos Vector2, endPos Vector2, col color.RGBA) { - drawLineV(*(*uintptr)(unsafe.Pointer(&startPos)), *(*uintptr)(unsafe.Pointer(&endPos)), *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawLineEx - Draw a line (using triangles/quads) -func DrawLineEx(startPos Vector2, endPos Vector2, thick float32, col color.RGBA) { - drawLineEx(*(*uintptr)(unsafe.Pointer(&startPos)), *(*uintptr)(unsafe.Pointer(&endPos)), thick, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawLineStrip - Draw lines sequence (using gl lines) -func DrawLineStrip(points []Vector2, col color.RGBA) { - pointCount := int32(len(points)) - drawLineStrip((unsafe.SliceData(points)), pointCount, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawLineBezier - Draw line segment cubic-bezier in-out interpolation -func DrawLineBezier(startPos Vector2, endPos Vector2, thick float32, col color.RGBA) { - drawLineBezier(*(*uintptr)(unsafe.Pointer(&startPos)), *(*uintptr)(unsafe.Pointer(&endPos)), thick, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawCircle - Draw a color-filled circle -func DrawCircle(centerX int32, centerY int32, radius float32, col color.RGBA) { - drawCircle(centerX, centerY, radius, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawCircleSector - Draw a piece of a circle -func DrawCircleSector(center Vector2, radius float32, startAngle float32, endAngle float32, segments int32, col color.RGBA) { - drawCircleSector(*(*uintptr)(unsafe.Pointer(¢er)), radius, startAngle, endAngle, segments, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawCircleSectorLines - Draw circle sector outline -func DrawCircleSectorLines(center Vector2, radius float32, startAngle float32, endAngle float32, segments int32, col color.RGBA) { - drawCircleSectorLines(*(*uintptr)(unsafe.Pointer(¢er)), radius, startAngle, endAngle, segments, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawCircleGradient - Draw a gradient-filled circle -func DrawCircleGradient(centerX int32, centerY int32, radius float32, inner color.RGBA, outer color.RGBA) { - drawCircleGradient(centerX, centerY, radius, *(*uintptr)(unsafe.Pointer(&inner)), *(*uintptr)(unsafe.Pointer(&outer))) -} - -// DrawCircleV - Draw a color-filled circle (Vector version) -func DrawCircleV(center Vector2, radius float32, col color.RGBA) { - drawCircleV(*(*uintptr)(unsafe.Pointer(¢er)), radius, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawCircleLines - Draw circle outline -func DrawCircleLines(centerX int32, centerY int32, radius float32, col color.RGBA) { - drawCircleLines(centerX, centerY, radius, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawCircleLinesV - Draw circle outline (Vector version) -func DrawCircleLinesV(center Vector2, radius float32, col color.RGBA) { - drawCircleLinesV(*(*uintptr)(unsafe.Pointer(¢er)), radius, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawEllipse - Draw ellipse -func DrawEllipse(centerX int32, centerY int32, radiusH float32, radiusV float32, col color.RGBA) { - drawEllipse(centerX, centerY, radiusH, radiusV, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawEllipseLines - Draw ellipse outline -func DrawEllipseLines(centerX int32, centerY int32, radiusH float32, radiusV float32, col color.RGBA) { - drawEllipseLines(centerX, centerY, radiusH, radiusV, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawRing - Draw ring -func DrawRing(center Vector2, innerRadius float32, outerRadius float32, startAngle float32, endAngle float32, segments int32, col color.RGBA) { - drawRing(*(*uintptr)(unsafe.Pointer(¢er)), innerRadius, outerRadius, startAngle, endAngle, segments, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawRingLines - Draw ring outline -func DrawRingLines(center Vector2, innerRadius float32, outerRadius float32, startAngle float32, endAngle float32, segments int32, col color.RGBA) { - drawRingLines(*(*uintptr)(unsafe.Pointer(¢er)), innerRadius, outerRadius, startAngle, endAngle, segments, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawRectangle - Draw a color-filled rectangle -func DrawRectangle(posX int32, posY int32, width int32, height int32, col color.RGBA) { - drawRectangle(posX, posY, width, height, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawRectangleV - Draw a color-filled rectangle (Vector version) -func DrawRectangleV(position Vector2, size Vector2, col color.RGBA) { - drawRectangleV(*(*uintptr)(unsafe.Pointer(&position)), *(*uintptr)(unsafe.Pointer(&size)), *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawRectangleRec - Draw a color-filled rectangle -func DrawRectangleRec(rec Rectangle, col color.RGBA) { - drawRectangleRec(uintptr(unsafe.Pointer(&rec)), *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawRectanglePro - Draw a color-filled rectangle with pro parameters -func DrawRectanglePro(rec Rectangle, origin Vector2, rotation float32, col color.RGBA) { - drawRectanglePro(uintptr(unsafe.Pointer(&rec)), *(*uintptr)(unsafe.Pointer(&origin)), rotation, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawRectangleGradientV - Draw a vertical-gradient-filled rectangle -func DrawRectangleGradientV(posX int32, posY int32, width int32, height int32, top color.RGBA, bottom color.RGBA) { - drawRectangleGradientV(posX, posY, width, height, *(*uintptr)(unsafe.Pointer(&top)), *(*uintptr)(unsafe.Pointer(&bottom))) -} - -// DrawRectangleGradientH - Draw a horizontal-gradient-filled rectangle -func DrawRectangleGradientH(posX int32, posY int32, width int32, height int32, left color.RGBA, right color.RGBA) { - drawRectangleGradientH(posX, posY, width, height, *(*uintptr)(unsafe.Pointer(&left)), *(*uintptr)(unsafe.Pointer(&right))) -} - -// DrawRectangleGradientEx - Draw a gradient-filled rectangle with custom vertex colors -func DrawRectangleGradientEx(rec Rectangle, topLeft color.RGBA, bottomLeft color.RGBA, topRight color.RGBA, bottomRight color.RGBA) { - drawRectangleGradientEx(uintptr(unsafe.Pointer(&rec)), *(*uintptr)(unsafe.Pointer(&topLeft)), *(*uintptr)(unsafe.Pointer(&bottomLeft)), *(*uintptr)(unsafe.Pointer(&topRight)), *(*uintptr)(unsafe.Pointer(&bottomRight))) -} - -// DrawRectangleLines - Draw rectangle outline -func DrawRectangleLines(posX int32, posY int32, width int32, height int32, col color.RGBA) { - drawRectangleLines(posX, posY, width, height, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawRectangleLinesEx - Draw rectangle outline with extended parameters -func DrawRectangleLinesEx(rec Rectangle, lineThick float32, col color.RGBA) { - drawRectangleLinesEx(uintptr(unsafe.Pointer(&rec)), lineThick, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawRectangleRounded - Draw rectangle with rounded edges -func DrawRectangleRounded(rec Rectangle, roundness float32, segments int32, col color.RGBA) { - drawRectangleRounded(uintptr(unsafe.Pointer(&rec)), roundness, segments, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawRectangleRoundedLines - Draw rectangle lines with rounded edges -func DrawRectangleRoundedLines(rec Rectangle, roundness float32, segments int32, col color.RGBA) { - drawRectangleRoundedLines(uintptr(unsafe.Pointer(&rec)), roundness, segments, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawRectangleRoundedLinesEx - Draw rectangle with rounded edges outline -func DrawRectangleRoundedLinesEx(rec Rectangle, roundness float32, segments int32, lineThick float32, col color.RGBA) { - drawRectangleRoundedLinesEx(uintptr(unsafe.Pointer(&rec)), roundness, segments, lineThick, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawTriangle - Draw a color-filled triangle (vertex in counter-clockwise order!) -func DrawTriangle(v1 Vector2, v2 Vector2, v3 Vector2, col color.RGBA) { - drawTriangle(*(*uintptr)(unsafe.Pointer(&v1)), *(*uintptr)(unsafe.Pointer(&v2)), *(*uintptr)(unsafe.Pointer(&v3)), *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawTriangleLines - Draw triangle outline (vertex in counter-clockwise order!) -func DrawTriangleLines(v1 Vector2, v2 Vector2, v3 Vector2, col color.RGBA) { - drawTriangleLines(*(*uintptr)(unsafe.Pointer(&v1)), *(*uintptr)(unsafe.Pointer(&v2)), *(*uintptr)(unsafe.Pointer(&v3)), *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawTriangleFan - Draw a triangle fan defined by points (first vertex is the center) -func DrawTriangleFan(points []Vector2, col color.RGBA) { - pointCount := int32(len(points)) - drawTriangleFan(unsafe.SliceData(points), pointCount, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawTriangleStrip - Draw a triangle strip defined by points -func DrawTriangleStrip(points []Vector2, col color.RGBA) { - pointCount := int32(len(points)) - drawTriangleStrip(unsafe.SliceData(points), pointCount, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawPoly - Draw a regular polygon (Vector version) -func DrawPoly(center Vector2, sides int32, radius float32, rotation float32, col color.RGBA) { - drawPoly(*(*uintptr)(unsafe.Pointer(¢er)), sides, radius, rotation, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawPolyLines - Draw a polygon outline of n sides -func DrawPolyLines(center Vector2, sides int32, radius float32, rotation float32, col color.RGBA) { - drawPolyLines(*(*uintptr)(unsafe.Pointer(¢er)), sides, radius, rotation, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawPolyLinesEx - Draw a polygon outline of n sides with extended parameters -func DrawPolyLinesEx(center Vector2, sides int32, radius float32, rotation float32, lineThick float32, col color.RGBA) { - drawPolyLinesEx(*(*uintptr)(unsafe.Pointer(¢er)), sides, radius, rotation, lineThick, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawSplineLinear - Draw spline: Linear, minimum 2 points -func DrawSplineLinear(points []Vector2, thick float32, col color.RGBA) { - pointCount := int32(len(points)) - drawSplineLinear(unsafe.SliceData(points), pointCount, thick, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawSplineBasis - Draw spline: B-Spline, minimum 4 points -func DrawSplineBasis(points []Vector2, thick float32, col color.RGBA) { - pointCount := int32(len(points)) - drawSplineBasis(unsafe.SliceData(points), pointCount, thick, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawSplineCatmullRom - Draw spline: Catmull-Rom, minimum 4 points -func DrawSplineCatmullRom(points []Vector2, thick float32, col color.RGBA) { - pointCount := int32(len(points)) - drawSplineCatmullRom(unsafe.SliceData(points), pointCount, thick, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawSplineBezierQuadratic - Draw spline: Quadratic Bezier, minimum 3 points (1 control point): [p1, c2, p3, c4...] -func DrawSplineBezierQuadratic(points []Vector2, thick float32, col color.RGBA) { - pointCount := int32(len(points)) - drawSplineBezierQuadratic(unsafe.SliceData(points), pointCount, thick, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawSplineBezierCubic - Draw spline: Cubic Bezier, minimum 4 points (2 control points): [p1, c2, c3, p4, c5, c6...] -func DrawSplineBezierCubic(points []Vector2, thick float32, col color.RGBA) { - pointCount := int32(len(points)) - drawSplineBezierCubic(unsafe.SliceData(points), pointCount, thick, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawSplineSegmentLinear - Draw spline segment: Linear, 2 points -func DrawSplineSegmentLinear(p1 Vector2, p2 Vector2, thick float32, col color.RGBA) { - drawSplineSegmentLinear(*(*uintptr)(unsafe.Pointer(&p1)), *(*uintptr)(unsafe.Pointer(&p2)), thick, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawSplineSegmentBasis - Draw spline segment: B-Spline, 4 points -func DrawSplineSegmentBasis(p1 Vector2, p2 Vector2, p3 Vector2, p4 Vector2, thick float32, col color.RGBA) { - drawSplineSegmentBasis(*(*uintptr)(unsafe.Pointer(&p1)), *(*uintptr)(unsafe.Pointer(&p2)), *(*uintptr)(unsafe.Pointer(&p3)), *(*uintptr)(unsafe.Pointer(&p4)), thick, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawSplineSegmentCatmullRom - Draw spline segment: Catmull-Rom, 4 points -func DrawSplineSegmentCatmullRom(p1 Vector2, p2 Vector2, p3 Vector2, p4 Vector2, thick float32, col color.RGBA) { - drawSplineSegmentCatmullRom(*(*uintptr)(unsafe.Pointer(&p1)), *(*uintptr)(unsafe.Pointer(&p2)), *(*uintptr)(unsafe.Pointer(&p3)), *(*uintptr)(unsafe.Pointer(&p4)), thick, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawSplineSegmentBezierQuadratic - Draw spline segment: Quadratic Bezier, 2 points, 1 control point -func DrawSplineSegmentBezierQuadratic(p1 Vector2, c2 Vector2, p3 Vector2, thick float32, col color.RGBA) { - drawSplineSegmentBezierQuadratic(*(*uintptr)(unsafe.Pointer(&p1)), *(*uintptr)(unsafe.Pointer(&c2)), *(*uintptr)(unsafe.Pointer(&p3)), thick, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawSplineSegmentBezierCubic - Draw spline segment: Cubic Bezier, 2 points, 2 control points -func DrawSplineSegmentBezierCubic(p1 Vector2, c2 Vector2, c3 Vector2, p4 Vector2, thick float32, col color.RGBA) { - drawSplineSegmentBezierCubic(*(*uintptr)(unsafe.Pointer(&p1)), *(*uintptr)(unsafe.Pointer(&c2)), *(*uintptr)(unsafe.Pointer(&c3)), *(*uintptr)(unsafe.Pointer(&p4)), thick, *(*uintptr)(unsafe.Pointer(&col))) -} - -// GetSplinePointLinear - Get (evaluate) spline point: Linear -func GetSplinePointLinear(startPos Vector2, endPos Vector2, t float32) Vector2 { - ret := getSplinePointLinear(*(*uintptr)(unsafe.Pointer(&startPos)), *(*uintptr)(unsafe.Pointer(&endPos)), t) - return *(*Vector2)(unsafe.Pointer(&ret)) -} - -// GetSplinePointBasis - Get (evaluate) spline point: B-Spline -func GetSplinePointBasis(p1 Vector2, p2 Vector2, p3 Vector2, p4 Vector2, t float32) Vector2 { - ret := getSplinePointBasis(*(*uintptr)(unsafe.Pointer(&p1)), *(*uintptr)(unsafe.Pointer(&p2)), *(*uintptr)(unsafe.Pointer(&p3)), *(*uintptr)(unsafe.Pointer(&p4)), t) - return *(*Vector2)(unsafe.Pointer(&ret)) -} - -// GetSplinePointCatmullRom - Get (evaluate) spline point: Catmull-Rom -func GetSplinePointCatmullRom(p1 Vector2, p2 Vector2, p3 Vector2, p4 Vector2, t float32) Vector2 { - ret := getSplinePointCatmullRom(*(*uintptr)(unsafe.Pointer(&p1)), *(*uintptr)(unsafe.Pointer(&p2)), *(*uintptr)(unsafe.Pointer(&p3)), *(*uintptr)(unsafe.Pointer(&p4)), t) - return *(*Vector2)(unsafe.Pointer(&ret)) -} - -// GetSplinePointBezierQuad - Get (evaluate) spline point: Quadratic Bezier -func GetSplinePointBezierQuad(p1 Vector2, c2 Vector2, p3 Vector2, t float32) Vector2 { - ret := getSplinePointBezierQuad(*(*uintptr)(unsafe.Pointer(&p1)), *(*uintptr)(unsafe.Pointer(&c2)), *(*uintptr)(unsafe.Pointer(&p3)), t) - return *(*Vector2)(unsafe.Pointer(&ret)) -} - -// GetSplinePointBezierCubic - Get (evaluate) spline point: Cubic Bezier -func GetSplinePointBezierCubic(p1 Vector2, c2 Vector2, c3 Vector2, p4 Vector2, t float32) Vector2 { - ret := getSplinePointBezierCubic(*(*uintptr)(unsafe.Pointer(&p1)), *(*uintptr)(unsafe.Pointer(&c2)), *(*uintptr)(unsafe.Pointer(&c3)), *(*uintptr)(unsafe.Pointer(&p4)), t) - return *(*Vector2)(unsafe.Pointer(&ret)) -} - -// CheckCollisionRecs - Check collision between two rectangles -func CheckCollisionRecs(rec1 Rectangle, rec2 Rectangle) bool { - return checkCollisionRecs(uintptr(unsafe.Pointer(&rec1)), uintptr(unsafe.Pointer(&rec2))) -} - -// CheckCollisionCircles - Check collision between two circles -func CheckCollisionCircles(center1 Vector2, radius1 float32, center2 Vector2, radius2 float32) bool { - return checkCollisionCircles(*(*uintptr)(unsafe.Pointer(¢er1)), radius1, *(*uintptr)(unsafe.Pointer(¢er2)), radius2) -} - -// CheckCollisionCircleRec - Check collision between circle and rectangle -func CheckCollisionCircleRec(center Vector2, radius float32, rec Rectangle) bool { - return checkCollisionCircleRec(*(*uintptr)(unsafe.Pointer(¢er)), radius, uintptr(unsafe.Pointer(&rec))) -} - -// CheckCollisionCircleLine - Check if circle collides with a line created betweeen two points [p1] and [p2] -func CheckCollisionCircleLine(center Vector2, radius float32, p1, p2 Vector2) bool { - return checkCollisionCircleLine(*(*uintptr)(unsafe.Pointer(¢er)), radius, *(*uintptr)(unsafe.Pointer(&p1)), *(*uintptr)(unsafe.Pointer(&p2))) -} - -// CheckCollisionPointRec - Check if point is inside rectangle -func CheckCollisionPointRec(point Vector2, rec Rectangle) bool { - return checkCollisionPointRec(*(*uintptr)(unsafe.Pointer(&point)), uintptr(unsafe.Pointer(&rec))) -} - -// CheckCollisionPointCircle - Check if point is inside circle -func CheckCollisionPointCircle(point Vector2, center Vector2, radius float32) bool { - return checkCollisionPointCircle(*(*uintptr)(unsafe.Pointer(&point)), *(*uintptr)(unsafe.Pointer(¢er)), radius) -} - -// CheckCollisionPointTriangle - Check if point is inside a triangle -func CheckCollisionPointTriangle(point Vector2, p1 Vector2, p2 Vector2, p3 Vector2) bool { - return checkCollisionPointTriangle(*(*uintptr)(unsafe.Pointer(&point)), *(*uintptr)(unsafe.Pointer(&p1)), *(*uintptr)(unsafe.Pointer(&p2)), *(*uintptr)(unsafe.Pointer(&p3))) -} - -// CheckCollisionPointPoly - Check if point is within a polygon described by array of vertices -func CheckCollisionPointPoly(point Vector2, points []Vector2) bool { - pointCount := int32(len(points)) - return checkCollisionPointPoly(*(*uintptr)(unsafe.Pointer(&point)), unsafe.SliceData(points), pointCount) -} - -// CheckCollisionLines - Check the collision between two lines defined by two points each, returns collision point by reference -func CheckCollisionLines(startPos1 Vector2, endPos1 Vector2, startPos2 Vector2, endPos2 Vector2, collisionPoint *Vector2) bool { - return checkCollisionLines(*(*uintptr)(unsafe.Pointer(&startPos1)), *(*uintptr)(unsafe.Pointer(&endPos1)), *(*uintptr)(unsafe.Pointer(&startPos2)), *(*uintptr)(unsafe.Pointer(&endPos2)), collisionPoint) -} - -// CheckCollisionPointLine - Check if point belongs to line created between two points [p1] and [p2] with defined margin in pixels [threshold] -func CheckCollisionPointLine(point Vector2, p1 Vector2, p2 Vector2, threshold int32) bool { - return checkCollisionPointLine(*(*uintptr)(unsafe.Pointer(&point)), *(*uintptr)(unsafe.Pointer(&p1)), *(*uintptr)(unsafe.Pointer(&p2)), threshold) -} - -// GetCollisionRec - Get collision rectangle for two rectangles collision -func GetCollisionRec(rec1 Rectangle, rec2 Rectangle) Rectangle { - var rec Rectangle - getCollisionRec(uintptr(unsafe.Pointer(&rec)), uintptr(unsafe.Pointer(&rec1)), uintptr(unsafe.Pointer(&rec2))) - return rec -} - -// LoadImage - Load image from file into CPU memory (RAM) -func LoadImage(fileName string) *Image { - var img Image - loadImage(uintptr(unsafe.Pointer(&img)), fileName) - return &img -} - -// LoadImageRaw - Load image from RAW file data -func LoadImageRaw(fileName string, width int32, height int32, format PixelFormat, headerSize int32) *Image { - var img Image - loadImageRaw(uintptr(unsafe.Pointer(&img)), fileName, width, height, int32(format), headerSize) - return &img -} - -// LoadImageAnim - Load image sequence from file (frames appended to image.data) -func LoadImageAnim(fileName string, frames *int32) *Image { - var img Image - loadImageAnim(uintptr(unsafe.Pointer(&img)), fileName, frames) - return &img -} - -// LoadImageAnimFromMemory - Load image sequence from memory buffer -func LoadImageAnimFromMemory(fileType string, fileData []byte, dataSize int32, frames *int32) *Image { - var img Image - loadImageAnimFromMemory(uintptr(unsafe.Pointer(&img)), fileType, fileData, dataSize, frames) - return &img -} - -// LoadImageFromMemory - Load image from memory buffer, fileType refers to extension: i.e. '.png' -func LoadImageFromMemory(fileType string, fileData []byte, dataSize int32) *Image { - var img Image - loadImageFromMemory(uintptr(unsafe.Pointer(&img)), fileType, fileData, dataSize) - return &img -} - -// LoadImageFromTexture - Load image from GPU texture data -func LoadImageFromTexture(texture Texture2D) *Image { - var img Image - loadImageFromTexture(uintptr(unsafe.Pointer(&img)), uintptr(unsafe.Pointer(&texture))) - return &img -} - -// LoadImageFromScreen - Load image from screen buffer and (screenshot) -func LoadImageFromScreen() *Image { - var img Image - loadImageFromScreen(uintptr(unsafe.Pointer(&img))) - return &img -} - -// IsImageValid - Check if an image is valid (data and parameters) -func IsImageValid(image *Image) bool { - return isImageValid(uintptr(unsafe.Pointer(image))) -} - -// UnloadImage - Unload image from CPU memory (RAM) -func UnloadImage(image *Image) { - unloadImage(uintptr(unsafe.Pointer(image))) -} - -// ExportImage - Export image data to file, returns true on success -func ExportImage(image Image, fileName string) bool { - return exportImage(uintptr(unsafe.Pointer(&image)), fileName) -} - -// ExportImageToMemory - Export image to memory buffer -func ExportImageToMemory(image Image, fileType string) []byte { - var fileSize int32 - ret := exportImageToMemory(uintptr(unsafe.Pointer(&image)), fileType, &fileSize) - return unsafe.Slice(ret, fileSize) -} - -// GenImageColor - Generate image: plain color -func GenImageColor(width int, height int, col color.RGBA) *Image { - var image Image - genImageColor(uintptr(unsafe.Pointer(&image)), int32(width), int32(height), *(*uintptr)(unsafe.Pointer(&col))) - return &image -} - -// GenImageGradientLinear - Generate image: linear gradient, direction in degrees [0..360], 0=Vertical gradient -func GenImageGradientLinear(width int, height int, direction int, start color.RGBA, end color.RGBA) *Image { - var image Image - genImageGradientLinear(uintptr(unsafe.Pointer(&image)), int32(width), int32(height), int32(direction), *(*uintptr)(unsafe.Pointer(&start)), *(*uintptr)(unsafe.Pointer(&end))) - return &image -} - -// GenImageGradientRadial - Generate image: radial gradient -func GenImageGradientRadial(width int, height int, density float32, inner color.RGBA, outer color.RGBA) *Image { - var image Image - genImageGradientRadial(uintptr(unsafe.Pointer(&image)), int32(width), int32(height), density, *(*uintptr)(unsafe.Pointer(&inner)), *(*uintptr)(unsafe.Pointer(&outer))) - return &image -} - -// GenImageGradientSquare - Generate image: square gradient -func GenImageGradientSquare(width int, height int, density float32, inner color.RGBA, outer color.RGBA) *Image { - var image Image - genImageGradientSquare(uintptr(unsafe.Pointer(&image)), int32(width), int32(height), density, *(*uintptr)(unsafe.Pointer(&inner)), *(*uintptr)(unsafe.Pointer(&outer))) - return &image -} - -// GenImageChecked - Generate image: checked -func GenImageChecked(width int, height int, checksX int, checksY int, col1 color.RGBA, col2 color.RGBA) *Image { - var image Image - genImageChecked(uintptr(unsafe.Pointer(&image)), int32(width), int32(height), int32(checksX), int32(checksY), *(*uintptr)(unsafe.Pointer(&col1)), *(*uintptr)(unsafe.Pointer(&col2))) - return &image -} - -// GenImageWhiteNoise - Generate image: white noise -func GenImageWhiteNoise(width int, height int, factor float32) *Image { - var image Image - genImageWhiteNoise(uintptr(unsafe.Pointer(&image)), int32(width), int32(height), factor) - return &image -} - -// GenImagePerlinNoise - Generate image: perlin noise -func GenImagePerlinNoise(width int, height int, offsetX int32, offsetY int32, scale float32) *Image { - var image Image - genImagePerlinNoise(uintptr(unsafe.Pointer(&image)), int32(width), int32(height), offsetX, offsetY, scale) - return &image -} - -// GenImageCellular - Generate image: cellular algorithm, bigger tileSize means bigger cells -func GenImageCellular(width int, height int, tileSize int) *Image { - var image Image - genImageCellular(uintptr(unsafe.Pointer(&image)), int32(width), int32(height), int32(tileSize)) - return &image -} - -// GenImageText - Generate image: grayscale image from text data -func GenImageText(width int, height int, text string) Image { - var image Image - genImageText(uintptr(unsafe.Pointer(&image)), int32(width), int32(height), text) - return image -} - -// ImageCopy - Create an image duplicate (useful for transformations) -func ImageCopy(image *Image) *Image { - var retImage Image - imageCopy(uintptr(unsafe.Pointer(&retImage)), uintptr(unsafe.Pointer(image))) - return &retImage -} - -// ImageFromImage - Create an image from another image piece -func ImageFromImage(image Image, rec Rectangle) Image { - var retImage Image - imageFromImage(uintptr(unsafe.Pointer(&retImage)), uintptr(unsafe.Pointer(&image)), uintptr(unsafe.Pointer(&rec))) - return retImage -} - -// ImageFromChannel - Create an image from a selected channel of another image (GRAYSCALE) -func ImageFromChannel(image Image, selectedChannel int32) Image { - var retImage Image - imageFromChannel(uintptr(unsafe.Pointer(&retImage)), uintptr(unsafe.Pointer(&image)), selectedChannel) - return retImage -} - -// ImageText - Create an image from text (default font) -func ImageText(text string, fontSize int32, col color.RGBA) Image { - var retImage Image - imageText(uintptr(unsafe.Pointer(&retImage)), text, fontSize, *(*uintptr)(unsafe.Pointer(&col))) - return retImage -} - -// ImageTextEx - Create an image from text (custom sprite font) -func ImageTextEx(font Font, text string, fontSize float32, spacing float32, tint color.RGBA) Image { - var retImage Image - imageTextEx(uintptr(unsafe.Pointer(&retImage)), uintptr(unsafe.Pointer(&font)), text, fontSize, spacing, *(*uintptr)(unsafe.Pointer(&tint))) - return retImage -} - -// ImageFormat - Convert image data to desired format -func ImageFormat(image *Image, newFormat PixelFormat) { - imageFormat(image, int32(newFormat)) -} - -// ImageToPOT - Convert image to POT (power-of-two) -func ImageToPOT(image *Image, fill color.RGBA) { - imageToPOT(image, *(*uintptr)(unsafe.Pointer(&fill))) -} - -// ImageCrop - Crop an image to a defined rectangle -func ImageCrop(image *Image, crop Rectangle) { - imageCrop(image, uintptr(unsafe.Pointer(&crop))) -} - -// ImageAlphaCrop - Crop image depending on alpha value -func ImageAlphaCrop(image *Image, threshold float32) { - imageAlphaCrop(image, threshold) -} - -// ImageAlphaClear - Clear alpha channel to desired color -func ImageAlphaClear(image *Image, col color.RGBA, threshold float32) { - imageAlphaClear(image, *(*uintptr)(unsafe.Pointer(&col)), threshold) -} - -// ImageAlphaMask - Apply alpha mask to image -func ImageAlphaMask(image *Image, alphaMask *Image) { - imageAlphaMask(image, uintptr(unsafe.Pointer(alphaMask))) -} - -// ImageAlphaPremultiply - Premultiply alpha channel -func ImageAlphaPremultiply(image *Image) { - imageAlphaPremultiply(image) -} - -// ImageBlurGaussian - Apply Gaussian blur using a box blur approximation -func ImageBlurGaussian(image *Image, blurSize int32) { - imageBlurGaussian(image, blurSize) -} - -// ImageKernelConvolution - Apply custom square convolution kernel to image -func ImageKernelConvolution(image *Image, kernel []float32) { - imageKernelConvolution(image, kernel, int32(len(kernel))) -} - -// ImageResize - Resize image (Bicubic scaling algorithm) -func ImageResize(image *Image, newWidth int32, newHeight int32) { - imageResize(image, newWidth, newHeight) -} - -// ImageResizeNN - Resize image (Nearest-Neighbor scaling algorithm) -func ImageResizeNN(image *Image, newWidth int32, newHeight int32) { - imageResizeNN(image, newWidth, newHeight) -} - -// ImageResizeCanvas - Resize canvas and fill with color -func ImageResizeCanvas(image *Image, newWidth int32, newHeight int32, offsetX int32, offsetY int32, fill color.RGBA) { - imageResizeCanvas(image, newWidth, newHeight, offsetX, offsetY, *(*uintptr)(unsafe.Pointer(&fill))) -} - -// ImageMipmaps - Compute all mipmap levels for a provided image -func ImageMipmaps(image *Image) { - imageMipmaps(image) -} - -// ImageDither - Dither image data to 16bpp or lower (Floyd-Steinberg dithering) -func ImageDither(image *Image, rBpp int32, gBpp int32, bBpp int32, aBpp int32) { - imageDither(image, rBpp, gBpp, bBpp, aBpp) -} - -// ImageFlipVertical - Flip image vertically -func ImageFlipVertical(image *Image) { - imageFlipVertical(image) -} - -// ImageFlipHorizontal - Flip image horizontally -func ImageFlipHorizontal(image *Image) { - imageFlipHorizontal(image) -} - -// ImageRotate - Rotate image by input angle in degrees (-359 to 359) -func ImageRotate(image *Image, degrees int32) { - imageRotate(image, degrees) -} - -// ImageRotateCW - Rotate image clockwise 90deg -func ImageRotateCW(image *Image) { - imageRotateCW(image) -} - -// ImageRotateCCW - Rotate image counter-clockwise 90deg -func ImageRotateCCW(image *Image) { - imageRotateCCW(image) -} - -// ImageColorTint - Modify image color: tint -func ImageColorTint(image *Image, col color.RGBA) { - imageColorTint(image, *(*uintptr)(unsafe.Pointer(&col))) -} - -// ImageColorInvert - Modify image color: invert -func ImageColorInvert(image *Image) { - imageColorInvert(image) -} - -// ImageColorGrayscale - Modify image color: grayscale -func ImageColorGrayscale(image *Image) { - imageColorGrayscale(image) -} - -// ImageColorContrast - Modify image color: contrast (-100 to 100) -func ImageColorContrast(image *Image, contrast float32) { - imageColorContrast(image, contrast) -} - -// ImageColorBrightness - Modify image color: brightness (-255 to 255) -func ImageColorBrightness(image *Image, brightness int32) { - imageColorBrightness(image, brightness) -} - -// ImageColorReplace - Modify image color: replace color -func ImageColorReplace(image *Image, col color.RGBA, replace color.RGBA) { - imageColorReplace(image, *(*uintptr)(unsafe.Pointer(&col)), *(*uintptr)(unsafe.Pointer(&replace))) -} - -// LoadImageColors - Load color data from image as a Color array (RGBA - 32bit) -// -// NOTE: Memory allocated should be freed using UnloadImageColors() -func LoadImageColors(image *Image) []color.RGBA { - ret := loadImageColors(uintptr(unsafe.Pointer(image))) - return unsafe.Slice(ret, image.Width*image.Height) -} - -// LoadImagePalette - Load colors palette from image as a Color array (RGBA - 32bit) -// -// NOTE: Memory allocated should be freed using UnloadImagePalette() -func LoadImagePalette(image Image, maxPaletteSize int32) []color.RGBA { - var colorCount int32 - ret := loadImagePalette(uintptr(unsafe.Pointer(&image)), maxPaletteSize, &colorCount) - return unsafe.Slice(ret, colorCount) -} - -// UnloadImageColors - Unload color data loaded with LoadImageColors() -func UnloadImageColors(colors []color.RGBA) { - unloadImageColors(unsafe.SliceData(colors)) -} - -// UnloadImagePalette - Unload colors palette loaded with LoadImagePalette() -func UnloadImagePalette(colors []color.RGBA) { - unloadImagePalette(unsafe.SliceData(colors)) -} - -// GetImageAlphaBorder - Get image alpha border rectangle -func GetImageAlphaBorder(image Image, threshold float32) Rectangle { - var rec Rectangle - getImageAlphaBorder(uintptr(unsafe.Pointer(&rec)), uintptr(unsafe.Pointer(&image)), threshold) - return rec -} - -// GetImageColor - Get image pixel color at (x, y) position -func GetImageColor(image Image, x int32, y int32) color.RGBA { - ret := getImageColor(uintptr(unsafe.Pointer(&image)), x, y) - return *(*color.RGBA)(unsafe.Pointer(&ret)) -} - -// ImageClearBackground - Clear image background with given color -func ImageClearBackground(dst *Image, col color.RGBA) { - imageClearBackground(dst, *(*uintptr)(unsafe.Pointer(&col))) -} - -// ImageDrawPixel - Draw pixel within an image -func ImageDrawPixel(dst *Image, posX int32, posY int32, col color.RGBA) { - imageDrawPixel(dst, posX, posY, *(*uintptr)(unsafe.Pointer(&col))) -} - -// ImageDrawPixelV - Draw pixel within an image (Vector version) -func ImageDrawPixelV(dst *Image, position Vector2, col color.RGBA) { - imageDrawPixelV(dst, *(*uintptr)(unsafe.Pointer(&position)), *(*uintptr)(unsafe.Pointer(&col))) -} - -// ImageDrawLine - Draw line within an image -func ImageDrawLine(dst *Image, startPosX int32, startPosY int32, endPosX int32, endPosY int32, col color.RGBA) { - imageDrawLine(dst, startPosX, startPosY, endPosX, endPosY, *(*uintptr)(unsafe.Pointer(&col))) -} - -// ImageDrawLineV - Draw line within an image (Vector version) -func ImageDrawLineV(dst *Image, start, end Vector2, col color.RGBA) { - imageDrawLineV(dst, *(*uintptr)(unsafe.Pointer(&start)), *(*uintptr)(unsafe.Pointer(&end)), *(*uintptr)(unsafe.Pointer(&col))) -} - -// ImageDrawLineEx - Draw a line defining thickness within an image -func ImageDrawLineEx(dst *Image, start, end Vector2, thick int32, col color.RGBA) { - imageDrawLineEx(dst, *(*uintptr)(unsafe.Pointer(&start)), *(*uintptr)(unsafe.Pointer(&end)), thick, *(*uintptr)(unsafe.Pointer(&col))) -} - -// ImageDrawCircle - Draw a filled circle within an image -func ImageDrawCircle(dst *Image, centerX int32, centerY int32, radius int32, col color.RGBA) { - imageDrawCircle(dst, centerX, centerY, radius, *(*uintptr)(unsafe.Pointer(&col))) -} - -// ImageDrawCircleV - Draw a filled circle within an image (Vector version) -func ImageDrawCircleV(dst *Image, center Vector2, radius int32, col color.RGBA) { - imageDrawCircleV(dst, *(*uintptr)(unsafe.Pointer(¢er)), radius, *(*uintptr)(unsafe.Pointer(&col))) -} - -// ImageDrawCircleLines - Draw circle outline within an image -func ImageDrawCircleLines(dst *Image, centerX int32, centerY int32, radius int32, col color.RGBA) { - imageDrawCircleLines(dst, centerX, centerY, radius, *(*uintptr)(unsafe.Pointer(&col))) -} - -// ImageDrawCircleLinesV - Draw circle outline within an image (Vector version) -func ImageDrawCircleLinesV(dst *Image, center Vector2, radius int32, col color.RGBA) { - imageDrawCircleLinesV(dst, *(*uintptr)(unsafe.Pointer(¢er)), radius, *(*uintptr)(unsafe.Pointer(&col))) -} - -// ImageDrawRectangle - Draw rectangle within an image -func ImageDrawRectangle(dst *Image, posX int32, posY int32, width int32, height int32, col color.RGBA) { - imageDrawRectangle(dst, posX, posY, width, height, *(*uintptr)(unsafe.Pointer(&col))) -} - -// ImageDrawRectangleV - Draw rectangle within an image (Vector version) -func ImageDrawRectangleV(dst *Image, position Vector2, size Vector2, col color.RGBA) { - imageDrawRectangleV(dst, *(*uintptr)(unsafe.Pointer(&position)), *(*uintptr)(unsafe.Pointer(&size)), *(*uintptr)(unsafe.Pointer(&col))) -} - -// ImageDrawRectangleRec - Draw rectangle within an image -func ImageDrawRectangleRec(dst *Image, rec Rectangle, col color.RGBA) { - imageDrawRectangleRec(dst, uintptr(unsafe.Pointer(&rec)), *(*uintptr)(unsafe.Pointer(&col))) -} - -// ImageDrawRectangleLines - Draw rectangle lines within an image -func ImageDrawRectangleLines(dst *Image, rec Rectangle, thick int, col color.RGBA) { - imageDrawRectangleLines(dst, uintptr(unsafe.Pointer(&rec)), int32(thick), *(*uintptr)(unsafe.Pointer(&col))) -} - -// ImageDrawTriangle - Draw triangle within an image -func ImageDrawTriangle(dst *Image, v1, v2, v3 Vector2, col color.RGBA) { - imageDrawTriangle(dst, *(*uintptr)(unsafe.Pointer(&v1)), *(*uintptr)(unsafe.Pointer(&v2)), *(*uintptr)(unsafe.Pointer(&v3)), *(*uintptr)(unsafe.Pointer(&col))) -} - -// ImageDrawTriangleEx - Draw triangle with interpolated colors within an image -func ImageDrawTriangleEx(dst *Image, v1, v2, v3 Vector2, c1, c2, c3 color.RGBA) { - imageDrawTriangleEx(dst, *(*uintptr)(unsafe.Pointer(&v1)), *(*uintptr)(unsafe.Pointer(&v2)), *(*uintptr)(unsafe.Pointer(&v3)), *(*uintptr)(unsafe.Pointer(&c1)), *(*uintptr)(unsafe.Pointer(&c2)), *(*uintptr)(unsafe.Pointer(&c3))) -} - -// ImageDrawTriangleLines - Draw triangle outline within an image -func ImageDrawTriangleLines(dst *Image, v1, v2, v3 Vector2, col color.RGBA) { - imageDrawTriangleLines(dst, *(*uintptr)(unsafe.Pointer(&v1)), *(*uintptr)(unsafe.Pointer(&v2)), *(*uintptr)(unsafe.Pointer(&v3)), *(*uintptr)(unsafe.Pointer(&col))) -} - -// ImageDrawTriangleFan - Draw a triangle fan defined by points within an image (first vertex is the center) -func ImageDrawTriangleFan(dst *Image, points []Vector2, col color.RGBA) { - pointCount := int32(len(points)) - imageDrawTriangleFan(dst, (unsafe.SliceData(points)), pointCount, *(*uintptr)(unsafe.Pointer(&col))) -} - -// ImageDrawTriangleStrip - Draw a triangle strip defined by points within an image -func ImageDrawTriangleStrip(dst *Image, points []Vector2, col color.RGBA) { - pointCount := int32(len(points)) - imageDrawTriangleStrip(dst, (unsafe.SliceData(points)), pointCount, *(*uintptr)(unsafe.Pointer(&col))) -} - -// ImageDraw - Draw a source image within a destination image (tint applied to source) -func ImageDraw(dst *Image, src *Image, srcRec Rectangle, dstRec Rectangle, tint color.RGBA) { - imageDraw(dst, uintptr(unsafe.Pointer(src)), uintptr(unsafe.Pointer(&srcRec)), uintptr(unsafe.Pointer(&dstRec)), *(*uintptr)(unsafe.Pointer(&tint))) -} - -// ImageDrawText - Draw text (using default font) within an image (destination) -func ImageDrawText(dst *Image, posX int32, posY int32, text string, fontSize int32, col color.RGBA) { - imageDrawText(dst, text, posX, posY, fontSize, *(*uintptr)(unsafe.Pointer(&col))) - -} - -// ImageDrawTextEx - Draw text (custom sprite font) within an image (destination) -func ImageDrawTextEx(dst *Image, position Vector2, font Font, text string, fontSize float32, spacing float32, tint color.RGBA) { - imageDrawTextEx(dst, uintptr(unsafe.Pointer(&font)), text, *(*uintptr)(unsafe.Pointer(&position)), fontSize, spacing, *(*uintptr)(unsafe.Pointer(&tint))) -} - -// LoadTexture - Load texture from file into GPU memory (VRAM) -func LoadTexture(fileName string) Texture2D { - var texture Texture2D - loadTexture(uintptr(unsafe.Pointer(&texture)), fileName) - return texture -} - -// LoadTextureFromImage - Load texture from image data -func LoadTextureFromImage(image *Image) Texture2D { - var texture Texture2D - loadTextureFromImage(uintptr(unsafe.Pointer(&texture)), uintptr(unsafe.Pointer(image))) - return texture -} - -// LoadTextureCubemap - Load cubemap from image, multiple image cubemap layouts supported -func LoadTextureCubemap(image *Image, layout int32) Texture2D { - var texture Texture2D - loadTextureCubemap(uintptr(unsafe.Pointer(&texture)), uintptr(unsafe.Pointer(image)), layout) - return texture -} - -// LoadRenderTexture - Load texture for rendering (framebuffer) -func LoadRenderTexture(width int32, height int32) RenderTexture2D { - var texture RenderTexture2D - loadRenderTexture(uintptr(unsafe.Pointer(&texture)), width, height) - return texture -} - -// IsTextureValid - Check if a texture is valid (loaded in GPU) -func IsTextureValid(texture Texture2D) bool { - return isTextureValid(uintptr(unsafe.Pointer(&texture))) -} - -// UnloadTexture - Unload texture from GPU memory (VRAM) -func UnloadTexture(texture Texture2D) { - unloadTexture(uintptr(unsafe.Pointer(&texture))) -} - -// IsRenderTextureValid - Check if a render texture is valid (loaded in GPU) -func IsRenderTextureValid(target RenderTexture2D) bool { - return isRenderTextureValid(uintptr(unsafe.Pointer(&target))) -} - -// UnloadRenderTexture - Unload render texture from GPU memory (VRAM) -func UnloadRenderTexture(target RenderTexture2D) { - unloadRenderTexture(uintptr(unsafe.Pointer(&target))) -} - -// UpdateTexture - Update GPU texture with new data -func UpdateTexture(texture Texture2D, pixels []color.RGBA) { - updateTexture(uintptr(unsafe.Pointer(&texture)), unsafe.SliceData(pixels)) -} - -// UpdateTextureRec - Update GPU texture rectangle with new data -func UpdateTextureRec(texture Texture2D, rec Rectangle, pixels []color.RGBA) { - updateTextureRec(uintptr(unsafe.Pointer(&texture)), uintptr(unsafe.Pointer(&rec)), unsafe.SliceData(pixels)) -} - -// GenTextureMipmaps - Generate GPU mipmaps for a texture -func GenTextureMipmaps(texture *Texture2D) { - genTextureMipmaps(texture) -} - -// SetTextureFilter - Set texture scaling filter mode -func SetTextureFilter(texture Texture2D, filter TextureFilterMode) { - setTextureFilter(uintptr(unsafe.Pointer(&texture)), int32(filter)) -} - -// SetTextureWrap - Set texture wrapping mode -func SetTextureWrap(texture Texture2D, wrap TextureWrapMode) { - setTextureWrap(uintptr(unsafe.Pointer(&texture)), int32(wrap)) -} - -// DrawTexture - Draw a Texture2D -func DrawTexture(texture Texture2D, posX int32, posY int32, tint color.RGBA) { - drawTexture(uintptr(unsafe.Pointer(&texture)), posX, posY, *(*uintptr)(unsafe.Pointer(&tint))) -} - -// DrawTextureV - Draw a Texture2D with position defined as Vector2 -func DrawTextureV(texture Texture2D, position Vector2, tint color.RGBA) { - drawTextureV(uintptr(unsafe.Pointer(&texture)), *(*uintptr)(unsafe.Pointer(&position)), *(*uintptr)(unsafe.Pointer(&tint))) -} - -// DrawTextureEx - Draw a Texture2D with extended parameters -func DrawTextureEx(texture Texture2D, position Vector2, rotation float32, scale float32, tint color.RGBA) { - drawTextureEx(uintptr(unsafe.Pointer(&texture)), *(*uintptr)(unsafe.Pointer(&position)), rotation, scale, *(*uintptr)(unsafe.Pointer(&tint))) -} - -// DrawTextureRec - Draw a part of a texture defined by a rectangle -func DrawTextureRec(texture Texture2D, source Rectangle, position Vector2, tint color.RGBA) { - drawTextureRec(uintptr(unsafe.Pointer(&texture)), uintptr(unsafe.Pointer(&source)), *(*uintptr)(unsafe.Pointer(&position)), *(*uintptr)(unsafe.Pointer(&tint))) -} - -// DrawTexturePro - Draw a part of a texture defined by a rectangle with 'pro' parameters -func DrawTexturePro(texture Texture2D, source Rectangle, dest Rectangle, origin Vector2, rotation float32, tint color.RGBA) { - drawTexturePro(uintptr(unsafe.Pointer(&texture)), uintptr(unsafe.Pointer(&source)), uintptr(unsafe.Pointer(&dest)), *(*uintptr)(unsafe.Pointer(&origin)), rotation, *(*uintptr)(unsafe.Pointer(&tint))) -} - -// DrawTextureNPatch - Draws a texture (or part of it) that stretches or shrinks nicely -func DrawTextureNPatch(texture Texture2D, nPatchInfo NPatchInfo, dest Rectangle, origin Vector2, rotation float32, tint color.RGBA) { - drawTextureNPatch(uintptr(unsafe.Pointer(&texture)), uintptr(unsafe.Pointer(&nPatchInfo)), uintptr(unsafe.Pointer(&dest)), *(*uintptr)(unsafe.Pointer(&origin)), rotation, *(*uintptr)(unsafe.Pointer(&tint))) -} - -// Fade - Get color with alpha applied, alpha goes from 0.0f to 1.0f -func Fade(col color.RGBA, alpha float32) color.RGBA { - ret := fade(*(*uintptr)(unsafe.Pointer(&col)), alpha) - return *(*color.RGBA)(unsafe.Pointer(&ret)) -} - -// ColorToInt - Get hexadecimal value for a Color (0xRRGGBBAA) -func ColorToInt(col color.RGBA) int32 { - return colorToInt(*(*uintptr)(unsafe.Pointer(&col))) -} - -// ColorNormalize - Get Color normalized as float [0..1] -func ColorNormalize(col color.RGBA) Vector4 { - var vector4 Vector4 - colorNormalize(uintptr(unsafe.Pointer(&vector4)), *(*uintptr)(unsafe.Pointer(&col))) - return vector4 -} - -// ColorFromNormalized - Get Color from normalized values [0..1] -func ColorFromNormalized(normalized Vector4) color.RGBA { - ret := colorFromNormalized(uintptr(unsafe.Pointer(&normalized))) - return *(*color.RGBA)(unsafe.Pointer(&ret)) -} - -// ColorToHSV - Get HSV values for a Color, hue [0..360], saturation/value [0..1] -func ColorToHSV(col color.RGBA) Vector3 { - var vector3 Vector3 - colorToHSV(uintptr(unsafe.Pointer(&vector3)), *(*uintptr)(unsafe.Pointer(&col))) - return vector3 -} - -// ColorFromHSV - Get a Color from HSV values, hue [0..360], saturation/value [0..1] -func ColorFromHSV(hue float32, saturation float32, value float32) color.RGBA { - ret := colorFromHSV(hue, saturation, value) - return *(*color.RGBA)(unsafe.Pointer(&ret)) -} - -// ColorTint - Get color multiplied with another color -func ColorTint(col color.RGBA, tint color.RGBA) color.RGBA { - ret := colorTint(*(*uintptr)(unsafe.Pointer(&col)), *(*uintptr)(unsafe.Pointer(&tint))) - return *(*color.RGBA)(unsafe.Pointer(&ret)) -} - -// ColorBrightness - Get color with brightness correction, brightness factor goes from -1.0f to 1.0f -func ColorBrightness(col color.RGBA, factor float32) color.RGBA { - ret := colorBrightness(*(*uintptr)(unsafe.Pointer(&col)), factor) - return *(*color.RGBA)(unsafe.Pointer(&ret)) -} - -// ColorContrast - Get color with contrast correction, contrast values between -1.0f and 1.0f -func ColorContrast(col color.RGBA, contrast float32) color.RGBA { - ret := colorContrast(*(*uintptr)(unsafe.Pointer(&col)), contrast) - return *(*color.RGBA)(unsafe.Pointer(&ret)) -} - -// ColorAlpha - Get color with alpha applied, alpha goes from 0.0f to 1.0f -func ColorAlpha(col color.RGBA, alpha float32) color.RGBA { - ret := colorAlpha(*(*uintptr)(unsafe.Pointer(&col)), alpha) - return *(*color.RGBA)(unsafe.Pointer(&ret)) -} - -// ColorAlphaBlend - Get src alpha-blended into dst color with tint -func ColorAlphaBlend(dst color.RGBA, src color.RGBA, tint color.RGBA) color.RGBA { - ret := colorAlphaBlend(*(*uintptr)(unsafe.Pointer(&dst)), *(*uintptr)(unsafe.Pointer(&src)), *(*uintptr)(unsafe.Pointer(&tint))) - return *(*color.RGBA)(unsafe.Pointer(&ret)) -} - -// ColorLerp - Get color lerp interpolation between two colors, factor [0.0f..1.0f] -func ColorLerp(col1, col2 color.RGBA, factor float32) color.RGBA { - ret := colorLerp(*(*uintptr)(unsafe.Pointer(&col1)), *(*uintptr)(unsafe.Pointer(&col2)), factor) - return *(*color.RGBA)(unsafe.Pointer(&ret)) -} - -// GetColor - Get Color structure from hexadecimal value -func GetColor(hexValue uint) color.RGBA { - ret := getColor(uint32(hexValue)) - return *(*color.RGBA)(unsafe.Pointer(&ret)) -} - -// GetPixelColor - Get Color from a source pixel pointer of certain format -func GetPixelColor(srcPtr unsafe.Pointer, format int32) color.RGBA { - ret := getPixelColor(srcPtr, format) - return *(*color.RGBA)(unsafe.Pointer(&ret)) -} - -// SetPixelColor - Set color formatted into destination pixel pointer -func SetPixelColor(dstPtr unsafe.Pointer, col color.RGBA, format int32) { - setPixelColor(dstPtr, *(*uintptr)(unsafe.Pointer(&col)), format) -} - -// GetPixelDataSize - Get pixel data size in bytes for certain format -func GetPixelDataSize(width int32, height int32, format int32) int32 { - return getPixelDataSize(width, height, format) -} - -// GetFontDefault - Get the default Font -func GetFontDefault() Font { - var font Font - getFontDefault(uintptr(unsafe.Pointer(&font))) - return font -} - -// LoadFont - Load font from file into GPU memory (VRAM) -func LoadFont(fileName string) Font { - var font Font - loadFont(uintptr(unsafe.Pointer(&font)), fileName) - return font -} - - -// LoadFontFromImage - Load font from Image (XNA style) -func LoadFontFromImage(image Image, key color.RGBA, firstChar rune) Font { - var font Font - loadFontFromImage(uintptr(unsafe.Pointer(&font)), uintptr(unsafe.Pointer(&image)), *(*uintptr)(unsafe.Pointer(&key)), firstChar) - return font -} - -// LoadFontFromMemory - Load font from memory buffer, fileType refers to extension: i.e. '.ttf' -func LoadFontFromMemory(fileType string, fileData []byte, fontSize int32, codepoints []rune) Font { - var font Font - dataSize := int32(len(fileData)) - codepointCount := int32(len(codepoints)) - loadFontFromMemory(uintptr(unsafe.Pointer(&font)), fileType, fileData, dataSize, fontSize, codepoints, codepointCount) - return font -} - -// IsFontValid - Check if a font is valid (font data loaded, WARNING: GPU texture not checked) -func IsFontValid(font Font) bool { - return isFontValid(uintptr(unsafe.Pointer(&font))) -} - -// LoadFontData - Load font data for further use -func LoadFontData(fileData []byte, fontSize int32, codepoints []rune, codepointCount, typ int32) []GlyphInfo { - dataSize := int32(len(fileData)) - // In case no chars count provided, default to 95 - if codepointCount <= 0 { - codepointCount = 95 - } - ret := loadFontData(fileData, dataSize, fontSize, codepoints, codepointCount, typ) - return unsafe.Slice(ret, codepointCount) -} - -// GenImageFontAtlas - Generate image font atlas using chars info -func GenImageFontAtlas(glyphs []GlyphInfo, glyphRecs []*Rectangle, fontSize int32, padding int32, packMethod int32) Image { - var image Image - glyphCount := int32(len(glyphs)) - genImageFontAtlas(uintptr(unsafe.Pointer(&image)), unsafe.SliceData(glyphs), glyphRecs, glyphCount, fontSize, padding, packMethod) - return image -} - -// UnloadFontData - Unload font chars info data (RAM) -func UnloadFontData(glyphs []GlyphInfo) { - glyphCount := int32(len(glyphs)) - unloadFontData(unsafe.SliceData(glyphs), glyphCount) -} - -// UnloadFont - Unload font from GPU memory (VRAM) -func UnloadFont(font Font) { - unloadFont(uintptr(unsafe.Pointer(&font))) -} - -// DrawFPS - Draw current FPS -func DrawFPS(posX int32, posY int32) { - drawFPS(posX, posY) -} - -// DrawText - Draw text (using default font) -func DrawText(text string, posX int32, posY int32, fontSize int32, col color.RGBA) { - drawText(text, posX, posY, fontSize, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawTextEx - Draw text using font and additional parameters -func DrawTextEx(font Font, text string, position Vector2, fontSize float32, spacing float32, tint color.RGBA) { - drawTextEx(uintptr(unsafe.Pointer(&font)), text, *(*uintptr)(unsafe.Pointer(&position)), fontSize, spacing, *(*uintptr)(unsafe.Pointer(&tint))) -} - -// DrawTextPro - Draw text using Font and pro parameters (rotation) -func DrawTextPro(font Font, text string, position Vector2, origin Vector2, rotation float32, fontSize float32, spacing float32, tint color.RGBA) { - drawTextPro(uintptr(unsafe.Pointer(&font)), text, *(*uintptr)(unsafe.Pointer(&position)), *(*uintptr)(unsafe.Pointer(&origin)), rotation, fontSize, spacing, *(*uintptr)(unsafe.Pointer(&tint))) -} - -// DrawTextCodepoint - Draw one character (codepoint) -func DrawTextCodepoint(font Font, codepoint rune, position Vector2, fontSize float32, tint color.RGBA) { - drawTextCodepoint(uintptr(unsafe.Pointer(&font)), codepoint, *(*uintptr)(unsafe.Pointer(&position)), fontSize, *(*uintptr)(unsafe.Pointer(&tint))) -} - -// DrawTextCodepoints - Draw multiple character (codepoint) -func DrawTextCodepoints(font Font, codepoints []rune, position Vector2, fontSize float32, spacing float32, tint color.RGBA) { - codepointCount := int32(len(codepoints)) - drawTextCodepoints(uintptr(unsafe.Pointer(&font)), codepoints, codepointCount, *(*uintptr)(unsafe.Pointer(&position)), fontSize, spacing, *(*uintptr)(unsafe.Pointer(&tint))) -} - -// SetTextLineSpacing - Set vertical line spacing when drawing with line-breaks -func SetTextLineSpacing(spacing int) { - setTextLineSpacing(int32(spacing)) -} - -// MeasureText - Measure string width for default font -func MeasureText(text string, fontSize int32) int32 { - return measureText(text, fontSize) -} - -// MeasureTextEx - Measure string size for Font -func MeasureTextEx(font Font, text string, fontSize float32, spacing float32) Vector2 { - ret := measureTextEx(uintptr(unsafe.Pointer(&font)), text, fontSize, spacing) - return *(*Vector2)(unsafe.Pointer(&ret)) -} - -// GetGlyphIndex - Get glyph index position in font for a codepoint (unicode character), fallback to '?' if not found -func GetGlyphIndex(font Font, codepoint rune) int32 { - return getGlyphIndex(uintptr(unsafe.Pointer(&font)), codepoint) -} - -// GetGlyphInfo - Get glyph font info data for a codepoint (unicode character), fallback to '?' if not found -func GetGlyphInfo(font Font, codepoint rune) GlyphInfo { - var glyphInfo GlyphInfo - getGlyphInfo(uintptr(unsafe.Pointer(&glyphInfo)), uintptr(unsafe.Pointer(&font)), codepoint) - return glyphInfo -} - -// GetGlyphAtlasRec - Get glyph rectangle in font atlas for a codepoint (unicode character), fallback to '?' if not found -func GetGlyphAtlasRec(font Font, codepoint rune) Rectangle { - var rec Rectangle - getGlyphAtlasRec(uintptr(unsafe.Pointer(&rec)), uintptr(unsafe.Pointer(&font)), codepoint) - return rec -} - -// DrawLine3D - Draw a line in 3D world space -func DrawLine3D(startPos Vector3, endPos Vector3, col color.RGBA) { - drawLine3D(uintptr(unsafe.Pointer(&startPos)), uintptr(unsafe.Pointer(&endPos)), *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawPoint3D - Draw a point in 3D space, actually a small line -func DrawPoint3D(position Vector3, col color.RGBA) { - drawPoint3D(uintptr(unsafe.Pointer(&position)), *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawCircle3D - Draw a circle in 3D world space -func DrawCircle3D(center Vector3, radius float32, rotationAxis Vector3, rotationAngle float32, col color.RGBA) { - drawCircle3D(uintptr(unsafe.Pointer(¢er)), radius, uintptr(unsafe.Pointer(&rotationAxis)), rotationAngle, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawTriangle3D - Draw a color-filled triangle (vertex in counter-clockwise order!) -func DrawTriangle3D(v1 Vector3, v2 Vector3, v3 Vector3, col color.RGBA) { - drawTriangle3D(uintptr(unsafe.Pointer(&v1)), uintptr(unsafe.Pointer(&v2)), uintptr(unsafe.Pointer(&v3)), *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawTriangleStrip3D - Draw a triangle strip defined by points -func DrawTriangleStrip3D(points []Vector3, col color.RGBA) { - pointCount := int32(len(points)) - drawTriangleStrip3D(unsafe.SliceData(points), pointCount, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawCube - Draw cube -func DrawCube(position Vector3, width float32, height float32, length float32, col color.RGBA) { - drawCube(uintptr(unsafe.Pointer(&position)), width, height, length, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawCubeV - Draw cube (Vector version) -func DrawCubeV(position Vector3, size Vector3, col color.RGBA) { - drawCubeV(uintptr(unsafe.Pointer(&position)), uintptr(unsafe.Pointer(&size)), *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawCubeWires - Draw cube wires -func DrawCubeWires(position Vector3, width float32, height float32, length float32, col color.RGBA) { - drawCubeWires(uintptr(unsafe.Pointer(&position)), width, height, length, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawCubeWiresV - Draw cube wires (Vector version) -func DrawCubeWiresV(position Vector3, size Vector3, col color.RGBA) { - drawCubeWiresV(uintptr(unsafe.Pointer(&position)), uintptr(unsafe.Pointer(&size)), *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawSphere - Draw sphere -func DrawSphere(centerPos Vector3, radius float32, col color.RGBA) { - drawSphere(uintptr(unsafe.Pointer(¢erPos)), radius, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawSphereEx - Draw sphere with extended parameters -func DrawSphereEx(centerPos Vector3, radius float32, rings int32, slices int32, col color.RGBA) { - drawSphereEx(uintptr(unsafe.Pointer(¢erPos)), radius, rings, slices, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawSphereWires - Draw sphere wires -func DrawSphereWires(centerPos Vector3, radius float32, rings int32, slices int32, col color.RGBA) { - drawSphereWires(uintptr(unsafe.Pointer(¢erPos)), radius, rings, slices, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawCylinder - Draw a cylinder/cone -func DrawCylinder(position Vector3, radiusTop float32, radiusBottom float32, height float32, slices int32, col color.RGBA) { - drawCylinder(uintptr(unsafe.Pointer(&position)), radiusTop, radiusBottom, height, slices, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawCylinderEx - Draw a cylinder with base at startPos and top at endPos -func DrawCylinderEx(startPos Vector3, endPos Vector3, startRadius float32, endRadius float32, sides int32, col color.RGBA) { - drawCylinderEx(uintptr(unsafe.Pointer(&startPos)), uintptr(unsafe.Pointer(&endPos)), startRadius, endRadius, sides, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawCylinderWires - Draw a cylinder/cone wires -func DrawCylinderWires(position Vector3, radiusTop float32, radiusBottom float32, height float32, slices int32, col color.RGBA) { - drawCylinderWires(uintptr(unsafe.Pointer(&position)), radiusTop, radiusBottom, height, slices, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawCylinderWiresEx - Draw a cylinder wires with base at startPos and top at endPos -func DrawCylinderWiresEx(startPos Vector3, endPos Vector3, startRadius float32, endRadius float32, sides int32, col color.RGBA) { - drawCylinderWiresEx(uintptr(unsafe.Pointer(&startPos)), uintptr(unsafe.Pointer(&endPos)), startRadius, endRadius, sides, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawCapsule - Draw a capsule with the center of its sphere caps at startPos and endPos -func DrawCapsule(startPos Vector3, endPos Vector3, radius float32, slices int32, rings int32, col color.RGBA) { - drawCapsule(uintptr(unsafe.Pointer(&startPos)), uintptr(unsafe.Pointer(&endPos)), radius, slices, rings, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawCapsuleWires - Draw capsule wireframe with the center of its sphere caps at startPos and endPos -func DrawCapsuleWires(startPos Vector3, endPos Vector3, radius float32, slices int32, rings int32, col color.RGBA) { - drawCapsuleWires(uintptr(unsafe.Pointer(&startPos)), uintptr(unsafe.Pointer(&endPos)), radius, slices, rings, *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawPlane - Draw a plane XZ -func DrawPlane(centerPos Vector3, size Vector2, col color.RGBA) { - drawPlane(uintptr(unsafe.Pointer(¢erPos)), *(*uintptr)(unsafe.Pointer(&size)), *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawRay - Draw a ray line -func DrawRay(ray Ray, col color.RGBA) { - drawRay(uintptr(unsafe.Pointer(&ray)), *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawGrid - Draw a grid (centered at (0, 0, 0)) -func DrawGrid(slices int32, spacing float32) { - drawGrid(slices, spacing) -} - -// LoadModel - Load model from files (meshes and materials) -func LoadModel(fileName string) Model { - var model Model - loadModel(uintptr(unsafe.Pointer(&model)), fileName) - return model -} - -// LoadModelFromMesh - Load model from generated mesh (default material) -func LoadModelFromMesh(mesh Mesh) Model { - var model Model - loadModelFromMesh(uintptr(unsafe.Pointer(&model)), uintptr(unsafe.Pointer(&mesh))) - return model -} - -// IsModelValid - Check if a model is valid (loaded in GPU, VAO/VBOs) -func IsModelValid(model Model) bool { - return isModelValid(uintptr(unsafe.Pointer(&model))) -} - -// UnloadModel - Unload model (including meshes) from memory (RAM and/or VRAM) -func UnloadModel(model Model) { - unloadModel(uintptr(unsafe.Pointer(&model))) -} - -// GetModelBoundingBox - Compute model bounding box limits (considers all meshes) -func GetModelBoundingBox(model Model) BoundingBox { - var boundingBox BoundingBox - getModelBoundingBox(uintptr(unsafe.Pointer(&boundingBox)), uintptr(unsafe.Pointer(&model))) - return boundingBox -} - -// DrawModel - Draw a model (with texture if set) -func DrawModel(model Model, position Vector3, scale float32, tint color.RGBA) { - drawModel(uintptr(unsafe.Pointer(&model)), uintptr(unsafe.Pointer(&position)), scale, *(*uintptr)(unsafe.Pointer(&tint))) -} - -// DrawModelEx - Draw a model with extended parameters -func DrawModelEx(model Model, position Vector3, rotationAxis Vector3, rotationAngle float32, scale Vector3, tint color.RGBA) { - drawModelEx(uintptr(unsafe.Pointer(&model)), uintptr(unsafe.Pointer(&position)), uintptr(unsafe.Pointer(&rotationAxis)), rotationAngle, uintptr(unsafe.Pointer(&scale)), *(*uintptr)(unsafe.Pointer(&tint))) -} - -// DrawModelWires - Draw a model wires (with texture if set) -func DrawModelWires(model Model, position Vector3, scale float32, tint color.RGBA) { - drawModelWires(uintptr(unsafe.Pointer(&model)), uintptr(unsafe.Pointer(&position)), scale, *(*uintptr)(unsafe.Pointer(&tint))) -} - -// DrawModelWiresEx - Draw a model wires (with texture if set) with extended parameters -func DrawModelWiresEx(model Model, position Vector3, rotationAxis Vector3, rotationAngle float32, scale Vector3, tint color.RGBA) { - drawModelWiresEx(uintptr(unsafe.Pointer(&model)), uintptr(unsafe.Pointer(&position)), uintptr(unsafe.Pointer(&rotationAxis)), rotationAngle, uintptr(unsafe.Pointer(&scale)), *(*uintptr)(unsafe.Pointer(&tint))) -} - -// DrawModelPoints - Draw a model as points -func DrawModelPoints(model Model, position Vector3, scale float32, tint color.RGBA) { - drawModelPoints(uintptr(unsafe.Pointer(&model)), uintptr(unsafe.Pointer(&position)), scale, *(*uintptr)(unsafe.Pointer(&tint))) -} - -// DrawModelPointsEx - Draw a model as points with extended parameters -func DrawModelPointsEx(model Model, position Vector3, rotationAxis Vector3, rotationAngle float32, scale Vector3, tint color.RGBA) { - drawModelPointsEx(uintptr(unsafe.Pointer(&model)), uintptr(unsafe.Pointer(&position)), uintptr(unsafe.Pointer(&rotationAxis)), rotationAngle, uintptr(unsafe.Pointer(&scale)), *(*uintptr)(unsafe.Pointer(&tint))) -} - -// DrawBoundingBox - Draw bounding box (wires) -func DrawBoundingBox(box BoundingBox, col color.RGBA) { - drawBoundingBox(uintptr(unsafe.Pointer(&box)), *(*uintptr)(unsafe.Pointer(&col))) -} - -// DrawBillboard - Draw a billboard texture -func DrawBillboard(camera Camera, texture Texture2D, position Vector3, scale float32, tint color.RGBA) { - drawBillboard(uintptr(unsafe.Pointer(&camera)), uintptr(unsafe.Pointer(&texture)), uintptr(unsafe.Pointer(&position)), scale, *(*uintptr)(unsafe.Pointer(&tint))) -} - -// DrawBillboardRec - Draw a billboard texture defined by source -func DrawBillboardRec(camera Camera, texture Texture2D, source Rectangle, position Vector3, size Vector2, tint color.RGBA) { - drawBillboardRec(uintptr(unsafe.Pointer(&camera)), uintptr(unsafe.Pointer(&texture)), uintptr(unsafe.Pointer(&source)), uintptr(unsafe.Pointer(&position)), *(*uintptr)(unsafe.Pointer(&size)), *(*uintptr)(unsafe.Pointer(&tint))) -} - -// DrawBillboardPro - Draw a billboard texture defined by source and rotation -func DrawBillboardPro(camera Camera, texture Texture2D, source Rectangle, position Vector3, up Vector3, size Vector2, origin Vector2, rotation float32, tint color.RGBA) { - drawBillboardPro(uintptr(unsafe.Pointer(&camera)), uintptr(unsafe.Pointer(&texture)), uintptr(unsafe.Pointer(&source)), uintptr(unsafe.Pointer(&position)), uintptr(unsafe.Pointer(&up)), *(*uintptr)(unsafe.Pointer(&size)), *(*uintptr)(unsafe.Pointer(&origin)), rotation, *(*uintptr)(unsafe.Pointer(&tint))) -} - -// UploadMesh - Upload mesh vertex data in GPU and provide VAO/VBO ids -func UploadMesh(mesh *Mesh, dynamic bool) { - uploadMesh(mesh, dynamic) -} - -// UpdateMeshBuffer - Update mesh vertex data in GPU for a specific buffer index -func UpdateMeshBuffer(mesh Mesh, index int32, data []byte, offset int) { - dataSize := int32(len(data)) - updateMeshBuffer(uintptr(unsafe.Pointer(&mesh)), index, data, dataSize, int32(offset)) -} - -// UnloadMesh - Unload mesh data from CPU and GPU -func UnloadMesh(mesh *Mesh) { - unloadMesh(uintptr(unsafe.Pointer(mesh))) -} - -// DrawMesh - Draw a 3d mesh with material and transform -func DrawMesh(mesh Mesh, material Material, transform Matrix) { - drawMesh(uintptr(unsafe.Pointer(&mesh)), uintptr(unsafe.Pointer(&material)), uintptr(unsafe.Pointer(&transform))) -} - -// DrawMeshInstanced - Draw multiple mesh instances with material and different transforms -func DrawMeshInstanced(mesh Mesh, material Material, transforms []Matrix, instances int32) { - drawMeshInstanced(uintptr(unsafe.Pointer(&mesh)), uintptr(unsafe.Pointer(&material)), transforms, instances) -} - -// ExportMesh - Export mesh data to file, returns true on success -func ExportMesh(mesh Mesh, fileName string) bool { - return exportMesh(uintptr(unsafe.Pointer(&mesh)), fileName) -} - -// GetMeshBoundingBox - Compute mesh bounding box limits -func GetMeshBoundingBox(mesh Mesh) BoundingBox { - var boundingBox BoundingBox - getMeshBoundingBox(uintptr(unsafe.Pointer(&boundingBox)), uintptr(unsafe.Pointer(&mesh))) - return boundingBox -} - -// GenMeshTangents - Compute mesh tangents -func GenMeshTangents(mesh *Mesh) { - genMeshTangents(mesh) -} - -// GenMeshPoly - Generate polygonal mesh -func GenMeshPoly(sides int, radius float32) Mesh { - var mesh Mesh - genMeshPoly(uintptr(unsafe.Pointer(&mesh)), int32(sides), radius) - return mesh -} - -// GenMeshPlane - Generate plane mesh (with subdivisions) -func GenMeshPlane(width float32, length float32, resX int, resZ int) Mesh { - var mesh Mesh - genMeshPlane(uintptr(unsafe.Pointer(&mesh)), width, length, int32(resX), int32(resZ)) - return mesh -} - -// GenMeshCube - Generate cuboid mesh -func GenMeshCube(width float32, height float32, length float32) Mesh { - var mesh Mesh - genMeshCube(uintptr(unsafe.Pointer(&mesh)), width, height, length) - return mesh -} - -// GenMeshSphere - Generate sphere mesh (standard sphere) -func GenMeshSphere(radius float32, rings int, slices int) Mesh { - var mesh Mesh - genMeshSphere(uintptr(unsafe.Pointer(&mesh)), radius, int32(rings), int32(slices)) - return mesh -} - -// GenMeshHemiSphere - Generate half-sphere mesh (no bottom cap) -func GenMeshHemiSphere(radius float32, rings int, slices int) Mesh { - var mesh Mesh - genMeshHemiSphere(uintptr(unsafe.Pointer(&mesh)), radius, int32(rings), int32(slices)) - return mesh -} - -// GenMeshCylinder - Generate cylinder mesh -func GenMeshCylinder(radius float32, height float32, slices int) Mesh { - var mesh Mesh - genMeshCylinder(uintptr(unsafe.Pointer(&mesh)), radius, height, int32(slices)) - return mesh -} - -// GenMeshCone - Generate cone/pyramid mesh -func GenMeshCone(radius float32, height float32, slices int) Mesh { - var mesh Mesh - genMeshCone(uintptr(unsafe.Pointer(&mesh)), radius, height, int32(slices)) - return mesh -} - -// GenMeshTorus - Generate torus mesh -func GenMeshTorus(radius float32, size float32, radSeg int, sides int) Mesh { - var mesh Mesh - genMeshTorus(uintptr(unsafe.Pointer(&mesh)), radius, size, int32(radSeg), int32(sides)) - return mesh -} - -// GenMeshKnot - Generate trefoil knot mesh -func GenMeshKnot(radius float32, size float32, radSeg int, sides int) Mesh { - var mesh Mesh - genMeshKnot(uintptr(unsafe.Pointer(&mesh)), radius, size, int32(radSeg), int32(sides)) - return mesh -} - -// GenMeshHeightmap - Generate heightmap mesh from image data -func GenMeshHeightmap(heightmap Image, size Vector3) Mesh { - var mesh Mesh - genMeshHeightmap(uintptr(unsafe.Pointer(&mesh)), uintptr(unsafe.Pointer(&heightmap)), uintptr(unsafe.Pointer(&size))) - return mesh -} - -// GenMeshCubicmap - Generate cubes-based map mesh from image data -func GenMeshCubicmap(cubicmap Image, cubeSize Vector3) Mesh { - var mesh Mesh - genMeshCubicmap(uintptr(unsafe.Pointer(&mesh)), uintptr(unsafe.Pointer(&cubicmap)), uintptr(unsafe.Pointer(&cubeSize))) - return mesh -} - -// LoadMaterials - Load materials from model file -func LoadMaterials(fileName string) []Material { - var materialCount int32 - ret := loadMaterials(fileName, &materialCount) - return unsafe.Slice(ret, materialCount) -} - -// LoadMaterialDefault - Load default material (Supports: DIFFUSE, SPECULAR, NORMAL maps) -func LoadMaterialDefault() Material { - var material Material - loadMaterialDefault(uintptr(unsafe.Pointer(&material))) - return material -} - -// IsMaterialValid - Check if a material is valid (shader assigned, map textures loaded in GPU) -func IsMaterialValid(material Material) bool { - return isMaterialValid(uintptr(unsafe.Pointer(&material))) -} - -// UnloadMaterial - Unload material from GPU memory (VRAM) -func UnloadMaterial(material Material) { - unloadMaterial(uintptr(unsafe.Pointer(&material))) -} - -// SetMaterialTexture - Set texture for a material map type (MATERIAL_MAP_DIFFUSE, MATERIAL_MAP_SPECULAR...) -func SetMaterialTexture(material *Material, mapType int32, texture Texture2D) { - setMaterialTexture(material, mapType, uintptr(unsafe.Pointer(&texture))) -} - -// SetModelMeshMaterial - Set material for a mesh -func SetModelMeshMaterial(model *Model, meshId int32, materialId int32) { - setModelMeshMaterial(model, meshId, materialId) -} - -// LoadModelAnimations - Load model animations from file -func LoadModelAnimations(fileName string) []ModelAnimation { - var animCount int32 - ret := loadModelAnimations(fileName, &animCount) - return unsafe.Slice(ret, animCount) -} - -// UpdateModelAnimation - Update model animation pose (CPU) -func UpdateModelAnimation(model Model, anim ModelAnimation, frame int32) { - updateModelAnimation(uintptr(unsafe.Pointer(&model)), uintptr(unsafe.Pointer(&anim)), frame) -} - -// UpdateModelAnimationBones - Update model animation mesh bone matrices (GPU skinning) -func UpdateModelAnimationBones(model Model, anim ModelAnimation, frame int32) { - updateModelAnimationBones(uintptr(unsafe.Pointer(&model)), uintptr(unsafe.Pointer(&anim)), frame) -} - -// UnloadModelAnimation - Unload animation data -func UnloadModelAnimation(anim ModelAnimation) { - unloadModelAnimation(uintptr(unsafe.Pointer(&anim))) -} - -// UnloadModelAnimations - Unload animation array data -func UnloadModelAnimations(animations []ModelAnimation) { - animCount := int32(len(animations)) - unloadModelAnimations(unsafe.SliceData(animations), animCount) -} - -// IsModelAnimationValid - Check model animation skeleton match -func IsModelAnimationValid(model Model, anim ModelAnimation) bool { - return isModelAnimationValid(uintptr(unsafe.Pointer(&model)), uintptr(unsafe.Pointer(&anim))) -} - -// CheckCollisionSpheres - Check collision between two spheres -func CheckCollisionSpheres(center1 Vector3, radius1 float32, center2 Vector3, radius2 float32) bool { - return checkCollisionSpheres(uintptr(unsafe.Pointer(¢er1)), radius1, uintptr(unsafe.Pointer(¢er2)), radius2) -} - -// CheckCollisionBoxes - Check collision between two bounding boxes -func CheckCollisionBoxes(box1 BoundingBox, box2 BoundingBox) bool { - return checkCollisionBoxes(uintptr(unsafe.Pointer(&box1)), uintptr(unsafe.Pointer(&box2))) -} - -// CheckCollisionBoxSphere - Check collision between box and sphere -func CheckCollisionBoxSphere(box BoundingBox, center Vector3, radius float32) bool { - return checkCollisionBoxSphere(uintptr(unsafe.Pointer(&box)), uintptr(unsafe.Pointer(¢er)), radius) -} - -// GetRayCollisionSphere - Get collision info between ray and sphere -func GetRayCollisionSphere(ray Ray, center Vector3, radius float32) RayCollision { - var rayCollision RayCollision - getRayCollisionSphere(uintptr(unsafe.Pointer(&rayCollision)), uintptr(unsafe.Pointer(&ray)), uintptr(unsafe.Pointer(¢er)), radius) - return rayCollision -} - -// GetRayCollisionBox - Get collision info between ray and box -func GetRayCollisionBox(ray Ray, box BoundingBox) RayCollision { - var rayCollision RayCollision - getRayCollisionBox(uintptr(unsafe.Pointer(&rayCollision)), uintptr(unsafe.Pointer(&ray)), uintptr(unsafe.Pointer(&box))) - return rayCollision -} - -// GetRayCollisionMesh - Get collision info between ray and mesh -func GetRayCollisionMesh(ray Ray, mesh Mesh, transform Matrix) RayCollision { - var rayCollision RayCollision - getRayCollisionMesh(uintptr(unsafe.Pointer(&rayCollision)), uintptr(unsafe.Pointer(&ray)), uintptr(unsafe.Pointer(&mesh)), uintptr(unsafe.Pointer(&transform))) - return rayCollision -} - -// GetRayCollisionTriangle - Get collision info between ray and triangle -func GetRayCollisionTriangle(ray Ray, p1 Vector3, p2 Vector3, p3 Vector3) RayCollision { - var rayCollision RayCollision - getRayCollisionTriangle(uintptr(unsafe.Pointer(&rayCollision)), uintptr(unsafe.Pointer(&ray)), uintptr(unsafe.Pointer(&p1)), uintptr(unsafe.Pointer(&p2)), uintptr(unsafe.Pointer(&p3))) - return rayCollision -} - -// GetRayCollisionQuad - Get collision info between ray and quad -func GetRayCollisionQuad(ray Ray, p1 Vector3, p2 Vector3, p3 Vector3, p4 Vector3) RayCollision { - var rayCollision RayCollision - getRayCollisionQuad(uintptr(unsafe.Pointer(&rayCollision)), uintptr(unsafe.Pointer(&ray)), uintptr(unsafe.Pointer(&p1)), uintptr(unsafe.Pointer(&p2)), uintptr(unsafe.Pointer(&p3)), uintptr(unsafe.Pointer(&p4))) - return rayCollision -} - -// InitAudioDevice - Initialize audio device and context -func InitAudioDevice() { - initAudioDevice() -} - -// CloseAudioDevice - Close the audio device and context -func CloseAudioDevice() { - closeAudioDevice() -} - -// IsAudioDeviceReady - Check if audio device has been initialized successfully -func IsAudioDeviceReady() bool { - return isAudioDeviceReady() -} - -// SetMasterVolume - Set master volume (listener) -func SetMasterVolume(volume float32) { - setMasterVolume(volume) -} - -// GetMasterVolume - Get master volume (listener) -func GetMasterVolume() float32 { - return getMasterVolume() -} - -// LoadWave - Load wave data from file -func LoadWave(fileName string) Wave { - var wave Wave - loadWave(uintptr(unsafe.Pointer(&wave)), fileName) - return wave -} - -// LoadWaveFromMemory - Load wave from memory buffer, fileType refers to extension: i.e. '.wav' -func LoadWaveFromMemory(fileType string, fileData []byte, dataSize int32) Wave { - var wave Wave - loadWaveFromMemory(uintptr(unsafe.Pointer(&wave)), fileType, fileData, dataSize) - return wave -} - -// IsWaveValid - Checks if wave data is valid (data loaded and parameters) -func IsWaveValid(wave Wave) bool { - return isWaveValid(uintptr(unsafe.Pointer(&wave))) -} - -// LoadSound - Load sound from file -func LoadSound(fileName string) Sound { - var sound Sound - loadSound(uintptr(unsafe.Pointer(&sound)), fileName) - return sound -} - -// LoadSoundFromWave - Load sound from wave data -func LoadSoundFromWave(wave Wave) Sound { - var sound Sound - loadSoundFromWave(uintptr(unsafe.Pointer(&sound)), uintptr(unsafe.Pointer(&wave))) - return sound -} - -// LoadSoundAlias - Create a new sound that shares the same sample data as the source sound, does not own the sound data -func LoadSoundAlias(source Sound) Sound { - var sound Sound - loadSoundAlias(uintptr(unsafe.Pointer(&sound)), uintptr(unsafe.Pointer(&source))) - return sound -} - -// IsSoundValid - Checks if a sound is valid (data loaded and buffers initialized) -func IsSoundValid(sound Sound) bool { - return isSoundValid(uintptr(unsafe.Pointer(&sound))) -} - -// UpdateSound - Update sound buffer with new data -func UpdateSound(sound Sound, data []byte, sampleCount int32) { - updateSound(uintptr(unsafe.Pointer(&sound)), data, sampleCount) -} - -// UnloadWave - Unload wave data -func UnloadWave(wave Wave) { - unloadWave(uintptr(unsafe.Pointer(&wave))) -} - -// UnloadSound - Unload sound -func UnloadSound(sound Sound) { - unloadSound(uintptr(unsafe.Pointer(&sound))) -} - -// UnloadSoundAlias - Unload a sound alias (does not deallocate sample data) -func UnloadSoundAlias(alias Sound) { - unloadSoundAlias(uintptr(unsafe.Pointer(&alias))) -} - -// ExportWave - Export wave data to file, returns true on success -func ExportWave(wave Wave, fileName string) bool { - return exportWave(uintptr(unsafe.Pointer(&wave)), fileName) -} - -// PlaySound - Play a sound -func PlaySound(sound Sound) { - playSound(uintptr(unsafe.Pointer(&sound))) -} - -// StopSound - Stop playing a sound -func StopSound(sound Sound) { - stopSound(uintptr(unsafe.Pointer(&sound))) -} - -// PauseSound - Pause a sound -func PauseSound(sound Sound) { - pauseSound(uintptr(unsafe.Pointer(&sound))) -} - -// ResumeSound - Resume a paused sound -func ResumeSound(sound Sound) { - resumeSound(uintptr(unsafe.Pointer(&sound))) -} - -// IsSoundPlaying - Check if a sound is currently playing -func IsSoundPlaying(sound Sound) bool { - return isSoundPlaying(uintptr(unsafe.Pointer(&sound))) -} - -// SetSoundVolume - Set volume for a sound (1.0 is max level) -func SetSoundVolume(sound Sound, volume float32) { - setSoundVolume(uintptr(unsafe.Pointer(&sound)), volume) -} - -// SetSoundPitch - Set pitch for a sound (1.0 is base level) -func SetSoundPitch(sound Sound, pitch float32) { - setSoundPitch(uintptr(unsafe.Pointer(&sound)), pitch) -} - -// SetSoundPan - Set pan for a sound (0.5 is center) -func SetSoundPan(sound Sound, pan float32) { - setSoundPan(uintptr(unsafe.Pointer(&sound)), pan) -} - -// WaveCopy - Copy a wave to a new wave -func WaveCopy(wave Wave) Wave { - var copy Wave - waveCopy(uintptr(unsafe.Pointer(©)), uintptr(unsafe.Pointer(&wave))) - return copy -} - -// WaveCrop - Crop a wave to defined frames range -func WaveCrop(wave *Wave, initFrame int32, finalFrame int32) { - waveCrop(wave, initFrame, finalFrame) -} - -// WaveFormat - Convert wave data to desired format -func WaveFormat(wave *Wave, sampleRate int32, sampleSize int32, channels int32) { - waveFormat(wave, sampleRate, sampleRate, channels) -} - -// LoadWaveSamples - Load samples data from wave as a 32bit float data array -func LoadWaveSamples(wave Wave) []float32 { - ret := loadWaveSamples(uintptr(unsafe.Pointer(&wave))) - return unsafe.Slice(ret, wave.FrameCount*wave.Channels) -} - -// UnloadWaveSamples - Unload samples data loaded with LoadWaveSamples() -func UnloadWaveSamples(samples []float32) { - unloadWaveSamples(samples) -} - -// LoadMusicStream - Load music stream from file -func LoadMusicStream(fileName string) Music { - var music Music - loadMusicStream(uintptr(unsafe.Pointer(&music)), fileName) - return music -} - -// LoadMusicStreamFromMemory - Load music stream from data -func LoadMusicStreamFromMemory(fileType string, data []byte, dataSize int32) Music { - var music Music - loadMusicStreamFromMemory(uintptr(unsafe.Pointer(&music)), fileType, data, dataSize) - return music -} - -// IsMusicValid - Checks if a music stream is valid (context and buffers initialized) -func IsMusicValid(music Music) bool { - return isMusicValid(uintptr(unsafe.Pointer(&music))) -} - -// UnloadMusicStream - Unload music stream -func UnloadMusicStream(music Music) { - unloadMusicStream(uintptr(unsafe.Pointer(&music))) -} - -// PlayMusicStream - Start music playing -func PlayMusicStream(music Music) { - playMusicStream(uintptr(unsafe.Pointer(&music))) -} - -// IsMusicStreamPlaying - Check if music is playing -func IsMusicStreamPlaying(music Music) bool { - return isMusicStreamPlaying(uintptr(unsafe.Pointer(&music))) -} - -// UpdateMusicStream - Updates buffers for music streaming -func UpdateMusicStream(music Music) { - updateMusicStream(uintptr(unsafe.Pointer(&music))) -} - -// StopMusicStream - Stop music playing -func StopMusicStream(music Music) { - stopMusicStream(uintptr(unsafe.Pointer(&music))) -} - -// PauseMusicStream - Pause music playing -func PauseMusicStream(music Music) { - pauseMusicStream(uintptr(unsafe.Pointer(&music))) -} - -// ResumeMusicStream - Resume playing paused music -func ResumeMusicStream(music Music) { - resumeMusicStream(uintptr(unsafe.Pointer(&music))) -} - -// SeekMusicStream - Seek music to a position (in seconds) -func SeekMusicStream(music Music, position float32) { - seekMusicStream(uintptr(unsafe.Pointer(&music)), position) -} - -// SetMusicVolume - Set volume for music (1.0 is max level) -func SetMusicVolume(music Music, volume float32) { - setMusicVolume(uintptr(unsafe.Pointer(&music)), volume) -} - -// SetMusicPitch - Set pitch for a music (1.0 is base level) -func SetMusicPitch(music Music, pitch float32) { - setMusicPitch(uintptr(unsafe.Pointer(&music)), pitch) -} - -// SetMusicPan - Set pan for a music (0.5 is center) -func SetMusicPan(music Music, pan float32) { - setMusicPan(uintptr(unsafe.Pointer(&music)), pan) -} - -// GetMusicTimeLength - Get music time length (in seconds) -func GetMusicTimeLength(music Music) float32 { - return getMusicTimeLength(uintptr(unsafe.Pointer(&music))) -} - -// GetMusicTimePlayed - Get current music time played (in seconds) -func GetMusicTimePlayed(music Music) float32 { - return getMusicTimePlayed(uintptr(unsafe.Pointer(&music))) -} - -// LoadAudioStream - Load audio stream (to stream raw audio pcm data) -func LoadAudioStream(sampleRate uint32, sampleSize uint32, channels uint32) AudioStream { - var audioStream AudioStream - loadAudioStream(uintptr(unsafe.Pointer(&audioStream)), sampleRate, sampleSize, channels) - return audioStream -} - -// IsAudioStreamValid - Checks if an audio stream is valid (buffers initialized) -func IsAudioStreamValid(stream AudioStream) bool { - return isAudioStreamValid(uintptr(unsafe.Pointer(&stream))) -} - -// UnloadAudioStream - Unload audio stream and free memory -func UnloadAudioStream(stream AudioStream) { - unloadAudioStream(uintptr(unsafe.Pointer(&stream))) -} - -// UpdateAudioStream - Update audio stream buffers with data -func UpdateAudioStream(stream AudioStream, data []float32) { - frameCount := int32(len(data)) - updateAudioStream(uintptr(unsafe.Pointer(&stream)), data, frameCount) -} - -// IsAudioStreamProcessed - Check if any audio stream buffers requires refill -func IsAudioStreamProcessed(stream AudioStream) bool { - return isAudioStreamProcessed(uintptr(unsafe.Pointer(&stream))) -} - -// PlayAudioStream - Play audio stream -func PlayAudioStream(stream AudioStream) { - playAudioStream(uintptr(unsafe.Pointer(&stream))) -} - -// PauseAudioStream - Pause audio stream -func PauseAudioStream(stream AudioStream) { - pauseAudioStream(uintptr(unsafe.Pointer(&stream))) -} - -// ResumeAudioStream - Resume audio stream -func ResumeAudioStream(stream AudioStream) { - resumeAudioStream(uintptr(unsafe.Pointer(&stream))) -} - -// IsAudioStreamPlaying - Check if audio stream is playing -func IsAudioStreamPlaying(stream AudioStream) bool { - return isAudioStreamPlaying(uintptr(unsafe.Pointer(&stream))) -} - -// StopAudioStream - Stop audio stream -func StopAudioStream(stream AudioStream) { - stopAudioStream(uintptr(unsafe.Pointer(&stream))) -} - -// SetAudioStreamVolume - Set volume for audio stream (1.0 is max level) -func SetAudioStreamVolume(stream AudioStream, volume float32) { - setAudioStreamVolume(uintptr(unsafe.Pointer(&stream)), volume) -} - -// SetAudioStreamPitch - Set pitch for audio stream (1.0 is base level) -func SetAudioStreamPitch(stream AudioStream, pitch float32) { - setAudioStreamPitch(uintptr(unsafe.Pointer(&stream)), pitch) -} - -// SetAudioStreamPan - Set pan for audio stream (0.5 is centered) -func SetAudioStreamPan(stream AudioStream, pan float32) { - setAudioStreamPan(uintptr(unsafe.Pointer(&stream)), pan) -} - -// SetAudioStreamBufferSizeDefault - Default size for new audio streams -func SetAudioStreamBufferSizeDefault(size int32) { - setAudioStreamBufferSizeDefault(size) -} - -// SetAudioStreamCallback - Audio thread callback to request new data -func SetAudioStreamCallback(stream AudioStream, callback AudioCallback) { - fn := purego.NewCallback(func(bufferData unsafe.Pointer, frames int32) uintptr { - callback(unsafe.Slice((*float32)(bufferData), frames), int(frames)) - return 0 - }) - setAudioStreamCallback(uintptr(unsafe.Pointer(&stream)), fn) -} - -// AttachAudioStreamProcessor - Attach audio stream processor to stream, receives the samples as s -func AttachAudioStreamProcessor(stream AudioStream, processor AudioCallback) { - fn := purego.NewCallback(func(bufferData unsafe.Pointer, frames int32) uintptr { - processor(unsafe.Slice((*float32)(bufferData), frames), int(frames)) - return 0 - }) - ptr := uintptr(reflect.ValueOf(processor).UnsafePointer()) - audioCallbacks[ptr] = fn - attachAudioStreamProcessor(uintptr(unsafe.Pointer(&stream)), fn) -} - -// DetachAudioStreamProcessor - Detach audio stream processor from stream -func DetachAudioStreamProcessor(stream AudioStream, processor AudioCallback) { - ptr := uintptr(reflect.ValueOf(processor).UnsafePointer()) - fn := audioCallbacks[ptr] - detachAudioStreamProcessor(uintptr(unsafe.Pointer(&stream)), fn) -} - -// AttachAudioMixedProcessor - Attach audio stream processor to the entire audio pipeline, receives the samples as s -func AttachAudioMixedProcessor(processor AudioCallback) { - fn := purego.NewCallback(func(bufferData unsafe.Pointer, frames int32) uintptr { - processor(unsafe.Slice((*float32)(bufferData), frames), int(frames)) - return 0 - }) - ptr := uintptr(reflect.ValueOf(processor).UnsafePointer()) - audioCallbacks[ptr] = fn - attachAudioMixedProcessor(fn) -} - -// DetachAudioMixedProcessor - Detach audio stream processor from the entire audio pipeline -func DetachAudioMixedProcessor(processor AudioCallback) { - ptr := uintptr(reflect.ValueOf(processor).UnsafePointer()) - fn := audioCallbacks[ptr] - detachAudioMixedProcessor(fn) -} - -// SetCallbackFunc - Sets callback function -func SetCallbackFunc(func()) { -} - -// NewImageFromImage - Returns new Image from Go image.Image -func NewImageFromImage(img image.Image) *Image { - size := img.Bounds().Size() - - ret := GenImageColor(size.X, size.Y, White) - - for y := 0; y < size.Y; y++ { - for x := 0; x < size.X; x++ { - col := img.At(x, y) - r, g, b, a := col.RGBA() - rcolor := NewColor(uint8(r>>8), uint8(g>>8), uint8(b>>8), uint8(a>>8)) - ImageDrawPixel(ret, int32(x), int32(y), rcolor) - } - } - - return ret -} - -// ToImage converts a Image to Go image.Image -func (i *Image) ToImage() image.Image { - img := image.NewRGBA(image.Rect(0, 0, int(i.Width), int(i.Height))) - - // Get pixel data from image (RGBA 32bit) - ret := LoadImageColors(i) - pixels := (*[1 << 24]uint8)(unsafe.Pointer(unsafe.SliceData(ret)))[0 : i.Width*i.Height*4] - - img.Pix = pixels - - return img -} - -// OpenAsset - Open asset -func OpenAsset(name string) (Asset, error) { - f, err := os.Open(name) - if err != nil { - return nil, err - } - return f, nil -} - -// HomeDir - Returns user home directory -// NOTE: On Android this returns internal data path and must be called after InitWindow -func HomeDir() string { - if homeDir, err := os.UserHomeDir(); err == nil { - return homeDir - } - return "" -} diff --git a/testdata/rl/.gitkeep b/testdata/rl/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/testdata/rl/aliases_gen_formatted.go b/testdata/rl/aliases_gen_formatted.go new file mode 100644 index 0000000..85f4693 --- /dev/null +++ b/testdata/rl/aliases_gen_formatted.go @@ -0,0 +1,20 @@ +// AUTOGENERATED FILE. DO NOT EDIT + +//go:build js + +package rl + +// Quaternion, 4 components (Vector4 alias) +type Quaternion = Vector4 + +// Texture2D, same as Texture +type Texture2D = Texture + +// TextureCubemap, same as Texture +type TextureCubemap = Texture + +// RenderTexture2D, same as RenderTexture +type RenderTexture2D = RenderTexture + +// Camera type fallback, defaults to Camera3D +type Camera = Camera3D diff --git a/testdata/rl/defines_gen_formatted.go b/testdata/rl/defines_gen_formatted.go new file mode 100644 index 0000000..de37abb --- /dev/null +++ b/testdata/rl/defines_gen_formatted.go @@ -0,0 +1,121 @@ +// AUTOGENERATED FILE. DO NOT EDIT + +//go:build js + +package rl + +const RaylibVersionMajor = 5 + +const RaylibVersionMinor = 6 + +const RaylibVersionPatch = 0 + +const RaylibVersion = "5.6-dev" + +const Pi = 3.14159265358979323846 + +const Deg2Rad = (Pi / 180.0) + +const Rad2Deg = (180.0 / Pi) + +//Light Gray +var Lightgray = Color{200, 200, 200, 255} + +//Gray +var Gray = Color{130, 130, 130, 255} + +//Dark Gray +var Darkgray = Color{80, 80, 80, 255} + +//Yellow +var Yellow = Color{253, 249, 0, 255} + +//Gold +var Gold = Color{255, 203, 0, 255} + +//Orange +var Orange = Color{255, 161, 0, 255} + +//Pink +var Pink = Color{255, 109, 194, 255} + +//Red +var Red = Color{230, 41, 55, 255} + +//Maroon +var Maroon = Color{190, 33, 55, 255} + +//Green +var Green = Color{0, 228, 48, 255} + +//Lime +var Lime = Color{0, 158, 47, 255} + +//Dark Green +var Darkgreen = Color{0, 117, 44, 255} + +//Sky Blue +var Skyblue = Color{102, 191, 255, 255} + +//Blue +var Blue = Color{0, 121, 241, 255} + +//Dark Blue +var Darkblue = Color{0, 82, 172, 255} + +//Purple +var Purple = Color{200, 122, 255, 255} + +//Violet +var Violet = Color{135, 60, 190, 255} + +//Dark Purple +var Darkpurple = Color{112, 31, 126, 255} + +//Beige +var Beige = Color{211, 176, 131, 255} + +//Brown +var Brown = Color{127, 106, 79, 255} + +//Dark Brown +var Darkbrown = Color{76, 63, 47, 255} + +//White +var White = Color{255, 255, 255, 255} + +//Black +var Black = Color{0, 0, 0, 255} + +//Blank (Transparent) +var Blank = Color{0, 0, 0, 0} + +//Magenta +var Magenta = Color{255, 0, 255, 255} + +//My own White (raylib logo) +var Raywhite = Color{245, 245, 245, 255} + +// +const MouseLeftButton = MOUSE_BUTTON_LEFT + +// +const MouseRightButton = MOUSE_BUTTON_RIGHT + +// +const MouseMiddleButton = MOUSE_BUTTON_MIDDLE + +// +const MaterialMapDiffuse = MATERIAL_MAP_ALBEDO + +// +const MaterialMapSpecular = MATERIAL_MAP_METALNESS + +// +const ShaderLocMapDiffuse = SHADER_LOC_MAP_ALBEDO + +// +const ShaderLocMapSpecular = SHADER_LOC_MAP_METALNESS + +//Compatibility hack for previous raylib versions +var GetMouseRay = GetScreenToWorldRay diff --git a/testdata/rl/enums_gen_formatted.go b/testdata/rl/enums_gen_formatted.go new file mode 100644 index 0000000..303b8d2 --- /dev/null +++ b/testdata/rl/enums_gen_formatted.go @@ -0,0 +1,741 @@ +// AUTOGENERATED FILE. DO NOT EDIT + +//go:build js + +package rl + +// System/Window config flags +type ConfigFlags = int32 + +const ( + // Set to try enabling V-Sync on GPU + FlagVsyncHint = 64 + // Set to run program in fullscreen + FlagFullscreenMode = 2 + // Set to allow resizable window + FlagWindowResizable = 4 + // Set to disable window decoration (frame and buttons) + FlagWindowUndecorated = 8 + // Set to hide window + FlagWindowHidden = 128 + // Set to minimize window (iconify) + FlagWindowMinimized = 512 + // Set to maximize window (expanded to monitor) + FlagWindowMaximized = 1024 + // Set to window non focused + FlagWindowUnfocused = 2048 + // Set to window always on top + FlagWindowTopmost = 4096 + // Set to allow windows running while minimized + FlagWindowAlwaysRun = 256 + // Set to allow transparent framebuffer + FlagWindowTransparent = 16 + // Set to support HighDPI + FlagWindowHighdpi = 8192 + // Set to support mouse passthrough, only supported when FLAG_WINDOW_UNDECORATED + FlagWindowMousePassthrough = 16384 + // Set to run program in borderless windowed mode + FlagBorderlessWindowedMode = 32768 + // Set to try enabling MSAA 4X + FlagMsaa4XHint = 32 + // Set to try enabling interlaced video format (for V3D) + FlagInterlacedHint = 65536 +) + +// Trace log level +type TraceLogLevel = int32 + +const ( + // Display all logs + LogAll = 0 + // Trace logging, intended for internal use only + LogTrace = 1 + // Debug logging, used for internal debugging, it should be disabled on release builds + LogDebug = 2 + // Info logging, used for program execution info + LogInfo = 3 + // Warning logging, used on recoverable failures + LogWarning = 4 + // Error logging, used on unrecoverable failures + LogError = 5 + // Fatal logging, used to abort program: exit(EXIT_FAILURE) + LogFatal = 6 + // Disable logging + LogNone = 7 +) + +// Keyboard keys (US keyboard layout) +type KeyboardKey = int32 + +const ( + // Key: NULL, used for no key pressed + KeyNull = 0 + // Key: ' + KeyApostrophe = 39 + // Key: , + KeyComma = 44 + // Key: - + KeyMinus = 45 + // Key: . + KeyPeriod = 46 + // Key: / + KeySlash = 47 + // Key: 0 + KeyZero = 48 + // Key: 1 + KeyOne = 49 + // Key: 2 + KeyTwo = 50 + // Key: 3 + KeyThree = 51 + // Key: 4 + KeyFour = 52 + // Key: 5 + KeyFive = 53 + // Key: 6 + KeySix = 54 + // Key: 7 + KeySeven = 55 + // Key: 8 + KeyEight = 56 + // Key: 9 + KeyNine = 57 + // Key: ; + KeySemicolon = 59 + // Key: = + KeyEqual = 61 + // Key: A | a + KeyA = 65 + // Key: B | b + KeyB = 66 + // Key: C | c + KeyC = 67 + // Key: D | d + KeyD = 68 + // Key: E | e + KeyE = 69 + // Key: F | f + KeyF = 70 + // Key: G | g + KeyG = 71 + // Key: H | h + KeyH = 72 + // Key: I | i + KeyI = 73 + // Key: J | j + KeyJ = 74 + // Key: K | k + KeyK = 75 + // Key: L | l + KeyL = 76 + // Key: M | m + KeyM = 77 + // Key: N | n + KeyN = 78 + // Key: O | o + KeyO = 79 + // Key: P | p + KeyP = 80 + // Key: Q | q + KeyQ = 81 + // Key: R | r + KeyR = 82 + // Key: S | s + KeyS = 83 + // Key: T | t + KeyT = 84 + // Key: U | u + KeyU = 85 + // Key: V | v + KeyV = 86 + // Key: W | w + KeyW = 87 + // Key: X | x + KeyX = 88 + // Key: Y | y + KeyY = 89 + // Key: Z | z + KeyZ = 90 + // Key: [ + KeyLeftBracket = 91 + // Key: '\' + KeyBackslash = 92 + // Key: ] + KeyRightBracket = 93 + // Key: ` + KeyGrave = 96 + // Key: Space + KeySpace = 32 + // Key: Esc + KeyEscape = 256 + // Key: Enter + KeyEnter = 257 + // Key: Tab + KeyTab = 258 + // Key: Backspace + KeyBackspace = 259 + // Key: Ins + KeyInsert = 260 + // Key: Del + KeyDelete = 261 + // Key: Cursor right + KeyRight = 262 + // Key: Cursor left + KeyLeft = 263 + // Key: Cursor down + KeyDown = 264 + // Key: Cursor up + KeyUp = 265 + // Key: Page up + KeyPageUp = 266 + // Key: Page down + KeyPageDown = 267 + // Key: Home + KeyHome = 268 + // Key: End + KeyEnd = 269 + // Key: Caps lock + KeyCapsLock = 280 + // Key: Scroll down + KeyScrollLock = 281 + // Key: Num lock + KeyNumLock = 282 + // Key: Print screen + KeyPrintScreen = 283 + // Key: Pause + KeyPause = 284 + // Key: F1 + KeyF1 = 290 + // Key: F2 + KeyF2 = 291 + // Key: F3 + KeyF3 = 292 + // Key: F4 + KeyF4 = 293 + // Key: F5 + KeyF5 = 294 + // Key: F6 + KeyF6 = 295 + // Key: F7 + KeyF7 = 296 + // Key: F8 + KeyF8 = 297 + // Key: F9 + KeyF9 = 298 + // Key: F10 + KeyF10 = 299 + // Key: F11 + KeyF11 = 300 + // Key: F12 + KeyF12 = 301 + // Key: Shift left + KeyLeftShift = 340 + // Key: Control left + KeyLeftControl = 341 + // Key: Alt left + KeyLeftAlt = 342 + // Key: Super left + KeyLeftSuper = 343 + // Key: Shift right + KeyRightShift = 344 + // Key: Control right + KeyRightControl = 345 + // Key: Alt right + KeyRightAlt = 346 + // Key: Super right + KeyRightSuper = 347 + // Key: KB menu + KeyKbMenu = 348 + // Key: Keypad 0 + KeyKp0 = 320 + // Key: Keypad 1 + KeyKp1 = 321 + // Key: Keypad 2 + KeyKp2 = 322 + // Key: Keypad 3 + KeyKp3 = 323 + // Key: Keypad 4 + KeyKp4 = 324 + // Key: Keypad 5 + KeyKp5 = 325 + // Key: Keypad 6 + KeyKp6 = 326 + // Key: Keypad 7 + KeyKp7 = 327 + // Key: Keypad 8 + KeyKp8 = 328 + // Key: Keypad 9 + KeyKp9 = 329 + // Key: Keypad . + KeyKpDecimal = 330 + // Key: Keypad / + KeyKpDivide = 331 + // Key: Keypad * + KeyKpMultiply = 332 + // Key: Keypad - + KeyKpSubtract = 333 + // Key: Keypad + + KeyKpAdd = 334 + // Key: Keypad Enter + KeyKpEnter = 335 + // Key: Keypad = + KeyKpEqual = 336 + // Key: Android back button + KeyBack = 4 + // Key: Android menu button + KeyMenu = 5 + // Key: Android volume up button + KeyVolumeUp = 24 + // Key: Android volume down button + KeyVolumeDown = 25 +) + +// Mouse buttons +type MouseButton = int32 + +const ( + // Mouse button left + MouseButtonLeft = 0 + // Mouse button right + MouseButtonRight = 1 + // Mouse button middle (pressed wheel) + MouseButtonMiddle = 2 + // Mouse button side (advanced mouse device) + MouseButtonSide = 3 + // Mouse button extra (advanced mouse device) + MouseButtonExtra = 4 + // Mouse button forward (advanced mouse device) + MouseButtonForward = 5 + // Mouse button back (advanced mouse device) + MouseButtonBack = 6 +) + +// Mouse cursor +type MouseCursor = int32 + +const ( + // Default pointer shape + MouseCursorDefault = 0 + // Arrow shape + MouseCursorArrow = 1 + // Text writing cursor shape + MouseCursorIbeam = 2 + // Cross shape + MouseCursorCrosshair = 3 + // Pointing hand cursor + MouseCursorPointingHand = 4 + // Horizontal resize/move arrow shape + MouseCursorResizeEw = 5 + // Vertical resize/move arrow shape + MouseCursorResizeNs = 6 + // Top-left to bottom-right diagonal resize/move arrow shape + MouseCursorResizeNwse = 7 + // The top-right to bottom-left diagonal resize/move arrow shape + MouseCursorResizeNesw = 8 + // The omnidirectional resize/move cursor shape + MouseCursorResizeAll = 9 + // The operation-not-allowed shape + MouseCursorNotAllowed = 10 +) + +// Gamepad buttons +type GamepadButton = int32 + +const ( + // Unknown button, just for error checking + GamepadButtonUnknown = 0 + // Gamepad left DPAD up button + GamepadButtonLeftFaceUp = 1 + // Gamepad left DPAD right button + GamepadButtonLeftFaceRight = 2 + // Gamepad left DPAD down button + GamepadButtonLeftFaceDown = 3 + // Gamepad left DPAD left button + GamepadButtonLeftFaceLeft = 4 + // Gamepad right button up (i.e. PS3: Triangle, Xbox: Y) + GamepadButtonRightFaceUp = 5 + // Gamepad right button right (i.e. PS3: Circle, Xbox: B) + GamepadButtonRightFaceRight = 6 + // Gamepad right button down (i.e. PS3: Cross, Xbox: A) + GamepadButtonRightFaceDown = 7 + // Gamepad right button left (i.e. PS3: Square, Xbox: X) + GamepadButtonRightFaceLeft = 8 + // Gamepad top/back trigger left (first), it could be a trailing button + GamepadButtonLeftTrigger1 = 9 + // Gamepad top/back trigger left (second), it could be a trailing button + GamepadButtonLeftTrigger2 = 10 + // Gamepad top/back trigger right (first), it could be a trailing button + GamepadButtonRightTrigger1 = 11 + // Gamepad top/back trigger right (second), it could be a trailing button + GamepadButtonRightTrigger2 = 12 + // Gamepad center buttons, left one (i.e. PS3: Select) + GamepadButtonMiddleLeft = 13 + // Gamepad center buttons, middle one (i.e. PS3: PS, Xbox: XBOX) + GamepadButtonMiddle = 14 + // Gamepad center buttons, right one (i.e. PS3: Start) + GamepadButtonMiddleRight = 15 + // Gamepad joystick pressed button left + GamepadButtonLeftThumb = 16 + // Gamepad joystick pressed button right + GamepadButtonRightThumb = 17 +) + +// Gamepad axes +type GamepadAxis = int32 + +const ( + // Gamepad left stick X axis + GamepadAxisLeftX = 0 + // Gamepad left stick Y axis + GamepadAxisLeftY = 1 + // Gamepad right stick X axis + GamepadAxisRightX = 2 + // Gamepad right stick Y axis + GamepadAxisRightY = 3 + // Gamepad back trigger left, pressure level: [1..-1] + GamepadAxisLeftTrigger = 4 + // Gamepad back trigger right, pressure level: [1..-1] + GamepadAxisRightTrigger = 5 +) + +// Material map index +type MaterialMapIndex = int32 + +const ( + // Albedo material (same as: MATERIAL_MAP_DIFFUSE) + MaterialMapAlbedo = 0 + // Metalness material (same as: MATERIAL_MAP_SPECULAR) + MaterialMapMetalness = 1 + // Normal material + MaterialMapNormal = 2 + // Roughness material + MaterialMapRoughness = 3 + // Ambient occlusion material + MaterialMapOcclusion = 4 + // Emission material + MaterialMapEmission = 5 + // Heightmap material + MaterialMapHeight = 6 + // Cubemap material (NOTE: Uses GL_TEXTURE_CUBE_MAP) + MaterialMapCubemap = 7 + // Irradiance material (NOTE: Uses GL_TEXTURE_CUBE_MAP) + MaterialMapIrradiance = 8 + // Prefilter material (NOTE: Uses GL_TEXTURE_CUBE_MAP) + MaterialMapPrefilter = 9 + // Brdf material + MaterialMapBrdf = 10 +) + +// Shader location index +type ShaderLocationIndex = int32 + +const ( + // Shader location: vertex attribute: position + ShaderLocVertexPosition = 0 + // Shader location: vertex attribute: texcoord01 + ShaderLocVertexTexcoord01 = 1 + // Shader location: vertex attribute: texcoord02 + ShaderLocVertexTexcoord02 = 2 + // Shader location: vertex attribute: normal + ShaderLocVertexNormal = 3 + // Shader location: vertex attribute: tangent + ShaderLocVertexTangent = 4 + // Shader location: vertex attribute: color + ShaderLocVertexColor = 5 + // Shader location: matrix uniform: model-view-projection + ShaderLocMatrixMvp = 6 + // Shader location: matrix uniform: view (camera transform) + ShaderLocMatrixView = 7 + // Shader location: matrix uniform: projection + ShaderLocMatrixProjection = 8 + // Shader location: matrix uniform: model (transform) + ShaderLocMatrixModel = 9 + // Shader location: matrix uniform: normal + ShaderLocMatrixNormal = 10 + // Shader location: vector uniform: view + ShaderLocVectorView = 11 + // Shader location: vector uniform: diffuse color + ShaderLocColorDiffuse = 12 + // Shader location: vector uniform: specular color + ShaderLocColorSpecular = 13 + // Shader location: vector uniform: ambient color + ShaderLocColorAmbient = 14 + // Shader location: sampler2d texture: albedo (same as: SHADER_LOC_MAP_DIFFUSE) + ShaderLocMapAlbedo = 15 + // Shader location: sampler2d texture: metalness (same as: SHADER_LOC_MAP_SPECULAR) + ShaderLocMapMetalness = 16 + // Shader location: sampler2d texture: normal + ShaderLocMapNormal = 17 + // Shader location: sampler2d texture: roughness + ShaderLocMapRoughness = 18 + // Shader location: sampler2d texture: occlusion + ShaderLocMapOcclusion = 19 + // Shader location: sampler2d texture: emission + ShaderLocMapEmission = 20 + // Shader location: sampler2d texture: height + ShaderLocMapHeight = 21 + // Shader location: samplerCube texture: cubemap + ShaderLocMapCubemap = 22 + // Shader location: samplerCube texture: irradiance + ShaderLocMapIrradiance = 23 + // Shader location: samplerCube texture: prefilter + ShaderLocMapPrefilter = 24 + // Shader location: sampler2d texture: brdf + ShaderLocMapBrdf = 25 + // Shader location: vertex attribute: boneIds + ShaderLocVertexBoneids = 26 + // Shader location: vertex attribute: boneWeights + ShaderLocVertexBoneweights = 27 + // Shader location: array of matrices uniform: boneMatrices + ShaderLocBoneMatrices = 28 + // Shader location: vertex attribute: instanceTransform + ShaderLocVertexInstanceTx = 29 +) + +// Shader uniform data type +type ShaderUniformDataType = int32 + +const ( + // Shader uniform type: float + ShaderUniformFloat = 0 + // Shader uniform type: vec2 (2 float) + ShaderUniformVec2 = 1 + // Shader uniform type: vec3 (3 float) + ShaderUniformVec3 = 2 + // Shader uniform type: vec4 (4 float) + ShaderUniformVec4 = 3 + // Shader uniform type: int + ShaderUniformInt = 4 + // Shader uniform type: ivec2 (2 int) + ShaderUniformIvec2 = 5 + // Shader uniform type: ivec3 (3 int) + ShaderUniformIvec3 = 6 + // Shader uniform type: ivec4 (4 int) + ShaderUniformIvec4 = 7 + // Shader uniform type: unsigned int + ShaderUniformUint = 8 + // Shader uniform type: uivec2 (2 unsigned int) + ShaderUniformUivec2 = 9 + // Shader uniform type: uivec3 (3 unsigned int) + ShaderUniformUivec3 = 10 + // Shader uniform type: uivec4 (4 unsigned int) + ShaderUniformUivec4 = 11 + // Shader uniform type: sampler2d + ShaderUniformSampler2D = 12 +) + +// Shader attribute data types +type ShaderAttributeDataType = int32 + +const ( + // Shader attribute type: float + ShaderAttribFloat = 0 + // Shader attribute type: vec2 (2 float) + ShaderAttribVec2 = 1 + // Shader attribute type: vec3 (3 float) + ShaderAttribVec3 = 2 + // Shader attribute type: vec4 (4 float) + ShaderAttribVec4 = 3 +) + +// Pixel formats +type PixelFormat = int32 + +const ( + // 8 bit per pixel (no alpha) + PixelformatUncompressedGrayscale = 1 + // 8*2 bpp (2 channels) + PixelformatUncompressedGrayAlpha = 2 + // 16 bpp + PixelformatUncompressedR5G6B5 = 3 + // 24 bpp + PixelformatUncompressedR8G8B8 = 4 + // 16 bpp (1 bit alpha) + PixelformatUncompressedR5G5B5A1 = 5 + // 16 bpp (4 bit alpha) + PixelformatUncompressedR4G4B4A4 = 6 + // 32 bpp + PixelformatUncompressedR8G8B8A8 = 7 + // 32 bpp (1 channel - float) + PixelformatUncompressedR32 = 8 + // 32*3 bpp (3 channels - float) + PixelformatUncompressedR32G32B32 = 9 + // 32*4 bpp (4 channels - float) + PixelformatUncompressedR32G32B32A32 = 10 + // 16 bpp (1 channel - half float) + PixelformatUncompressedR16 = 11 + // 16*3 bpp (3 channels - half float) + PixelformatUncompressedR16G16B16 = 12 + // 16*4 bpp (4 channels - half float) + PixelformatUncompressedR16G16B16A16 = 13 + // 4 bpp (no alpha) + PixelformatCompressedDxt1Rgb = 14 + // 4 bpp (1 bit alpha) + PixelformatCompressedDxt1Rgba = 15 + // 8 bpp + PixelformatCompressedDxt3Rgba = 16 + // 8 bpp + PixelformatCompressedDxt5Rgba = 17 + // 4 bpp + PixelformatCompressedEtc1Rgb = 18 + // 4 bpp + PixelformatCompressedEtc2Rgb = 19 + // 8 bpp + PixelformatCompressedEtc2EacRgba = 20 + // 4 bpp + PixelformatCompressedPvrtRgb = 21 + // 4 bpp + PixelformatCompressedPvrtRgba = 22 + // 8 bpp + PixelformatCompressedAstc4X4Rgba = 23 + // 2 bpp + PixelformatCompressedAstc8X8Rgba = 24 +) + +// Texture parameters: filter mode +type TextureFilter = int32 + +const ( + // No filter, just pixel approximation + TextureFilterPoint = 0 + // Linear filtering + TextureFilterBilinear = 1 + // Trilinear filtering (linear with mipmaps) + TextureFilterTrilinear = 2 + // Anisotropic filtering 4x + TextureFilterAnisotropic4X = 3 + // Anisotropic filtering 8x + TextureFilterAnisotropic8X = 4 + // Anisotropic filtering 16x + TextureFilterAnisotropic16X = 5 +) + +// Texture parameters: wrap mode +type TextureWrap = int32 + +const ( + // Repeats texture in tiled mode + TextureWrapRepeat = 0 + // Clamps texture to edge pixel in tiled mode + TextureWrapClamp = 1 + // Mirrors and repeats the texture in tiled mode + TextureWrapMirrorRepeat = 2 + // Mirrors and clamps to border the texture in tiled mode + TextureWrapMirrorClamp = 3 +) + +// Cubemap layouts +type CubemapLayout = int32 + +const ( + // Automatically detect layout type + CubemapLayoutAutoDetect = 0 + // Layout is defined by a vertical line with faces + CubemapLayoutLineVertical = 1 + // Layout is defined by a horizontal line with faces + CubemapLayoutLineHorizontal = 2 + // Layout is defined by a 3x4 cross with cubemap faces + CubemapLayoutCrossThreeByFour = 3 + // Layout is defined by a 4x3 cross with cubemap faces + CubemapLayoutCrossFourByThree = 4 +) + +// Font type, defines generation method +type FontType = int32 + +const ( + // Default font generation, anti-aliased + FontDefault = 0 + // Bitmap font generation, no anti-aliasing + FontBitmap = 1 + // SDF font generation, requires external shader + FontSdf = 2 +) + +// Color blending modes (pre-defined) +type BlendMode = int32 + +const ( + // Blend textures considering alpha (default) + BlendAlpha = 0 + // Blend textures adding colors + BlendAdditive = 1 + // Blend textures multiplying colors + BlendMultiplied = 2 + // Blend textures adding colors (alternative) + BlendAddColors = 3 + // Blend textures subtracting colors (alternative) + BlendSubtractColors = 4 + // Blend premultiplied textures considering alpha + BlendAlphaPremultiply = 5 + // Blend textures using custom src/dst factors (use rlSetBlendFactors()) + BlendCustom = 6 + // Blend textures using custom rgb/alpha separate src/dst factors (use rlSetBlendFactorsSeparate()) + BlendCustomSeparate = 7 +) + +// Gesture +type Gesture = int32 + +const ( + // No gesture + GestureNone = 0 + // Tap gesture + GestureTap = 1 + // Double tap gesture + GestureDoubletap = 2 + // Hold gesture + GestureHold = 4 + // Drag gesture + GestureDrag = 8 + // Swipe right gesture + GestureSwipeRight = 16 + // Swipe left gesture + GestureSwipeLeft = 32 + // Swipe up gesture + GestureSwipeUp = 64 + // Swipe down gesture + GestureSwipeDown = 128 + // Pinch in gesture + GesturePinchIn = 256 + // Pinch out gesture + GesturePinchOut = 512 +) + +// Camera system modes +type CameraMode = int32 + +const ( + // Camera custom, controlled by user (UpdateCamera() does nothing) + CameraCustom = 0 + // Camera free mode + CameraFree = 1 + // Camera orbital, around target, zoom supported + CameraOrbital = 2 + // Camera first person + CameraFirstPerson = 3 + // Camera third person + CameraThirdPerson = 4 +) + +// Camera projection +type CameraProjection = int32 + +const ( + // Perspective projection + CameraPerspective = 0 + // Orthographic projection + CameraOrthographic = 1 +) + +// N-patch layout +type NPatchLayout = int32 + +const ( + // Npatch layout: 3x3 tiles + NpatchNinePatch = 0 + // Npatch layout: 1x3 tiles + NpatchThreePatchVertical = 1 + // Npatch layout: 3x1 tiles + NpatchThreePatchHorizontal = 2 +) diff --git a/testdata/rl/go.mod b/testdata/rl/go.mod new file mode 100644 index 0000000..2556a58 --- /dev/null +++ b/testdata/rl/go.mod @@ -0,0 +1,4 @@ +module rl + +go 1.25.6 + diff --git a/testdata/rl/structs_gen_formatted.go b/testdata/rl/structs_gen_formatted.go new file mode 100644 index 0000000..a10fb6d --- /dev/null +++ b/testdata/rl/structs_gen_formatted.go @@ -0,0 +1,307 @@ +// AUTOGENERATED FILE. DO NOT EDIT + +//go:build js + +package rl + +// Vector2, 2 components +type Vector2 struct { + X float32 // Vector x component + Y float32 // Vector y component +} + +// Vector3, 3 components +type Vector3 struct { + X float32 // Vector x component + Y float32 // Vector y component + Z float32 // Vector z component +} + +// Vector4, 4 components +type Vector4 struct { + X float32 // Vector x component + Y float32 // Vector y component + Z float32 // Vector z component + W float32 // Vector w component +} + +// Matrix, 4x4 components, column major, OpenGL style, right-handed +type Matrix struct { + M0 float32 // Matrix first row (4 components) + M4 float32 // Matrix first row (4 components) + M8 float32 // Matrix first row (4 components) + M12 float32 // Matrix first row (4 components) + M1 float32 // Matrix second row (4 components) + M5 float32 // Matrix second row (4 components) + M9 float32 // Matrix second row (4 components) + M13 float32 // Matrix second row (4 components) + M2 float32 // Matrix third row (4 components) + M6 float32 // Matrix third row (4 components) + M10 float32 // Matrix third row (4 components) + M14 float32 // Matrix third row (4 components) + M3 float32 // Matrix fourth row (4 components) + M7 float32 // Matrix fourth row (4 components) + M11 float32 // Matrix fourth row (4 components) + M15 float32 // Matrix fourth row (4 components) +} + +// Color, 4 components, R8G8B8A8 (32bit) +type Color struct { + R byte // Color red value + G byte // Color green value + B byte // Color blue value + A byte // Color alpha value +} + +// Rectangle, 4 components +type Rectangle struct { + X float32 // Rectangle top-left corner position x + Y float32 // Rectangle top-left corner position y + Width float32 // Rectangle width + Height float32 // Rectangle height +} + +// Image, pixel data stored in CPU memory (RAM) +type Image struct { + Data cptr // Image raw data + Width int32 // Image base width + Height int32 // Image base height + Mipmaps int32 // Mipmap levels, 1 by default + Format int32 // Data format (PixelFormat type) +} + +// Texture, tex data stored in GPU memory (VRAM) +type Texture struct { + Id uint32 // OpenGL texture id + Width int32 // Texture base width + Height int32 // Texture base height + Mipmaps int32 // Mipmap levels, 1 by default + Format int32 // Data format (PixelFormat type) +} + +// RenderTexture, fbo for texture rendering +type RenderTexture struct { + Id uint32 // OpenGL framebuffer object id + Texture Texture // Color buffer attachment texture + Depth Texture // Depth buffer attachment texture +} + +// NPatchInfo, n-patch layout info +type NPatchInfo struct { + Source Rectangle // Texture source rectangle + Left int32 // Left border offset + Top int32 // Top border offset + Right int32 // Right border offset + Bottom int32 // Bottom border offset + Layout int32 // Layout of the n-patch: 3x3, 1x3 or 3x1 +} + +// GlyphInfo, font characters glyphs info +type GlyphInfo struct { + Value int32 // Character value (Unicode) + OffsetX int32 // Character offset X when drawing + OffsetY int32 // Character offset Y when drawing + AdvanceX int32 // Character advance position X + Image Image // Character image data +} + +// Font, font texture and GlyphInfo array data +type Font struct { + BaseSize int32 // Base size (default chars height) + GlyphCount int32 // Number of glyph characters + GlyphPadding int32 // Padding around the glyph characters + Texture Texture2D // Texture atlas containing the glyphs + Recs cptr // Rectangles in texture for the glyphs + Glyphs cptr // Glyphs info data +} + +// Camera, defines position/orientation in 3d space +type Camera3D struct { + Position Vector3 // Camera position + Target Vector3 // Camera target it looks-at + Up Vector3 // Camera up vector (rotation over its axis) + Fovy float32 // Camera field-of-view aperture in Y (degrees) in perspective, used as near plane height in world units in orthographic + Projection int32 // Camera projection: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC +} + +// Camera2D, defines position/orientation in 2d space +type Camera2D struct { + Offset Vector2 // Camera offset (screen space offset from window origin) + Target Vector2 // Camera target (world space target point that is mapped to screen space offset) + Rotation float32 // Camera rotation in degrees (pivots around target) + Zoom float32 // Camera zoom (scaling around target), must not be set to 0, set to 1.0f for no scale +} + +// Mesh, vertex data and vao/vbo +type Mesh struct { + VertexCount int32 // Number of vertices stored in arrays + TriangleCount int32 // Number of triangles stored (indexed or not) + Vertices cptr // Vertex position (XYZ - 3 components per vertex) (shader-location = 0) + Texcoords cptr // Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1) + Texcoords2 cptr // Vertex texture second coordinates (UV - 2 components per vertex) (shader-location = 5) + Normals cptr // Vertex normals (XYZ - 3 components per vertex) (shader-location = 2) + Tangents cptr // Vertex tangents (XYZW - 4 components per vertex) (shader-location = 4) + Colors cptr // Vertex colors (RGBA - 4 components per vertex) (shader-location = 3) + Indices cptr // Vertex indices (in case vertex data comes indexed) + AnimVertices cptr // Animated vertex positions (after bones transformations) + AnimNormals cptr // Animated normals (after bones transformations) + BoneIds cptr // Vertex bone ids, max 255 bone ids, up to 4 bones influence by vertex (skinning) (shader-location = 6) + BoneWeights cptr // Vertex bone weight, up to 4 bones influence by vertex (skinning) (shader-location = 7) + BoneMatrices cptr // Bones animated transformation matrices + BoneCount int32 // Number of bones + VaoId uint32 // OpenGL Vertex Array Object id + VboId cptr // OpenGL Vertex Buffer Objects id (default vertex data) +} + +// Shader +type Shader struct { + Id uint32 // Shader program id + Locs cptr // Shader locations array (RL_MAX_SHADER_LOCATIONS) +} + +// MaterialMap +type MaterialMap struct { + Texture Texture2D // Material map texture + Color Color // Material map color + Value float32 // Material map value +} + +// Material, includes shader and maps +type Material struct { + Shader Shader // Material shader + Maps cptr // Material maps array (MAX_MATERIAL_MAPS) + Params [4]float32 // Material generic parameters (if required) +} + +// Transform, vertex transformation data +type Transform struct { + Translation Vector3 // Translation + Rotation Quaternion // Rotation + Scale Vector3 // Scale +} + +// Bone, skeletal animation bone +type BoneInfo struct { + Name [32]byte // Bone name + Parent int32 // Bone parent +} + +// Model, meshes, materials and animation data +type Model struct { + Transform Matrix // Local transform matrix + MeshCount int32 // Number of meshes + MaterialCount int32 // Number of materials + Meshes cptr // Meshes array + Materials cptr // Materials array + MeshMaterial cptr // Mesh material number + BoneCount int32 // Number of bones + Bones cptr // Bones information (skeleton) + BindPose cptr // Bones base transformation (pose) +} + +// ModelAnimation +type ModelAnimation struct { + BoneCount int32 // Number of bones + FrameCount int32 // Number of animation frames + Bones cptr // Bones information (skeleton) + FramePoses cptr // Poses array by frame + Name [32]byte // Animation name +} + +// Ray, ray for raycasting +type Ray struct { + Position Vector3 // Ray position (origin) + Direction Vector3 // Ray direction (normalized) +} + +// RayCollision, ray hit information +type RayCollision struct { + Hit bool // Did the ray hit something? + Distance float32 // Distance to the nearest hit + Point Vector3 // Point of the nearest hit + Normal Vector3 // Surface normal of hit +} + +// BoundingBox +type BoundingBox struct { + Min Vector3 // Minimum vertex box-corner + Max Vector3 // Maximum vertex box-corner +} + +// Wave, audio wave data +type Wave struct { + FrameCount uint32 // Total number of frames (considering channels) + SampleRate uint32 // Frequency (samples per second) + SampleSize uint32 // Bit depth (bits per sample): 8, 16, 32 (24 not supported) + Channels uint32 // Number of channels (1-mono, 2-stereo, ...) + Data cptr // Buffer data pointer +} + +// AudioStream, custom audio stream +type AudioStream struct { + Buffer cptr // Pointer to internal data used by the audio system + Processor cptr // Pointer to internal data processor, useful for audio effects + SampleRate uint32 // Frequency (samples per second) + SampleSize uint32 // Bit depth (bits per sample): 8, 16, 32 (24 not supported) + Channels uint32 // Number of channels (1-mono, 2-stereo, ...) +} + +// Sound +type Sound struct { + Stream AudioStream // Audio stream + FrameCount uint32 // Total number of frames (considering channels) +} + +// Music, audio stream, anything longer than ~10 seconds should be streamed +type Music struct { + Stream AudioStream // Audio stream + FrameCount uint32 // Total number of frames (considering channels) + Looping bool // Music looping enable + CtxType int32 // Type of music context (audio filetype) + CtxData cptr // Audio context data, depends on type +} + +// VrDeviceInfo, Head-Mounted-Display device parameters +type VrDeviceInfo struct { + HResolution int32 // Horizontal resolution in pixels + VResolution int32 // Vertical resolution in pixels + HScreenSize float32 // Horizontal size in meters + VScreenSize float32 // Vertical size in meters + EyeToScreenDistance float32 // Distance between eye and display in meters + LensSeparationDistance float32 // Lens separation distance in meters + InterpupillaryDistance float32 // IPD (distance between pupils) in meters + LensDistortionValues [4]float32 // Lens distortion constant parameters + ChromaAbCorrection [4]float32 // Chromatic aberration correction parameters +} + +// VrStereoConfig, VR stereo rendering configuration for simulator +type VrStereoConfig struct { + Projection [2]Matrix // VR projection matrices (per eye) + ViewOffset [2]Matrix // VR view offset matrices (per eye) + LeftLensCenter [2]float32 // VR left lens center + RightLensCenter [2]float32 // VR right lens center + LeftScreenCenter [2]float32 // VR left screen center + RightScreenCenter [2]float32 // VR right screen center + Scale [2]float32 // VR distortion scale + ScaleIn [2]float32 // VR distortion scale in +} + +// File path list +type FilePathList struct { + Count uint32 // Filepaths entries count + Paths cptr // Filepaths entries +} + +// Automation event +type AutomationEvent struct { + Frame uint32 // Event frame + Type uint32 // Event type (AutomationEventType) + Params [4]int32 // Event parameters (if required) +} + +// Automation event list +type AutomationEventList struct { + Capacity uint32 // Events max entries (MAX_AUTOMATION_EVENTS) + Count uint32 // Events entries count + Events cptr // Events entries +} diff --git a/testdata/rl/wasm.go b/testdata/rl/wasm.go new file mode 100644 index 0000000..2a43f3d --- /dev/null +++ b/testdata/rl/wasm.go @@ -0,0 +1,151 @@ +//go:build js + +package rl + +import ( + "syscall/js" + "unsafe" +) + +// cptr is a pointer to raylib wasm memory +type cptr = uint32 + +// Allocates memory on raylib heap +// +//go:wasmimport raylib _malloc +//go:noescape +func malloc(size cptr) cptr + +// malloc the size of V +func mallocV[T any](V T) (cptr, func()) { + ptr := malloc(sizeof(V)) + return ptr, func() { free(ptr) } +} + +// free memory allocated on raylib heap +// +//go:wasmimport raylib _free +//go:noescape +func free(cptr) + +// _copyToC copies a Go type/struct to C memory. Useful for copying slices and structs. +// +// Destination C array must have enough space. +// +// NOTE: Value must be a type, it cannot be a slice. +// To pass a slice, use [unsafe.SliceData] +// +//go:wasmimport gojs CopyToC +//go:noescape +func _copyToC(Value unsafe.Pointer, srcSize, dstCptr cptr) + +// copies C memory to a Go pointer. Useful for copying C structs into Go structs +// +// example usage: +// +// type Person struct{ +// Age int32 +// } +// +// var cPtrToPersonInCHeap cptr = ... +// +// var p Person +// CopyToGo(unsafe.Pointer(&p),unsafe.SizeOf(p),cPtrToPersonInCHeap) +// +// p.Age == (whatever it was in C) +// +//go:wasmimport gojs CopyToGo +//go:noescape +func _copyToGo(dstGoPtr unsafe.Pointer, size cptr, src cptr) + +// Copies the src value to the dst cptr +func copyToC[T any](src *T, dst cptr) { + size := sizeof(src) + _copyToC(unsafe.Pointer(src), size, dst) +} + +// The alocated C string lives on the raylib heap and must be free()'d +// +//go:wasmimport gojs CStringFromGoString +//go:noescape +func cString(string) cptr + +// Scan for null terminator and return length excluding the null terminator. +// +//go:wasmimport gojs CStringGetLength +//go:noescape +func _cStringGetLength(cstr cptr) cptr + +// Copies a C string to Go memory without freeing the C string. +func goString(cstr cptr) string { + size := _cStringGetLength(cstr) + dstStr := make([]byte, size) + copySliceToGo(cstr, dstStr) + return string(dstStr) +} + +// copyValueToC copies a value to C and returns a pointer to it. +// +// NOTE: Value cannot be a slice. For a slice, use [copySliceToC] +func copyValueToC[T any](srcValue T) (cptr, func()) { + size := sizeof(srcValue) + dst := malloc(size) + copyToC(&srcValue, dst) + return dst, func() { free(dst) } +} + +// copySliceToC allocates a copy of a slice in C memory and returns a cptr to it. +// +// NOTE: Value MUST be a slice +func copySliceToC[Slice ~[]E, E any](s Slice) (cptr, func()) { + // size of the slice's underlying array in bytes + sliceSize := cptr(unsafe.Sizeof(s[0])) * cptr(len(s)) + // allocate C array to hold Value + dstCptr := malloc(sliceSize) + // copy underlying array memory to C + _copyToC(unsafe.Pointer(unsafe.SliceData(s)), sliceSize, dstCptr) + return dstCptr, func() { free(dstCptr) } +} + +// copyValueToGo copies a value from C memory to Go memory. +// Useful for copying structs +// +// NOTE: Slices are not supported. Use [copySliceToGo] +func copyValueToGo[T any](src cptr, dst *T) { + size := sizeof(*dst) + _copyToGo(unsafe.Pointer(dst), size, src) +} + +// copySliceToGo copies a C array into a Go Slice. +// +// It copies bytes to the underlying array of the slice. +func copySliceToGo[Slice ~[]E, E any](src cptr, dst Slice) { + // size of underlying array + var occupiedSize = len(dst) + if occupiedSize == 0 { + occupiedSize = cap(dst) + } + size := cptr(unsafe.Sizeof(dst[0])) * cptr(occupiedSize) + dstPtr := unsafe.SliceData(dst) + _copyToGo(unsafe.Pointer(dstPtr), size, src) +} + +//go:wasmimport gojs Alert +//go:noescape +func alert(string) + +// Use this instead of a for loop on web platform +// Everything that you would do inside the for-loop must be done inside UpdateAndDrawFrame +func SetMain(UpdateAndDrawFrame func()) { + var updateLoop js.Func + updateLoop = js.FuncOf(func(this js.Value, args []js.Value) any { + UpdateAndDrawFrame() + js.Global().Call("requestAnimationFrame", updateLoop) + return nil + }) + js.Global().Call("requestAnimationFrame", updateLoop) + select {} +} + +// return sizeof of v in bytes +func sizeof[T any](v T) cptr { return cptr(unsafe.Sizeof(v)) } diff --git a/testdata/templates/aliases.go.gotmpl b/testdata/templates/aliases.go.gotmpl new file mode 100644 index 0000000..717f967 --- /dev/null +++ b/testdata/templates/aliases.go.gotmpl @@ -0,0 +1,16 @@ +{{- $root := . -}} + +// AUTOGENERATED FILE. DO NOT EDIT +{{if .BuildTags}} +//go:build {{.BuildTags}} +{{end}} +package rl + +{{- range .Imports }} +import {{ . }} +{{- end }} + +{{- range .Aliases}} +// {{ .Description}} +type {{ .Name}} = {{.Type}} +{{- end}} diff --git a/testdata/templates/defines.go.gotmpl b/testdata/templates/defines.go.gotmpl new file mode 100644 index 0000000..56513eb --- /dev/null +++ b/testdata/templates/defines.go.gotmpl @@ -0,0 +1,30 @@ +{{- $root := . -}} + +// AUTOGENERATED FILE. DO NOT EDIT +{{if .BuildTags}} +//go:build {{.BuildTags}} +{{end}} +package rl + +{{- range .Imports }} +import {{ . }} +{{- end }} + + +{{- range .Defines}} +{{if contains .Type "INT" "FLOAT" "FLOAT_MATH" "STRING" }} + {{if .Description}} + // {{- .Description}} + {{- end}} + const {{.Name}} = {{.Value}} +{{- end}} +{{if contains .Type "COLOR"}} + //{{- .Description}} + var {{.Name}} = {{.Value}} +{{- end}} + +{{if contains .Type "UNKNOWN"}} + // {{- .Description}} + {{.Value}} +{{- end}} +{{- end}} diff --git a/testdata/templates/enums.go.gotmpl b/testdata/templates/enums.go.gotmpl new file mode 100644 index 0000000..f06dd4b --- /dev/null +++ b/testdata/templates/enums.go.gotmpl @@ -0,0 +1,23 @@ + +{{- $root := . -}} + +// AUTOGENERATED FILE. DO NOT EDIT +{{if .BuildTags}} +//go:build {{.BuildTags}} +{{end}} +package rl + +{{- range .Imports }} +import {{ . }} +{{- end }} + +{{- range .Enums}} +// {{ .Description}} +type {{ .Name}} = int32 +const ( + {{- range .Values}} + // {{.Description}} + {{.Name}} = {{.Value}} + {{- end}} +) +{{- end}} diff --git a/testdata/templates/structs.go.gotmpl b/testdata/templates/structs.go.gotmpl new file mode 100644 index 0000000..46f641b --- /dev/null +++ b/testdata/templates/structs.go.gotmpl @@ -0,0 +1,22 @@ +{{- $root := . -}} + +// AUTOGENERATED FILE. DO NOT EDIT +{{if .BuildTags}} +//go:build {{.BuildTags}} +{{end}} +package rl + +{{- range .Imports }} +import {{ . }} +{{- end }} + +{{- range .Structs}} + +// {{ .Description}} +type {{ .Name}} struct { + {{- range .Fields }} + {{ .Name }} {{ .Type }} // {{.Description}} + {{- end }} +} + +{{- end}} diff --git a/testdata/templates/templates.go b/testdata/templates/templates.go new file mode 100644 index 0000000..3600221 --- /dev/null +++ b/testdata/templates/templates.go @@ -0,0 +1,57 @@ +package templates + +import ( + "bytes" + _ "embed" + "fmt" + "go/format" + "os" + "text/template" +) + +// LoadTemplate takes in a gotempl as a string and a name for the template. +// It panics if template could not be parsed. +func LoadTemplate(templ, name string) *template.Template { + return template.Must(template.New(name). + Parse(templ)) +} + +// LoadTemplate takes in a gotempl as a string and a name for the template. +// It panics if template could not be parsed. +func LoadTemplateFuncs(templ, name string, funcs template.FuncMap) *template.Template { + return template.Must(template.New(name). + Funcs(funcs). + Parse(templ)) +} + +// GenerateCode will generate the template using model. and write a file to disk in the format: +// rl/{name}_gen_unformatted.go +func GenerateCode(model any, templ string, name string, funcs template.FuncMap) { + structs := LoadTemplateFuncs(templ, name, funcs) + var buf bytes.Buffer + if err := structs.Execute(&buf, model); err != nil { + panic(err) + } + if err := os.WriteFile(fmt.Sprintf("rl/%s_gen_unformatted.go", name), buf.Bytes(), 0644); err != nil { + panic(err) + } +} + +// GenerateCode will generate the template using model. and write a file to disk in the format: +// rl/{name}_gen_formatted.go +func GenerateCodeFormatted(model any, templ string, name string, funcs template.FuncMap) { + structs := LoadTemplateFuncs(templ, name, funcs) + var buf bytes.Buffer + if err := structs.Execute(&buf, model); err != nil { + panic(err) + } + + formatted, err := format.Source(buf.Bytes()) + if err != nil { + panic(err) + } + + if err := os.WriteFile(fmt.Sprintf("rl/%s_gen_formatted.go", name), formatted, 0644); err != nil { + panic(err) + } +} diff --git a/testdata/util.go b/testdata/util.go new file mode 100644 index 0000000..6892bba --- /dev/null +++ b/testdata/util.go @@ -0,0 +1,104 @@ +package main + +import ( + "codegen/api" + "fmt" + "slices" + "strings" + + "github.com/iancoleman/strcase" +) + +// GoTypeFromC maps a C type to a Go type +func GoTypeFromC(t string) string { + oneToOneTypes := map[string]string{ + "char": "byte", + "float": "float32", + "unsigned char": "byte", + "unsigned int": "uint32", + "int": "int32", + } + if mapping, ok := oneToOneTypes[t]; ok { + return mapping + } + runed := []rune(t) + if runed[len(runed)-1] == '*' { + return "cptr" + } + if index := slices.Index(runed, '['); index >= 0 { + arraySize := runed[index:] + arrayType := runed[:index] + arrayType = []rune(GoTypeFromC(string(arrayType))) + return string(arraySize) + string(arrayType) + } + return t +} + +// ParseDefines prepares data for inserting into the template. +// Different C #define macros map to different Go constructs. +// +// It also makes the Name of the define PascalCase +// This function maps them to the proper Go constructs. +// See template templates/defines.go.gotmpl +func ParseDefines(defs []api.RlDefine) []api.RlDefine { + defs = slices.Clone(defs) + for i, d := range defs { + def := &defs[i] + // make name of defines PascalCase + def.Name = PascalCase(def.Name) + switch d.Type { + case "STRING": + // add quotes around value so the template can do const {{.Name}} = {{.Value}} + def.Value = "\"" + def.Value + "\"" + case "FLOAT_MATH": + // remove the trailing "f" from float values. + def.Value = api.StringyValue(strings.ReplaceAll(string(def.Value), "f", "")) + // make PI pascal case. + def.Value = api.StringyValue(strings.ReplaceAll(string(def.Value), "PI", "Pi")) + case "COLOR": + // turn CLITERAL(Color){ 200, 200, 200, 255 } into Color{ 200, 200, 200, 255 } + v := strings.ReplaceAll(string(def.Value), "CLITERAL(Color)", "Color") + def.Value = api.StringyValue(v) + case "UNKNOWN": + // Special cases need to be handled properly. + switch def.Name { + case "GetMouseRay": + def.Value = api.StringyValue(fmt.Sprintf("var %s = %s", def.Name, def.Value)) + case "Rlapi": + *def = api.RlDefine{} + default: + def.Value = api.StringyValue( + fmt.Sprintf("const %v = %v", def.Name, def.Value), + ) + } + } + } + return defs +} + +// Sets the Name field to PascaleCase. And converts type field to a Go type. +func ProcessStructFields(fields []api.RlField) { + for i := range fields { + f := &fields[i] + f.Name = PascalCase(f.Name) + f.Type = GoTypeFromC(f.Type) + } +} + +// Use for adding custom acronym mapping for PascalCase conversion. Eg. (DEG2RAD:Deg2Rad) +func RegisterPascalCaseAcronym(key, val string) { + strcase.ConfigureAcronym(key, val) +} + +func PascalCaseEnums(enums []api.RlEnum) { + for i := range enums { + enum := enums[i] + for i := range enum.Values { + v := &enum.Values[i] + v.Name = PascalCase(v.Name) + } + } +} + +// convert string to PascalCase +func PascalCase(v string) string { return strcase.ToCamel(v) }