Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
example use of ofGetAppPtr()

###ofGetAppPtr() example

from a .cpp file, for example, "particle.cpp" you can do two things:

  • a) include "ofApp.h" (so you know what's inside the ofApp)
  • b) cast the ofGetAppPtr as a ptr

you can't include ofApp.h inside another .h file, as you would recursive includes (ie, ofApp includes particle, particle includes ofApp), but putting it in the .cpp is fine.

example code:

    //particle.cpp particle class
    #include "particle.h"
    #include "ofApp.h"
    void particle::update(){
      ((ofApp*) ofGetAppPtr())->someVariableThatsInOFApp = 100; //update ofApp var
      int myParticleInt = ((ofApp*) ofGetAppPtr())->someIntVarInOFApp; //reference ofApp var
      if(someLocalVar > 10)
        ((ofApp*) ofGetAppPtr())->somOFAppMethod(); //run ofApp function from here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment