chris_c
Posts: 156
Joined: Sun May 06, 2012 10:23 am

Jgles2pi lowlevel thin (Java) wrapper of GLES for the PI

Wed Sep 16, 2015 6:37 pm

I've had a desktop GLES2 java wrapper up on git hub a while and to celebrate the launch of the PI's "official" LCD (not that I have mine yet!) I thought I'd port it to the Raspberry PI (basically I took it back to before GLFW was added and then introduced some broadcom boiler plate and reimplemented keyboard handling)

its initial release has the following features

* EGL and GLES2 wrapped very lightly - almost bare metal GLES2 programming!
* a util class to handle keyboard (mouse coming soon) and simple broadcom abstraction

works with or without X running (keyboard routines rely only on raw evdev)

the example has...
* PNG loading
* bitmap fonts (useful for debugging)
* extensive math classes

While the utils class needs properly documenting (I'll do the mouse stuff first...) it should be very easy to see how to use it from the example included

I find it most useful to quickly try out ideas/experiments with GLES2 - while I can and do code in C I find Java coding far more fun!

a JDK and ANT are required (specifying no ant target will compile everything the example relies on, jni library etc and then run it)

https://github.com/chriscamacho/Jgles2pi

chris_c
Posts: 156
Joined: Sun May 06, 2012 10:23 am

Re: Jgles2pi lowlevel thin (Java) wrapper of GLES for the PI

Wed Sep 16, 2015 8:52 pm

got chance to add simple mouse support

you can get relative or absolute position and the button states

Enjoy!

chris_c
Posts: 156
Joined: Sun May 06, 2012 10:23 am

Re: Jgles2pi lowlevel thin (Java) wrapper of GLES for the PI

Thu Sep 17, 2015 12:15 pm

some very brief documentation to the utils class can be had here http://bedroomcoders.co.uk/jgles2pi-thi ... -and-gles/

chris_c
Posts: 156
Joined: Sun May 06, 2012 10:23 am

JGLES2PI

Tue Sep 22, 2015 10:09 pm

so I realise the internet will fall on me and break my neck for cross posting but I put something in the wrong place not realising there was a Java forum!

So anyway.... viewtopic.php?f=68&t=120863

Announced to underwhelming interest.... a very thin wrapper around GLES2... everything you need to try out quick ideas with GLES2, includes Java classes for math etc, included "test" gives you all the boiler plate you need to start hacking straight away!

https://github.com/chriscamacho/Jgles2pi

Enjoy!

User avatar
xranby
Posts: 540
Joined: Sat Mar 03, 2012 10:02 pm
Contact: Website

Re: JGLES2PI

Tue Sep 22, 2015 11:36 pm

Hi! Nice to see one more Java OpenGL ES bindings that can be used on the Pi.

It would be good to know which license your work use or if you have contributed the work to be under public domain.
I ask because there is much code overlap how to hande mouse and keyboard input systems with existing java opengl es bindings.
It would be good to share common code and ideas across projects.
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12979
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: JGLES2PI

Tue Sep 22, 2015 11:41 pm

merged two subjects, (threads) and moved to java.

chris_c
Posts: 156
Joined: Sun May 06, 2012 10:23 am

Re: JGLES2PI

Wed Sep 23, 2015 6:11 am

I'm not a lawyer.... But as I understand it code published without a licence is implicitly public domain, which was certainly my intention...

Do what you like with the code, it can certainly be improved !

User avatar
xranby
Posts: 540
Joined: Sat Mar 03, 2012 10:02 pm
Contact: Website

Re: JGLES2PI

Wed Sep 23, 2015 8:41 am

chris_c wrote:I'm not a lawyer.... But as I understand it code published without a licence is implicitly public domain, which was certainly my intention...

Do what you like with the code, it can certainly be improved !
Thank you for explicit clarify that you intend to put the work under public domain. KUDOS!

The emerge of raspberry pi touch screens has uncovered at least one cornercase for me when reciving absolute screen coordinates using the touch events. Thus I enjoy seeing that your mouse handler contain some manual workaround code to remedy that.

Personally I have written a similar keyboard /dev/input/event evevent parser and /dev/input/mice mouse parser handling code to handle mouse and keyboard events on the raspberry pi when running from console. licensed under the 'New BSD 2-Clause License'
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby

User avatar
xranby
Posts: 540
Joined: Sat Mar 03, 2012 10:02 pm
Contact: Website

Re: JGLES2PI

Wed Sep 23, 2015 10:13 am

I tried to compile your project by running ant on a raspberry pi.
however the pkg-config failed to resolve the include path of egl thus the build fail on a default installed raspbian system.

Code: Select all

$(shell pkg-config egl --libs)
It would be good if the build instructions mentioned which -dev packages if any needs to be installed for the jni parts to compile on a raspberry pi or if the user have to add a manual workaround in order for pkg-config to know about the egl paths.

build output below:

Code: Select all

pi@raspberrypi ~/Jgles2pi $ ant
Buildfile: /home/pi/Jgles2pi/build.xml

jni:
     [exec] gcc -fPIC -I/opt/vc/include/ -I/opt/vc/include/interface/vmcs_host/linux -I`readlink -f /usr/bin/javac | sed "s:bin/javac::"`/include/ -I`readlink -f /usr/bin/javac | sed "s:bin/javac::"`/include/linux  -c jni/util.c -o jni/util.o
     [exec] Package egl was not found in the pkg-config search path.
     [exec] Perhaps you should add the directory containing `egl.pc'
     [exec] to the PKG_CONFIG_PATH environment variable
     [exec] No package 'egl' found
     [exec] In file included from /opt/vc/include/interface/vcos/vcos_assert.h:149:0,
     [exec]                  from /opt/vc/include/interface/vcos/vcos.h:114,
     [exec]                  from /opt/vc/include/interface/vmcs_host/vc_dispmanx.h:33,
     [exec]                  from /opt/vc/include/EGL/eglplatform.h:110,
     [exec]                  from /opt/vc/include/EGL/egl.h:36,
     [exec]                  from jni/util.c:2:
     [exec] /opt/vc/include/interface/vcos/vcos_types.h:38:33: fatal error: vcos_platform_types.h: No such file or directory
     [exec] compilation terminated.
     [exec] make: *** [jni/util.o] Error 1
     [exec] jni/Makefile:20: recipe for target 'jni/util.o' failed

BUILD FAILED
/home/pi/Jgles2pi/build.xml:7: exec returned: 2

Total time: 11 seconds
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby

chris_c
Posts: 156
Joined: Sun May 06, 2012 10:23 am

Re: JGLES2PI

Wed Sep 23, 2015 12:02 pm

I need to double check that, it might be getting includes from where it shouldn't (really)

the ant file is inherited from the desktop version (or at least platforms with xorg ready egl)

when I get chance I'll look at what includes are in /opt/vc - really shouldn't be using the mesa includes if there are VC ones...

chris_c
Posts: 156
Joined: Sun May 06, 2012 10:23 am

Re: JGLES2PI

Wed Sep 23, 2015 1:14 pm

Okay, pushed a new commit, removing the cross platform stuff with the stuff that needs to be RPI specific (like hard coded paths /opt/vc)

I made a new raspbian sd card and tested it and it all seems hunky dory :)

I'm thinking of making a few tutorials from simplest hello world triangle to make complex things like render to texture and shaders etc.

Is there any interest in this or would I be wasting my time?

User avatar
xranby
Posts: 540
Joined: Sat Mar 03, 2012 10:02 pm
Contact: Website

Re: JGLES2PI

Wed Sep 23, 2015 2:51 pm

chris_c wrote:Okay, pushed a new commit, removing the cross platform stuff with the stuff that needs to be RPI specific (like hard coded paths /opt/vc)

I made a new raspbian sd card and tested it and it all seems hunky dory :)
It compiles fine for me now as well!
chris_c wrote:I'm thinking of making a few tutorials from simplest hello world triangle to make complex things like render to texture and shaders etc.

Is there any interest in this or would I be wasting my time?
I do enjoy the quick ~1 second startup time.

running
java -Djava.library.path=. -cp Jgles2.jar:test Main
is fast
also quite nice demo application :)

I think it is a good example how Java JNI work.
It also work as a nice introduction to OpenGL ES 2!

However the design on the API makes it highly coupled to the way opengl es is initialized on the raspberry pi thus it is not ideal for multi-platform-os use.
Also there is the debate if OpenGL should be mapped as an static API when it actually is not static at all.
Last edited by xranby on Wed Sep 23, 2015 4:07 pm, edited 1 time in total.
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby

chris_c
Posts: 156
Joined: Sun May 06, 2012 10:23 am

Re: JGLES2PI

Wed Sep 23, 2015 3:02 pm

thanks, as its basically doing as little as possible, it has very little overhead

as a point of interest I originally made it basically as a way of learning JNI, however I've ended up coming back to it time and time again, every time I have an experiment or GLES2 idea I want to test out.

While some parts could possibly do with wrapping - for example some EGL functions return or accept arrays of values which currently use native io buffers - however typically once set up you don't tend to need to deal with buffers so I don't know if its worth the trouble, and it fits in with a 1:1 coupling with the C interface

If anyone has ideas for or would like to contribute demos / tutorials please do let me know...

Return to “Java”