//--------------------------------------
void ofSetFrameRate(int targetRate){
	auto window = ofGetMainLoop()->getCurrentWindow();
	if(window){
		window->events().setFrameRate(targetRate);
	}else{
		ofLogWarning("ofEvents") << "Trying to set framerate before mainloop is ready";
	}
}
//--------------------------------------
int ofGetPreviousMouseX(){
	auto window = ofGetMainLoop()->getCurrentWindow();
	if(window){
		return window->events().getPreviousMouseX();
	}else{
		return 0;
	}
}
//--------------------------------------
bool ofGetMousePressed(int button){ //by default any button
	auto window = ofGetMainLoop()->getCurrentWindow();
	if(window){
		return window->events().getMousePressed(button);
	}else{
		return false;
	}
}
//--------------------------------------
bool ofGetKeyPressed(int key){
	auto window = ofGetMainLoop()->getCurrentWindow();
	if(window){
		return window->events().getKeyPressed(key);
	}else{
		return false;
	}
}
//--------------------------------------
double ofGetLastFrameTime(){
	auto window = ofGetMainLoop()->getCurrentWindow();
	if(window){
		return window->events().getLastFrameTime();
	}else{
		return 0.f;
	}
}
//--------------------------------------
uint64_t ofGetFrameNum(){
	auto window = ofGetMainLoop()->getCurrentWindow();
	if(window){
		return window->events().getFrameNum();
	}else{
		return 0;
	}
}
//--------------------------------------
float ofGetTargetFrameRate(){
	auto window = ofGetMainLoop()->getCurrentWindow();
	if(window){
		return window->events().getTargetFrameRate();
	}else{
		return 0.f;
	}
}
	//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);
	}
Beispiel #9
0
void Renderer::notifyWindowInitGL( eq::Window* eqWindow )
{
    _windows[ eqWindow ] =  shared_ptr<internal::Window>( new internal::Window( eqWindow ) );
    _windows[ eqWindow ]->initialiaze();

    ofGetMainLoop()->addWindow( _windows[ eqWindow ] );
    ///> TODO: Loop through windows.
    ofGetMainLoop()->setCurrentWindow( _windows[ eqWindow ] );

    if( _userRenderer ) return;

    _userRenderer = static_cast<stardust::Application&>(getApplication()).createStardustRenderer();

    if( _userRenderer )
    {
        _userRenderer->setImplementation(this);
        _userRenderer->init( _initData );
    }

}
Beispiel #10
0
	void terminateApp(const std::string & module, const std::string & reason, float secondsOnScreen){
		
		ofLogFatalError("ofxApp") << "terminateApp()!";
		ofxSimpleHttp::destroySslContext();
		ofLogFatalError("ofxApp") << "";
		ofLogFatalError("ofxApp") << "-----------------------------------------------------------------------------------------------------------";
		ofLogFatalError("ofxApp") << "";
		ofLogFatalError("ofxApp") << "ofxApp is terminating because the module \"" << module << "\" found an unrecoverable error.";
		ofLogFatalError("ofxApp") << "\"" << reason << "\"";
		ofLogFatalError("ofxApp") << "This message will be on screen for " << (int)secondsOnScreen << " seconds, then the app will quit.";
		ofLogFatalError("ofxApp") << "";
		ofLogFatalError("ofxApp") << "-----------------------------------------------------------------------------------------------------------";
		ofLogFatalError("ofxApp") << "";
		ofxThreadSafeLog::one()->close();
		if(ofxApp::get().isWindowSetup()){
			ofxSuperLog::getLogger()->setScreenLoggingEnabled(true); //show log if json error
			ofxSuperLog::getLogger()->getDisplayLogger().setPanelWidth(1.0);
			int numFrames = secondsOnScreen * 1000 / 16; //stay up a bit so that you can read logs on screen
			
			OFXAPP_REPORT("ofxAppTerminate_" + module, reason, 2);
			
			//hijack OF and refresh screen & events by hand at ~60fps
			if(ofGetWindowPtr()){
				for(int i = 0; i < numFrames; i++ ){
					ofSetupScreen();
					ofClear(0,0,0,255);
					ofxSuperLog::getLogger()->getDisplayLogger().draw(ofGetWidth(), ofGetHeight());
					ofGetMainLoop()->pollEvents();
					if(ofGetWindowPtr()->getWindowShouldClose()){
						ofLogFatalError("ofxApp") << "Quitting by user action";
						std::exit(-1);
					}
					ofGetWindowPtr()->swapBuffers();
					ofSleepMillis(16);
				}
			}
		}else{
			ofLogFatalError("ofxApp") << "Terminating ofxApp before the app window is setup.";
		}
		std::exit(0);
	};
Beispiel #11
0
void reopenWindow090(CX_WindowConfiguration config) {

	bool firstCall = (CX::Private::appWindow == nullptr);

	if (firstCall) {
		CX::Private::appWindow = shared_ptr<ofAppBaseWindow>(new CX::Private::CX_AppWindow);
	} else {
		CX::Private::appWindow->close();
	}

	std::shared_ptr<CX::Private::CX_AppWindow> awp = std::dynamic_pointer_cast<CX::Private::CX_AppWindow>(CX::Private::appWindow);

	ofGLFWWindowSettings settings;
	settings.windowMode = config.mode;
	settings.glVersionMajor = config.desiredOpenGLVersion.major;
	settings.glVersionMinor = config.desiredOpenGLVersion.minor;
	settings.numSamples = config.msaaSampleCount;
	settings.resizable = config.resizeable;
	settings.width = config.width;
	settings.height = config.height;

	awp->setup(settings);

	awp->events().enable();
	
	if (firstCall) {
		ofGetMainLoop()->addWindow(awp);
	}

	if (awp->getGLFWWindow() != nullptr) {

		setDesiredRenderer(config, true, CX::Private::appWindow.get());

		ofAddListener(ofEvents().exit, &exitCallbackHandler, ofEventOrder::OF_EVENT_ORDER_AFTER_APP);

		//ofAppGLFWWindow doesn't show the window until the first call to update()
		glfwShowWindow(glfwGetCurrentContext());
	}
}
Beispiel #12
0
int main() {
    
    int numWindows = 3;

    shared_ptr<ofApp> mainApp(new ofApp);

    vector< shared_ptr<ofAppBaseWindow> > windows;
    /*for(int i=0;i<numWindows;i++){
        
        ofGLFWWindowSettings settings;
        settings.width = 600;
        settings.height = 600;
        settings.setPosition(ofVec2f(1920*i+100,0));
        settings.resizable = true;
        if(i > 0){
            settings.shareContextWith = ofGetMainLoop()->getCurrentWindow();
        }

        shared_ptr<ofAppBaseWindow> win = ofCreateWindow(settings);
        
        win->setVerticalSync(false);
        win->setFullscreen(true);
        windows.push_back(win);
        //win.setMultiDisplayFullscreen(true); //this makes the fullscreen window span across all your monitors
        
        ofRunApp(windows[i], mainApp);

    }*/
    
    ofGLFWWindowSettings settings;
    settings.width = 600;
    settings.height = 600;
    settings.setPosition(ofVec2f(1600,0));
    settings.resizable = false;
    settings.decorated = false;
    settings.monitor = 1;
    
    shared_ptr<ofAppBaseWindow> win = ofCreateWindow(settings);
    
    win->setVerticalSync(false);
    win->setWindowTitle("Projector 1");
    windows.push_back(win);
    

    
    settings.width = 600;
    settings.height = 600;
    settings.setPosition(ofVec2f(1920,0));
    settings.resizable = false;
    settings.shareContextWith = ofGetMainLoop()->getCurrentWindow();
    
    shared_ptr<ofAppBaseWindow> win2 = ofCreateWindow(settings);
    win2->setWindowTitle("Projector 2+3");
    win2->setVerticalSync(false);
    windows.push_back(win2);

  /*
    win->setWindowPosition(1920, 0);
    win->setWindowShape(1920,  1200);
    
    win2->setWindowPosition(1920, 0);

    */
    mainApp->windows = windows;
    
    ofRunApp(windows[0], mainApp);
    ofRunApp(windows[1], mainApp);

    ofRunMainLoop();
}
Beispiel #13
0
void Renderer::processWindowEvent( eq::Window* eqWindow, const eq::Event& event )
{
    ///> forward moused/keyboard events...
    windows_iterator = _windows.find( getCurrentWindow() );
    if( windows_iterator != _windows.end() )
    {
        switch(event.type)
        {
            case eq::Event::WINDOW_POINTER_BUTTON_PRESS:
            {
                ofGetMainLoop()->setCurrentWindow(windows_iterator->second);
                const eq::PointerEvent& pressEvent = event.pointerButtonPress;
                int button = 0;
                switch( pressEvent.button )
                {
                    case eq::PTR_BUTTON1:
                    {
                        button = OF_MOUSE_BUTTON_LEFT;
                        break;
                    }
                    case eq::PTR_BUTTON2:
                    {
                        button = OF_MOUSE_BUTTON_MIDDLE;
                        break;
                    }
                    case eq::PTR_BUTTON3:
                    {
                        button = OF_MOUSE_BUTTON_RIGHT;
                        break;
                    }
                }
                windows_iterator->second->_buttonPressed = true;
                windows_iterator->second->_buttonInUse = button;
                windows_iterator->second->events().notifyMousePressed( pressEvent.x, pressEvent.y, button );
                break;
            }
            case eq::Event::WINDOW_POINTER_BUTTON_RELEASE:
            {
                ofGetMainLoop()->setCurrentWindow(windows_iterator->second);
                const eq::PointerEvent& releaseEvent = event.pointerButtonRelease;
                int button = 0;
                switch( releaseEvent.button )
                {
                    case eq::PTR_BUTTON1:
                    {
                        button = OF_MOUSE_BUTTON_LEFT;
                        break;
                    }
                    case eq::PTR_BUTTON2:
                    {
                        button = OF_MOUSE_BUTTON_MIDDLE;
                        break;
                    }
                    case eq::PTR_BUTTON3:
                    {
                        button = OF_MOUSE_BUTTON_RIGHT;
                        break;
                    }
                }
                windows_iterator->second->_buttonPressed = false;
                windows_iterator->second->_buttonInUse = button;
                windows_iterator->second->events().notifyMouseReleased( releaseEvent.x, releaseEvent.y, button );
                break;
            }
            case eq::Event::WINDOW_POINTER_MOTION:
            {
                ofGetMainLoop()->setCurrentWindow(windows_iterator->second);
                if( windows_iterator->second->_buttonPressed )
                {
                    windows_iterator->second->events().notifyMouseDragged( event.pointerMotion.x, event.pointerMotion.y, windows_iterator->second->_buttonInUse );
                }
                else
                {
                    windows_iterator->second->events().notifyMouseMoved( event.pointerMotion.x, event.pointerMotion.y );
                }
                break;
            }
            default:
            {
                break;
            }
        }
    }
}