Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge ofxiOS into ofxiPhone #921

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions addons/ofxiPhone/ofxiPhoneExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ ofAppiPhoneWindow* ofxiPhoneGetOFWindow();
// return application delegate
ofxiPhoneAppDelegate *ofxiPhoneGetAppDelegate();

// return iphone view controller.
ofxiPhoneViewController *ofxiPhoneGetViewController();

// brings the OpenGL view to the front of any other UIViews
// the OpenGL view will receive touchXXXXX events, but other UIViews will not
Expand Down Expand Up @@ -201,6 +203,7 @@ string ofxiPhoneGetDocumentsDirectory();
#define iPhoneGetGLView ofxiPhoneGetGLView
#define iPhoneGetOFWindow ofxiPhoneGetOFWindow
#define iPhoneGetAppDelegate ofxiPhoneGetAppDelegate
#define iPhoneGetViewController ofxiPhoneGetViewController
#define iPhoneSendGLViewToFront ofxiPhoneSendGLViewToFront
#define iPhoneSendGLViewToBack ofxiPhoneSendGLViewToBack
#define iPhoneSetGLViewTransparent ofxiPhoneSetGLViewTransparent
Expand Down
1 change: 1 addition & 0 deletions addons/ofxiPhone/src/ofAppiPhoneWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class ofAppiPhoneWindow : public ofAppBaseWindow{
virtual void setupOpenGL(int w, int h, int screenMode);
virtual void initializeWindow();
virtual void runAppViaInfiniteLoop(ofBaseApp * appPtr);
virtual void startAppWithDelegate( string appDelegateClassName );

virtual void hideCursor() {};
virtual void showCursor() {};
Expand Down
135 changes: 78 additions & 57 deletions addons/ofxiPhone/src/ofAppiPhoneWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
// use for checking if stuff has been initialized
#define NOT_INITIALIZED -1000000

static bool bAppCreated = false;

static ofAppiPhoneWindow *_instance = NULL;

ofAppiPhoneWindow* ofAppiPhoneWindow::getInstance() {
Expand Down Expand Up @@ -93,12 +95,31 @@
void ofAppiPhoneWindow::runAppViaInfiniteLoop(ofBaseApp * appPtr) {
ofLog(OF_LOG_VERBOSE, "ofAppiPhoneWindow::runAppViaInfiniteLoop()");

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
UIApplicationMain(nil, nil, nil, @"ofxiPhoneAppDelegate"); // this will run the infinite loop checking all events
[pool release];
if( bAppCreated ) // app already created, only reset values.
{
nFrameCount = 0;
lastFrameTime = 0;
fps = frameRate = 60.0f;
timeNow = 0.0;
timeThen = 0.0;
}
else // app not yet created, created it!
{
startAppWithDelegate( "ofxiPhoneAppDelegate" );
}
}


void ofAppiPhoneWindow::startAppWithDelegate ( string appDelegateClassName )
{
if( bAppCreated )
return;

bAppCreated = true;

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
UIApplicationMain( nil, nil, nil, ofxStringToNSString( appDelegateClassName ) );
[ pool release ];
}


/******** Set Window properties ************/
Expand Down Expand Up @@ -179,7 +200,7 @@ void setWindowShape(int w, int h) {

/******** Other stuff ************/
void ofAppiPhoneWindow::setFrameRate(float targetRate) {
[ofxiPhoneGetAppDelegate() setFrameRate:targetRate];
[ [ ofxiPhoneGetAppDelegate() glViewController ] setFrameRate : targetRate ];
}

int ofAppiPhoneWindow::getFrameNum() {
Expand Down Expand Up @@ -308,56 +329,56 @@ void setWindowShape(int w, int h) {
return retinaEnabled;
}

void ofAppiPhoneWindow::timerLoop() {
static ofEventArgs voidEventArgs;
ofGetAppPtr()->update();
#ifdef OF_USING_POCO
ofNotifyEvent( ofEvents.update, voidEventArgs);
#endif
[ofxiPhoneGetAppDelegate() lockGL];

[ofxiPhoneGetGLView() startRender];

//we do this as ofGetWidth() now accounts for rotation
//so we just make our viewport across the whole screen
glViewport( 0, 0, getScreenSize().x, getScreenSize().y );

float * bgPtr = ofBgColorPtr();
bool bClearAuto = ofbClearBg();
if ( bClearAuto == true){
glClearColor(bgPtr[0],bgPtr[1],bgPtr[2], bgPtr[3]);
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
if(bEnableSetupScreen) {
ofSetupScreen();
}
ofGetAppPtr()->draw();
#ifdef OF_USING_POCO
ofNotifyEvent( ofEvents.draw, voidEventArgs );
#endif
[ofxiPhoneGetGLView() finishRender];
[ofxiPhoneGetAppDelegate() unlockGL];

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;
// --------------
nFrameCount++; // increase the overall frame count
void ofAppiPhoneWindow::timerLoop()
{
ofBaseApp* appPtr = ofGetAppPtr();
if( !appPtr )
return;
static ofEventArgs voidEventArgs;
appPtr->update();
#ifdef OF_USING_POCO
ofNotifyEvent( ofEvents.update, voidEventArgs);
#endif
[ ofxiPhoneGetViewController() lockGL ];
[ ofxiPhoneGetGLView() startRender ];
//we do this as ofGetWidth() now accounts for rotation
//so we just make our viewport across the whole screen
glViewport( 0, 0, getScreenSize().x, getScreenSize().y );
float * bgPtr = ofBgColorPtr();
bool bClearAuto = ofbClearBg();
if ( bClearAuto == true){
glClearColor(bgPtr[0],bgPtr[1],bgPtr[2], bgPtr[3]);
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
if(bEnableSetupScreen) {
ofSetupScreen();
}
appPtr->draw();
#ifdef OF_USING_POCO
ofNotifyEvent( ofEvents.draw, voidEventArgs );
#endif
[ ofxiPhoneGetGLView() finishRender ];
[ ofxiPhoneGetViewController() unlockGL ];
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;
// --------------
nFrameCount++; // increase the overall frame count
}
26 changes: 7 additions & 19 deletions addons/ofxiPhone/src/ofxiPhoneAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,17 @@
#pragma once

#import <UIKit/UIKit.h>
#import "ofxiPhoneViewController.h"

#import "EAGLView.h"
#import "ofAppiPhoneWindow.h"
@interface ofxiPhoneAppDelegate : NSObject <UIApplicationDelegate>

@interface ofxiPhoneAppDelegate : NSObject <UIApplicationDelegate> {
NSTimer *animationTimer;
BOOL animating;
BOOL displayLinkSupported;
float animationFrameInterval;
id displayLink;

EAGLView *glView;
@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) ofxiPhoneViewController *glViewController;

NSLock *glLock;
}
-(BOOL) application : (UIApplication*) application
handleOpenURL : (NSURL*) url;

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url;
-(void) receivedRotate:(NSNotification*)notification;
-(void) setFrameRate:(float)frameRate;
-(EAGLView*) getGLView;

-(void)lockGL;
-(void)unlockGL;
-(void) receivedRotate : (NSNotification*) notification;

@end

Loading