SpanglefishDMS Consulting | sitemap | log in
This is a free Spanglefish 1 website.

Raspberry PI Java OpenGL ES API

The Project

The idea behind this project was to create a Java API to access the OpenGL ES routines on the Raspberry PI. The PI has a rich collection of GLES routines from OpenGL ES 2 together with some from GL ES 1.

The Package

The package was developed on a PC using Eclipse and Java. The GLES routines were developed from Android GLES Java and 'C' sources. This was not as straightforward as first thought. Android has different JNI routines to OpenJDK so a lot of code had to be changed. The API's for BCM, EGL and VC were written from scratch.
The first release is a Beta release and is likely to be buggy. There are a large number of routines and testing each one with every option was just not possible. Having said that, the example program was quite complex so quite a lot is working.

Installing Java

The first file to install is a Java Run Time Environment (jre). If you want to compile java on the PI you will need to find a Java JDK.
I used Eclipse on a PC to write the code and tested the routines on the PI.
Note - Oracles ejre does not yet run under Raspbian. You will need a system built from a wheezy-armel.img. To install a Java jre download -
ejre-7u4-fcs-b20-linux-arm-vfp-client_headless-12_apr_2012.tar.gz
To access the PI from my PC I use Putty and to transfer file Psftp.

Logon as root and transfer the tar.gz file to /root.
cd /usr/local
tar -xvzf /root/ejre-7u4-fcs-b20-linux-arm-vfp-client_headless-12_apr_2012.tar.gz
ls /usr/local/
This should list several folders including ejre1.7.0_04.
/usr/local/ejre1.7.0_04/bin/java -fullversion
This should print - java full version "1.7.0_04-ea-b20"

Installing Java OpenGL ES Routines

The files that need to be installed can be found on SourceForge.

sourceforge.net/p/rp-java-gles/files/

Start by downloading -
java-script-betax.tar.gz
jni-so-betax.tar.gz
rp-class-betaxn.tar.gz
rp-doc-betax-tar.gz
textures-betax-tar.gz
gles-java-betax.tar.gz
Transfer the files to the PI to your home directory. (/home/pi)
Run the following for each tar.gz file - tar -xvzf filename
This will create a jni folder containing the RP jni shared libraries and a java folder containing the java classes.
The other files on SourceForge contain the source for the JNI 'C' and Java routines. 

Running the Java examples

In the folder java/gles is the source and class files for several examples. To run Cube or any of the Example programs you need to be in the java folder.
./java gles.Cube should run the Cube example.
./java gles.ExampleA should run ExampleA.
Because of a mistake in an early version of wheezy-armel you may get an error -
./java gles.Cube fails with failed to open vchiq instance.

Follow this link and look under Troubleshooting.

The Examples

Cube is a Java version of the example triangle.c supplied with the RP image. All the set-up calls to BCM, EGL and VC are in the class OGLSetup.
One thing to notice is the use of the java classes ByteBuffer and FloatBuffer. These are used because of more efficient array handling. Byte[],Float[] can still be used and the jni supports them but the arrays are not released in the jni (OpenGL needs them to remain) so they may cause memory leaks.
The Examples are OpenGL 'C' programs found on the web and converted to Java. They are included because they are fairly simple and easy to modify. Try them and then look at the source.
ExampleI was included to show perspective. The glFrustumf routine sets this up. There is a very interesting set of OpenGL Lectures by Tom Duff and George Ledin Jr. Have a look at -

glFrustum Case Studies and then try changing the example.

Under Development

I would like to get Java3D running on the PI. I have a limited version running under Android and hope to put this up together with a large Java3D library of mine.
Why Java3D - it is a higher level language than OpenGL so it needs less code. I feel it is much easier to write complex animations using it.

Support

You can contact me via the Raspberry PI forum

Search for Java, JNI, OpenGL

Links

The Raspberry PI Foundation

Java-Embedded-Raspberry-Pi

Interests and links

Home Page

WikanikoWork from Home
sitemap | cookie policy | privacy policy