Rene8888
Posts: 8
Joined: Fri Sep 20, 2013 10:33 pm

Graphics without X11

Mon Mar 31, 2014 9:01 am

Hi!

I want to draw graphics to the screen without using X11. The resolution is 1920x1080.

I want to try it with OpenGL, so I don't stress the CPU too.
I never used OpenGL, but i should be able to draw some rectangles and write some text
The real problem is getting the image to the screen without X11. Do you know a solution?

The second approach would be drawing to the framebuffer. As is know, drawing to a BufferedImage is really slow and uses a lot of CPU and RAM.

Another idea is to make the drawing with C. Writing to the framebuffer via Java actually requires a native lib. So why don't send the data from the java programm to the native lib and then visualize the data in C.

Is the first idea even possible? If not, second or third idea?

Thanks,
Rene8888

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6234
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Graphics without X11

Mon Mar 31, 2014 9:06 am

All of that is possible. Take a look at the source code examples in /opt/vc

You can use SDL, but the current version doesn't use the GPU. I am under the impression that sdl 3 does/will and I've seen patches to enable it in sdl 2. Take a look at openvg as well. There are lots of ways to go about this.

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

Re: Graphics without X11

Mon Mar 31, 2014 9:15 am

Rene8888 wrote:Hi!

I want to draw graphics to the screen without using X11. The resolution is 1920x1080.

I want to try it with OpenGL, so I don't stress the CPU too.
I never used OpenGL, but i should be able to draw some rectangles and write some text
The real problem is getting the image to the screen without X11. Do you know a solution?
You can use JogAmp JOGL to access OpenGL ES 1 and OpenGL ES 2 from Java on the Pi.
JogAmp JOGL can initialize a screen with input without using X11 using the JOGL NEWT API, you also get a mouse-pointer!
The jogamp api is designed to make the opengl initialization identical on all platforms thus you can focus on the OpenGL code.
http://jogamp.org/

http://labb.zafena.se/?p=547 - i have posted a tutorial how to get started and getting OpenGL ES 2 running on the Pi using JogAmp back in the summer of 2012
http://www.raspberrypi.org/phpBB3/viewt ... 81&t=15466 - Java OpenGL ES 2 bindings using JogAmp JOGL 2
Image

please ask if you have further questions
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby

Rene8888
Posts: 8
Joined: Fri Sep 20, 2013 10:33 pm

Re: Graphics without X11

Mon Mar 31, 2014 9:28 am

Thank you for your answers! I will try it with JogAmp first. It looks really promising :D

And thank you for your help and quick answers!

Rene8888
Posts: 8
Joined: Fri Sep 20, 2013 10:33 pm

Re: Graphics without X11

Mon Mar 31, 2014 1:30 pm

Since 3 hours I am trying to get a string rendered on the screen...

Is it possible to get graphics rendered on the screen with for example LWJGL? There I can use slick2d...

User avatar
Fidelius
Posts: 460
Joined: Wed Jan 01, 2014 8:40 pm
Location: Germany

Re: Graphics without X11

Mon Mar 31, 2014 1:43 pm

Rene8888 wrote:I want to draw graphics to the screen without using X11. The resolution is 1920x1080.

I want to try it with OpenGL, so I don't stress the CPU too.
I never used OpenGL, but i should be able to draw some rectangles and write some text
I think the simplest way to achieve what you want, is to use the new Java 8. Its built-in JavaFX provides hardware-accelerated 2D and 3D graphics on all platforms, including the nice Pi. For the latter JavaFX uses OpenGL-ES without X11.

Please see my recent short reference to Java 8 on the Pi here :
Re: The fasters way to get started with a 3D game

The Oracle Fx tutorial shows how simple it is to see results in no time. Extraordinary. And pure Java.

Having said this, there's always cases where you need pure OpenGL or OpenAL via Jogamp/Jogl. And I'm thankful for the good work from the teams behind it.
Last edited by Fidelius on Mon Mar 31, 2014 1:54 pm, edited 1 time in total.

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

Re: Graphics without X11

Mon Mar 31, 2014 1:51 pm

Rene8888 wrote:Since 3 hours I am trying to get a string rendered on the screen...

Is it possible to get graphics rendered on the screen with for example LWJGL? There I can use slick2d...
There exist a port of LWJGL for use on the Pi made by spsn. This LWJGL port still require X11 in order to handle input.
http://www.raspberrypi.org/phpBB3/viewt ... p?p=211087

JogAmp JOGL is similar to LWJGL that you need to combine JogAmp with an OpenGL 3D engine or OpenGL utility classes, or your own engine in order to facilitate easy text rendering.

You can for example use JogAmp in combination with libGDX that contains its own "scene2d" UI toolkit, thus you can find a similar easy to use API compared to slick2d by using libgdx in combination with JogAmp JOGL on the Pi!

I have a branch of libgdx that uses JogAmp JOGL as a backend that you can try.
https://github.com/xranby/libgdx/tree/j ... gl-backend
http://forum.jogamp.org/JOGL-2-0-OpenGL ... 27689.html


Slick2D was not designed with OpenGL ES 2 in mind, its still unfixed
https://bitbucket.org/kevglass/slick/is ... 20-support
lika stated in that bugreport, you may combine Slick2D with libgdx in order to get slick2d applications running on OpenGL ES 2 devices. a possible solution are: slick2d -> Slick-AE -> libgdx -> jogaml jogl if you like to use the slick 2d API.


noxo experimented using jmonkeyengine 3 on the pi and got it running a year ago, here everything worked ok as long as you used the right textures, a limitation by the Pi GPU drivers. (ABGR texture are not supported by RPI's VideoCoreIV binary blob)
https://github.com/noxo/jmonkey-engine- ... d_renderer

Inside the JogAmp project we are working on a super fast way to render text by drawing all the curves using the GPU directly.
We call this GPU rendered UI toolkit "Graph", it is based on the patent free "Resolution Independent NURBS Curves Rendering using Programmable Graphics Pipeline" paper by Rami Santina. Graph work great on both desktop ( OpenGL 2, 3 and opengl 4 core) and mobile (tested on many android opengl es 2 & 3 devices, meego nokia n9). Last time I checked there was some issues using graph on the Pi due to some missing optional GLSL intrinsic function support by the Pi GPU drivers. that can be fixed now with the recently opensourced Pi GPU drivers!
http://forum.jogamp.org/Graph-UI-Teaser ... 31945.html
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby

Rene8888
Posts: 8
Joined: Fri Sep 20, 2013 10:33 pm

Re: Graphics without X11

Mon Mar 31, 2014 8:41 pm

Thank you for your suggestions! I really appreciate it!

I want to try it with JavaFX first. Its the simplest and fastest approach. If I get really bad performance, there will be no other way then switching to OpenGL.

Thanks

User avatar
Fidelius
Posts: 460
Joined: Wed Jan 01, 2014 8:40 pm
Location: Germany

Re: Graphics without X11

Tue Apr 01, 2014 6:43 am

Rene8888 wrote:Thank you for your suggestions! I really appreciate it!

I want to try it with JavaFX first. Its the simplest and fastest approach. If I get really bad performance, there will be no other way then switching to OpenGL.
Good luck with trying out.
I'm still trying it out and it's good so far. Currently I'm exploring Fx's 3D API, but also its 2D performance is good. This is what you want to do: 2D, I suppose? Please see my little Rtype-like Pi-demo here, running @ 60 fps.

Java 8's Fx library uses a mixed 2D & 3D scenegraph, so all graphic operations are done with the same OpenGL-ES pipeline.

mikerr
Posts: 2826
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: Graphics without X11

Tue Apr 01, 2014 9:29 am

Java8 now suports accelerated 3d on the Pi:

Guide to installing java8 on pi here:
http://helloraspberrypi.blogspot.co.uk/ ... lable.html


next install a 3d demo:

http://www.interactivemesh.org/models/jfx3dtuxcube.html

Code: Select all

wget http://www.interactivemesh.org/models/download/FXTuxCube0.7.1.zip
unzip FXTuxCube0.7.1.zip
then run it as:

Code: Select all

java -Xmx1024m -Dcom.sun.javafx.experimental.embedded.3d=true -Djavafx.animation.fullspeed=true -Dprism.dirtyopts=false -cp ./:jimObjModelImporterJFX.jar:fxTuxCube.jar org.interactivemesh.jfx.sample3d.tuxcube.FXTuxCube
( the option "-Dcom.sun.javafx.experimental.embedded.3d=true" added to make it work on pi)

Image
https://www.youtube.com/watch?v=bTBqI0RhOVw

That gets 24fps, and is also a good demo of the mouse control and GUI elements.
Android app - Raspi Card Imager - download and image SD cards - No PC required !

User avatar
Fidelius
Posts: 460
Joined: Wed Jan 01, 2014 8:40 pm
Location: Germany

Re: Graphics without X11

Tue Apr 01, 2014 11:52 am

mikerr wrote:Java8 now suports accelerated 3d on the Pi:

Guide to installing java8 on pi here:
http://helloraspberrypi.blogspot.co.uk/ ... lable.html
That's a nice video from Oracle, thanks for linking to it.

Those wanting to test Java 8 now next to Raspbian's Java 7 (until Raspbians comes with Java 8 pre-installed, as announced in other threads), i.e. without a full install, could also just download the JDK 8 tar-gz file from Oracle here (Linux ARM, 83 MB), and untar it to a place like /opt/jdk1.8.0/

And then either start java from there: /opt/jdk1.8.0/bin/java -jar program.jar
... or add to the end of file "/etc/profile" a line like this :
PATH=/opt/jdk1.8.0/bin:"$PATH"


Also don't miss the official JDK "Demos and Samples" which are downloadable on the above linked Oracle's JDK website.
Next to the general Ensemble8.jar demo, there's an interesting 3DViewer.jar which imports Wavefront and Maya 3d model files and then lets you explore the models on-screen, or also export them as JavaFx XML format files for direct use in own applications without the need of an importer. Very handy indeed.

On the bigger platforms this 3DViewer.jar has an open file dialogue to select the files to import, which however is missing in Java 8 on the Pi (as is the new Javafx sound-package), so you have to specify the model file as a parameter, like so:

Code: Select all

java -Dcom.sun.javafx.experimental.embedded.3d=true -jar 3DViewer.jar Yourmodel.obj

Return to “Java”