//------------------------------------------------------------
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();

	}
}
/* 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);

}
//------------------------------------------------------------
void ofxAppMacScreenSaver::display(void){
	
	//--------------------------------
	// when I had "glutFullScreen()"
	// in the initOpenGl, I was gettings a "heap" allocation error
	// when debugging via visual studio.  putting it here, changes that.
	// maybe it's voodoo, or I am getting rid of the problem
	// by removing something unrelated, but everything seems
	// to work if I put fullscreen on the first frame of display.
	
	///// MAREK HERE	
	// set viewport, clear the screen
	////ofViewport(0, 0, glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT));		// used to be glViewport( 0, 0, width, height );
	float * bgPtr = ofBgColorPtr();
	bool bClearAuto = ofbClearBg();
	
    // to do non auto clear on PC for now - we do something like "single" buffering --
    // it's not that pretty but it work for the most part
	

	
	if ( bClearAuto == true || nFrameCount < 3){
		ofClear(bgPtr[0]*255,bgPtr[1]*255,bgPtr[2]*255, bgPtr[3]*255);
	}
	
	if( bEnableSetupScreen )ofSetupScreen();
	
	ofNotifyDraw();
	ofAppPtr->draw();

	if (bClearAuto == false){
		// in accum mode resizing a window is BAD, so we clear on resize events.
		if (nFramesSinceWindowResized < 3){
			ofClear(bgPtr[0]*255,bgPtr[1]*255,bgPtr[2]*255, bgPtr[3]*255);
		}
	}
	
	//// MAREK HERE
	////glutSwapBuffers();

	
    nFramesSinceWindowResized++;
	
	//fps calculation moved to idle_cb as we were having fps speedups when heavy drawing was occuring
	//wasn't reflecting on the actual app fps which was in reality slower.
	//could be caused by some sort of deferred drawing?
	
	nFrameCount++;		// increase the overall frame count
	
	//setFrameNum(nFrameCount); // get this info to ofUtils for people to access
	
}
Beispiel #4
0
//------------------------------------------------------------
void ofAppGlutWindow::display(void){

	//--------------------------------
	// when I had "glutFullScreen()"
	// in the initOpenGl, I was gettings a "heap" allocation error
	// when debugging via visual studio.  putting it here, changes that.
	// maybe it's voodoo, or I am getting rid of the problem
	// by removing something unrelated, but everything seems
	// to work if I put fullscreen on the first frame of display.

	if (windowMode != OF_GAME_MODE){
		if ( bNewScreenMode ){
			if( windowMode == OF_FULLSCREEN){

				//----------------------------------------------------
				// before we go fullscreen, take a snapshot of where we are:
				nonFullScreenX = glutGet(GLUT_WINDOW_X);
				nonFullScreenY = glutGet(GLUT_WINDOW_Y);
				//----------------------------------------------------

				glutFullScreen();

				#ifdef TARGET_OSX
					SetSystemUIMode(kUIModeAllHidden,NULL);
				#endif

			}else if( windowMode == OF_WINDOW ){

				glutReshapeWindow(requestedWidth, requestedHeight);

				//----------------------------------------------------
				// if we have recorded the screen posion, put it there
				// if not, better to let the system do it (and put it where it wants)
				if (nFrameCount > 0){
					glutPositionWindow(nonFullScreenX,nonFullScreenY);
				}
				//----------------------------------------------------

				#ifdef TARGET_OSX
					SetSystemUIMode(kUIModeNormal,NULL);
				#endif
			}
			bNewScreenMode = false;
		}
	}

	// set viewport, clear the screen
	ofViewport(0, 0, glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT));		// used to be glViewport( 0, 0, width, height );
	float * bgPtr = ofBgColorPtr();
	bool bClearAuto = ofbClearBg();

    // to do non auto clear on PC for now - we do something like "single" buffering --
    // it's not that pretty but it work for the most part

    #ifdef TARGET_WIN32
    if (bClearAuto == false){
        glDrawBuffer (GL_FRONT);
    }
    #endif

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

	if( bEnableSetupScreen )ofSetupScreen();

	ofNotifyDraw();

    #ifdef TARGET_WIN32
    if (bClearAuto == false){
        // on a PC resizing a window with this method of accumulation (essentially single buffering)
        // is BAD, so we clear on resize events.
        if (nFramesSinceWindowResized < 3){
        	ofClear(bgPtr[0]*255,bgPtr[1]*255,bgPtr[2]*255, bgPtr[3]*255);
        } else {
            if (nFrameCount < 3 || nFramesSinceWindowResized < 3)    glutSwapBuffers();
            else                                                     glFlush();
        }
    } else {
        glutSwapBuffers();
    }
    #else
		if (bClearAuto == false){
			// in accum mode resizing a window is BAD, so we clear on resize events.
			if (nFramesSinceWindowResized < 3){
				ofClear(bgPtr[0]*255,bgPtr[1]*255,bgPtr[2]*255, bgPtr[3]*255);
			}
		}
        glutSwapBuffers();
    #endif

    nFramesSinceWindowResized++;

	//fps calculation moved to idle_cb as we were having fps speedups when heavy drawing was occuring
	//wasn't reflecting on the actual app fps which was in reality slower.
	//could be caused by some sort of deferred drawing?

	nFrameCount++;		// increase the overall frame count

	//setFrameNum(nFrameCount); // get this info to ofUtils for people to access

}
/* 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();
	}

}
/* 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);

}