commit f2cdca50d8be9e5ac0dede4a98ef5caef0fa5718 Author: Joshua Moerman Date: Fri May 4 11:47:56 2012 +0200 Initial Commit diff --git a/GLGameTemplate.xcodeproj/project.pbxproj b/GLGameTemplate.xcodeproj/project.pbxproj new file mode 100644 index 0000000..b5db56d --- /dev/null +++ b/GLGameTemplate.xcodeproj/project.pbxproj @@ -0,0 +1,312 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 4280A91C1553DD4C00664DC2 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4280A91B1553DD4C00664DC2 /* UIKit.framework */; }; + 4280A91E1553DD4C00664DC2 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4280A91D1553DD4C00664DC2 /* Foundation.framework */; }; + 4280A9201553DD4C00664DC2 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4280A91F1553DD4C00664DC2 /* CoreGraphics.framework */; }; + 4280A9221553DD4C00664DC2 /* GLKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4280A9211553DD4C00664DC2 /* GLKit.framework */; }; + 4280A9241553DD4C00664DC2 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4280A9231553DD4C00664DC2 /* OpenGLES.framework */; }; + 4280A92A1553DD4C00664DC2 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 4280A9281553DD4C00664DC2 /* InfoPlist.strings */; }; + 4280A92C1553DD4C00664DC2 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 4280A92B1553DD4C00664DC2 /* main.m */; }; + 4280A9301553DD4C00664DC2 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4280A92F1553DD4C00664DC2 /* AppDelegate.m */; }; + 4280A9321553DD4C00664DC2 /* Shader.fsh in Resources */ = {isa = PBXBuildFile; fileRef = 4280A9311553DD4C00664DC2 /* Shader.fsh */; }; + 4280A9341553DD4C00664DC2 /* Shader.vsh in Resources */ = {isa = PBXBuildFile; fileRef = 4280A9331553DD4C00664DC2 /* Shader.vsh */; }; + 4280A9371553DD4C00664DC2 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4280A9361553DD4C00664DC2 /* ViewController.m */; }; + 4280A93A1553DD4C00664DC2 /* ViewController_iPhone.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4280A9381553DD4C00664DC2 /* ViewController_iPhone.xib */; }; + 4280A93D1553DD4C00664DC2 /* ViewController_iPad.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4280A93B1553DD4C00664DC2 /* ViewController_iPad.xib */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 4280A9171553DD4C00664DC2 /* GLGameTemplate.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GLGameTemplate.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 4280A91B1553DD4C00664DC2 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; + 4280A91D1553DD4C00664DC2 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; + 4280A91F1553DD4C00664DC2 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; + 4280A9211553DD4C00664DC2 /* GLKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GLKit.framework; path = System/Library/Frameworks/GLKit.framework; sourceTree = SDKROOT; }; + 4280A9231553DD4C00664DC2 /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; }; + 4280A9271553DD4C00664DC2 /* GLGameTemplate-Info.plist */ = {isa = PBXFileReference; path = "GLGameTemplate-Info.plist"; sourceTree = ""; }; + 4280A9291553DD4C00664DC2 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; + 4280A92B1553DD4C00664DC2 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 4280A92D1553DD4C00664DC2 /* GLGameTemplate-Prefix.pch */ = {isa = PBXFileReference; path = "GLGameTemplate-Prefix.pch"; sourceTree = ""; }; + 4280A92E1553DD4C00664DC2 /* AppDelegate.h */ = {isa = PBXFileReference; path = AppDelegate.h; sourceTree = ""; }; + 4280A92F1553DD4C00664DC2 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 4280A9311553DD4C00664DC2 /* Shader.fsh */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.glsl; name = Shader.fsh; path = Shaders/Shader.fsh; sourceTree = ""; }; + 4280A9331553DD4C00664DC2 /* Shader.vsh */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.glsl; name = Shader.vsh; path = Shaders/Shader.vsh; sourceTree = ""; }; + 4280A9351553DD4C00664DC2 /* ViewController.h */ = {isa = PBXFileReference; path = ViewController.h; sourceTree = ""; }; + 4280A9361553DD4C00664DC2 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; + 4280A9391553DD4C00664DC2 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/ViewController_iPhone.xib; sourceTree = ""; }; + 4280A93C1553DD4C00664DC2 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/ViewController_iPad.xib; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 4280A9141553DD4C00664DC2 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 4280A91C1553DD4C00664DC2 /* UIKit.framework in Frameworks */, + 4280A91E1553DD4C00664DC2 /* Foundation.framework in Frameworks */, + 4280A9201553DD4C00664DC2 /* CoreGraphics.framework in Frameworks */, + 4280A9221553DD4C00664DC2 /* GLKit.framework in Frameworks */, + 4280A9241553DD4C00664DC2 /* OpenGLES.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 4280A90C1553DD4C00664DC2 = { + isa = PBXGroup; + children = ( + 4280A9251553DD4C00664DC2 /* GLGameTemplate */, + 4280A91A1553DD4C00664DC2 /* Frameworks */, + 4280A9181553DD4C00664DC2 /* Products */, + ); + sourceTree = ""; + }; + 4280A9181553DD4C00664DC2 /* Products */ = { + isa = PBXGroup; + children = ( + 4280A9171553DD4C00664DC2 /* GLGameTemplate.app */, + ); + name = Products; + sourceTree = ""; + }; + 4280A91A1553DD4C00664DC2 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 4280A91B1553DD4C00664DC2 /* UIKit.framework */, + 4280A91D1553DD4C00664DC2 /* Foundation.framework */, + 4280A91F1553DD4C00664DC2 /* CoreGraphics.framework */, + 4280A9211553DD4C00664DC2 /* GLKit.framework */, + 4280A9231553DD4C00664DC2 /* OpenGLES.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; + 4280A9251553DD4C00664DC2 /* GLGameTemplate */ = { + isa = PBXGroup; + children = ( + 4280A92E1553DD4C00664DC2 /* AppDelegate.h */, + 4280A92F1553DD4C00664DC2 /* AppDelegate.m */, + 4280A9311553DD4C00664DC2 /* Shader.fsh */, + 4280A9331553DD4C00664DC2 /* Shader.vsh */, + 4280A9351553DD4C00664DC2 /* ViewController.h */, + 4280A9361553DD4C00664DC2 /* ViewController.m */, + 4280A9381553DD4C00664DC2 /* ViewController_iPhone.xib */, + 4280A93B1553DD4C00664DC2 /* ViewController_iPad.xib */, + 4280A9261553DD4C00664DC2 /* Supporting Files */, + ); + path = GLGameTemplate; + sourceTree = ""; + }; + 4280A9261553DD4C00664DC2 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 4280A9271553DD4C00664DC2 /* GLGameTemplate-Info.plist */, + 4280A9281553DD4C00664DC2 /* InfoPlist.strings */, + 4280A92B1553DD4C00664DC2 /* main.m */, + 4280A92D1553DD4C00664DC2 /* GLGameTemplate-Prefix.pch */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 4280A9161553DD4C00664DC2 /* GLGameTemplate */ = { + isa = PBXNativeTarget; + buildConfigurationList = 4280A9401553DD4C00664DC2 /* Build configuration list for PBXNativeTarget "GLGameTemplate" */; + buildPhases = ( + 4280A9131553DD4C00664DC2 /* Sources */, + 4280A9141553DD4C00664DC2 /* Frameworks */, + 4280A9151553DD4C00664DC2 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = GLGameTemplate; + productName = GLGameTemplate; + productReference = 4280A9171553DD4C00664DC2 /* GLGameTemplate.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 4280A90E1553DD4C00664DC2 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0430; + ORGANIZATIONNAME = Vadovas; + }; + buildConfigurationList = 4280A9111553DD4C00664DC2 /* Build configuration list for PBXProject "GLGameTemplate" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 4280A90C1553DD4C00664DC2; + productRefGroup = 4280A9181553DD4C00664DC2 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 4280A9161553DD4C00664DC2 /* GLGameTemplate */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 4280A9151553DD4C00664DC2 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 4280A92A1553DD4C00664DC2 /* InfoPlist.strings in Resources */, + 4280A9321553DD4C00664DC2 /* Shader.fsh in Resources */, + 4280A9341553DD4C00664DC2 /* Shader.vsh in Resources */, + 4280A93A1553DD4C00664DC2 /* ViewController_iPhone.xib in Resources */, + 4280A93D1553DD4C00664DC2 /* ViewController_iPad.xib in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 4280A9131553DD4C00664DC2 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 4280A92C1553DD4C00664DC2 /* main.m in Sources */, + 4280A9301553DD4C00664DC2 /* AppDelegate.m in Sources */, + 4280A9371553DD4C00664DC2 /* ViewController.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 4280A9281553DD4C00664DC2 /* InfoPlist.strings */ = { + isa = PBXVariantGroup; + children = ( + 4280A9291553DD4C00664DC2 /* en */, + ); + name = InfoPlist.strings; + sourceTree = ""; + }; + 4280A9381553DD4C00664DC2 /* ViewController_iPhone.xib */ = { + isa = PBXVariantGroup; + children = ( + 4280A9391553DD4C00664DC2 /* en */, + ); + name = ViewController_iPhone.xib; + sourceTree = ""; + }; + 4280A93B1553DD4C00664DC2 /* ViewController_iPad.xib */ = { + isa = PBXVariantGroup; + children = ( + 4280A93C1553DD4C00664DC2 /* en */, + ); + name = ViewController_iPad.xib; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 4280A93E1553DD4C00664DC2 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ARCHS = "$(ARCHS_STANDARD_32_BIT)"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 5.1; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 4280A93F1553DD4C00664DC2 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ARCHS = "$(ARCHS_STANDARD_32_BIT)"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 5.1; + OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 4280A9411553DD4C00664DC2 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "GLGameTemplate/GLGameTemplate-Prefix.pch"; + "GCC_THUMB_SUPPORT[arch=armv6]" = ""; + INFOPLIST_FILE = "GLGameTemplate/GLGameTemplate-Info.plist"; + PRODUCT_NAME = "$(TARGET_NAME)"; + WRAPPER_EXTENSION = app; + }; + name = Debug; + }; + 4280A9421553DD4C00664DC2 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "GLGameTemplate/GLGameTemplate-Prefix.pch"; + "GCC_THUMB_SUPPORT[arch=armv6]" = ""; + INFOPLIST_FILE = "GLGameTemplate/GLGameTemplate-Info.plist"; + PRODUCT_NAME = "$(TARGET_NAME)"; + WRAPPER_EXTENSION = app; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 4280A9111553DD4C00664DC2 /* Build configuration list for PBXProject "GLGameTemplate" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 4280A93E1553DD4C00664DC2 /* Debug */, + 4280A93F1553DD4C00664DC2 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 4280A9401553DD4C00664DC2 /* Build configuration list for PBXNativeTarget "GLGameTemplate" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 4280A9411553DD4C00664DC2 /* Debug */, + 4280A9421553DD4C00664DC2 /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; +/* End XCConfigurationList section */ + }; + rootObject = 4280A90E1553DD4C00664DC2 /* Project object */; +} diff --git a/GLGameTemplate/AppDelegate.h b/GLGameTemplate/AppDelegate.h new file mode 100644 index 0000000..2803fef --- /dev/null +++ b/GLGameTemplate/AppDelegate.h @@ -0,0 +1,19 @@ +// +// AppDelegate.h +// GLGameTemplate +// +// Created by Joshua Moerman on 5/4/12. +// Copyright (c) 2012 Vadovas. All rights reserved. +// + +#import + +@class ViewController; + +@interface AppDelegate : UIResponder + +@property (strong, nonatomic) UIWindow *window; + +@property (strong, nonatomic) ViewController *viewController; + +@end diff --git a/GLGameTemplate/AppDelegate.m b/GLGameTemplate/AppDelegate.m new file mode 100644 index 0000000..9cf88be --- /dev/null +++ b/GLGameTemplate/AppDelegate.m @@ -0,0 +1,66 @@ +// +// AppDelegate.m +// GLGameTemplate +// +// Created by Joshua Moerman on 5/4/12. +// Copyright (c) 2012 Vadovas. All rights reserved. +// + +#import "AppDelegate.h" + +#import "ViewController.h" + +@implementation AppDelegate + +@synthesize window = _window; +@synthesize viewController = _viewController; + +- (void)dealloc +{ + [_window release]; + [_viewController release]; + [super dealloc]; +} + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions +{ + self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; + // Override point for customization after application launch. + if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { + self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil] autorelease]; + } else { + self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil] autorelease]; + } + self.window.rootViewController = self.viewController; + [self.window makeKeyAndVisible]; + return YES; +} + +- (void)applicationWillResignActive:(UIApplication *)application +{ + // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. +} + +- (void)applicationDidEnterBackground:(UIApplication *)application +{ + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. +} + +- (void)applicationWillEnterForeground:(UIApplication *)application +{ + // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. +} + +- (void)applicationDidBecomeActive:(UIApplication *)application +{ + // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. +} + +- (void)applicationWillTerminate:(UIApplication *)application +{ + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. +} + +@end diff --git a/GLGameTemplate/GLGameTemplate-Info.plist b/GLGameTemplate/GLGameTemplate-Info.plist new file mode 100644 index 0000000..a64dc7a --- /dev/null +++ b/GLGameTemplate/GLGameTemplate-Info.plist @@ -0,0 +1,47 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleDisplayName + ${PRODUCT_NAME} + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + Vadovas.${PRODUCT_NAME:rfc1034identifier} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + LSRequiresIPhoneOS + + UIRequiredDeviceCapabilities + + armv7 + + UIStatusBarHidden + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/GLGameTemplate/GLGameTemplate-Prefix.pch b/GLGameTemplate/GLGameTemplate-Prefix.pch new file mode 100644 index 0000000..e8d5ce9 --- /dev/null +++ b/GLGameTemplate/GLGameTemplate-Prefix.pch @@ -0,0 +1,14 @@ +// +// Prefix header for all source files of the 'GLGameTemplate' target in the 'GLGameTemplate' project +// + +#import + +#ifndef __IPHONE_5_0 +#warning "This project uses features only available in iOS SDK 5.0 and later." +#endif + +#ifdef __OBJC__ + #import + #import +#endif diff --git a/GLGameTemplate/Shaders/Shader.fsh b/GLGameTemplate/Shaders/Shader.fsh new file mode 100644 index 0000000..48d5e43 --- /dev/null +++ b/GLGameTemplate/Shaders/Shader.fsh @@ -0,0 +1,14 @@ +// +// Shader.fsh +// GLGameTemplate +// +// Created by Joshua Moerman on 5/4/12. +// Copyright (c) 2012 Vadovas. All rights reserved. +// + +varying lowp vec4 colorVarying; + +void main() +{ + gl_FragColor = colorVarying; +} diff --git a/GLGameTemplate/Shaders/Shader.vsh b/GLGameTemplate/Shaders/Shader.vsh new file mode 100644 index 0000000..aede603 --- /dev/null +++ b/GLGameTemplate/Shaders/Shader.vsh @@ -0,0 +1,28 @@ +// +// Shader.vsh +// GLGameTemplate +// +// Created by Joshua Moerman on 5/4/12. +// Copyright (c) 2012 Vadovas. All rights reserved. +// + +attribute vec4 position; +attribute vec3 normal; + +varying lowp vec4 colorVarying; + +uniform mat4 modelViewProjectionMatrix; +uniform mat3 normalMatrix; + +void main() +{ + vec3 eyeNormal = normalize(normalMatrix * normal); + vec3 lightPosition = vec3(0.0, 0.0, 1.0); + vec4 diffuseColor = vec4(0.4, 0.4, 1.0, 1.0); + + float nDotVP = max(0.0, dot(eyeNormal, normalize(lightPosition))); + + colorVarying = diffuseColor * nDotVP; + + gl_Position = modelViewProjectionMatrix * position; +} diff --git a/GLGameTemplate/ViewController.h b/GLGameTemplate/ViewController.h new file mode 100644 index 0000000..ce609ef --- /dev/null +++ b/GLGameTemplate/ViewController.h @@ -0,0 +1,14 @@ +// +// ViewController.h +// GLGameTemplate +// +// Created by Joshua Moerman on 5/4/12. +// Copyright (c) 2012 Vadovas. All rights reserved. +// + +#import +#import + +@interface ViewController : GLKViewController + +@end diff --git a/GLGameTemplate/ViewController.m b/GLGameTemplate/ViewController.m new file mode 100644 index 0000000..b55795e --- /dev/null +++ b/GLGameTemplate/ViewController.m @@ -0,0 +1,401 @@ +// +// ViewController.m +// GLGameTemplate +// +// Created by Joshua Moerman on 5/4/12. +// Copyright (c) 2012 Vadovas. All rights reserved. +// + +#import "ViewController.h" + +#define BUFFER_OFFSET(i) ((char *)NULL + (i)) + +// Uniform index. +enum +{ + UNIFORM_MODELVIEWPROJECTION_MATRIX, + UNIFORM_NORMAL_MATRIX, + NUM_UNIFORMS +}; +GLint uniforms[NUM_UNIFORMS]; + +// Attribute index. +enum +{ + ATTRIB_VERTEX, + ATTRIB_NORMAL, + NUM_ATTRIBUTES +}; + +GLfloat gCubeVertexData[216] = +{ + // Data layout for each line below is: + // positionX, positionY, positionZ, normalX, normalY, normalZ, + 0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f, + 0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f, + 0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f, + 0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f, + 0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f, + 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f, + + 0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, + -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, + 0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, + 0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, + -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, + -0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, + + -0.5f, 0.5f, -0.5f, -1.0f, 0.0f, 0.0f, + -0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f, + -0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f, + -0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f, + -0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f, + -0.5f, -0.5f, 0.5f, -1.0f, 0.0f, 0.0f, + + -0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f, + 0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f, + -0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f, + -0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f, + 0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f, + 0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f, + + 0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, + -0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, + 0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, + 0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, + -0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, + -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, + + 0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, + -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, + 0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, + 0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, + -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, + -0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f +}; + +@interface ViewController () { + GLuint _program; + + GLKMatrix4 _modelViewProjectionMatrix; + GLKMatrix3 _normalMatrix; + float _rotation; + + GLuint _vertexArray; + GLuint _vertexBuffer; +} +@property (strong, nonatomic) EAGLContext *context; +@property (strong, nonatomic) GLKBaseEffect *effect; + +- (void)setupGL; +- (void)tearDownGL; + +- (BOOL)loadShaders; +- (BOOL)compileShader:(GLuint *)shader type:(GLenum)type file:(NSString *)file; +- (BOOL)linkProgram:(GLuint)prog; +- (BOOL)validateProgram:(GLuint)prog; +@end + +@implementation ViewController + +@synthesize context = _context; +@synthesize effect = _effect; + +- (void)dealloc +{ + [_context release]; + [_effect release]; + [super dealloc]; +} + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + self.context = [[[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2] autorelease]; + + if (!self.context) { + NSLog(@"Failed to create ES context"); + } + + GLKView *view = (GLKView *)self.view; + view.context = self.context; + view.drawableDepthFormat = GLKViewDrawableDepthFormat24; + + [self setupGL]; +} + +- (void)viewDidUnload +{ + [super viewDidUnload]; + + [self tearDownGL]; + + if ([EAGLContext currentContext] == self.context) { + [EAGLContext setCurrentContext:nil]; + } + self.context = nil; +} + +- (void)didReceiveMemoryWarning +{ + [super didReceiveMemoryWarning]; + // Release any cached data, images, etc. that aren't in use. +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation +{ + if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { + return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); + } else { + return YES; + } +} + +- (void)setupGL +{ + [EAGLContext setCurrentContext:self.context]; + + [self loadShaders]; + + self.effect = [[[GLKBaseEffect alloc] init] autorelease]; + self.effect.light0.enabled = GL_TRUE; + self.effect.light0.diffuseColor = GLKVector4Make(1.0f, 0.4f, 0.4f, 1.0f); + + glEnable(GL_DEPTH_TEST); + + glGenVertexArraysOES(1, &_vertexArray); + glBindVertexArrayOES(_vertexArray); + + glGenBuffers(1, &_vertexBuffer); + glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer); + glBufferData(GL_ARRAY_BUFFER, sizeof(gCubeVertexData), gCubeVertexData, GL_STATIC_DRAW); + + glEnableVertexAttribArray(GLKVertexAttribPosition); + glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(0)); + glEnableVertexAttribArray(GLKVertexAttribNormal); + glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(12)); + + glBindVertexArrayOES(0); +} + +- (void)tearDownGL +{ + [EAGLContext setCurrentContext:self.context]; + + glDeleteBuffers(1, &_vertexBuffer); + glDeleteVertexArraysOES(1, &_vertexArray); + + self.effect = nil; + + if (_program) { + glDeleteProgram(_program); + _program = 0; + } +} + +#pragma mark - GLKView and GLKViewController delegate methods + +- (void)update +{ + float aspect = fabsf(self.view.bounds.size.width / self.view.bounds.size.height); + GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(65.0f), aspect, 0.1f, 100.0f); + + self.effect.transform.projectionMatrix = projectionMatrix; + + GLKMatrix4 baseModelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, -4.0f); + baseModelViewMatrix = GLKMatrix4Rotate(baseModelViewMatrix, _rotation, 0.0f, 1.0f, 0.0f); + + // Compute the model view matrix for the object rendered with GLKit + GLKMatrix4 modelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, -1.5f); + modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, _rotation, 1.0f, 1.0f, 1.0f); + modelViewMatrix = GLKMatrix4Multiply(baseModelViewMatrix, modelViewMatrix); + + self.effect.transform.modelviewMatrix = modelViewMatrix; + + // Compute the model view matrix for the object rendered with ES2 + modelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, 1.5f); + modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, _rotation, 1.0f, 1.0f, 1.0f); + modelViewMatrix = GLKMatrix4Multiply(baseModelViewMatrix, modelViewMatrix); + + _normalMatrix = GLKMatrix3InvertAndTranspose(GLKMatrix4GetMatrix3(modelViewMatrix), NULL); + + _modelViewProjectionMatrix = GLKMatrix4Multiply(projectionMatrix, modelViewMatrix); + + _rotation += self.timeSinceLastUpdate * 0.5f; +} + +- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect +{ + glClearColor(0.65f, 0.65f, 0.65f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glBindVertexArrayOES(_vertexArray); + + // Render the object with GLKit + [self.effect prepareToDraw]; + + glDrawArrays(GL_TRIANGLES, 0, 36); + + // Render the object again with ES2 + glUseProgram(_program); + + glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEWPROJECTION_MATRIX], 1, 0, _modelViewProjectionMatrix.m); + glUniformMatrix3fv(uniforms[UNIFORM_NORMAL_MATRIX], 1, 0, _normalMatrix.m); + + glDrawArrays(GL_TRIANGLES, 0, 36); +} + +#pragma mark - OpenGL ES 2 shader compilation + +- (BOOL)loadShaders +{ + GLuint vertShader, fragShader; + NSString *vertShaderPathname, *fragShaderPathname; + + // Create shader program. + _program = glCreateProgram(); + + // Create and compile vertex shader. + vertShaderPathname = [[NSBundle mainBundle] pathForResource:@"Shader" ofType:@"vsh"]; + if (![self compileShader:&vertShader type:GL_VERTEX_SHADER file:vertShaderPathname]) { + NSLog(@"Failed to compile vertex shader"); + return NO; + } + + // Create and compile fragment shader. + fragShaderPathname = [[NSBundle mainBundle] pathForResource:@"Shader" ofType:@"fsh"]; + if (![self compileShader:&fragShader type:GL_FRAGMENT_SHADER file:fragShaderPathname]) { + NSLog(@"Failed to compile fragment shader"); + return NO; + } + + // Attach vertex shader to program. + glAttachShader(_program, vertShader); + + // Attach fragment shader to program. + glAttachShader(_program, fragShader); + + // Bind attribute locations. + // This needs to be done prior to linking. + glBindAttribLocation(_program, ATTRIB_VERTEX, "position"); + glBindAttribLocation(_program, ATTRIB_NORMAL, "normal"); + + // Link program. + if (![self linkProgram:_program]) { + NSLog(@"Failed to link program: %d", _program); + + if (vertShader) { + glDeleteShader(vertShader); + vertShader = 0; + } + if (fragShader) { + glDeleteShader(fragShader); + fragShader = 0; + } + if (_program) { + glDeleteProgram(_program); + _program = 0; + } + + return NO; + } + + // Get uniform locations. + uniforms[UNIFORM_MODELVIEWPROJECTION_MATRIX] = glGetUniformLocation(_program, "modelViewProjectionMatrix"); + uniforms[UNIFORM_NORMAL_MATRIX] = glGetUniformLocation(_program, "normalMatrix"); + + // Release vertex and fragment shaders. + if (vertShader) { + glDetachShader(_program, vertShader); + glDeleteShader(vertShader); + } + if (fragShader) { + glDetachShader(_program, fragShader); + glDeleteShader(fragShader); + } + + return YES; +} + +- (BOOL)compileShader:(GLuint *)shader type:(GLenum)type file:(NSString *)file +{ + GLint status; + const GLchar *source; + + source = (GLchar *)[[NSString stringWithContentsOfFile:file encoding:NSUTF8StringEncoding error:nil] UTF8String]; + if (!source) { + NSLog(@"Failed to load vertex shader"); + return NO; + } + + *shader = glCreateShader(type); + glShaderSource(*shader, 1, &source, NULL); + glCompileShader(*shader); + +#if defined(DEBUG) + GLint logLength; + glGetShaderiv(*shader, GL_INFO_LOG_LENGTH, &logLength); + if (logLength > 0) { + GLchar *log = (GLchar *)malloc(logLength); + glGetShaderInfoLog(*shader, logLength, &logLength, log); + NSLog(@"Shader compile log:\n%s", log); + free(log); + } +#endif + + glGetShaderiv(*shader, GL_COMPILE_STATUS, &status); + if (status == 0) { + glDeleteShader(*shader); + return NO; + } + + return YES; +} + +- (BOOL)linkProgram:(GLuint)prog +{ + GLint status; + glLinkProgram(prog); + +#if defined(DEBUG) + GLint logLength; + glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &logLength); + if (logLength > 0) { + GLchar *log = (GLchar *)malloc(logLength); + glGetProgramInfoLog(prog, logLength, &logLength, log); + NSLog(@"Program link log:\n%s", log); + free(log); + } +#endif + + glGetProgramiv(prog, GL_LINK_STATUS, &status); + if (status == 0) { + return NO; + } + + return YES; +} + +- (BOOL)validateProgram:(GLuint)prog +{ + GLint logLength, status; + + glValidateProgram(prog); + glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &logLength); + if (logLength > 0) { + GLchar *log = (GLchar *)malloc(logLength); + glGetProgramInfoLog(prog, logLength, &logLength, log); + NSLog(@"Program validate log:\n%s", log); + free(log); + } + + glGetProgramiv(prog, GL_VALIDATE_STATUS, &status); + if (status == 0) { + return NO; + } + + return YES; +} + +@end diff --git a/GLGameTemplate/en.lproj/InfoPlist.strings b/GLGameTemplate/en.lproj/InfoPlist.strings new file mode 100644 index 0000000..477b28f --- /dev/null +++ b/GLGameTemplate/en.lproj/InfoPlist.strings @@ -0,0 +1,2 @@ +/* Localized versions of Info.plist keys */ + diff --git a/GLGameTemplate/en.lproj/ViewController_iPad.xib b/GLGameTemplate/en.lproj/ViewController_iPad.xib new file mode 100644 index 0000000..d276cc8 --- /dev/null +++ b/GLGameTemplate/en.lproj/ViewController_iPad.xib @@ -0,0 +1,110 @@ + + + + 1280 + 11C25 + 1919 + 1138.11 + 566.00 + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + 916 + + + IBProxyObject + IBUIView + + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + PluginDependencyRecalculationVersion + + + + + IBFilesOwner + IBIPadFramework + + + IBFirstResponder + IBIPadFramework + + + + 274 + {{0, 20}, {768, 1004}} + + + + 3 + MQA + + 2 + + + + 2 + + IBIPadFramework + + + + + + + view + + + + 3 + + + + + + 0 + + + + + + 1 + + + + + -1 + + + File's Owner + + + -2 + + + + + + + ViewController + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + UIResponder + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + GLKView + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + + + + 3 + + + 0 + IBIPadFramework + YES + 3 + 916 + + diff --git a/GLGameTemplate/en.lproj/ViewController_iPhone.xib b/GLGameTemplate/en.lproj/ViewController_iPhone.xib new file mode 100644 index 0000000..7fcd2b4 --- /dev/null +++ b/GLGameTemplate/en.lproj/ViewController_iPhone.xib @@ -0,0 +1,108 @@ + + + + 1280 + 11C25 + 1919 + 1138.11 + 566.00 + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + 916 + + + IBProxyObject + IBUIView + + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + PluginDependencyRecalculationVersion + + + + + IBFilesOwner + IBCocoaTouchFramework + + + IBFirstResponder + IBCocoaTouchFramework + + + + 274 + {320, 460} + + + + 3 + MQA + + 2 + + + NO + IBCocoaTouchFramework + + + + + + + view + + + + 3 + + + + + + 0 + + + + + + -1 + + + File's Owner + + + -2 + + + + + 2 + + + + + + + ViewController + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + UIResponder + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + GLKView + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + + + + 4 + + + 0 + IBCocoaTouchFramework + YES + 3 + 916 + + diff --git a/GLGameTemplate/main.m b/GLGameTemplate/main.m new file mode 100644 index 0000000..243c730 --- /dev/null +++ b/GLGameTemplate/main.m @@ -0,0 +1,18 @@ +// +// main.m +// GLGameTemplate +// +// Created by Joshua Moerman on 5/4/12. +// Copyright (c) 2012 Vadovas. All rights reserved. +// + +#import + +#import "AppDelegate.h" + +int main(int argc, char *argv[]) +{ + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } +}