Quantcast
Viewing all articles
Browse latest Browse all 40524

Force a draw - outside of the ::draw() method?

Thanks for the example @hahakid - however, I couldn't really apply it to my use case. So I made a buildable minimal "working" example, based on examples/emptyExample. Use standard Makefile and main.cpp; and then:

ofApp.h

#pragma once

#include "ofMain.h"

#define BUFLEN 2000000

class ofApp : public ofBaseApp{
  public:
    unsigned char myBuf[BUFLEN];
    int state = 0;
    bool doLoad;
    void LoadAndInitHeavyHog();
    ofTrueTypeFont myfont;

        void setup();
        void update();
        void draw();

        void keyPressed(int key);
        void keyReleased(int key);
        void mouseMoved(int x, int y);
        void mouseDragged(int x, int y, int button);
        void mousePressed(int x, int y, int button);
        void mouseReleased(int x, int y, int button);
        void mouseEntered(int x, int y);
        void mouseExited(int x, int y);
        void windowResized(int w, int h);
        void dragEvent(ofDragInfo dragInfo);
        void gotMessage(ofMessage msg);
};

ofApp.cpp

#include "ofApp.h"

void ofApp::LoadAndInitHeavyHog(){
  for(unsigned long i=0; i<BUFLEN; i++) {
    unsigned char val = ((i + i/3)/150)%255;
    myBuf[i] = val;
    if ( (i%25) == 0 ) {
      ofLogNotice() << " ... i: " << i; //hog even more by dumping to stdout
    }
  }
  state = 1;
  doLoad = false;
}


//--------------------------------------------------------------
void ofApp::setup(){
  ofSetLogLevel(OF_LOG_NOTICE);
  state = 0;
  doLoad = false;
  myfont.load("arial.ttf", 32);
}

//--------------------------------------------------------------
void ofApp::update(){

}

//--------------------------------------------------------------
void ofApp::draw(){
  if (state == 0) {
    myfont.drawString("State 0 - click anywhere", 100,100);
  }
  if ((state == 0) && (doLoad)) {
    myfont.drawString(" --- LOADING --- ", 100,100);
    LoadAndInitHeavyHog();
  }
  if (state == 1) {
    myfont.drawString("State 1 - loaded...", 100,100);
  }
}

//--------------------------------------------------------------
void ofApp::keyPressed(int key){

}

//--------------------------------------------------------------
void ofApp::keyReleased(int key){

}

//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y){

}

//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){

}

//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
  ofLogNotice() << "::mousePressed ";
  if (state == 0) {
    doLoad = true;
  }
}

//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){

}

//--------------------------------------------------------------
void ofApp::mouseEntered(int x, int y){

}

//--------------------------------------------------------------
void ofApp::mouseExited(int x, int y){

}

//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){

}

//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){

}

//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){

}

In this example, when I build it on Linux, the " --- LOADING --- " message is not shown when I click the window, however, as evidenced by the log messages in stdout, the LoadAndInitHeavyHog() runs - and when it's done, I do get "State 1 - loaded..." shown...

Any hints on how do I get the LOADING message to show in this case?


Viewing all articles
Browse latest Browse all 40524

Trending Articles