Loading...
Logo
Processing Forum

Force draw / refresh

in Programming Questions  •  2 years ago  
Hi all,

I have a program which does some heavy computation inside the draw() loop.  Every time I run the program, it only displays the window after the first instance of draw() is run, after which it won't update again until the draw loop terminates.  Is there some way to force the program to redraw the screen at each instance of draw()?

Gene

Replies(4)

" to redraw the screen at each instance of draw()"
That's exactly what it does currently! Except draw() has no instances, only calls...

I think the article in the I display images in sequence but I see only the last one. Why? page is relevant to your problem.
a while ago i tried to find a way to "manually" update the screen.
im not sure if the following code can help you, but maybe you can extract some lines, that are useful for you.



void setup(){
  size(400,400);
  background(255);
}

void draw(){
  background(255);
  fill(255,0,0);
  frameRateLastNanos = System.nanoTime();
  while(true){
    //background(255);
    handleFrameRate();
   
    //g.beginDraw();
    //if (recorder != null)  recorder.beginDraw();
    //preMethods.handle();
    ellipse(mouseX, mouseY, 10, 10);
            //dmouseX = mouseX;
    //dmouseY = mouseY;
    //println(emouseX+", "+dmouseX +", "+pmouseX);

    dequeueMouseEvents();
    dequeueKeyEvents();
    //drawMethods.handle();


    //g.endDraw();
    //if (recorder != null)  recorder.endDraw();

    paint();
    //postMethods.handle();
    println(frameRate);
  }
 
}

void handleFrameRate(){
  long now = System.nanoTime();
  frameRate = (frameRate * 0.9f) + 1E08f / (System.nanoTime() - frameRateLastNanos);
  frameRateLastNanos = now;
  frameCount++;
}

void keyPressed(){
  println("void keyPressed()");
}



thomas
Hi,

Unfortunately neither of these worked for me.  The bizarre thing is that while it is drawing, if I minimize and then reopen the window it updates.   But as long as I am just looking at the window, it doesn't update until the very end!  Any ideas?

gene
I figured it out!  I was not terminating the draw loop properly, containing everything in a while loop -- so now I stop with noLoop instead.  Thanks for the answers!