jaylib icon indicating copy to clipboard operation
jaylib copied to clipboard

Loading jarfile Textures solved

Open glowiak opened this issue 2 years ago • 8 comments

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.

glowiak avatar Nov 02 '23 21:11 glowiak

Well done.

I forgot Raylib had LoadImageFromMemory function, which is what you’ve used. So yeah you could extract to memory rather than a temp file.

electronstudio avatar Nov 02 '23 21:11 electronstudio

@electronstudio Would be nice to to add some info about this to the readme, so that newcomers know how to workaround that.

glowiak avatar Nov 02 '23 21:11 glowiak

@electronstudio Also, are there any plans to update Jaylib to 4.5?

glowiak avatar Nov 02 '23 22:11 glowiak

I released 4.5.

The best place to put the jar image loader would probably be https://github.com/electronstudio/jaylib-example-project/tree/master/src/main/java/examples

electronstudio avatar Nov 05 '23 05:11 electronstudio

@electronstudio The image loader in examples? Seems weird.

In my game it is just in a jarfile in the lib directory alongside with jaylib.

glowiak avatar Nov 05 '23 12:11 glowiak

I’m reluctant to put any code into Jaylib that isn’t auto generated from Raylib. There is a small amount in Jaylib.java but if I put it there I’d have to check the quality of the code and maybe rewrite it.

electronstudio avatar Nov 05 '23 12:11 electronstudio

Then just better to leave it as is, maybe optionally including a link in the readme.

glowiak avatar Nov 05 '23 12:11 glowiak

@electronstudio I am working on also loading music streams from jars (as I plan to implement some sort of SFX in my game soon).

The MusicLoader class works, but only outside of jar. Weirdly, when running from jar the JVM itself crashes.

I will be working on that.

glowiak avatar Nov 06 '23 18:11 glowiak