Git Product home page Git Product logo

jaylib's People

Contributors

electronstudio avatar mores avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

jaylib's Issues

better constructors

Javacpp creates noarg constructors and expects you use the fluent methods to initialize, e.g.:
new Vector3().x(16).y(8).z(16)

It would be nicer for Java programmers if we could make a constructor so you could do:
new Vector3(16,8,16)

I know how to do this as a helper method, but I don't know how to insert it as a constructor into the generated Raylib.java source.

[Proposal] Use the Project Panama FFI

As we all know, FFI in Java is a mess. From Sun you have JNI which requires you to write C code, you have JNA which doesn't require C but is slower and still needs a generator program (long since abandoned) to avoid writing it by hand. Then there are third party solutions, like JavaCPP which we are currently using. It's the best I have found so far but still not easy to configure.

The latest attempt from Oracle to fix this is Project Panama, which is available now in Early Access and may perhaps be in Java 17 or 18. https://jdk.java.net/panama/

So should we switch to this?

I've tried the EA and it works, but the generator currently doesn't seem to generate anything to automate access to data structures. For example, to print the mouse coordinates you would do this:

         MemorySegment vector2 = GetMousePosition(newImplicitScope());
         System.out.println(Vector2.x$get(vector2)+" "+Vector2.y$get(vector2));

To clear the screen with a colour:

        BeginDrawing();
        MemorySegment color = MemorySegment.allocateNative(Color.$LAYOUT(),newImplicitScope());
        Color.r$set(color, (byte) 255);
        Color.g$set(color, (byte) 255);
        Color.b$set(color, (byte) 255);
        Color.a$set(color, (byte) 255);
        ClearBackground(color);
        EndDrawing();

I have not read every page of the docs, so I don't know if they have implemented or are planning to implement automatic generator of helpers to do all this. If you know the answer please comment. But my feeling at the moment is we would have to write so much wrapper code to make an API that is easy to use we may as well use JNI.

Cross platform deployment

Greetings, I'm very interested in this Java binding for "raylib". I would like to know if there are any future plans for adding support to many platforms, especially for Android and HTML5. If not, then at least explain how can I try to do it on my own, please. I realise it's easy to say, but much harder to do.

bug with Rectangle()

when i use and compile:
this.teste = new Rectangle(0.0f, 0.0f, 64.0f, 64.0f);

I receive this:

BattleTank.java:54: error: no suitable constructor found for Rectangle(float,float,float,float)
this.teste = new Rectangle(0.0f, 0.0f, 64.0f, 64.0f);
^
constructor Rectangle.Rectangle() is not applicable
(actual and formal argument lists differ in length)
constructor Rectangle.Rectangle(long) is not applicable
(actual and formal argument lists differ in length)
constructor Rectangle.Rectangle(Pointer) is not applicable
(actual and formal argument lists differ in length)
1 error

i didn't build jaylib and i running it in windows 7 x64

RLGL and raymath

RLGL works on Linux. On Windows, it requires raymath.h as well, and then compilation fails due to unexpected brackets around line 1030. Only way to fix this seems to be to delete the code it doesn't like (I can't understand why it doesn't like code) which may or may not break raymath and/or RLGL.

So risk including broken versions, or dont include them on windows, or dont include them on any platform?

gradle build script

The Javacpp build process is a bit unusual and the docs are not great, so I wrote bash scripts to get it working. Would be preferable to replace them with gradle scripts.

The need to .close() colours

For some reason, the Raylib.Color class is treated as a resource, and thus needs to be closed.

Why is that?

Shouldn't it be treated by the garbage collector, just like any other class?

Loading jarfile Textures solved

Dear @electronstudio , as I said I wrote a wrapper that allows to load Textures and Images from within the jarfile.

Without shipping the resources elsewhere.
Without extracting them somewhere to a temporary location.
Without using libGDX.

All I done (but it took me two days of research) was figuring out how RL loads images, and replacing all C-specific code with Java-specific code so that it does work.

Library: https://codeberg.org/glowiak/librlimg

I am not proposing a pull request, as you would probably f*ck it away as being bad code.
Maybe it is bad code, but it works.

Access variables of raylib structs

I have finished my wrapper (hope it works), and I want to test it on some image, but all images I have are too big to fit in the window.

Obvious solution would be to modify the .width and .height values of the Texture2D struct, but in this binding these are not variables, but getters (confirmed with a decompiler).

How to access the variables of the structs? I looked into the code and there seem to be no setters.

[Proposal] Use GraalVM Polyglot

GraalVM can call code in any supported language from any supported language, and one of the 'languages' is LLVM bitcode.

Compiling Raylib to LLVM bitcode works fine. However we then have some problems:

  1. Passing a Java string as a function argument doesn't work because it doesn't convert it to a char*.
       Context polyglot = Context.newBuilder().
               allowAllAccess(true).build();
       File file = new File("libraylib.so.3.7.0");
       Source source = Source.newBuilder("llvm", file).build();
       Value cpart = polyglot.eval(source);
       cpart.invokeMember("InitWindow", 300, 300, "foo");

You can also do 'execute' rather than 'invokeMember' but the result is the same:

Exception in thread "main" org.graalvm.polyglot.PolyglotException: com.oracle.truffle.api.dsl.UnsupportedSpecializationException: Unexpected values provided for <core.c:664:29>:664 LLVMI8LoadNodeGen#1: [foo], [String]

Some image manipulation functions don't work

I'm writing a game engine using Jaylib, and some of the image manipulation functions, such as:

void ImageFlipVertical(Image image);                                                        
void ImageFlipHorizontal(Image image);                                                           
void ImageRotateCW(Image image);                                                                 
void ImageRotateCCW(Image image);                                                                
void ImageColorTint(Image image, Color color);                                                   
void ImageColorInvert(Image image);                                                           
void ImageColorGrayscale(Image image);

Don't work. The image resizing functions do work, but these ones don't. I checked the docs, and im using them correctly, so im not exactly sure why it isnt working. This is my code:

public class Sprite {
    @Getter
    private String path;

    @Getter
    private Image img;

    @Getter
    private Texture rawTex;

    public Sprite(String path) {
        this.path = path;
        this.img = LoadImage(path);
        this.rawTex = LoadTextureFromImage(img);
    }

    public void flip() {
        ImageFlipVertical(img);
    }

    public void resize(Vector2f newSize) {
        // Use nearest neighbour scaling algorithm instead of the default bicubic scaling algorithm
        // https://en.wikipedia.org/wiki/Nearest-neighbor_interpolation
        ImageResizeNN(this.img, (int) newSize.x, (int) newSize.y);

        // reload the texture after resizing
        this.rawTex = LoadTextureFromImage(this.img);
    }

    public void resizeBicubic(Vector2f newSize) {
        // Raylib uses the bicubic resizing algorithm by default
        // https://en.wikipedia.org/wiki/Bicubic_interpolation
        ImageResize(this.img, (int) newSize.x, (int) newSize.y);

        // reload the texture after resizing
        this.rawTex = LoadTextureFromImage(this.img);
    }

    public void dispose() {
        UnloadImage(img);
        UnloadTexture(rawTex);
    }
}

and the sprite.flip() function isn't changing anything in the image.

Publish on maven repo

Publishing on Jitpack is quite easy, but since I'm not using this project for anything yet I haven't done it. JCentral would be better but is perhaps more work.

better arrays

Javacpp accesses C arrays via pointers, e.g.
model.materials().position(1).maps().position(2)

This is weird for a Java programmer because it isn't just an accessor; it modifies the position field of the object, and is obviously highly unsafe. It would be better if we could convert the C arrays into Java arrays, or at least wrap a List interface around them.

textures crash the program

when you use loadTexture or LoadTextureFromImage it crashes the program instantly

error:

# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000000000000, pid=11408, tid=17568

then it prints out a file containing heap and stack info

hs_err_pid13004.log
.

include raygui (RayLib GUI) and physac

When testing the Jaylib jar, I realized that the "physac" in not in jar, and this is included in the RayLib 3.0 as its "default" 2D physics engine/component. I think it would quite useful if it (physac.h) can be included in the Jaylib jar.

similar reason for the "raygui.h"

many thanks

Load a Texture2D from this.getClass().getResource()?

In all of the examples of Jaylib I see all the Texture2Ds being loaded from local files.

Is there any way to use this.getClass().getResource() with this?

Because distributing a game in a single jarfile is much more convinient than having to have a resources directory.

Link static library on Windows

I can't get raylib_static.lib to link on Windows. Therefore we have a runtime dependency on raylib.dll being in the library path.

Possible solutions:

  1. Someone figures out the right flags to get Windows C compiler to statically link.
  2. Raylib.dll is embedded in the jar file and extracted at runtime. I think JavaCPP ought to be able to do this, but it's not documented how.

[Proposal] Use GraalVM nativeimage

There are two ways to do this:

  1. With the Jaylib bindings.

Problem: All the JNI method calls need to be listed in a file META-INF/native-image/jni-config.json. This file can be generated by the 'native-image-agent' but it's very incomplete. So someone would have to manually add every JNI call which seems a pretty big job.

  1. Make new bindings that don't use JNI.

There's a nice example of this here: https://github.com/praj-foss/opengl-graal-examples

Seems like it should be very fast. But it will only ever work with GraalVM in nativeimage mode which might limit how many people would want to use it. Is there a tool to autogenerate these or are we back to having to do it manually?

Fixing HighDPI causes text blurring issue in jaylib doesn't works!

As jaylib is almost same as raylib in C,I managed to fix HighDPI causes text blurring issue in raylib by the line that raysan5 mentioned in this issue
raysan5/raylib#1111 (comment)

SetTextureFilter(GetFontDefault().texture, FILTER_POINT);

I think it should works as same as in raylib C but it gives error in the following image

Screenshot (238)

Here is the full file source code,Called Game.java

import com.raylib.Raylib;
import static com.raylib.Jaylib.*;

public class Game {
    public static void main(String[] args) {
        
        SetConfigFlags(FLAG_VSYNC_HINT);
        SetConfigFlags(FLAG_MSAA_4X_HINT);
        
        InitWindow(800, 600, "Game");
        SetTargetFPS(60);
        
        SetTextureFilter(GetFontDefault().texture, FILTER_POINT);
        
        while (!WindowShouldClose()) {
            BeginDrawing();
            ClearBackground(WHITE);
            
            DrawRectangleLines(100, 100, 100, 50, BLUE);
            DrawCircleLines(200, 100, 25, RED);
            DrawLine(300, 100, 600, 100, BLACK);
            DrawTriangleLines(new Vector2(500, 300), new Vector2(600, 400), new Vector2(500, 200), BROWN);
            DrawPolyLines(new Vector2(500, 600), 6, 50, 0, GOLD);
            DrawEllipseLines(500, 400, 100, 50, PURPLE);
            
            EndDrawing();
        }
        
        Raylib.CloseWindow();
    }
}

I don't know until now what causes this,Thanks for helping me if you can!

MacOS Arm64 does not display windows

System Information:
M2 Macbook Air
Sonoma 14.3.1

Trying to compile my project which depends on Jaylib results in the following error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: Platform "macosx-arm64" not supported by class com.raylib.Raylib
	at org.bytedeco.javacpp.Loader.load(Loader.java:1184)
	at org.bytedeco.javacpp.Loader.load(Loader.java:1157)
	at org.bytedeco.javacpp.Loader.load(Loader.java:1133)
	at com.raylib.Raylib.<clinit>(Raylib.java:10)
	at dev.yeff.orbital.graphics.Window.start(Window.java:39)
	at dev.yeff.orbital.Game.start(Game.java:45)
	at dev.yeff.Main.main(Main.java:21)

Does Jaylib not support MacOS, or is there something I need to add myself, like an extra dependency, etc.?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.