Ejemplo n.º 1
0
//------------------------------------------------------------
void ofAppGlutWindow::runAppViaInfiniteLoop(ofBaseApp * appPtr){
	ofAppPtr = appPtr;

	ofNotifySetup();
	ofNotifyUpdate();

	glutMainLoop();
}
Ejemplo n.º 2
0
//------------------------------------------------------------
void ofxAppMacScreenSaver::runAppViaInfiniteLoop(ofBaseApp * appPtr){
	ofAppPtr = appPtr;
	
	ofNotifySetup();
	ofNotifyUpdate();
	
	//glutMainLoop();
}
Ejemplo n.º 3
0
//------------------------------------------------------------
void ofxAppNoWindow::runAppViaInfiniteLoop(ofBaseApp * appPtr){

	ofSetCurrentRenderer(ofPtr<ofBaseRenderer>(new ofNoopRenderer));

	ofAppPtr = appPtr;

	#if defined TARGET_OSX || defined TARGET_LINUX
	// for keyboard
	//set_conio_terminal_mode();
	#endif

	ofNotifySetup();

//    ofLogNotice("ofxAppNoWindow")
//		<< "***" << endl
//		<< "***" << endl
//		<< "*** running a headless (no window) app" << endl
//		<< "***" << endl
//		<< "*** keyboard input works here" << endl
//		<< "***"<< endl
//		<< "*** press Esc or Ctrl-C to quit" << endl
//		<< "***" << endl;

	while (true)
	{
        /// listen for escape
        #ifdef TARGET_WIN32
        if (GetAsyncKeyState(VK_ESCAPE))
            ofNotifyKeyPressed(OF_KEY_ESC);
        #endif

		#if defined TARGET_OSX || defined TARGET_LINUX
		while ( kbhit() )
		{
			int key = getch();
			if ( key == 27 )
			{
				ofNotifyKeyPressed(OF_KEY_ESC);
			}
			else if ( key == /* ctrl-c */ 3 )
			{
				ofLogNotice("ofxAppNoWindow") << "Ctrl-C pressed" << endl;
				OF_EXIT_APP(0);
			}
			else
			{
				ofNotifyKeyPressed(key);
			}
		}
		#endif


		ofNotifyUpdate();
		ofNotifyDraw();

	}
}
Ejemplo n.º 4
0
/* Call to render the next GL frame */
void
Java_cc_openframeworks_OFAndroid_render( JNIEnv*  env, jclass  thiz )
{
	int beginFrameMillis = ofGetElapsedTimeMillis();

	if(paused) return;
	//LOGI("update");
	ofNotifyUpdate();


	int width, height;

	width  = sWindowWidth;
	height = sWindowHeight;

	height = height > 0 ? height : 1;
	// set viewport, clear the screen
	//glViewport( 0, 0, width, height );
	ofViewport(0, 0, width, height, false);		// used to be glViewport( 0, 0, width, height );
	float * bgPtr = ofBgColorPtr();
	bool bClearAuto = ofbClearBg();

	if ( bClearAuto == true || nFrameCount < 3){
		ofClear(bgPtr[0]*255,bgPtr[1]*255,bgPtr[2]*255, bgPtr[3]*255);
	}

	if(bSetupScreen) ofSetupScreen();
	ofNotifyDraw();

	/*timeNow = ofGetElapsedTimef();
	double diff = timeNow-timeThen;
	if( diff  > 0.00001 ){
		fps			= 1.0 / diff;
		frameRate	*= 0.9f;
		frameRate	+= 0.1f*fps;
	 }
	 lastFrameTime	= diff;
	 timeThen		= timeNow;*/
	// --------------

	int currTime = ofGetElapsedTimeMillis();
	if(currTime - onesec>=1000){
		frameRate = frames;
		frames = 0;
		onesec = currTime;
	}
	frames++;
	int frameMillis = currTime - beginFrameMillis;
	lastFrameTime = double(frameMillis)/1000.;

	previousFrameMillis = currTime;

	nFrameCount++;		// increase the overall frame count*/

	if(bFrameRateSet && frameMillis<oneFrameTime) ofSleepMillis(oneFrameTime-frameMillis);

}
Ejemplo n.º 5
0
//------------------------------------------------------------
void ofAppGlutWindow::runAppViaInfiniteLoop(ofBaseApp * appPtr){
	static ofEventArgs voidEventArgs;

	ofAppPtr = appPtr;

	ofNotifySetup();
	ofNotifyUpdate();
	
	glutMainLoop();
}
Ejemplo n.º 6
0
void ofxFensterManager::runAppViaInfiniteLoop(ofBaseApp* appPtr) {

	ofNotifySetup();
	while(true) {
		ofNotifyUpdate();

		for(vector<ofxFensterPtr>::iterator it = windows.begin(); it != windows.end(); it++) {
			(*it)->display(*it == mainWindow);
		}

		glfwPollEvents();
	}
}
Ejemplo n.º 7
0
//------------------------------------------------------------
void ofAppGlutWindow::idle_cb(void) {
	static ofEventArgs voidEventArgs;

	//	thanks to jorge for the fix:
	//	http://www.openframeworks.cc/forum/viewtopic.php?t=515&highlight=frame+rate

	if (nFrameCount != 0 && bFrameRateSet == true){
		diffMillis = ofGetElapsedTimeMillis() - prevMillis;
		if (diffMillis > millisForFrame){
			; // we do nothing, we are already slower than target frame
		} else {
			int waitMillis = millisForFrame - diffMillis;
			#ifdef TARGET_WIN32
				Sleep(waitMillis);         //windows sleep in milliseconds
			#else
				usleep(waitMillis * 1000);   //mac sleep in microseconds - cooler :)
			#endif
		}
	}
	prevMillis = ofGetElapsedTimeMillis(); // you have to measure here
	
    // -------------- fps calculation:
	// theo - now moved from display to idle_cb
	// discuss here: http://github.com/openframeworks/openFrameworks/issues/labels/0062#issue/187
	// 
	//
	// theo - please don't mess with this without letting me know.
	// there was some very strange issues with doing ( timeNow-timeThen ) producing different values to: double diff = timeNow-timeThen;
	// http://www.openframeworks.cc/forum/viewtopic.php?f=7&t=1892&p=11166#p11166

	timeNow = ofGetElapsedTimef();
	double diff = timeNow-timeThen;
	if( diff  > 0.00001 ){
		fps			= 1.0 / diff;
		frameRate	*= 0.9f;
		frameRate	+= 0.1f*fps;
	 }
	 lastFrameTime	= diff;
	 timeThen		= timeNow;
  	// --------------	

	ofNotifyUpdate();

	glutPostRedisplay();
}
Ejemplo n.º 8
0
/* Call to render the next GL frame */
void
Java_cc_openframeworks_OFAndroid_render( JNIEnv*  env, jclass  thiz )
{

	if(paused || surfaceDestroyed) return;

	if(!threadedTouchEvents){
		mutex.lock();
		queue<ofTouchEventArgs> events = touchEventArgsQueue;
		while(!touchEventArgsQueue.empty()) touchEventArgsQueue.pop();
		mutex.unlock();

		while(!events.empty()){
			switch(events.front().type){
			case ofTouchEventArgs::down:
				ofNotifyMousePressed(events.front().x,events.front().y,0);
				ofNotifyEvent(ofEvents().touchDown,events.front());
				break;
			case ofTouchEventArgs::up:
				ofNotifyMouseReleased(events.front().x,events.front().y,0);
				ofNotifyEvent(ofEvents().touchUp,events.front());
				break;
			case ofTouchEventArgs::move:
				ofNotifyMouseMoved(events.front().x,events.front().y);
				ofNotifyMouseDragged(events.front().x,events.front().y,0);
				ofNotifyEvent(ofEvents().touchMoved,events.front());
				break;
			case ofTouchEventArgs::doubleTap:
				ofNotifyEvent(ofEvents().touchDoubleTap,events.front());
				break;
			case ofTouchEventArgs::cancel:
				ofNotifyEvent(ofEvents().touchCancelled,events.front());
				break;
			}
			events.pop();
		}
	}

	ofNotifyUpdate();


	if(ofGetGLProgrammableRenderer()){
		ofGetGLProgrammableRenderer()->startRender();
	}
	int width, height;

	width  = sWindowWidth;
	height = sWindowHeight;

	height = height > 0 ? height : 1;
	// set viewport, clear the screen
	//glViewport( 0, 0, width, height );
	ofViewport(0, 0, width, height, false);		// used to be glViewport( 0, 0, width, height );
	float * bgPtr = ofBgColorPtr();
	bool bClearAuto = ofbClearBg();

	if ( bClearAuto == true || ofGetFrameNum() < 3){
		ofClear(bgPtr[0]*255,bgPtr[1]*255,bgPtr[2]*255, bgPtr[3]*255);
	}

	if(bSetupScreen) ofSetupScreen();
	ofNotifyDraw();

	if(ofGetGLProgrammableRenderer()){
		ofGetGLProgrammableRenderer()->finishRender();
	}

}
Ejemplo n.º 9
0
/* Call to render the next GL frame */
void
Java_cc_openframeworks_OFAndroid_render( JNIEnv*  env, jclass  thiz )
{
	unsigned long beginFrameMicros = ofGetElapsedTimeMicros();

	if(paused) return;

	lastFrameTime = double(beginFrameMicros - previousFrameMicros)/1000000.;

	previousFrameMicros = beginFrameMicros;

	if(!threadedTouchEvents){
		mutex.lock();
		while(!touchEventArgsQueue.empty()){
			switch(touchEventArgsQueue.front().type){
			case ofTouchEventArgs::down:
				ofNotifyEvent(ofEvents().touchDown,touchEventArgsQueue.front());
				break;
			case ofTouchEventArgs::up:
				ofNotifyEvent(ofEvents().touchUp,touchEventArgsQueue.front());
				break;
			case ofTouchEventArgs::move:
				ofNotifyEvent(ofEvents().touchMoved,touchEventArgsQueue.front());
				break;
			case ofTouchEventArgs::doubleTap:
				ofNotifyEvent(ofEvents().touchDoubleTap,touchEventArgsQueue.front());
				break;
			}
			touchEventArgsQueue.pop();
		}
		mutex.unlock();
	}

	ofNotifyUpdate();


	int width, height;

	width  = sWindowWidth;
	height = sWindowHeight;

	height = height > 0 ? height : 1;
	// set viewport, clear the screen
	//glViewport( 0, 0, width, height );
	ofViewport(0, 0, width, height, false);		// used to be glViewport( 0, 0, width, height );
	float * bgPtr = ofBgColorPtr();
	bool bClearAuto = ofbClearBg();

	if ( bClearAuto == true || nFrameCount < 3){
		ofClear(bgPtr[0]*255,bgPtr[1]*255,bgPtr[2]*255, bgPtr[3]*255);
	}

	if(bSetupScreen) ofSetupScreen();
	ofNotifyDraw();

	unsigned long currTime = ofGetElapsedTimeMicros();
	unsigned long frameMicros = currTime - beginFrameMicros;

	nFrameCount++;		// increase the overall frame count*/
	frames++;

	if(currTime - onesec>=1000000){
		frameRate = frames;
		frames = 0;
		onesec = currTime;
	}

	if(bFrameRateSet && frameMicros<oneFrameTime) usleep(oneFrameTime-frameMicros);

}