Skip to content

Instantly share code, notes, and snippets.

@jmsaavedra
Last active August 26, 2017 18:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jmsaavedra/7964315 to your computer and use it in GitHub Desktop.
Save jmsaavedra/7964315 to your computer and use it in GitHub Desktop.
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