#pragma once #include "ofMain.h" #include "ofxJSONElement.h" long ofToLong(const string& intString); class instagramLoader : public ofThread{ public: float interval; //time between refreshes in seconds int count; // threaded fucntions that share data need to use lock (mutex) // and unlock in order to write to that data // otherwise it's possible to get crashes. // // also no opengl specific stuff will work in a thread... // threads can't create textures, or draw stuff on the screen // since opengl is single thread safe //-------------------------- std::string url; ofxJSONElement response; std::map images; deque to_update; instagramLoader(){ count = 0; url = "https://api.instagram.com/v1/tags/tycleeson/media/recent?client_id=c1d74d701fdf4ddd9f8d30ee9e8f944b"; } void set_interval(float _interval){ interval=_interval; } void start(){ startThread(true, false); // blocking, verbose } void stop(){ stopThread(); } //-------------------------- void threadedFunction(){ cout << "Api: " << url<::iterator i=images.begin();i!=images.end();++i){ if(i->second.isUsingTexture()){ drawcount++; } } cout<<"loaded "<::iterator i=images.begin();i!=images.end();++i){ if(i->second.isUsingTexture()){ i->second.draw(ofToLong(i->first)%(long)(ofGetWidth()-i->second.getWidth()+1),ofToLong(i->first)%(long)(ofGetHeight()-i->second.getHeight()+1)); } } unlock(); } } }; class exampleApp : public ofBaseApp { public: void setup(); void update(); void draw(); instagramLoader loader; };