Quantcast
Channel: openFrameworks - Latest posts
Viewing all articles
Browse latest Browse all 40524

How to run update() and draw() in keyPressed() event

$
0
0

@hyro,

if you're trying to limit drawing to a given event, try doing that drawing in a separate function. the idea is that, with background clearing disabled, you treat the OpenGL window as a buffer that accumulates all of the shapes that you draw into it. every time you call that separate function to draw additional shapes, they will build up on screen.

void drawShapes(){

  ofSetColor( ofRandom(255), ofRandom(255), ofRandom(255)); 
  ofEllipse( ofRandom(ofGetWidth(), ofRandom(ofGetHeight), 30, 30);

}

note that in the code your shared, because of the 'break' statement, that someUpdateFunction() is only running once. also is there any reason to have a for loop with that modulo test in it? why not just count to 10 if you want to draw 10 shapes?

void testApp::keyPressed(int key) {
     switch (key) {
         case ' ':
              for(int i=0 i < 100; i++){
                 if(i % 10 == 0){
                     drawShapes();
                 }
              }
              break;
      }
}

Viewing all articles
Browse latest Browse all 40524

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>