{"id":21844039,"url":"https://github.com/electronstudio/jaylib-ffm","last_synced_at":"2025-04-14T12:10:51.522Z","repository":{"id":240089427,"uuid":"801218088","full_name":"electronstudio/jaylib-ffm","owner":"electronstudio","description":null,"archived":false,"fork":false,"pushed_at":"2024-12-28T21:48:41.000Z","size":11736,"stargazers_count":31,"open_issues_count":7,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T01:14:27.336Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/electronstudio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-15T20:12:29.000Z","updated_at":"2025-03-27T15:20:35.000Z","dependencies_parsed_at":"2024-11-22T10:25:42.804Z","dependency_job_id":"984a1220-e19d-4472-8065-e919aeb2ccf2","html_url":"https://github.com/electronstudio/jaylib-ffm","commit_stats":null,"previous_names":["electronstudio/jaylib2","electronstudio/jaylib-ffm"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/electronstudio%2Fjaylib-ffm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/electronstudio%2Fjaylib-ffm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/electronstudio%2Fjaylib-ffm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/electronstudio%2Fjaylib-ffm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/electronstudio","download_url":"https://codeload.github.com/electronstudio/jaylib-ffm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248877958,"owners_count":21176244,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-27T22:18:13.617Z","updated_at":"2025-04-14T12:10:51.515Z","avatar_url":"https://github.com/electronstudio.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Jaylib-FFM - Java FFM binding for Raylib 5.5, RLGL, Raymath\n\nJaylib-FFM is a [Java FFM](https://docs.oracle.com/en/java/javase/22/core/foreign-function-and-memory-api.html) ('Project Panama')\nbinding for Raylib.  This makes it faster than any binding that uses older tech, even JNI as used by Jaylib.\nHowever it does require Java 22 or newer to use.\n\nThe core of the library is generated using Jextract.  This has the advantage over JavaCPP that it is a first party tool and far\neasier to understand.  The structs are in [com.raylib.jextract.*](https://electronstudio.github.io/jaylib-ffm/com/raylib/jextract/package-summary.html)\nThe functions are in [com.raylib.jextract.raylib_h](https://electronstudio.github.io/jaylib-ffm/com/raylib/jextract/raylib_h.html).\n\nUnfortunately, compared to JavaCPP, the generated API is quite basic.  You need to be familiar with FFM memory management\nand it doesn't enforce type safety.\n\nTherefore we also generate high level wrappers ourselves based on raylib_api.json.  These should be nice and easy to\nuse.\n\nThe wrapped structs are in [com.raylib.*](https://electronstudio.github.io/jaylib-ffm/com/raylib/package-summary.html).\n\nThe wrapped functions are in [com.raylib.Raylib](https://electronstudio.github.io/jaylib-ffm/com/raylib/Raylib.html).\n\nThe official Raylib DLLs are included in the jar.  There isn't one for ARM Linux (Raspberry Pi) but it will attempt\nto load the external file /usr/lib/libraylib.so.\n\n## Alpha testing\n\nNot production ready.  Please test, report what doesn't work and add what is missing.\n\nMost C types are now wrapped as Java types.  If a function returns a MemorySegment it means that type hasn't been wrapped.\nThis may be because there is no Java equivalent that makes sense, but if you think otherwise report it and I might\nadd it.\n\n## Example project\n\nDownload ([example project](https://github.com/electronstudio/jaylib-ffm-example-project)and import it into IntelliJ or Eclipse to get up and running immediately.\n\n## How to use with Gradle\n\n```\n\ndependencies {\n    implementation 'io.github.electronstudio:jaylib:5.5.0-0'\n}\n\n```\n\n## How to use with Maven\n\n```\n\n    \u003cdependencies\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003eio.github.electronstudio\u003c/groupId\u003e\n            \u003cartifactId\u003ejaylib-ffm\u003c/artifactId\u003e\n            \u003cversion\u003e5.5.0-0\u003c/version\u003e\n        \u003c/dependency\u003e\n    \u003c/dependencies\u003e\n\n```\n\n## If your project is modular\n\n```\nmodule com.example {\n    requires io.github.electronstudio.jaylib.ffm;\n}\n```\n\n## How to use from command line\n\nDownload the latest `jaylib-ffm.jar` from [releases](https://github.com/electronstudio/jaylib-ffm/releases)\n\nWrite a demo program, e.g. Demo.java\n\n```java\nimport static com.raylib.Raylib.*;\nimport static com.raylib.Raylib.CameraMode.CAMERA_ORBITAL;\nimport static com.raylib.Raylib.CameraProjection.CAMERA_PERSPECTIVE;\n\nimport com.raylib.Camera3D;\nimport com.raylib.Vector3;\n\npublic class Main {\n    public static void main(String args[]) {\n        initWindow(800, 450, \"Demo\");\n        setTargetFPS(60);\n        Camera3D camera = new Camera3D(new Vector3(18,16,18),\n                new Vector3(),\n                new Vector3(0,1,0),\n                45, CAMERA_PERSPECTIVE);\n\n        while (!windowShouldClose()) {\n            updateCamera(camera, CAMERA_ORBITAL);\n            beginDrawing();\n            clearBackground(RAYWHITE);\n            beginMode3D(camera);\n            drawGrid(20, 1.0f);\n            endMode3D();\n            drawText(\"Hello world\", 190, 200, 20, VIOLET);\n            drawFPS(20, 20);\n            endDrawing();\n        }\n        closeWindow();\n    }\n}\n```\n\nCompile it:\n\n    javac -cp jaylib-ffm-5.5.0-0.jar Demo.java\n\nRun it:\n\n    java -cp jaylib-ffm-5.5.0-0.jar:. Demo\n\nOn MacOS you need this additional option:\n\n    java -XstartOnFirstThread -cp jaylib-ffm-5.5.0-0.jar:. Demo\n\nOn weirdy Windows you use semi-colons:\n\n    java -cp jaylib-ffm-5.5.0-0.jar;. Demo\n\n## Arrays\n\nC has a problem known as \"array to pointer decay\".  C will automatically convert an array type and to a pointer\ntype. Therefore the computer can't tell\nif a function parameter is an array of many items or a pointer to a single item.\nI don't know if modern C has solved this, but Raylib certainly hasn't.  The info isn't in raylib_api.json.\nYou just have to read the docs for each\nfunction to find out which it is.\n\nSo sometimes you will get a Java object that may represent one struct, or may represent an array of structs.\nYou'll need to check the Raylib docs or the Javadoc for the function to know which it has given you.\n\nIf it's an array, you can use the getArrayElement() method to access the other structs.  To create a new array\nthere is allocateArray() method.\n\n(I suppose we could provide List-like wrappers but to actually make them safe would require working out every\nfunction that uses arrays and what parameter it uses to store the size of the array. Nice to have but a luxury\nthat users of C Raylib don't have, and requiring manual maintance work, so out of scope for now.)\n\nArrays of ints and floats are wrapped as IntBuffer and FloatBuffer.  Note if you create your own you should use\nRaylib.createIntBuffer(1) to ensure you create a direct, native buffer.\n\n## Building\n\n    gcc raylib/parser/raylib_parser.c -o raylib_parser\n    ./raylib_parser --input /usr/local/include/raylib.h --output raylib_api.json --format JSON\n    ./raylib_parser --input raylib/src/raymath.h --output raymath_api.json --format JSON --define RMAPI\n    ./raylib_parser --input raylib/src/rlgl.h --output rlgl_api.json --format JSON --truncate \"RLGL IMPLEMENTATION\"\n    jextract -l :./libraylib.so --output src/main/java/ --target-package com.raylib.jextract raylib.h\n    sed -i 's/\".\\/libraylib.so\"/uk.co.electronstudio.Util.extractDLLforOS()/g' src/main/java/com/raylib/jextract/raylib_h_1.java\n    python3.12 generate.py\n    mvn package\n    java -cp target/jaylib-ffm-5.5.0-0.jar uk.co.electronstudio.tests.Bunnymark\n\n## See also\n\n[Megabunny](https://github.com/electronstudio/megabunny) - Raylib benchmarks\n\n[Jaylib](https://github.com/electronstudio/jaylib) - Java JNI Raylib binding","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felectronstudio%2Fjaylib-ffm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felectronstudio%2Fjaylib-ffm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felectronstudio%2Fjaylib-ffm/lists"}