/*! This function initializes CX functionality. It should probably only be called once, at program start. \param config The intial CX configuration. \return `true` if intialization was successful, `false` if there was an error. If there was an error, it should be logged. */ bool initializeCX(CX_InitConfiguation config) { if (config.clockPrecisionTestIterations < 10000) { config.clockPrecisionTestIterations = 10000; } #if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR == 9 && OF_VERSION_PATCH >= 0 ofInit(); #else //Older versions... ofSetWorkingDirectoryToDefault(); #endif ofSetEscapeQuitsApp(false); CX::Instances::Log.captureOFLogMessages(config.captureOFLogMessages); CX::Instances::Log.levelForAllModules(CX_Logger::Level::LOG_ALL); CX::Instances::Log.levelForModule(CX_Logger::Level::LOG_NOTICE, "ofShader"); //Try to eliminate some of the verbose shader gobbeldygook. CX::Private::learnOpenGLVersion(); //Should come before reopenWindow. bool openedSucessfully = CX::reopenWindow(config.windowConfig); //or for the first time. if (!openedSucessfully) { CX::Instances::Log.error("CX_EntryPoint") << "The window was not opened successfully."; } else { // Set up the clock CX::Instances::Clock.setup(nullptr, true, config.clockPrecisionTestIterations); CX::Instances::Input.pollEvents(); //Do this so that the window is at least minimally responding and doesn't get killed by the OS. //This must happen after the window is configured because it relies on GLFW. if (config.framePeriodEstimationInterval != CX_Millis(0)) { CX::Instances::Disp.estimateFramePeriod(config.framePeriodEstimationInterval); CX::Instances::Log.notice("CX_EntryPoint") << "Estimated frame period for display: " << CX::Instances::Disp.getFramePeriod().millis() << " ms."; } setupKeyboardShortcuts(); // Set up sound CX::Instances::SoundPlayer.setup(&CX::Instances::SoundStream); CX::Instances::SoundRecorder.setup(&CX::Instances::SoundStream); //This is temporary: I think there's an oF bug about it #if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR == 8 glfwSetWindowPos(CX::Private::glfwContext, 200, 200); #endif } CX::Instances::Log.verbose() << endl << endl << "### End of startup logging data ###" << endl << endl; CX::Instances::Log.flush(); //Flush logs after setup, so user can see if any errors happened during setup. CX::Instances::Log.levelForAllModules(CX_Logger::Level::LOG_NOTICE); CX::Instances::Log.levelForModule(CX_Logger::Level::LOG_WARNING, "ofFbo"); //It isn't clear that this should be here, but the fbos //are really verbose when allocated and it is a lot of gibberish. return openedSucessfully; }
//special case so we preserve supplied settngs //TODO: remove me when we remove the ofAppGLFWWindow setters. //-------------------------------------- void ofSetupOpenGL(shared_ptr<ofAppGLFWWindow> windowPtr, int w, int h, ofWindowMode screenMode){ ofInit(); auto settings = windowPtr->getSettings(); settings.width = w; settings.height = h; settings.windowMode = screenMode; ofGetMainLoop()->addWindow(windowPtr); windowPtr->setup(settings); }
//======================================================================== int main( ) { ofInit(); auto window = make_shared<ofAppNoWindow>(); auto app = make_shared<ofApp>(); // this kicks off the running of my app // can be OF_WINDOW or OF_FULLSCREEN // pass in width and height too: ofRunApp(window, app); return ofRunMainLoop(); }
bool Application::init( const int argc, char** argv, co::Object* initData ) { ofInit(); if( !seq::Application::init( argc, argv, initData )) { return false; } return true; }
shared_ptr<ofAppBaseWindow> ofCreateWindow(const ofWindowSettings & settings){ ofInit(); return ofCreateMainLoop()->createWindow(settings); }