Problem getting code to run from book

edited February 2014 in Android Mode

I can't get this code to run on the emulator and I'm not getting any errors in the console. So I'm hoping someone who is able to run the code can post what they have as the virtual emulator, if any sketch permissions are needed. Or what you think is needs to be downloaded from the SDK.

the virtual emulator i have has the Target name Android 2.3.3, platform 2.3.3 and API level 10

void setup() {
  size(displayWidth, displayHeight, P3D);   //(1)
  orientation(LANDSCAPE);
  noStroke();
}
void draw() 
{
  background(0);
  float lightX = map(mouseX, 0, width, 1, -1);  //(2)
  float lightY = map(mouseY, 0, height, 1, -1);  //(3)

  lights();  //(4)
  directionalLight(200, 255, 200, lightX, lightY, -1);  //(5)

  translate(width/4, height/2, 0); 
  box(height/3); 
  translate(width/2, 0, 0);
  sphere(height/4);
}

Answers

  • edited February 2014

    What book do you take this example from? It doesn't really matter, but it would be good to know...

    I don't see anything wrong with the code. The problem is probably with your emulator setup. I don't know exactly what error you are experiencing... but try starting the emulator first and then running the sketch after it has fully loaded.

  • I tried it in java mode and it seems to work, but in android mode i get a sketch fails error on the emulator.

  • Could you elaborate? What exactly is a "sketch fails error"?

  • On the emulator i get a box when i try to start the app in it that says "The application(name of the file) has stopped unexpectedly. Please try again.

  • edited February 2014

    I just spent some time on this problem. Basically, the emulator cannot run OpenGL accelerated graphics with Processing currently. It fails on sketches that use P2D, P3D and OPENGL.

    The Android SDK must be at least Revision 15 to get OGL graphics in the emulator. Processing uses Revision 10 for it's Android mode and installing a higher Android revision will not work. Cheers.

  • @SiriusCG: This was once the case, but no longer. You have the correct answer... but here is the solution: Faster Emulator with Better Hardware

    To enable OpenGL on your emulator:

    1. Open the AVD Manager - Select "Android" > "Android AVD Manager" from the PDE.
    2. Select the existing emulator and click "Edit".
    3. Under "Hardware", select "New".
    4. Select "GPU Emulation" and click "OK".
    5. Select property "GPU Emulation" and change it to "yes".
    6. Click "Edit AVD".

    Your emulator should now support OpenGL hardware acceleration. Please keep in mind that the performance will be less than that achievable by an actual device. This feature may not work for all GPUs.

  • Tried the above did not work.

    I tried running the program through a nexus 1 and a nexus 7 as well and the program did not work either, is this a problem with the processing compiler perhaps?

    I'm running version 2.0.3 if it means anything.

  • @calsign: Unfortunately, this does not seem to remedy the problem, at least for me. I made the suggested configuration changes, retested a number of sketches from the Android examples folder, those with either P2D, P3D or OPENGL in them, and got the same error (in this example the directional light sketch):

    "The application (processing processing.test.directional) has stopped unexpectedly. Please try again."

    I have the requisite libraries and revisions installed, the compiler produces no error and all other Processing sketches that don't use the aforementioned flags run fine.

    So, if it's working for others, I'll chock it up to a hardware issue with my current Radeon card, and continue to wait on Google to get the Nexus 11 in the channel. Thanks however for taking the time to point this out. Cheers. :)

  • Okay, I suppose it doesn't work. If I had to guess, it's probably a problem with Processing's OpenGL implementation... or maybe the feature is just broken.

  • edited February 2014

    No worries. If I'm reading it correctly, the accelerated graphics code was part of Android SDK 15 which is 4.0.3 Revision 2. Processing 2.1.1 (the latest revision that I'm using currently) uses Android SDK 10 which is 2.3.3 ...

    Cheers.

Sign In or Register to comment.