Loading...
Logo
Processing Forum
Hello guys,

I have been working with processing for a few, primarly to make some animations and interactivity to my kids (processing/oF). Now I want to do some water ripples (my logical next move) but I have had slow framerate problems.

the process I am following is:
1.render everything
2.loadpixels
3.move pixels to pixels of a PImage.pixels (canvas.pixel)
4.alter the canvas.pixels with the ripple effect (that I have ported from C++ where I have made a few of them that run fast ecough).
5.render the canvas.

now, if I don't do the ripple, the framerate of my animations is steady at 60 (setFramerate(60);) but when I add the ripple effect, the framerate goes to 3 or 4.

Actually, by just doing steps 2 and 3 (skipping ripple function) my framerate drops to 3 or 4.

knowing my problem, I'd like to ask:
1.¿Is there a way of changing the default canvas for rendering to a PImage? eg. set processing canvas to x, so whenever I render instead of rendering to screen I'd render to a buffer.
2.-if not, ¿How can I render to a PImage? canvas.Image()?
3.-Is there a faster way of getting the rendering buffer pixels than loadpixels and copying to a PImage.pixels?

and another question not related to my foolish problem. Is there a way of using the GPU for doing some math with processing, like OpenCL? I am more C++ than Java, but Processing is making Java more interesting... :)

thanks in advanced for the replies.

Replies(4)

maybe have a look at the glgraphics library by Andres Colubri, gives you a good performance boost especially when doing pixel processing on textures or using shaders with it. There is also an OpenCL wrapper for java by Victor Martins posted here, but am not sure about the status.

andreas schlegel, http://www.sojamo.de
Thank you for the links andreas.schlegel, but I still have the same problem. when runing the particle examples, the framerate went down to 2 frames per second. I believe it's time to test on the desktop computer, not my laptop, as it seems my Inter Video card cannot handle the OpenGL render that good (even though I can play StarCraft II nicely on it). The libraries are very good though, and the GSVideo library (sibling of glgraphics) is very good too... but my problem persists...

I found that PGraphics is a rendering context, so I tried creating one and writing everything to it:
Copy code
  1. PGraphics canvas;
  2. ....
  3. void setup() {
  4. ...
  5.       canvas = createGraphics(width,height,OPENGL);
  6. ...
  7. }
  8. ...
  9. void draw() {
  10.       canvas.beginDraw();
  11.       canvas.background(0);
  12.       canvas.image(rocks,0,0);
  13. ....
  14.       Boid.render(canvas);
  15. ....
  16.       canvas.endDraw();
  17.       image(canvas,0,0);
  18. }
on Boid class, i have:
Copy code
  1. void render(PGraphics canvas)
  2. {
  3.       canvas.beginDraw();
  4.       ...
  5.       //all drawring vertex with canvas.vertex(...)
  6.       ...
  7.       canvas.endDraw();
  8. }
if I add the canvas begin and end draw, it gives me an IndexOutOfBoundsException: Required 2103300 remaining bytes in buffer, only had 2097152. if I take out the beginand endDraw then I get GLException: Context not current on current thread.

I'm still wandering around... any ideas would be great.
Updating... I moved from my laptop (i read about processing not supporting intel graphics, even 4500 HD) to my desktop, using a core 2 duo, 4GB RAM, 1GB GForce 9500... and still moved from 4 FPS to 16 FPS. I even tried the Sun and Water example at http://www.openprocessing.org/visuals/?visualID=10846 which runs fast, until you create a bigger frame. I've been reading about using GLSL... I will try it, and let you know what happens.
OK, I have found the problem. Not the solution...

I'm using OPENGL canvas and when I use the loadPixels, the framerate drops to 4. If I use P3D or P2D (without rendering the OpenGL QUAD_STRIPS) everithing runs quite fast... 60 FPS on Intel GFX and 130 on GForce GFX.

now the problem would be. How Can I render a QUAD_STRIP on P3D? I'm using texturing on it so it's not shown when rendering there.

the render code is:
Copy code
  1.   void display() {
  2.     noStroke();
  3.     beginShape(QUAD_STRIP);
  4.     texture(skin);
  5.     for (int n = 0; n < numNodes; n++) {
  6.       float dx;
  7.       float dy;
  8.       if (n == 0) {
  9.         dx = node[1].x - node[0].x;
  10.         dy = node[1].y - node[0].y;
  11.       }
  12.       else {
  13.         dx = node[n].x - node[n - 1].x;
  14.         dy = node[n].y - node[n - 1].y;
  15.       }
  16.       float angle = -atan2(dy, dx);
  17.       float x1 = node[n].x + sin(angle) * -skinYspacing;
  18.       float y1 = node[n].y + cos(angle) * -skinYspacing;
  19.       float x2 = node[n].x + sin(angle) *  skinYspacing;
  20.       float y2 = node[n].y + cos(angle) *  skinYspacing;
  21.       float u = skinXspacing * n;
  22.       vertex(x1, y1, u, 0);
  23.       vertex(x2, y2, u, skin.height);
  24.     }
  25.     endShape();
  26.   }


thanks in advanced.