// --------------------------------------------------------------------------------------------------------------------------------------------------- // bool ofxAutoReloadedShader::load(string vertName, string fragName, string geomName) { unload(); ofShader::setGeometryOutputCount(geometryOutputCount); ofShader::setGeometryInputType(geometryInputType); ofShader::setGeometryOutputType(geometryOutputType); // hackety hack, clear errors or shader will fail to compile GLuint err = glGetError(); lastTimeCheckMillis = ofGetElapsedTimeMillis(); setMillisBetweenFileCheck( 2 * 1000 ); enableWatchFiles(); loadShaderNextFrame = false; vertexShaderFilename = vertName; fragmentShaderFilename = fragName; geometryShaderFilename = geomName; vertexShaderFile.clear(); fragmentShaderFile.clear(); geometryShaderFile.clear(); vertexShaderFile = ofFile( ofToDataPath( vertexShaderFilename ) ); fragmentShaderFile = ofFile( ofToDataPath( fragmentShaderFilename ) ); geometryShaderFile = ofFile( ofToDataPath( geometryShaderFilename ) ); ofBuffer vertexShaderBuffer = ofBufferFromFile( ofToDataPath( vertexShaderFilename ) ); ofBuffer fragmentShaderBuffer = ofBufferFromFile( ofToDataPath( fragmentShaderFilename ) ); ofBuffer geometryShaderBuffer = ofBufferFromFile( ofToDataPath( geometryShaderFilename ) ); fileChangedTimes.clear(); fileChangedTimes.push_back( getLastModified( vertexShaderFile ) ); fileChangedTimes.push_back( getLastModified( fragmentShaderFile ) ); fileChangedTimes.push_back( getLastModified( geometryShaderFile ) ); if( vertexShaderBuffer.size() > 0 ) { setupShaderFromSource(GL_VERTEX_SHADER, vertexShaderBuffer.getText() ); } if( fragmentShaderBuffer.size() > 0 ) { setupShaderFromSource(GL_FRAGMENT_SHADER, fragmentShaderBuffer.getText()); } #ifndef TARGET_OPENGLES if( geometryShaderBuffer.size() > 0 ) { setupShaderFromSource(GL_GEOMETRY_SHADER_EXT, geometryShaderBuffer.getText()); } #endif bindDefaults(); return linkProgram(); }
bool UIShader::load(string _name){ ofFile fragFile = ofFile(_name+".frag"); ofFile vertFile = ofFile(_name+".vert"); ofFile geomFile = ofFile(_name+".geom"); if( !vertFile.exists()){ ofBuffer vert; vert.append(vertexShader); ofBufferToFile(_name+".vert", vert); } if (!fragFile.exists() ){ ofBuffer frag; frag.append(fragmentShader); ofBufferToFile(_name+".frag", frag); } if(geomFile.exists()){ return load(_name+".frag",_name+".vert",_name+".geom"); } else if (geometryShader.length() > 2){ ofBuffer geom; geom.append(geometryShader); ofBufferToFile(_name+".geom", geom); return load(_name+".frag",_name+".vert",_name+".geom"); } else { return load(_name+".frag",_name+".vert"); } }
std::string mui::Helpers::muiPath( std::string path ){ // pretty much copy&pasted from OF Poco::Path outputPath; Poco::Path inputPath(path); string strippedDataPath = mui::MuiConfig::dataPath.toString(); strippedDataPath = ofFilePath::removeTrailingSlash(strippedDataPath); if (inputPath.toString().find(strippedDataPath) != 0) { outputPath = mui::MuiConfig::dataPath; outputPath.resolve(inputPath); } else { outputPath = inputPath; } if( !ofFile(outputPath.absolute().toString(), ofFile::Reference).exists() ){ // maybe in the data dir? string dataFile = ofToDataPath(path, true); if( ofFile(dataFile,ofFile::Reference).exists() ){ outputPath = Poco::Path(dataFile); } } if( mui::MuiConfig::logLevel <= OF_LOG_NOTICE ){ cout << "loading path: " << outputPath.toString() << " || " << outputPath.absolute().toString() << " || " << path << endl; } return outputPath.absolute().toString(); }
bool UIShader::reloadShader(string _fragPath, string _vertPath, string _geomPath){ ofShader::unload(); // hackety hack, clear errors or shader will fail to compile GLuint err = glGetError(); fragFile.clear(); fragFilename = ofToDataPath( _fragPath ); fragFile = ofFile( fragFilename ); fragChangedTimes = getLastModified( fragFile ); ofBuffer fragBuffer = ofBufferFromFile( fragFilename ); if( fragBuffer.size() > 0 ){ setupShaderFromSource(GL_FRAGMENT_SHADER, fragBuffer.getText()); } if (_vertPath != ""){ vertFile.clear(); vertFilename = ofToDataPath(_vertPath); vertFile = ofFile( vertFilename ); vertChangedTimes = getLastModified( vertFile ); ofBuffer vertBuffer = ofBufferFromFile( vertFilename ); if( vertBuffer.size() > 0 ){ setupShaderFromSource(GL_VERTEX_SHADER, vertBuffer.getText()); } bVertex = true; } if (_geomPath != ""){ geomFile.clear(); geomFilename = ofToDataPath(_geomPath); geomFile = ofFile( geomFilename ); geomChangedTimes = getLastModified( geomFile ); ofBuffer geomBuffer = ofBufferFromFile( geomFilename ); if( geomBuffer.size() > 0 ){ setupShaderFromSource(GL_GEOMETRY_SHADER, geomBuffer.getText()); } setGeometryInputType(geomInType); setGeometryOutputType(geomOutType); setGeometryOutputCount(geomOutCount); bGeometry = true; } lastTimeCheckMillis = ofGetElapsedTimeMillis(); if (linkProgram()){ extractUniforms(fragBuffer.getText()); return true; } else { return false; } }
/** * @param strFilename Name of the file. * @param dwOffset File offset the bound importdirectory will be written to. * @param fMakeValid If this flag is true a valid directory will be produced. **/ int BoundImportDirectory::write(const std::string& strFilename, dword dwOffset, bool fMakeValid) const { std::fstream ofFile(strFilename.c_str(), std::ios_base::in); if (!ofFile) { ofFile.clear(); ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary); } else { ofFile.close(); ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary); } if (!ofFile) { return ERROR_OPENING_FILE; } ofFile.seekp(dwOffset, std::ios::beg); std::vector<unsigned char> vBuffer; rebuild(vBuffer, fMakeValid); ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), static_cast<std::streamsize>(vBuffer.size())); ofFile.close(); return NO_ERROR; }
//---------------------------------------------------// // read // Reads the temperature value from the specified device //---------------------------------------------------// float DS18B20::read(int deviceNumber) { if (deviceNumber < _deviceNames.size()) { // Look for the specified device data file string dataPath = _devicesDir + _deviceNames.at(deviceNumber) + "/w1_slave"; ofFile dataFile = ofFile(dataPath); if (dataFile.doesFileExist(dataPath) && dataFile.canRead()) { // If the file is found read the text ofBuffer dataBuffer = dataFile.readToBuffer(); string dataStr = dataBuffer.getText(); int pos = dataStr.find("t="); // Find the start of the temp data if (pos > 0 && (pos+7 < dataStr.size())) { // Check that the temp data was found string data = dataStr.substr(pos+2, 5); // Extract the temp data float temp = atoi(data.c_str()); temp = temp / 1000; return temp; } else { ofLogWarning() << "DS18B20: Data missing for " << deviceNumber; return -1; } } else { ofLogError() << "DS18B20: Device " << deviceNumber << " not found"; return -1; } } else { ofLogError() << "DS18B20: Device " << deviceNumber << " not found"; return -1; } return -1; }
//-------------------------------------------------------------- void testApp::setup(){ ofSetWindowTitle("Ailove-Foursquare"); ofFile csvf = ofFile("test-data.csv"); ofBuffer csvb = csvf.readToBuffer(); minTimestamp = INT_MAX*2; maxTimestamp = 0; while(!csvb.isLastLine()) { string line = csvb.getNextLine(); vector<string> items = ofSplitString(line, ","); Checkin checkin; checkin.timestamp = ofToInt (items.at(0)); checkin.lng = ofToFloat(items.at(1)); checkin.lat = ofToFloat(items.at(2)); checkins.push_back(checkin); if(minTimestamp > checkin.timestamp) minTimestamp = checkin.timestamp; if(maxTimestamp < checkin.timestamp) maxTimestamp = checkin.timestamp; } csvf.close(); sort(checkins.begin(), checkins.end(), checkin_less()); // # MOSCOW BOUNDS cityArea.x = 37.33204993; cityArea.y = 55.55701887; cityArea.width = 37.89647254 - cityArea.x; cityArea.height = 55.92578046 - cityArea.y; ofBackground(0); }
void CloudsVisualSystem3DModelLoader::loadModel( string fileName ) { // perspCam.reset(); cout << "*** LOADING MODEL " << fileName << endl; //xxx string filePath = GetCloudsMediaPath() + "assets/3DModelLoader/models_binary/" + fileName; //string filePath = getVisualSystemDataPath(true) + "models_binary/" + fileName; // string filePath = getVisualSystemDataPath(false) + fileName; //ofStringReplace(filePath,"models/", "models_binary/"); //ofStringReplace(filePath,".obj", ".obm"); if(!ofFile(filePath).exists()){ ofLogError("CloudsVisualSystem3DModelLoader::loadModel") << filePath << " Doesn't exist"; } else{ cout << "Found path " << filePath << " to exist" << endl; } ofxBinaryMesh::load(filePath, modelMesh); // ofxObjLoader::load(filePath, modelMesh, true ); // ofxObjLoader::load_oldway(filePath, modelMesh, true ); cout << "*** FULL PATH " << filePath << " FOUND " << modelMesh.getNumVertices() << " verts " << endl; calcBoundingBox(); float mScl = maxDim / max( maxBound.x - minBound.x, max(maxBound.y-minBound.y, maxBound.z - minBound.z )); modelScl.set( mScl, mScl, mScl ); updateModelTransform(); setupMultipleCameras( modelTransform.getPosition() ); }
bool CloudsRGBDVideoPlayer::loadSubtitles(string path){ if (path == "") { return false; } if (!ofFile(path).exists()) { return false; } // need to know fps (all 24 except Higa (30)) int fps = 24; if (strstr(path.data(), "Higa") != NULL) { fps = 30; } int fontSize = 36; if(!nextSubtitles.setup(path, GetCloudsDataPath() + "font/Blender-BOOK.ttf", fontSize/2, fps, TEXT_JUSTIFICATION_CENTER)) { return false; } // find font size based on 85% canvas width and a predefined maximum string float requiredWidth = (float)CloudsVisualSystem::getStaticRenderTarget().getWidth()*0.85; string maxStr = "If I'd have to choose from something interesting, something beautiful or something useful,"; ofRectangle bounds = nextSubtitles.font.getStringBoundingBox(maxStr, 0, 0); // loop here until you find the right font size while (bounds.width > requiredWidth) { nextSubtitles.font.setSize(--fontSize); bounds = nextSubtitles.font.getStringBoundingBox(maxStr, 0, 0); } // cout << "font size is " << fontSize << endl; return true; }
/** * @param strFilename Name of the file which will be written. * @param uiOffset File offset where the debug directory will be stored. **/ int DebugDirectory::write(const std::string& strFilename, unsigned int uiOffset) const { std::fstream ofFile(strFilename.c_str(), std::ios_base::in); if (!ofFile) { ofFile.clear(); ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary); } else { ofFile.close(); ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary); } if (!ofFile) { return ERROR_OPENING_FILE; } ofFile.seekp(uiOffset, std::ios::beg); std::vector<unsigned char> vBuffer; rebuild(vBuffer); ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), static_cast<unsigned int>(vBuffer.size())); ofFile.close(); return NO_ERROR; }
void baseScene::loadCode( string fileName ){ ofBuffer buffer = ofBufferFromFile(fileName); code = ""; code += "// artwork by " + originalArtist + "\n"; code += "// re-coded by " + author + "\n"; code += "\n"; for (auto line : buffer.getLines()){ code += line; code += "\n"; } // Remove trailing newlines and spaces code.erase(std::find_if(code.rbegin(), code.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), code.end()); dataPath = ofFilePath::removeTrailingSlash(ofFilePath::getEnclosingDirectory(fileName)); bAnimateScene = true; bHasEndSet = false; if (ofFile(dataPath+"/paramsRecording.xml").exists()) { float duration; loadMidi(recData, &duration, dataPath+"/paramsRecording.xml"); cout << "got " << recData.size() << " events " << duration << endl; if (duration > 0) { setSceneEnd(duration); } } }
string ofShader::parseForIncludes( const string& source, vector<string>& included, int level, const string& sourceDirectoryPath) { if ( level > 32 ) { ofLogError( "ofShader", "glsl header inclusion depth limit reached, might be caused by cyclic header inclusion" ); return ""; } stringstream output; stringstream input; input << source; Poco::RegularExpression re("^\\s*#\\s*pragma\\s+include\\s+[\"<](.*)[\">].*"); Poco::RegularExpression::MatchVec matches; string line; while( std::getline( input, line ) ) { if ( re.match( line, 0, matches ) < 2 ) { output << line << endl; continue; } string include = line.substr(matches[1].offset, matches[1].length); if ( std::find( included.begin(), included.end(), include ) != included.end() ) { ofLogVerbose("ofShader") << include << " already included"; continue; } // we store the absolute paths so as have (more) unique file identifiers. include = ofFile(sourceDirectoryPath + include).getAbsolutePath(); included.push_back( include ); ofBuffer buffer = ofBufferFromFile( include ); if ( !buffer.size() ) { ofLogError("ofShader") <<"Could not open glsl include file " << include; continue; } string currentDir = ofFile(include).getEnclosingDirectory(); output << parseForIncludes( buffer.getText(), included, level + 1, currentDir ) << endl; } return output.str(); }
void ObjectFinder::setup(string cascadeFilename) { cascadeFilename = ofToDataPath(cascadeFilename); if(ofFile(cascadeFilename).exists()) { classifier.load(cascadeFilename); } else { ofLogError("ObjectFinder::setup") << "Couldn't find " << cascadeFilename; } }
//-------------------------------------------------------------- void ofApp::setup() { ofBackground(0); // setup system system.setup(ofFile("ice.pdb").path()); mesh = system.getModel(0).atomsMesh(0.5f); }
khLuaScript::khLuaScript( string LuaFile,string MatchFcn, string DrawFcn) { luaFile = ofFile(LuaFile); matchFcn = MatchFcn; drawFcn = DrawFcn; checkAndInitOfxLua(); }
//-------------------------------------------------------------- void ofApp::dragEvent(ofDragInfo dragInfo){ for (auto& file : dragInfo.files) { if (ofFile(file).isDirectory()) { cam.setPlaybackPath(file); return; } } }
ofxSymbolItem* ofxDocument::getSymbolItem(string name) { for (vector<ofxSymbolItem>::iterator iter = symbolItems.begin();iter!=symbolItems.end();iter++) { if (name == ofFile(iter->href).getBaseName()) { return &(*iter); } } cout << "could not find ofxSymbolItem: " << name << " - expect a crash" << endl; return NULL; }
spt<xml_document> AssetsManager::LoadResourcesXml(string path) { if (ofFile(path.c_str()).exists()) { spt<xml_document> xml = spt<xml_document>(new xml_document()); xml->load_file(path.c_str()); return xml; } return spt<xml_document>(); }
ksFileLoader::ksFileLoader(){ directory.listDir(""); directory.sort(); // in linux the file system doesn't return file lists ordered in alphabetical order //allocate the vector to have as many ofImages as files if( directory.size() ){ files.assign(directory.size(), ofFile()); } }
//-------------------------------------------------------------- void testApp::setup(){ //// utils char tmpstr[2000]; ofFile f = ofFile(); ofDirectory dir = ofDirectory(); /// indexes rota = 0; nimg = 0; nsnd = 9; image_duration = 0.1; image_timer = 0; silence_timer = 0; silence_trigger = false; //// LOAD IMAGES string rep_images = "intelligentsia/images/"; dir.open(rep_images); dir.allowExt("jpg"); dir.listDir(); Nimgs = dir.numFiles(); cout << Nimgs << endl; for (int i = 0; i < Nimgs; i++){ sprintf(tmpstr, "%s_%dx%d.jpeg",dir.getPath(i).c_str(), ofGetScreenWidth(), ofGetScreenHeight()); if (f.doesFileExist(tmpstr)) images[i].loadImage(tmpstr); else { images[i].loadImage(dir.getPath(i)); pt = scaleSize(images[i].width, images[i].height, ofGetScreenWidth(), ofGetScreenHeight()); images[i].resize(pt.x,pt.y); cout << "will save" << tmpstr << endl; images[i].saveImage(tmpstr); } cout << dir.getPath(i) << endl; }; //// LOAD SOUND string rep_sounds = "intelligentsia/sons/"; dir.open(rep_sounds); dir.allowExt("wav"); dir.listDir(); Nsnds = dir.numFiles(); cout << Nsnds << endl; for (int i = 0; i < Nsnds; i++){ sounds[i].loadSound(dir.getPath(i)); cout << dir.getPath(i) << endl; }; sounds[nsnd].play(); // GRAPHICS ofHideCursor(); ofSetFrameRate(120); ofSetVerticalSync(true); }
void ofxBitmapItem::load(float u,float v) { #ifndef TARGET_OPENGLES // cout << iter->image.loadImage(iter->sourceExternalFilepath); cout << href << ": " << image.loadImage("LIBRARY/"+href) << endl; #else ofFile file = ofFile(ofToDataPath("LIBRARY/"+href)); if (file.exists()) { image.setUseTexture(false); cout << href << ": " << image.loadImage("LIBRARY/"+href) << endl; // iter->bUseBig = (iter->image.getWidth() > MAX_TEXTURE_SIZE || iter->image.getHeight() > MAX_TEXTURE_SIZE); // if (iter->bUseBig) { // iter->bigImage.loadImage(iter->image, MAX_TEXTURE_SIZE); // } else { image.setUseTexture(true); image.reloadTexture(); // image.getTextureReference().setTextureMinMagFilter(GL_NEAREST, GL_NEAREST); // roikr: this was the trick to boost the fps as alternative to linear filtering... // } } else { cout << "no image for: " << href << endl; file = ofFile(file.getEnclosingDirectory()+file.getBaseName()+".pvr"); if (file.exists()) { cout << "load pvr for: " << name << endl; texture.load(file.getAbsolutePath()); this->u = u; this->v = v; this->width = u*texture._width; this->height = v*texture._height; } else { cout << "no pvr for: " << name << " - expect problems" << endl; } } // ofFile file = ofFile(iter->sourceExternalFilepath); #endif }
//-------------------------------------------------------------- bool Particles::saveState(const string & path) { auto stateFile = ofFile(path, ofFile::WriteOnly); nlohmann::json json; { this->particleSystem.serialize(json); } stateFile << json; return true; }
//-------------------------------------------------------------- void ofApp::setupGui() { gui.setup("settings"); gui.setDefaultBackgroundColor(ofColor(0, 0, 0, 127)); gui.setDefaultFillColor(ofColor(160, 160, 160, 160)); gui.add(guiFPS.set("average FPS", 0, 0, 60)); gui.add(guiMinFPS.set("minimum FPS", 0, 0, 60)); gui.add(doFullScreen.set("fullscreen (F)", false)); doFullScreen.addListener(this, &ofApp::setFullScreen); gui.add(toggleGuiDraw.set("show gui (G)", false)); gui.add(drawMode.set("draw mode", DRAW_COMPOSITE, DRAW_COMPOSITE, DRAW_VELDOTS)); drawMode.addListener(this, &ofApp::drawModeSetName); gui.add(drawName.set("MODE", "draw name")); int guiColorSwitch = 0; ofColor guiHeaderColor[2]; guiHeaderColor[0].set(160, 160, 80, 200); guiHeaderColor[1].set(80, 160, 160, 200); ofColor guiFillColor[2]; guiFillColor[0].set(160, 160, 80, 200); guiFillColor[1].set(80, 160, 160, 200); gui.setDefaultHeaderBackgroundColor(guiHeaderColor[guiColorSwitch]); gui.setDefaultFillColor(guiFillColor[guiColorSwitch]); guiColorSwitch = 1 - guiColorSwitch; gui.add(fluidSimulation.parameters); gui.setDefaultHeaderBackgroundColor(guiHeaderColor[guiColorSwitch]); gui.setDefaultFillColor(guiFillColor[guiColorSwitch]); guiColorSwitch = 1 - guiColorSwitch; gui.add(particleFlow.parameters); gui.setDefaultHeaderBackgroundColor(guiHeaderColor[guiColorSwitch]); gui.setDefaultFillColor(guiFillColor[guiColorSwitch]); guiColorSwitch = 1 - guiColorSwitch; gui.add(tuioForce.parameters); gui.setDefaultHeaderBackgroundColor(guiHeaderColor[guiColorSwitch]); gui.setDefaultFillColor(guiFillColor[guiColorSwitch]); guiColorSwitch = 1 - guiColorSwitch; gui.add(velocityDots.parameters); // if the settings file is not present the parameters will not be set during this setup if (!ofFile("fluidSettings.xml")) { gui.saveToFile("fluidSettings.xml"); } gui.loadFromFile("fluidSettings.xml"); gui.minimizeAll(); toggleGuiDraw = true; }
bool UIShader::loadFrag(string _fragShader){ bVertex = false; ofFile fragFile = ofFile(_fragShader); if (!fragFile.exists() ){ ofBuffer frag; frag.append(fragmentShader); ofBufferToFile(_fragShader, frag); } return reloadShader( _fragShader ); }
void testApp::setFiles(vector<string> files) { updateTimes.clear(); cppFiles.clear(); for(int i = 0; i < files.size(); i++) { cppFiles.push_back(ofFile(files[i])); updateTimes.push_back(getUpdateTime(cppFiles.back())); } clean(); compile(); string dylibName = linkObjects(); loadDylib("/tmp/livecode/"+dylibName); }
//-------------------------------------------------------------- bool Particles::loadState(const string & path) { auto stateFile = ofFile(path); if (stateFile.exists()) { nlohmann::json json; stateFile >> json; this->particleSystem.deserialize(json); return true; }
void Rules::checkWatchedFile() { Poco::File file = ofFile(watchedFileName).getPocoFile(); Poco::Timestamp timestamp = file.getLastModified(); if (timestamp != watchedLastModified) { clear(); load(watchedFileName); ofNotifyEvent(fileReloaded, branches, this); watchedLastModified = timestamp; } }
void InstagramView::loadProfileImage(){ ofRegisterURLNotification(this); size_t found = _args.profilePictureUrl.find_last_of("/\\"); string profilePictureFileName = _args.profilePictureUrl.substr(found + 1); // Before loading check if we already have the file ofFile file = ofFile(profilePictureFileName); if(file.exists() && Settings::instance()->getCache()){ initProfileImage(profilePictureFileName); }else{ ofSaveURLAsync(_args.profilePictureUrl, profilePictureFileName); } }
//-------------------------------------------------------------- void ofApp::setup() { system.setup(ofFile("2WY4.pdb").path()); atoms = system.getModel(0).atomsPointCloud(); ofBackground(0); glPointSize(4.0f); // log atom info for first 10 atoms for (int i = 0; i < 10; i++) { OfxMol::Atom atom = system.getModel(0).getAtom(i); ofLogNotice() << atom.log(); } }
//-------------------------------------------------------------- void testApp::keyPressed(int key){ ofFileDialogResult result = ofSystemLoadDialog(); cout << result.getPath() << endl; ofFile csvFile = ofFile(result.getPath()); string line; while(std::getline(csvFile,line)){ frames.push_back(LegFrame(line)); } fileLoaded = true; }