Problem Building Processing from Source for Raspberry Pi + Newt (P3D/OpenGL)

Hi All,

I'm trying to get a Processing Sketch (with P3D) running on the Raspberry Pi. Processing seems to run ok, but sketches using P3D give me an empty/transparent Processing screen and:

Listening for transport dt_socket at address: 8638
glGetError 0x500
glGetError 0x500
java.lang.ClassCastException: javax.media.nativewindow.DefaultGraphicsConfiguration cannot be cast to com.jogamp.nativewindow.awt.AWTGraphicsConfiguration
    at javax.media.opengl.awt.GLCanvas.chooseGraphicsConfiguration(GLCanvas.java:1421)
    at javax.media.opengl.awt.GLCanvas.addNotify(GLCanvas.java:630)
    at java.awt.Container.addImpl(Container.java:1114)
    at java.awt.Container.add(Container.java:966)
    at processing.opengl.PJOGL.initSurface(PJOGL.java:326)
    at processing.opengl.PGraphicsOpenGL.initPrimary(PGraphicsOpenGL.java:5988)
    at processing.opengl.PGraphicsOpenGL.requestDraw(PGraphicsOpenGL.java:1600)
    at processing.core.PApplet.run(PApplet.java:2177)
    at java.lang.Thread.run(Thread.java:724)

Quite a bit of research suggests that this is due to the Pi's inability to handle AWT, requiring that I need to build Processing from source and force it to draw to NEWT. So I'm working towards this solution from Xerxes Ranby.. Possibly with codeanticode's .glw library.

I should mention that I am not an experienced programmer, so building from source is somewhat unchartered territory for me so have been following these instructions.

But when I do:

cd build
ant run

I get the following:

/home/ben/processing
ben@ben-Ideapad-Z570:~/processing$ cd build
ben@ben-Ideapad-Z570:~/processing/build$ ant run
Buildfile: /home/ben/processing/build/build.xml

run:

revision-check:

linux-checkos:

subprojects-build:

compile:
  [methods] No changes to PApplet API.
    [mkdir] Created dir: /home/ben/processing/core/bin
    [javac] Compiling 45 source files to /home/ben/processing/core/bin
     [copy] Copying 1 file to /home/ben/processing/core/bin/japplemenubar
     [copy] Copying 15 files to /home/ben/processing/core/bin

build:
      [jar] Building jar: /home/ben/processing/core/library/core.jar
    [mkdir] Created dir: /home/ben/processing/app/generated/processing/mode/java/preproc

preproc:
    [antlr] ANTLR Parser Generator   Version 2.7.7 (2006-11-01)   1989-2005
    [antlr] /home/ben/processing/app/src/processing/mode/java/preproc/java15.g:941: warning:Syntactic predicate superfluous for single alternative
    [antlr] /home/ben/processing/app/src/processing/mode/java/preproc/java15.g:1397: warning:empty alternative makes no sense in (...)* or (...)+
    [antlr] ANTLR Parser Generator   Version 2.7.7 (2006-11-01)   1989-2005
    [antlr] /home/ben/processing/app/generated/processing/mode/java/preproc/expandedpde.g:1154: warning:empty alternative makes no sense in (...)* or (...)+
    [antlr] /home/ben/processing/app/generated/processing/mode/java/preproc/expandedpde.g:803: warning:Syntactic predicate superfluous for single alternative

compile:
    [mkdir] Created dir: /home/ben/processing/app/bin
    [javac] Compiling 101 source files to /home/ben/processing/app/bin
    [javac] ----------
    [javac] 1. ERROR in /home/ben/processing/app/src/processing/app/Base.java (at line 998)
    [javac]     final List<Mode> possibleModes = new ArrayList<>();
    [javac]                                                   ^
    [javac] Syntax error on token "<", ? expected after this token
    [javac] ----------
    [javac] 1 problem (1 error)

BUILD FAILED
/home/ben/processing/build/build.xml:201: The following error occurred while executing this line:
/home/ben/processing/build/build.xml:236: The following error occurred while executing this line:
/home/ben/processing/app/build.xml:97: Compile failed; see the compiler error output for details.

As I've said, I'm a bit out of my depth here, and have been on this for 3 days, so any help is greatly appreciated.

Thanks,

Ben.

Intel(R) Core(TM) i3-2350M CPU @ 2.30GHz; Ubuntu 13.10

Edit: To clarify - I haven't actually altered any code in the Processing build yet. At this stage I'm just trying to understand the build process before looking at how I go about forcing NEWT to port to the Raspberry Pi.

Answers

  • edited April 2014
    compile:
        [mkdir] Created dir: /home/ben/processing/app/bin
        [javac] Compiling 101 source files to /home/ben/processing/app/bin
        [javac] ----------
        [javac] 1. ERROR in /home/ben/processing/app/src/processing/app/Base.java (at line 998)
        [javac]     final List<Mode> possibleModes = new ArrayList<>();
        [javac]                                                   ^
        [javac] Syntax error on token "<", ? expected after this token
        [javac] ----------
        [javac] 1 problem (1 error)
    

    UPDATE: Since my last post, I tried the build instructions for Windows (rather than Linux) and got the same compile error.

    So I opened up the base.jar file and changed:

    final List<Mode> possibleModes = new ArrayList<>();

    to

    final List<Mode> possibleModes = new ArrayList<Mode>();

    I don't know a line of Java and just tried this on a whim, so please let me know if this is wrong, but it did result in Processing starting up.

  • edited April 2014

    Empty brackets <> is Java 7's syntax. Actually we can even remove it and it'd be compiled alright. Just an irritating warning!

    final List<Mode> possibleModes = new ArrayList();

    The final List<Mode> possibleModes = new ArrayList<Mode>(); is the more formal way though! :P

  • Yeah but with empty diamond it should work but it don't I've filed a bug report.

  • edited April 2014

    I've filed a bug report.

    Good luck w/ that! Processing's pre-processor has been in a crap state for years! >:P
    Even Java 5's enum isn't supported yet! Imagine Java 8's lambda expressions!!! :O)

    Another good example, full class w/ generic brackets:
    java.util.HashSet<Integer> sets;

    And some Java 7's niceties lacking like:

    • Binary literals: int binVal = 0b11010;
    • Underscored literals: long creditCardNumber = 1234_5678_9012_3456L;

    Whew! That's what I remember for now! >:)

  • Bens, fixed it, and the reason for problem is the build in ecj.jar has not neen updated. Therefore processing build is really on 1.7. Compile flags now reset to 1.6.

  • edited April 2014

    Bens, fixed it,...

    So when we're gonna be able to use nested enum, binary literals and underscored literals? :-<

    What about accented labels like: String açaí = "fruit";? :P

  • @whistler the glw library should be the way to go, it is not finished at this point and the main build script won't compile it and add it to the rest of the default libs (video, pdf, etc). You would need to run "ant build" manually in the folder of glw to get it compiled and installed.

  • (sorry for the repeated posts, had some problems to access the forum)

  • edited April 2014

    Another disabled Java 7's feature:

    final String s = "GoToLoop";
    
    // Cannot switch on a value of type String:
    switch (s) {
    case "GoToLoop": 
      println("My nick is " + s);
      break;
    
    default: 
      println("My nick isn't " + s);
    }
    
  • edited April 2014

    Hi Guys,

    Thanks for your feedback on this. I've managed to build the Processing source on the Pi, but have as yet been unable to get P3D working.

    codeanticode - Running the examples gives me a small transparent window (100,100), which closes after a few seconds, without anything else showing up, and then the error:

    glGetError 0x500
    glGetError 0x500
    glGetError 0x500
    javax.media.opengl.GLException: Not a GL2ES2 implementation
        at jogamp.opengl.es1.GLES1Impl.getGL2ES2(GLES1Impl.java:4886)
        at processing.opengl.PJOGL.getGL(PJOGL.java:657)
        at processing.glw.PNEWT.access$0(Unknown Source)
        at processing.glw.PNEWT$DummyListener.init(Unknown Source)
        at jogamp.opengl.GLDrawableHelper.init(GLDrawableHelper.java:617)
        at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:663)
        at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:649)
        at jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:399)
        at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1119)
        at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:994)
        at jogamp.opengl.GLAutoDrawableBase.defaultDisplay(GLAutoDrawableBase.java:432)
        at com.jogamp.opengl.GLAutoDrawableDelegate.display(GLAutoDrawableDelegate.java:167)
        at processing.glw.PNEWT.requestDraw(Unknown Source)
        at processing.opengl.PGraphicsOpenGL.requestDraw(PGraphicsOpenGL.java:1651)
        at processing.core.PApplet.run(PApplet.java:2254)
        at java.lang.Thread.run(Thread.java:724)
    

    I get something similar in Linux (on my PC), except that the second window/s open up for an instant before closing.

    I've also tried editing PJOGL.java, changing:

         else if (PApplet.platform == PConstants.LINUX) {
          WINDOW_TOOLKIT = AWT;
          EVENTS_TOOLKIT = AWT;
          USE_FBOLAYER_BY_DEFAULT = false;
          USE_JOGL_FBOLAYER = false;
    }
    

    to

         else if (PApplet.platform == PConstants.LINUX) {
          WINDOW_TOOLKIT = NEWT;
          EVENTS_TOOLKIT = NEWT;
          USE_FBOLAYER_BY_DEFAULT = false;
          USE_JOGL_FBOLAYER = false;
    }
    

    Any ideas where I'm going wrong?

    Thanks,

    B.

  • hi, the default opengl renderer won't work. Even if choose NEWT, it will try to embed the NEWT canvas inside an AWT frame, which is not supported on the rpi.

    You need to use the GLW library instead, which comes with its own separate renderer. It simply bypasses the frame created by Processing, and opens a native NEWT window w/out any AWT embedding. I believe the main ant build script will compile and install GLW, check if you have a glw section under Java Examples|Libraries. If not, you can compile GLW manually: change to the java/libraries/glw folder inside the processing source, and run "ant build". Then copy the glw folder (which should contain library/glw.jar) into modes/java/libraries of your processing build.

  • edited April 2014

    @codeanticode - Thanks for your reply. Sorry, I should have been clearer in my last post - I wrote that at around 5am after I had been staring at the command line for the previous few hours @-).

    Last night, I ran 'ant build' inside of ~/processing/java/libraries/glw. Ant reported 'build successful' and I believed that this installed the library as Processing compiles and attempts to run the sketch. Although it doesn't show up under sketch/import library. (I have tried this with and without the (NEWT) modification to PJOGL.java, with the same result).

    When I run either of your two example sketches, I get, what appears to be, the temporary AWT window (100,100), which then closes, before I get the above error: javax.media.opengl.GLException: Not a GL2ES2 implementation ...

    Other things I've tried today since reading your reply:

    1. Built GLW inside ~/processing/java/libraries/glw/ and then copied folder to ~/processing/build/linux/work/modes/java/libraries - THIS CAUSES GLW TO SHOW UP IN SKETCH/ IMPORT LIBRARY - BUT THE RESULT IS THE SAME

    2. Built GLW directly inside ~/processing/build/linux/work/modes/java/libraries/glw/ - This gives me the error: BUILD FAILED /home/pi/processing/build/linux/work/modes/java/libraries/glw/build.xml:13: PLease build the core library first and make sure it sits in ../../../core/library/core.jar

    3. Built GLW inside ~/processing/java/libraries/glw/ and then copyied folder to ~/processing-2.1(prebuilt from processsing.org)/modes/java/library

    4. Built GLW inside processing-2.1/modes/java/libraries (prebuilt from processsing.org) - Tells me to build core first

    5. Copied ~/processing/core/library/core.jar to ~/processing-2.1(prebuilt from processsing.org)/core/library/ ... Build failed. Build core first

    6. Copied folder ~/processing/core/library/ to ~/processing-2.1(prebuilt from processsing.org)/core/

  • edited April 2014

    ok, I think the build script is correctly installing glw, so you don't need to try 1-6. The problem seems to be that GLW cannot successfully initialize OpenGL into the GLES2 profile, which is the required profile to run shaders, etc. This is surprising because the RPi does support GLES2.

    One thing to note is that when working with GLW you shouldn't need to worry about PJOGL.java, since PNEWT.java is overriding the initialization methods. I cannot try things right now on the RPi, but I wonder if the line

    profile = GLProfile.getGL2ES1();

    in PNEWT.java shouldn't be:

    profile = GLProfile.getGL2ES2();

    instead.

  • I just tried editing that line in glw/src/processing/glw/PNEWT.java before rebuilding the library but still the same GLException error.

  • edited April 2014

    UPDATE: I realised that I needed to build GLW before building Processing, whereas previously I was building Processing first, which explains why I wasn't getting it showing up under import library.

    Now, when I change:

    profile = GLProfile.getGL2ES1();
    

    to:

    profile = GLProfile.getGL2ES2();
    

    I do at least get the NEWT window opening up after the smaller one closes, except that the window is black and I am unable to move it in either of the two examples (and only one window is visible in 'MultipeWindows' as they are overlaid one on top of the other), and I get the following:

    Listening for transport dt_socket at address: 8582
    glGetError 0x500
    glGetError 0x500
    glGetError 0x500
    glGetError 0x500
    OpenGL error 1280 at bot beginDraw(): invalid enumerant
    glGetError 0x500
    glGetError 0x500
    glGetError 0x500
    glGetError 0x500
    OpenGL error 1280 at bot endDraw(): invalid enumerant
    glGetError 0x500
    glGetError 0x500
    glGetError 0x500
    glGetError 0x500
    [...]
    

    glGetError 0x500 prints repeatedly as long as the sketch is running.

    If I comment out:

    canvas#.background(#);

    from 'MultipleWindows', I do get something like the intended sketch, though the window can't be moved and the error is the same.

    Another thought - should PNEWT.java also be edited so that:

              catch (GLException ex) {
              profile = GLProfile.getMaxFixedFunc(true);
            }
    

    becomes:

              catch (GLException ex) {
              profile = GLProfile.getMaxProgrammable(true);
            }
    

    ?

    I've tried changing this too - but no dice.

    @codeanticode - any thoughts?

  • edited April 2014

    what would be a minimal sketch that at least shows some kind of output? For instance, do you get a red window with the following code:

    import processing.glw.*;
    
    PGraphics pg;
    
    void setup() {
      size(100, 100, GLW.RENDERER);
    
      pg = createGraphics(300, 300, GLW.P2D);
      GLW.createWindow(pg);
    }
    
    void draw() {
      pg.beginDraw();    
      pg.background(255, 0, 0);  
      pg.endDraw();
    }
    
  • Thanks, I don't have the pi at the moment as I've had to send it to exhibition (I ended up outputting the sketch to video as a workaround since it is a simple animation loop). I've ordered another pi in the meantime, so will try this out when it arrives.

    I was actually getting rendered output with your 'MultipleWindows' example, but only if I removed the background() function from void draw(). This would give me ellipses drawing at mouseX, mouseY, but with the immovable canvas and recurring glGet Error noted above, which seemed to be printing once for each iteration of draw().

    Has the library been known to work on the RPi previously?

    What are your thoughts about editing:

    profile = GLProfile.getMaxFixedFunc(true);

    ? I had to research this stuff, so I might be spitting in the wind here, but I read somewhere that GL2ES2 is PSP only.

  • GLProfile.getMaxFixedFunc(true) won't work with Processing because the OpenGL renderer expects a fully programmable pipeline. My understanding is that the RPi supports GLES 2.0, but I might be wrong. You won't lose anything by trying though :-)

    I only did some very preliminar testing on an actual RPi before starting to work on the glw library. Back then I used a NEWT window to override the AWT frame that Processing creates by default. This is the approach I took with the library, but haven't had the time to do any additional testing/debugging. Even on the desktop, the library still needs work as the mouse events are not properly handled.

    I wonder if you could run some of the tests cases from jogl to see if opengl works fine without any overhead from Processing. This thread maybe is useful:

    http://www.raspberrypi.org/forums/viewtopic.php?f=81&t=27793

    Also, Xerxes Ranby did some early tests of Processing on the RPi, he might have some more (updated) leads:

    https://twitter.com/xranby

    I will do more work on the glw library, and RPi testing, as time permits.

Sign In or Register to comment.