diff --git a/addons/ofxiOS/src/core/ofxiOSGLKView.h b/addons/ofxiOS/src/core/ofxiOSGLKView.h index dd6ffc9a257..290c0ec0dff 100644 --- a/addons/ofxiOS/src/core/ofxiOSGLKView.h +++ b/addons/ofxiOS/src/core/ofxiOSGLKView.h @@ -30,13 +30,15 @@ class ofAppiOSWindow; + (ofxiOSGLKView *) getInstance; +- (id)initWithFrame:(CGRect)frame + andApp:(ofxiOSApp *)app; - (id)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup; - (void)setup; - (void)update; - (void)draw; - +- (void)setMSAA:(bool)on; - (void)updateDimensions; - (void)destroy; - (CGPoint)orientateTouchPoint:(CGPoint)touchPoint; diff --git a/addons/ofxiOS/src/core/ofxiOSGLKView.mm b/addons/ofxiOS/src/core/ofxiOSGLKView.mm index 6171eae5946..4d09645eadb 100644 --- a/addons/ofxiOS/src/core/ofxiOSGLKView.mm +++ b/addons/ofxiOS/src/core/ofxiOSGLKView.mm @@ -34,6 +34,10 @@ + (ofxiOSGLKView *) getInstance { return _instanceRef; } +- (id)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)appPtr { + return [self initWithFrame:frame andApp:appPtr sharegroup:nil]; +} + - (id)initWithFrame:(CGRect)frame andApp:(ofxiOSApp *)appPtr sharegroup:(EAGLSharegroup *)sharegroup{ window = dynamic_pointer_cast(ofGetMainLoop()->getCurrentWindow()); @@ -164,6 +168,14 @@ - (void)updateDimensions { *screenSize = glm::vec2(currentScreen.bounds.size.width * scaleFactor, currentScreen.bounds.size.height * scaleFactor); } +- (void) setMSAA:(bool)on +{ + if(on) + self.drawableMultisample = GLKViewDrawableMultisample4X; + else + self.drawableMultisample = GLKViewDrawableMultisampleNone; +} + - (void)notifyResized { // blank this. // we want to notifyResized at the end of layoutSubviews. diff --git a/addons/ofxiOS/src/core/ofxiOSGLKViewController.h b/addons/ofxiOS/src/core/ofxiOSGLKViewController.h index d01e9433325..622f82ff719 100644 --- a/addons/ofxiOS/src/core/ofxiOSGLKViewController.h +++ b/addons/ofxiOS/src/core/ofxiOSGLKViewController.h @@ -23,6 +23,7 @@ class ofxiOSApp; @property (nonatomic, retain) ofxiOSGLKView * glView; +- (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app; - (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup; - (UIInterfaceOrientation)currentInterfaceOrientation; @@ -31,6 +32,7 @@ class ofxiOSApp; animated:(BOOL)animated; - (BOOL)isReadyToRotate; - (void)setPreferredFPS:(int)fps; +- (void)setMSAA:(bool)value; - (EAGLSharegroup *)getSharegroup; @end diff --git a/addons/ofxiOS/src/core/ofxiOSGLKViewController.mm b/addons/ofxiOS/src/core/ofxiOSGLKViewController.mm index 9d8a65a849f..2925f7fb8eb 100644 --- a/addons/ofxiOS/src/core/ofxiOSGLKViewController.mm +++ b/addons/ofxiOS/src/core/ofxiOSGLKViewController.mm @@ -14,7 +14,7 @@ #import "ofxiOSExtras.h" #include "ofAppiOSWindow.h" -@interface ofxiOSGLKViewController() { +@interface ofxiOSGLKViewController() { UIInterfaceOrientation currentInterfaceOrientation; UIInterfaceOrientation pendingInterfaceOrientation; BOOL bReadyToRotate; @@ -27,6 +27,10 @@ @implementation ofxiOSGLKViewController @synthesize glView; +- (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app { + return [self initWithFrame:frame app:app sharegroup:nil]; +} + - (id)initWithFrame:(CGRect)frame app:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup{ currentInterfaceOrientation = pendingInterfaceOrientation = UIInterfaceOrientationPortrait; if((self = [super init])) { @@ -458,6 +462,12 @@ - (void)setPreferredFPS:(int)fps { } } +- (void)setMSAA:(bool)value { + if(self.glView != nil) { + [self.glView setMSAA:value]; + } +} + @end #endif diff --git a/addons/ofxiOS/src/gl/EAGLKView.h b/addons/ofxiOS/src/gl/EAGLKView.h index 7ef4663e36d..4f18592e9ca 100644 --- a/addons/ofxiOS/src/gl/EAGLKView.h +++ b/addons/ofxiOS/src/gl/EAGLKView.h @@ -12,7 +12,7 @@ #import #import "ESRenderer.h" -@protocol EAGLViewDelegate +@protocol EAGLKViewDelegate @optional - (void)glViewAnimationStarted; - (void)glViewAnimationStopped; @@ -61,6 +61,7 @@ andPreferedRenderer:(ESRendererVersion)rendererVersion #ifdef __IPHONE_9_1 - (void)touchesEstimatedPropertiesUpdated:(NSSet *)touches NS_AVAILABLE_IOS(9_1); #endif +- (void)setMSAA:(bool)on; - (void)notifyAnimationStarted; - (void)notifyAnimationStopped; - (void)notifyDraw; diff --git a/addons/ofxiOS/src/gl/EAGLKView.m b/addons/ofxiOS/src/gl/EAGLKView.m index 0fbd038b4c9..c55aeb0c456 100644 --- a/addons/ofxiOS/src/gl/EAGLKView.m +++ b/addons/ofxiOS/src/gl/EAGLKView.m @@ -149,6 +149,14 @@ - (void)updateScaleFactor { } } +- (void) setMSAA:(bool)on +{ + if(on) + self.drawableMultisample = GLKViewDrawableMultisample4X; + else + self.drawableMultisample = GLKViewDrawableMultisampleNone; +} + //------------------------------------------------------------------- notify. - (void) notifyAnimationStarted { if([self.delegate respondsToSelector:@selector(glViewAnimationStarted)]) { diff --git a/addons/ofxiOS/src/tvOS/ofxtvOSGLKViewController.mm b/addons/ofxiOS/src/tvOS/ofxtvOSGLKViewController.mm index 1bfee59c1d5..a01b95a0003 100644 --- a/addons/ofxiOS/src/tvOS/ofxtvOSGLKViewController.mm +++ b/addons/ofxiOS/src/tvOS/ofxtvOSGLKViewController.mm @@ -6,7 +6,7 @@ #include "ofxtvOSGLKViewController.h" #include "ofxiOSGLKView.h" -@interface ofxtvOSGLKViewController() { +@interface ofxtvOSGLKViewController() { UITapGestureRecognizer *tapRecognizer; } @end diff --git a/addons/ofxiOS/src/utils/ofxiOSExtras.h b/addons/ofxiOS/src/utils/ofxiOSExtras.h index d51e8c6e4c2..a52d0bbbf38 100644 --- a/addons/ofxiOS/src/utils/ofxiOSExtras.h +++ b/addons/ofxiOS/src/utils/ofxiOSExtras.h @@ -55,11 +55,14 @@ class ofAppiOSWindow; #if TARGET_OS_IOS || (TARGET_OS_IPHONE && !TARGET_OS_TV) @class ofxiOSAppDelegate; @class ofxiOSViewController; +@class ofxiOSGLKViewController; #elif TARGET_OS_TV @class ofxtvOSAppDelegate; @class ofxtvOSViewController; +@class ofxtvOSGLKViewController; #endif @class ofxiOSEAGLView; +@class ofxiOSGLKView; // this is the new way for getting device info. // we can add other parameters later. @@ -95,6 +98,8 @@ UIWindow * ofxiOSGetUIWindow(); // return openglview ofxiOSEAGLView * ofxiOSGetGLView(); +ofxiOSGLKView * ofxiOSGetGLKView(); + // return opengl parent view UIView * ofxiOSGetGLParentView(); diff --git a/addons/ofxiOS/src/utils/ofxiOSExtras.mm b/addons/ofxiOS/src/utils/ofxiOSExtras.mm index 589f0ab8bc6..12a3dda36b2 100644 --- a/addons/ofxiOS/src/utils/ofxiOSExtras.mm +++ b/addons/ofxiOS/src/utils/ofxiOSExtras.mm @@ -40,6 +40,7 @@ #include "ofxtvOSViewController.h" #endif #include "ofxiOSEAGLView.h" +#include "ofxiOSGLKView.h" #include "ofAppiOSWindow.h" #include "ofAppRunner.h" #include "ofImage.h" @@ -144,6 +145,11 @@ ofxiOSDeviceInfo ofxiOSGetDeviceInfo(){ return [ofxiOSEAGLView getInstance]; } +//-------------------------------------------------------------- +ofxiOSGLKView * ofxiOSGetGLKView() { + return [ofxiOSGLKView getInstance]; +} + //-------------------------------------------------------------- UIView * ofxiOSGetGLParentView() { return ofxiOSGetGLView().superview; diff --git a/examples/ios/GLKit/src/main.mm b/examples/ios/GLKit/src/main.mm new file mode 100644 index 00000000000..e1aaede07b1 --- /dev/null +++ b/examples/ios/GLKit/src/main.mm @@ -0,0 +1,23 @@ +#include "ofApp.h" + +int main() { + + // here are the most commonly used iOS window settings. + //------------------------------------------------------ + ofiOSWindowSettings settings; + settings.enableRetina = true; // enables retina resolution if the device supports it. + settings.enableDepth = false; // enables depth buffer for 3d drawing. + settings.enableAntiAliasing = false; // enables anti-aliasing which smooths out graphics on the screen. + settings.numOfAntiAliasingSamples = 0; // number of samples used for anti-aliasing. + settings.enableHardwareOrientation = false; // enables native view orientation. + settings.enableHardwareOrientationAnimation = false; // enables native orientation changes to be animated. + settings.glesVersion = OFXIOS_RENDERER_ES2; // type of renderer to use, ES1, ES2, ES3 + settings.windowControllerType = ofxiOSWindowControllerType::GL_KIT; // Window Controller Type + settings.colorType = ofxiOSRendererColorFormat::RGBA8888; // color format used default RGBA8888 + settings.depthType = ofxiOSRendererDepthFormat::DEPTH_NONE; // depth format (16/24) if depth enabled + settings.stencilType = ofxiOSRendererStencilFormat::STENCIL_NONE; // stencil mode + settings.windowMode = OF_FULLSCREEN; + ofCreateWindow(settings); + + return ofRunApp(new ofApp); +} diff --git a/examples/ios/GLKit/src/ofApp.h b/examples/ios/GLKit/src/ofApp.h new file mode 100644 index 00000000000..51660ad9224 --- /dev/null +++ b/examples/ios/GLKit/src/ofApp.h @@ -0,0 +1,26 @@ +#pragma once + +#include "ofxiOS.h" + +class ofApp : public ofxiOSApp { + + public: + void setup(); + void update(); + void draw(); + void exit(); + + void touchDown(ofTouchEventArgs & touch); + void touchMoved(ofTouchEventArgs & touch); + void touchUp(ofTouchEventArgs & touch); + void touchDoubleTap(ofTouchEventArgs & touch); + void touchCancelled(ofTouchEventArgs & touch); + + void lostFocus(); + void gotFocus(); + void gotMemoryWarning(); + void deviceOrientationChanged(int newOrientation); + +}; + + diff --git a/examples/ios/GLKit/src/ofApp.mm b/examples/ios/GLKit/src/ofApp.mm new file mode 100644 index 00000000000..ff28b64c216 --- /dev/null +++ b/examples/ios/GLKit/src/ofApp.mm @@ -0,0 +1,66 @@ +#include "ofApp.h" + +//-------------------------------------------------------------- +void ofApp::setup(){ + +} + +//-------------------------------------------------------------- +void ofApp::update(){ + +} + +//-------------------------------------------------------------- +void ofApp::draw(){ + +} + +//-------------------------------------------------------------- +void ofApp::exit(){ + +} + +//-------------------------------------------------------------- +void ofApp::touchDown(ofTouchEventArgs & touch){ + +} + +//-------------------------------------------------------------- +void ofApp::touchMoved(ofTouchEventArgs & touch){ + +} + +//-------------------------------------------------------------- +void ofApp::touchUp(ofTouchEventArgs & touch){ + +} + +//-------------------------------------------------------------- +void ofApp::touchDoubleTap(ofTouchEventArgs & touch){ + +} + +//-------------------------------------------------------------- +void ofApp::touchCancelled(ofTouchEventArgs & touch){ + +} + +//-------------------------------------------------------------- +void ofApp::lostFocus(){ + +} + +//-------------------------------------------------------------- +void ofApp::gotFocus(){ + +} + +//-------------------------------------------------------------- +void ofApp::gotMemoryWarning(){ + +} + +//-------------------------------------------------------------- +void ofApp::deviceOrientationChanged(int newOrientation){ + +} diff --git a/examples/ios/GLKitNativeARCExample/addons.make b/examples/ios/GLKitNativeARCExample/addons.make new file mode 100644 index 00000000000..e69de29bb2d diff --git a/examples/ios/GLKitNativeARCExample/bin/data/fonts/frabk.ttf b/examples/ios/GLKitNativeARCExample/bin/data/fonts/frabk.ttf new file mode 100644 index 00000000000..21c4ecfc553 Binary files /dev/null and b/examples/ios/GLKitNativeARCExample/bin/data/fonts/frabk.ttf differ diff --git a/examples/ios/GLKitNativeARCExample/bin/data/fonts/mono0755.ttf b/examples/ios/GLKitNativeARCExample/bin/data/fonts/mono0755.ttf new file mode 100644 index 00000000000..ffee24f3670 Binary files /dev/null and b/examples/ios/GLKitNativeARCExample/bin/data/fonts/mono0755.ttf differ diff --git a/examples/ios/GLKitNativeARCExample/bin/data/images/dive.jpg b/examples/ios/GLKitNativeARCExample/bin/data/images/dive.jpg new file mode 100644 index 00000000000..a47a3b1f277 Binary files /dev/null and b/examples/ios/GLKitNativeARCExample/bin/data/images/dive.jpg differ diff --git a/examples/ios/GLKitNativeARCExample/src/AppViewControllers/CircleAppViewController.h b/examples/ios/GLKitNativeARCExample/src/AppViewControllers/CircleAppViewController.h new file mode 100644 index 00000000000..08981eb7599 --- /dev/null +++ b/examples/ios/GLKitNativeARCExample/src/AppViewControllers/CircleAppViewController.h @@ -0,0 +1,5 @@ +#import "ofxiOSGLKViewController.h" + +@interface CircleAppViewController : ofxiOSGLKViewController + +@end diff --git a/examples/ios/GLKitNativeARCExample/src/AppViewControllers/CircleAppViewController.mm b/examples/ios/GLKitNativeARCExample/src/AppViewControllers/CircleAppViewController.mm new file mode 100644 index 00000000000..3e71e295e7c --- /dev/null +++ b/examples/ios/GLKitNativeARCExample/src/AppViewControllers/CircleAppViewController.mm @@ -0,0 +1,23 @@ +// +// CustomAppViewController.m +// Created by lukasz karluk on 8/02/12. +// + +#import "CircleAppViewController.h" +#import "ofxiOSExtras.h" +#import "ofAppiOSWindow.h" + +@implementation CircleAppViewController + +- (id) initWithFrame:(CGRect)frame app:(ofxiOSApp *)app { + + ofxiOSGetOFWindow()->setOrientation( OF_ORIENTATION_DEFAULT ); //-- default portait orientation. + + return self = [super initWithFrame:frame app:app sharegroup:nil]; +} + +- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { + return NO; +} + +@end diff --git a/examples/ios/GLKitNativeARCExample/src/AppViewControllers/ImageAppViewController.h b/examples/ios/GLKitNativeARCExample/src/AppViewControllers/ImageAppViewController.h new file mode 100644 index 00000000000..6af3583bda1 --- /dev/null +++ b/examples/ios/GLKitNativeARCExample/src/AppViewControllers/ImageAppViewController.h @@ -0,0 +1,5 @@ +#import "ofxiOSGLKViewController.h" + +@interface ImageAppViewController : ofxiOSGLKViewController + +@end diff --git a/examples/ios/GLKitNativeARCExample/src/AppViewControllers/ImageAppViewController.mm b/examples/ios/GLKitNativeARCExample/src/AppViewControllers/ImageAppViewController.mm new file mode 100644 index 00000000000..cb92b29512a --- /dev/null +++ b/examples/ios/GLKitNativeARCExample/src/AppViewControllers/ImageAppViewController.mm @@ -0,0 +1,18 @@ +#import "ImageAppViewController.h" +#import "ofxiOSExtras.h" +#import "ofAppiOSWindow.h" + +@implementation ImageAppViewController + +- (id) initWithFrame:(CGRect)frame app:(ofxiOSApp *)app { + + ofxiOSGetOFWindow()->setOrientation( OF_ORIENTATION_DEFAULT ); //-- default portait orientation. + + return self = [super initWithFrame:frame app:app sharegroup:nil]; +} + +- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { + return NO; +} + +@end diff --git a/examples/ios/GLKitNativeARCExample/src/AppViewControllers/SquareAppViewController.h b/examples/ios/GLKitNativeARCExample/src/AppViewControllers/SquareAppViewController.h new file mode 100644 index 00000000000..25ca6d2b446 --- /dev/null +++ b/examples/ios/GLKitNativeARCExample/src/AppViewControllers/SquareAppViewController.h @@ -0,0 +1,5 @@ +#import "ofxiOSGLKViewController.h" + +@interface SquareAppViewController : ofxiOSGLKViewController + +@end diff --git a/examples/ios/GLKitNativeARCExample/src/AppViewControllers/SquareAppViewController.mm b/examples/ios/GLKitNativeARCExample/src/AppViewControllers/SquareAppViewController.mm new file mode 100644 index 00000000000..9c8beebea65 --- /dev/null +++ b/examples/ios/GLKitNativeARCExample/src/AppViewControllers/SquareAppViewController.mm @@ -0,0 +1,23 @@ +// +// CustomAppViewController.m +// Created by lukasz karluk on 8/02/12. +// + +#import "SquareAppViewController.h" +#import "ofxiOSExtras.h" +#import "ofAppiOSWindow.h" + +@implementation SquareAppViewController + +- (id) initWithFrame:(CGRect)frame app:(ofxiOSApp *)app { + + ofxiOSGetOFWindow()->setOrientation( OF_ORIENTATION_DEFAULT ); //-- default portait orientation. + + return self = [super initWithFrame:frame app:app sharegroup:nil]; +} + +- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { + return NO; +} + +@end diff --git a/examples/ios/GLKitNativeARCExample/src/AppViewControllers/TriangleAppViewController.h b/examples/ios/GLKitNativeARCExample/src/AppViewControllers/TriangleAppViewController.h new file mode 100644 index 00000000000..33916f4d5a8 --- /dev/null +++ b/examples/ios/GLKitNativeARCExample/src/AppViewControllers/TriangleAppViewController.h @@ -0,0 +1,5 @@ +#import "ofxiOSGLKViewController.h" + +@interface TriangleAppViewController : ofxiOSGLKViewController + +@end diff --git a/examples/ios/GLKitNativeARCExample/src/AppViewControllers/TriangleAppViewController.mm b/examples/ios/GLKitNativeARCExample/src/AppViewControllers/TriangleAppViewController.mm new file mode 100644 index 00000000000..8c6a978783c --- /dev/null +++ b/examples/ios/GLKitNativeARCExample/src/AppViewControllers/TriangleAppViewController.mm @@ -0,0 +1,18 @@ +#import "TriangleAppViewController.h" +#import "ofxiOSExtras.h" +#import "ofAppiOSWindow.h" + +@implementation TriangleAppViewController + +- (id) initWithFrame:(CGRect)frame app:(ofxiOSApp *)app sharegroup:(EAGLSharegroup *)sharegroup{ + + ofxiOSGetOFWindow()->setOrientation( OF_ORIENTATION_DEFAULT ); //-- default portait orientation. + + return self = [super initWithFrame:frame app:app sharegroup:sharegroup]; +} + +- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { + return NO; +} + +@end diff --git a/examples/ios/GLKitNativeARCExample/src/Apps/CircleApp.h b/examples/ios/GLKitNativeARCExample/src/Apps/CircleApp.h new file mode 100644 index 00000000000..573e0349554 --- /dev/null +++ b/examples/ios/GLKitNativeARCExample/src/Apps/CircleApp.h @@ -0,0 +1,32 @@ +#pragma once + +#include "ofxiOS.h" + +class CircleApp : public ofxiOSApp { + +public: + + CircleApp (); + ~CircleApp (); + + void setup(); + void update(); + void draw(); + void exit(); + + void touchDown(ofTouchEventArgs &touch); + void touchMoved(ofTouchEventArgs &touch); + void touchUp(ofTouchEventArgs &touch); + void touchDoubleTap(ofTouchEventArgs &touch); + void touchCancelled(ofTouchEventArgs &touch); + + void lostFocus(); + void gotFocus(); + void gotMemoryWarning(); + void deviceOrientationChanged(int newOrientation); + + ofTrueTypeFont font; + +}; + + diff --git a/examples/ios/GLKitNativeARCExample/src/Apps/CircleApp.mm b/examples/ios/GLKitNativeARCExample/src/Apps/CircleApp.mm new file mode 100644 index 00000000000..7d301e05f75 --- /dev/null +++ b/examples/ios/GLKitNativeARCExample/src/Apps/CircleApp.mm @@ -0,0 +1,117 @@ +#include "CircleApp.h" + +//-------------------------------------------------------------- +CircleApp :: CircleApp () { + cout << "creating CircleApp" << endl; + //add this to listen to orientation events etc. + ofxiOSAlerts.addListener(this); +} + +//-------------------------------------------------------------- +CircleApp :: ~CircleApp () { + cout << "destroying CircleApp" << endl; + //add this to listen to orientation events etc. + ofxiOSAlerts.removeListener(this); +} + +//-------------------------------------------------------------- +void CircleApp::setup() { + ofBackground(127); + + int fontSize = 8; + if (ofxiOSGetOFWindow()-> isRetinaSupportedOnDevice()) + fontSize *= 2; + + font.load("fonts/frabk.ttf", fontSize); + +} + +//-------------------------------------------------------------- +void CircleApp::update(){ + +} + +//-------------------------------------------------------------- +void CircleApp::draw() { + int x = ofGetWidth() * 0.5; + int y = ofGetHeight() * 0.5; + int r = MIN(ofGetWidth(), ofGetHeight()) * 0.3; + int p = 0; + + ofSetColor(ofColor::red); + ofDrawCircle(x, y, r); + + x = ofGetWidth() * 0.2; + y = ofGetHeight() * 0.11; + p = ofGetHeight() * 0.035; + + ofSetColor(ofColor::white); + font.drawString("frame num = " + ofToString(ofGetFrameNum() ), x, y+=p); + font.drawString("frame rate = " + ofToString(ofGetFrameRate() ), x, y+=p); + font.drawString("screen width = " + ofToString(ofGetWidth() ), x, y+=p); + font.drawString("screen height = " + ofToString(ofGetHeight() ), x, y+=p); +} + +//-------------------------------------------------------------- +void CircleApp::exit() { + // +} + +//-------------------------------------------------------------- +void CircleApp::touchDown(ofTouchEventArgs &touch){ + int orient = ofGetOrientation(); + if(orient<4){ + orient++; + }else{ + orient = 1; + } + ofSetOrientation((ofOrientation)orient); +} + +//-------------------------------------------------------------- +void CircleApp::touchMoved(ofTouchEventArgs &touch){ + +} + +//-------------------------------------------------------------- +void CircleApp::touchUp(ofTouchEventArgs &touch){ + +} + +//-------------------------------------------------------------- +void CircleApp::touchDoubleTap(ofTouchEventArgs &touch){ + +} + +//-------------------------------------------------------------- +void CircleApp::lostFocus(){ + +} + +//-------------------------------------------------------------- +void CircleApp::gotFocus(){ + +} + +//-------------------------------------------------------------- +void CircleApp::gotMemoryWarning(){ + +} + +//-------------------------------------------------------------- +void CircleApp::deviceOrientationChanged(int newOrientation){ + if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)){ + // code for landscape orientation + cout<<"CircleApp::deviceOrientationChanged to landscape"<isRetinaSupportedOnDevice()) + fontSize *= 2; + + font.load("fonts/frabk.ttf", fontSize); + + image.load("images/dive.jpg"); +} + +//-------------------------------------------------------------- +void ImageApp::update(){ + +} + +//-------------------------------------------------------------- +void ImageApp::draw() { + int x = (ofGetWidth() - image.getWidth()) * 0.5; + int y = (ofGetHeight() - image.getHeight()) * 0.5; + int p = 0; + + ofSetColor(ofColor::white); + image.draw(x, y); + + x = ofGetWidth() * 0.2; + y = ofGetHeight() * 0.11; + p = ofGetHeight() * 0.035; + + ofSetColor(ofColor::white); + font.drawString("frame num = " + ofToString( ofGetFrameNum() ), x, y+=p); + font.drawString("frame rate = " + ofToString( ofGetFrameRate() ), x, y+=p); + font.drawString("screen width = " + ofToString( ofGetWidth() ), x, y+=p); + font.drawString("screen height = " + ofToString( ofGetHeight() ), x, y+=p); +} + +//-------------------------------------------------------------- +void ImageApp::exit() { + // +} + +//-------------------------------------------------------------- +void ImageApp::touchDown(ofTouchEventArgs &touch){ + +} + +//-------------------------------------------------------------- +void ImageApp::touchMoved(ofTouchEventArgs &touch){ + +} + +//-------------------------------------------------------------- +void ImageApp::touchUp(ofTouchEventArgs &touch){ + +} + +//-------------------------------------------------------------- +void ImageApp::touchDoubleTap(ofTouchEventArgs &touch){ + +} + +//-------------------------------------------------------------- +void ImageApp::lostFocus(){ + +} + +//-------------------------------------------------------------- +void ImageApp::gotFocus(){ + +} + +//-------------------------------------------------------------- +void ImageApp::gotMemoryWarning(){ + +} + +//-------------------------------------------------------------- +void ImageApp::deviceOrientationChanged(int newOrientation){ + +} + + +//-------------------------------------------------------------- +void ImageApp::touchCancelled(ofTouchEventArgs& args){ + +} + diff --git a/examples/ios/GLKitNativeARCExample/src/Apps/SquareApp.h b/examples/ios/GLKitNativeARCExample/src/Apps/SquareApp.h new file mode 100644 index 00000000000..e371d255c66 --- /dev/null +++ b/examples/ios/GLKitNativeARCExample/src/Apps/SquareApp.h @@ -0,0 +1,31 @@ +#pragma once + +#include "ofxiOS.h" + +class SquareApp : public ofxiOSApp { + +public: + + SquareApp (); + ~SquareApp (); + + void setup(); + void update(); + void draw(); + void exit(); + + void touchDown(ofTouchEventArgs &touch); + void touchMoved(ofTouchEventArgs &touch); + void touchUp(ofTouchEventArgs &touch); + void touchDoubleTap(ofTouchEventArgs &touch); + void touchCancelled(ofTouchEventArgs &touch); + + void lostFocus(); + void gotFocus(); + void gotMemoryWarning(); + void deviceOrientationChanged(int newOrientation); + + ofTrueTypeFont font; +}; + + diff --git a/examples/ios/GLKitNativeARCExample/src/Apps/SquareApp.mm b/examples/ios/GLKitNativeARCExample/src/Apps/SquareApp.mm new file mode 100644 index 00000000000..d71094a7294 --- /dev/null +++ b/examples/ios/GLKitNativeARCExample/src/Apps/SquareApp.mm @@ -0,0 +1,103 @@ +#include "SquareApp.h" + +//-------------------------------------------------------------- +SquareApp :: SquareApp () { + cout << "creating SquareApp" << endl; +} + +//-------------------------------------------------------------- +SquareApp :: ~SquareApp () { + cout << "destroying SquareApp" << endl; +} + +//-------------------------------------------------------------- +void SquareApp::setup() { + ofBackground(127); + + int fontSize = 8; + if (ofxiOSGetOFWindow()->isRetinaSupportedOnDevice()) + fontSize *= 2; + + font.load("fonts/frabk.ttf", fontSize); +} + +//-------------------------------------------------------------- +void SquareApp::update(){ + +} + +//-------------------------------------------------------------- +void SquareApp::draw() { + ofEnableAlphaBlending(); + + int w = MIN(ofGetWidth(), ofGetHeight()) * 0.6; + int h = w; + int x = (ofGetWidth() - w) * 0.5; + int y = (ofGetHeight() - h) * 0.5; + int p = 0; + + ofSetColor(ofColor::red); + ofDrawRectangle(x, y, w, h); + + x = ofGetWidth() * 0.2; + y = ofGetHeight() * 0.11; + p = ofGetHeight() * 0.035; + + ofSetColor(ofColor::white); + font.drawString("frame num = " + ofToString( ofGetFrameNum() ), x, y+=p); + font.drawString("frame rate = " + ofToString( ofGetFrameRate() ), x, y+=p); + font.drawString("screen width = " + ofToString( ofGetWidth() ), x, y+=p); + font.drawString("screen height = " + ofToString( ofGetHeight() ), x, y+=p); +} + +//-------------------------------------------------------------- +void SquareApp::exit() { + // +} + +//-------------------------------------------------------------- +void SquareApp::touchDown(ofTouchEventArgs &touch){ + +} + +//-------------------------------------------------------------- +void SquareApp::touchMoved(ofTouchEventArgs &touch){ + +} + +//-------------------------------------------------------------- +void SquareApp::touchUp(ofTouchEventArgs &touch){ + +} + +//-------------------------------------------------------------- +void SquareApp::touchDoubleTap(ofTouchEventArgs &touch){ + +} + +//-------------------------------------------------------------- +void SquareApp::lostFocus(){ + +} + +//-------------------------------------------------------------- +void SquareApp::gotFocus(){ + +} + +//-------------------------------------------------------------- +void SquareApp::gotMemoryWarning(){ + +} + +//-------------------------------------------------------------- +void SquareApp::deviceOrientationChanged(int newOrientation){ + +} + + +//-------------------------------------------------------------- +void SquareApp::touchCancelled(ofTouchEventArgs& args){ + +} + diff --git a/examples/ios/GLKitNativeARCExample/src/Apps/TriangleApp.h b/examples/ios/GLKitNativeARCExample/src/Apps/TriangleApp.h new file mode 100644 index 00000000000..086e416b235 --- /dev/null +++ b/examples/ios/GLKitNativeARCExample/src/Apps/TriangleApp.h @@ -0,0 +1,31 @@ +#pragma once + +#include "ofxiOS.h" + +class TriangleApp : public ofxiOSApp { + +public: + + TriangleApp (); + ~TriangleApp (); + + void setup(); + void update(); + void draw(); + void exit(); + + void touchDown(ofTouchEventArgs &touch); + void touchMoved(ofTouchEventArgs &touch); + void touchUp(ofTouchEventArgs &touch); + void touchDoubleTap(ofTouchEventArgs &touch); + void touchCancelled(ofTouchEventArgs &touch); + + void lostFocus(); + void gotFocus(); + void gotMemoryWarning(); + void deviceOrientationChanged(int newOrientation); + + ofTrueTypeFont font; +}; + + diff --git a/examples/ios/GLKitNativeARCExample/src/Apps/TriangleApp.mm b/examples/ios/GLKitNativeARCExample/src/Apps/TriangleApp.mm new file mode 100644 index 00000000000..646dc61e4f9 --- /dev/null +++ b/examples/ios/GLKitNativeARCExample/src/Apps/TriangleApp.mm @@ -0,0 +1,101 @@ +#include "TriangleApp.h" + +//-------------------------------------------------------------- +TriangleApp :: TriangleApp () { + cout << "creating TriangleApp" << endl; +} + +//-------------------------------------------------------------- +TriangleApp :: ~TriangleApp () { + cout << "destroying TriangleApp" << endl; +} + +//-------------------------------------------------------------- +void TriangleApp::setup() { + ofBackground(127); + + int fontSize = 8; + if (ofxiOSGetOFWindow()->isRetinaSupportedOnDevice()) + fontSize *= 2; + + font.load("fonts/frabk.ttf", fontSize); +} + +//-------------------------------------------------------------- +void TriangleApp::update(){ + +} + +//-------------------------------------------------------------- +void TriangleApp::draw() { + int a = MIN(ofGetWidth(), ofGetHeight()) * 0.3; + int b = sqrt( a * a + a * a ); + int x = ofGetWidth() * 0.5; + int y = ofGetHeight() * 0.5; + int p = 0; + + ofSetColor(ofColor::red); + ofDrawTriangle(x, y - a, x + b, y + b, x - b, y + b); + + x = ofGetWidth() * 0.2; + y = ofGetHeight() * 0.11; + p = ofGetHeight() * 0.035; + + ofSetColor(ofColor::white); + font.drawString("frame num = " + ofToString( ofGetFrameNum() ), x, y+=p); + font.drawString("frame rate = " + ofToString( ofGetFrameRate() ), x, y+=p); + font.drawString("screen width = " + ofToString( ofGetWidth() ), x, y+=p); + font.drawString("screen height = " + ofToString( ofGetHeight() ), x, y+=p); +} + +//-------------------------------------------------------------- +void TriangleApp::exit() { + // +} + +//-------------------------------------------------------------- +void TriangleApp::touchDown(ofTouchEventArgs &touch){ + +} + +//-------------------------------------------------------------- +void TriangleApp::touchMoved(ofTouchEventArgs &touch){ + +} + +//-------------------------------------------------------------- +void TriangleApp::touchUp(ofTouchEventArgs &touch){ + +} + +//-------------------------------------------------------------- +void TriangleApp::touchDoubleTap(ofTouchEventArgs &touch){ + +} + +//-------------------------------------------------------------- +void TriangleApp::lostFocus(){ + +} + +//-------------------------------------------------------------- +void TriangleApp::gotFocus(){ + +} + +//-------------------------------------------------------------- +void TriangleApp::gotMemoryWarning(){ + +} + +//-------------------------------------------------------------- +void TriangleApp::deviceOrientationChanged(int newOrientation){ + +} + + +//-------------------------------------------------------------- +void TriangleApp::touchCancelled(ofTouchEventArgs& args){ + +} + diff --git a/examples/ios/GLKitNativeARCExample/src/UI/MyAppDelegate.h b/examples/ios/GLKitNativeARCExample/src/UI/MyAppDelegate.h new file mode 100644 index 00000000000..be38a852dd7 --- /dev/null +++ b/examples/ios/GLKitNativeARCExample/src/UI/MyAppDelegate.h @@ -0,0 +1,14 @@ +// +// MyAppDelegate.h +// Created by lukasz karluk on 12/12/11. +// + +#import "ofxiOSAppDelegate.h" + +@interface MyAppDelegate : ofxiOSAppDelegate { + // +} + +@property (nonatomic, retain) UINavigationController* navigationController; + +@end diff --git a/examples/ios/GLKitNativeARCExample/src/UI/MyAppDelegate.mm b/examples/ios/GLKitNativeARCExample/src/UI/MyAppDelegate.mm new file mode 100644 index 00000000000..a89ddf836b1 --- /dev/null +++ b/examples/ios/GLKitNativeARCExample/src/UI/MyAppDelegate.mm @@ -0,0 +1,45 @@ +// +// MyAppDelegate.m +// Created by lukasz karluk on 12/12/11. +// + +#import "MyAppDelegate.h" +#import "MyAppViewController.h" + +@implementation MyAppDelegate + +@synthesize navigationController; + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + + [super applicationDidFinishLaunching:application]; + + /** + * + * Below is where you insert your own UIViewController and take control of the App. + * In this example im creating a UINavigationController and adding it as my RootViewController to the window. (this is essential) + * UINavigationController is handy for managing the navigation between multiple view controllers, more info here, + * http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html + * + * I then push oFAppViewController onto the UINavigationController stack. + * oFAppViewController is a custom view controller with a 3 button menu. + * + **/ + + self.navigationController = [[UINavigationController alloc] init]; + [self.window setRootViewController:self.navigationController]; + + [self.navigationController pushViewController:[[MyAppViewController alloc] init] animated:YES]; + + //--- style the UINavigationController + self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent; + self.navigationController.navigationBar.topItem.title = @"Home"; + + return YES; +} + +- (void) dealloc { + self.navigationController = nil; +} + +@end diff --git a/examples/ios/GLKitNativeARCExample/src/UI/MyAppViewController.h b/examples/ios/GLKitNativeARCExample/src/UI/MyAppViewController.h new file mode 100644 index 00000000000..df0ba656f6c --- /dev/null +++ b/examples/ios/GLKitNativeARCExample/src/UI/MyAppViewController.h @@ -0,0 +1,10 @@ +// +// MyAppViewController.h +// Created by lukasz karluk on 12/12/11. +// + +#import + +@interface MyAppViewController : UIViewController + +@end diff --git a/examples/ios/GLKitNativeARCExample/src/UI/MyAppViewController.mm b/examples/ios/GLKitNativeARCExample/src/UI/MyAppViewController.mm new file mode 100644 index 00000000000..4b348ba307e --- /dev/null +++ b/examples/ios/GLKitNativeARCExample/src/UI/MyAppViewController.mm @@ -0,0 +1,206 @@ +// +// MenuViewController.m +// Created by lukasz karluk on 12/12/11. +// Updated for iOS8+ by Andreas Borg 11/18/15 +// Updated for GLKit Dan Rosser 10/04/18 +#import "MyAppViewController.h" + +#import "SquareAppViewController.h" +#import "SquareApp.h" + +#import "CircleAppViewController.h" +#import "CircleApp.h" + +#import "TriangleAppViewController.h" +#import "TriangleApp.h" + +#import "ImageAppViewController.h" +#import "ImageApp.h" + + + +@interface MyAppViewController() +@property UIScrollView* containerView; +@end + +@implementation MyAppViewController + + + +- (UIButton*) makeButtonWithFrame:(CGRect)frame + andText:(NSString*)text { + UIFont *font; + font = [UIFont fontWithName:@"Georgia" size:30]; + + UILabel *label; + label = [[ UILabel alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)]; + label.backgroundColor = [UIColor colorWithWhite:1 alpha:0.95]; + label.textColor = [UIColor colorWithWhite:0 alpha:1]; + label.text = [text uppercaseString]; + label.textAlignment = NSTextAlignmentCenter; + label.font = font; + label.userInteractionEnabled = NO; + label.exclusiveTouch = NO; + + UIButton* button = [[UIButton alloc] initWithFrame:frame]; + [button setBackgroundColor:[UIColor clearColor]]; + [button addSubview:label]; + + return button; +} + +- (void)loadView { + [super loadView]; + + + + self.view.backgroundColor = [UIColor grayColor]; + + + CGRect screenRect = [[UIScreen mainScreen] bounds]; + + CGRect scrollViewFrame = CGRectMake(0.f, + 0.f, + screenRect.size.width, + screenRect.size.height); + + self.containerView = [[UIScrollView alloc] initWithFrame:scrollViewFrame]; + self.containerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + self.containerView.backgroundColor = [UIColor clearColor]; + self.containerView.showsHorizontalScrollIndicator = NO; + self.containerView.showsVerticalScrollIndicator = YES; + self.containerView.alwaysBounceVertical = YES; + [self.view addSubview:self.containerView]; + + NSArray *buttonTitles; + buttonTitles = [NSArray arrayWithObjects: @"square", @"circle", @"triangle", @"image", nil]; + + NSInteger buttonY = 44; // make room for navigation bar. + NSInteger buttonGap = 2; + NSInteger buttonHeight = (screenRect.size.height - 44) / [buttonTitles count] - buttonGap * ([buttonTitles count] - 1); + CGRect buttonRect = CGRectMake(0, 0, screenRect.size.width, buttonHeight); + + for (int i = 0; i < [buttonTitles count]; i++) { + UIButton *button; + button = [self makeButtonWithFrame:CGRectMake(0, buttonY, buttonRect.size.width, buttonRect.size.height) + andText:[buttonTitles objectAtIndex:i]]; + [self.containerView addSubview:button ]; + + if (i== 0) + [button addTarget:self action:@selector(button1Pressed:) forControlEvents:UIControlEventTouchUpInside]; + else if (i==1) + [button addTarget:self action:@selector(button2Pressed:) forControlEvents:UIControlEventTouchUpInside]; + else if (i==2) + [button addTarget:self action:@selector(button3Pressed:) forControlEvents:UIControlEventTouchUpInside]; + else if (i==3) + [button addTarget:self action:@selector(button4Pressed:) forControlEvents:UIControlEventTouchUpInside]; + + buttonY += buttonRect.size.height; + buttonY += buttonGap; + } + + self.containerView.contentSize = CGSizeMake(buttonRect.size.width, buttonRect.size.height * 3); +} + +- (void)button1Pressed:(id)sender { + SquareAppViewController *viewController; + viewController = [[SquareAppViewController alloc] initWithFrame:[[UIScreen mainScreen] bounds] + app:new SquareApp() sharegroup:nil]; + + [self.navigationController pushViewController:viewController animated:YES]; + self.navigationController.navigationBar.topItem.title = @"SquareApp"; +} + +- (void)button2Pressed:(id)sender { + CircleAppViewController *viewController; + viewController = [[CircleAppViewController alloc] initWithFrame:[[UIScreen mainScreen] bounds] + app:new CircleApp() sharegroup:nil]; + + [self.navigationController pushViewController:viewController animated:YES]; + self.navigationController.navigationBar.topItem.title = @"CircleApp"; +} + +- (void)button3Pressed:(id)sender { + TriangleAppViewController *viewController; + viewController = [[TriangleAppViewController alloc] initWithFrame:[[UIScreen mainScreen] bounds] + app:new TriangleApp() sharegroup:nil]; + + [self.navigationController pushViewController:viewController animated:YES]; + self.navigationController.navigationBar.topItem.title = @"TriangleApp"; +} + +- (void)button4Pressed:(id)sender { + ImageAppViewController *viewController; + viewController = [[ImageAppViewController alloc] initWithFrame:[[UIScreen mainScreen] bounds] + app:new ImageApp() sharegroup:nil]; + + [self.navigationController pushViewController:viewController animated:YES]; + self.navigationController.navigationBar.topItem.title = @"ImageApp"; +} +// iOS7- +//borg +- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { + return NO; +/* + BOOL bRotate = NO; + bRotate = bRotate || (toInterfaceOrientation == UIInterfaceOrientationPortrait); + bRotate = bRotate || (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown); + return bRotate; + */ +} + + + +// iOS8+ version of willAnimateRotationToInterfaceOrientation +//borg +- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator { + //this only reports accurately when this is actually in view. If you enter an app, + //then rotate and exit, it will not be updating correctly..hence still needs + //separate updateLayout checking active rotation + cout<<"MyAppViewController - w "<startAppWithDelegate("MyAppDelegate"); + + + +}