├── .gitignore ├── Base.lproj ├── MainWindow.xib └── PaintingViewController.xib ├── Classes ├── AppController.h ├── AppController.m ├── AppController.swift ├── OOPUtils │ └── NumTypes+Conversion.swift ├── PaintingView.h ├── PaintingView.m ├── PaintingView.swift ├── PaintingViewController.h ├── PaintingViewController.m ├── PaintingViewController.swift ├── SoundEffect.h ├── SoundEffect.m ├── SoundEffect.swift └── UtilSrc │ ├── debug.h │ ├── debug.swift │ ├── fileUtil.h │ ├── fileUtil.m │ ├── fileUtil.swift │ ├── shaderUtil.c │ ├── shaderUtil.h │ └── shaderUtil.swift ├── Erase.caf ├── GLPaint-Info.plist ├── GLPaint.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── dev.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── dev.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── GLPaint.xcscheme │ └── xcschememanagement.plist ├── Images ├── Blue.png ├── Green.png ├── Icon-72.png ├── Icon-Small-50.png ├── Icon-Small.png ├── Icon-Small@2x.png ├── Icon.png ├── Icon@2x.png ├── Purple.png ├── Red.png ├── Yellow.png └── iTunesArtwork ├── LaunchScreen.storyboard ├── Particle.png ├── Prefix.pch ├── README.md ├── ReadMe.txt ├── Recording.data ├── Select.caf ├── Shaders ├── point.fsh └── point.vsh └── main.m /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | -------------------------------------------------------------------------------- /Base.lproj/MainWindow.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Base.lproj/PaintingViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Classes/AppController.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: AppController.h 3 | Abstract: The UIApplication delegate class. 4 | Version: 1.13 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | @interface AppController : NSObject 49 | 50 | @property (nonatomic, strong) UIWindow *window; 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /Classes/AppController.m: -------------------------------------------------------------------------------- 1 | /* 2 | File: AppController.m 3 | Abstract: The UIApplication delegate class. 4 | Version: 1.13 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import "AppController.h" 49 | #import "PaintingViewController.h" 50 | 51 | @implementation AppController 52 | 53 | - (void)applicationDidFinishLaunching:(UIApplication*)application 54 | { 55 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 56 | 57 | PaintingViewController *controller = [[PaintingViewController alloc] initWithNibName:@"PaintingViewController" bundle:nil]; 58 | self.window.rootViewController = controller; 59 | [self.window makeKeyAndVisible]; 60 | } 61 | 62 | @end 63 | -------------------------------------------------------------------------------- /Classes/AppController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppController.swift 3 | // GLPaint 4 | // 5 | // Translated by OOPer in cooperation with shlab.jp, on 2015/1/5. 6 | // 7 | // 8 | /* 9 | File: AppController.h 10 | File: AppController.m 11 | Abstract: The UIApplication delegate class. 12 | Version: 1.13 13 | 14 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 15 | Inc. ("Apple") in consideration of your agreement to the following 16 | terms, and your use, installation, modification or redistribution of 17 | this Apple software constitutes acceptance of these terms. If you do 18 | not agree with these terms, please do not use, install, modify or 19 | redistribute this Apple software. 20 | 21 | In consideration of your agreement to abide by the following terms, and 22 | subject to these terms, Apple grants you a personal, non-exclusive 23 | license, under Apple's copyrights in this original Apple software (the 24 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 25 | Software, with or without modifications, in source and/or binary forms; 26 | provided that if you redistribute the Apple Software in its entirety and 27 | without modifications, you must retain this notice and the following 28 | text and disclaimers in all such redistributions of the Apple Software. 29 | Neither the name, trademarks, service marks or logos of Apple Inc. may 30 | be used to endorse or promote products derived from the Apple Software 31 | without specific prior written permission from Apple. Except as 32 | expressly stated in this notice, no other rights or licenses, express or 33 | implied, are granted by Apple herein, including but not limited to any 34 | patent rights that may be infringed by your derivative works or by other 35 | works in which the Apple Software may be incorporated. 36 | 37 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 38 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 39 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 40 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 41 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 42 | 43 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 44 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 45 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 46 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 47 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 48 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 49 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 50 | POSSIBILITY OF SUCH DAMAGE. 51 | 52 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 53 | 54 | */ 55 | import UIKit 56 | 57 | @UIApplicationMain 58 | @objc(AppController) 59 | class AppController: NSObject, UIApplicationDelegate { 60 | 61 | var window: UIWindow? 62 | 63 | func applicationDidFinishLaunching(_ application: UIApplication) { 64 | self.window = UIWindow(frame: UIScreen.main.bounds) 65 | 66 | let controller = PaintingViewController(nibName: "PaintingViewController", bundle: nil) 67 | self.window!.rootViewController = controller 68 | self.window!.makeKeyAndVisible() 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /Classes/OOPUtils/NumTypes+Conversion.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NumTypes+Conversion.swift 3 | // OOPUtils 4 | // 5 | // Created by OOPer in cooperation with shlab.jp, on 2014/12/31. 6 | // 7 | // 8 | /* 9 | Copyright (c) 2015, OOPer(NAGATA, Atsuyuki) 10 | All rights reserved. 11 | 12 | Use of any parts(functions, classes or any other program language components) 13 | of this file is permitted with no restrictions, unless you 14 | redistribute or use this file in its entirety without modification. 15 | In this case, providing any sort of warranties or not is the user's responsibility. 16 | 17 | Redistribution and use in source and/or binary forms, without 18 | modification, are permitted provided that the following conditions are met: 19 | 20 | 1. Redistributions of source code must retain the above copyright notice, 21 | this list of conditions and the following disclaimer. 22 | 2. Redistributions in binary form must reproduce the above copyright notice, 23 | this list of conditions and the following disclaimer in the documentation 24 | and/or other materials provided with the distribution. 25 | 26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 27 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 28 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 30 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 31 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 32 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 33 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 35 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | */ 37 | 38 | import UIKit 39 | 40 | //GLboolean, Boolean 41 | extension UInt8: ExpressibleByBooleanLiteral { 42 | public var boolValue: Bool { 43 | return self != 0 44 | } 45 | public init(booleanLiteral value: BooleanLiteralType) { 46 | self = value ? UInt8(1) : UInt8(0) 47 | } 48 | } 49 | //GLint 50 | extension Int32: ExpressibleByBooleanLiteral { 51 | public init(booleanLiteral value: BooleanLiteralType) { 52 | self = value ? Int32(1) : Int32(0) 53 | } 54 | } 55 | 56 | //long 57 | extension Int { 58 | public var g: CGFloat { 59 | return CGFloat(self) 60 | } 61 | public var d: Double { 62 | return Double(self) 63 | } 64 | public var f: Float { 65 | return Float(self) 66 | } 67 | public var b: Int8 { 68 | return Int8(self) 69 | } 70 | public var ub: UInt8 { 71 | return UInt8(self) 72 | } 73 | public var s: Int16 { 74 | return Int16(self) 75 | } 76 | public var us: UInt16 { 77 | return UInt16(self) 78 | } 79 | public var i: Int32 { 80 | return Int32(self) 81 | } 82 | public var ui: UInt32 { 83 | return UInt32(self) 84 | } 85 | // public var l: Int { 86 | // return Int(self) 87 | // } 88 | public var ul: UInt { 89 | return UInt(self) 90 | } 91 | public var ll: Int64 { 92 | return Int64(self) 93 | } 94 | public var ull: UInt64 { 95 | return UInt64(self) 96 | } 97 | } 98 | 99 | //unsigned long, size_t 100 | extension UInt { 101 | public var g: CGFloat { 102 | return CGFloat(self) 103 | } 104 | public var d: Double { 105 | return Double(self) 106 | } 107 | public var f: Float { 108 | return Float(self) 109 | } 110 | public var b: Int8 { 111 | return Int8(self) 112 | } 113 | public var ub: UInt8 { 114 | return UInt8(self) 115 | } 116 | public var s: Int16 { 117 | return Int16(self) 118 | } 119 | public var us: UInt16 { 120 | return UInt16(self) 121 | } 122 | public var i: Int32 { 123 | return Int32(self) 124 | } 125 | public var ui: UInt32 { 126 | return UInt32(self) 127 | } 128 | public var l: Int { 129 | return Int(self) 130 | } 131 | // public var ul: UInt { 132 | // return UInt(self) 133 | // } 134 | public var ll: Int64 { 135 | return Int64(self) 136 | } 137 | public var ull: UInt64 { 138 | return UInt64(self) 139 | } 140 | } 141 | 142 | //GLint, cl_int 143 | extension Int32 { 144 | public var g: CGFloat { 145 | return CGFloat(self) 146 | } 147 | public var d: Double { 148 | return Double(self) 149 | } 150 | public var f: Float { 151 | return Float(self) 152 | } 153 | public var b: Int8 { 154 | return Int8(self) 155 | } 156 | public var ub: UInt8 { 157 | return UInt8(self) 158 | } 159 | public var s: Int16 { 160 | return Int16(self) 161 | } 162 | public var us: UInt16 { 163 | return UInt16(self) 164 | } 165 | // public var i: Int32 { 166 | // return Int32(self) 167 | // } 168 | public var ui: UInt32 { 169 | return UInt32(self) 170 | } 171 | public var l: Int { 172 | return Int(self) 173 | } 174 | public var ul: UInt { 175 | return UInt(self) 176 | } 177 | public var ll: Int64 { 178 | return Int64(self) 179 | } 180 | public var ull: UInt64 { 181 | return UInt64(self) 182 | } 183 | } 184 | 185 | //GLuint, GLenum, GLsizei 186 | extension UInt32 { 187 | public var g: CGFloat { 188 | return CGFloat(self) 189 | } 190 | public var d: Double { 191 | return Double(self) 192 | } 193 | public var f: Float { 194 | return Float(self) 195 | } 196 | public var b: Int8 { 197 | return Int8(self) 198 | } 199 | public var ub: UInt8 { 200 | return UInt8(self) 201 | } 202 | public var s: Int16 { 203 | return Int16(self) 204 | } 205 | public var us: UInt16 { 206 | return UInt16(self) 207 | } 208 | public var i: Int32 { 209 | return Int32(self) 210 | } 211 | // public var ui: UInt32 { 212 | // return UInt32(self) 213 | // } 214 | public var l: Int { 215 | return Int(self) 216 | } 217 | public var ul: UInt { 218 | return UInt(self) 219 | } 220 | public var ll: Int64 { 221 | return Int64(self) 222 | } 223 | public var ull: UInt64 { 224 | return UInt64(self) 225 | } 226 | } 227 | 228 | //Darwin clock_types.h 229 | extension UInt64 { 230 | public var g: CGFloat { 231 | return CGFloat(self) 232 | } 233 | public var d: Double { 234 | return Double(self) 235 | } 236 | public var f: Float { 237 | return Float(self) 238 | } 239 | public var b: Int8 { 240 | return Int8(self) 241 | } 242 | public var ub: UInt8 { 243 | return UInt8(self) 244 | } 245 | public var s: Int16 { 246 | return Int16(self) 247 | } 248 | public var us: UInt16 { 249 | return UInt16(self) 250 | } 251 | public var i: Int32 { 252 | return Int32(self) 253 | } 254 | public var ui: UInt32 { 255 | return UInt32(self) 256 | } 257 | public var l: Int { 258 | return Int(self) 259 | } 260 | public var ul: UInt { 261 | return UInt(self) 262 | } 263 | public var ll: Int64 { 264 | return Int64(self) 265 | } 266 | // public var ull: UInt64 { 267 | // return UInt64(self) 268 | // } 269 | } 270 | 271 | //GLfloat, cl_float 272 | extension Float { 273 | public var g: CGFloat { 274 | return CGFloat(self) 275 | } 276 | public var d: Double { 277 | return Double(self) 278 | } 279 | } 280 | 281 | extension Double { 282 | public var g: CGFloat { 283 | return CGFloat(self) 284 | } 285 | public var f: Float { 286 | return Float(self) 287 | } 288 | } 289 | 290 | extension CGFloat { 291 | public var d: Double { 292 | return Double(self) 293 | } 294 | public var f: Float { 295 | return Float(self) 296 | } 297 | } 298 | 299 | //Int8 300 | extension CChar { 301 | public init(_ v: UnicodeScalar) { 302 | self = CChar(v.value) 303 | } 304 | } 305 | 306 | //UInt16 307 | extension unichar { 308 | public init(_ v: UnicodeScalar) { 309 | self = unichar(v.value) 310 | } 311 | } 312 | -------------------------------------------------------------------------------- /Classes/PaintingView.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: PaintingView.h 3 | Abstract: The class responsible for the finger painting. The class wraps the 4 | CAEAGLLayer from CoreAnimation into a convenient UIView subclass. The view 5 | content is basically an EAGL surface you render your OpenGL scene into. 6 | Version: 1.13 7 | 8 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 9 | Inc. ("Apple") in consideration of your agreement to the following 10 | terms, and your use, installation, modification or redistribution of 11 | this Apple software constitutes acceptance of these terms. If you do 12 | not agree with these terms, please do not use, install, modify or 13 | redistribute this Apple software. 14 | 15 | In consideration of your agreement to abide by the following terms, and 16 | subject to these terms, Apple grants you a personal, non-exclusive 17 | license, under Apple's copyrights in this original Apple software (the 18 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 19 | Software, with or without modifications, in source and/or binary forms; 20 | provided that if you redistribute the Apple Software in its entirety and 21 | without modifications, you must retain this notice and the following 22 | text and disclaimers in all such redistributions of the Apple Software. 23 | Neither the name, trademarks, service marks or logos of Apple Inc. may 24 | be used to endorse or promote products derived from the Apple Software 25 | without specific prior written permission from Apple. Except as 26 | expressly stated in this notice, no other rights or licenses, express or 27 | implied, are granted by Apple herein, including but not limited to any 28 | patent rights that may be infringed by your derivative works or by other 29 | works in which the Apple Software may be incorporated. 30 | 31 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 32 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 33 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 34 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 35 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 36 | 37 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 38 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 39 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 40 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 41 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 42 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 43 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 44 | POSSIBILITY OF SUCH DAMAGE. 45 | 46 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 47 | 48 | */ 49 | 50 | #import 51 | #import 52 | #import 53 | #import 54 | 55 | //CLASS INTERFACES: 56 | 57 | @interface PaintingView : UIView 58 | 59 | @property(nonatomic, readwrite) CGPoint location; 60 | @property(nonatomic, readwrite) CGPoint previousLocation; 61 | 62 | - (void)erase; 63 | - (void)setBrushColorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue; 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /Classes/PaintingView.m: -------------------------------------------------------------------------------- 1 | /* 2 | File: PaintingView.m 3 | Abstract: The class responsible for the finger painting. The class wraps the 4 | CAEAGLLayer from CoreAnimation into a convenient UIView subclass. The view 5 | content is basically an EAGL surface you render your OpenGL scene into. 6 | Version: 1.13 7 | 8 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 9 | Inc. ("Apple") in consideration of your agreement to the following 10 | terms, and your use, installation, modification or redistribution of 11 | this Apple software constitutes acceptance of these terms. If you do 12 | not agree with these terms, please do not use, install, modify or 13 | redistribute this Apple software. 14 | 15 | In consideration of your agreement to abide by the following terms, and 16 | subject to these terms, Apple grants you a personal, non-exclusive 17 | license, under Apple's copyrights in this original Apple software (the 18 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 19 | Software, with or without modifications, in source and/or binary forms; 20 | provided that if you redistribute the Apple Software in its entirety and 21 | without modifications, you must retain this notice and the following 22 | text and disclaimers in all such redistributions of the Apple Software. 23 | Neither the name, trademarks, service marks or logos of Apple Inc. may 24 | be used to endorse or promote products derived from the Apple Software 25 | without specific prior written permission from Apple. Except as 26 | expressly stated in this notice, no other rights or licenses, express or 27 | implied, are granted by Apple herein, including but not limited to any 28 | patent rights that may be infringed by your derivative works or by other 29 | works in which the Apple Software may be incorporated. 30 | 31 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 32 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 33 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 34 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 35 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 36 | 37 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 38 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 39 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 40 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 41 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 42 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 43 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 44 | POSSIBILITY OF SUCH DAMAGE. 45 | 46 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 47 | 48 | */ 49 | 50 | #import 51 | #import 52 | #import 53 | 54 | #import "PaintingView.h" 55 | #import "shaderUtil.h" 56 | #import "fileUtil.h" 57 | #import "debug.h" 58 | 59 | //CONSTANTS: 60 | 61 | #define kBrushOpacity (1.0 / 3.0) 62 | #define kBrushPixelStep 3 63 | #define kBrushScale 2 64 | 65 | 66 | // Shaders 67 | enum { 68 | PROGRAM_POINT, 69 | NUM_PROGRAMS 70 | }; 71 | 72 | enum { 73 | UNIFORM_MVP, 74 | UNIFORM_POINT_SIZE, 75 | UNIFORM_VERTEX_COLOR, 76 | UNIFORM_TEXTURE, 77 | NUM_UNIFORMS 78 | }; 79 | 80 | enum { 81 | ATTRIB_VERTEX, 82 | NUM_ATTRIBS 83 | }; 84 | 85 | typedef struct { 86 | char *vert, *frag; 87 | GLint uniform[NUM_UNIFORMS]; 88 | GLuint id; 89 | } programInfo_t; 90 | 91 | programInfo_t program[NUM_PROGRAMS] = { 92 | { "point.vsh", "point.fsh" }, // PROGRAM_POINT 93 | }; 94 | 95 | 96 | // Texture 97 | typedef struct { 98 | GLuint id; 99 | GLsizei width, height; 100 | } textureInfo_t; 101 | 102 | 103 | @interface PaintingView() 104 | { 105 | // The pixel dimensions of the backbuffer 106 | GLint backingWidth; 107 | GLint backingHeight; 108 | 109 | EAGLContext *context; 110 | 111 | // OpenGL names for the renderbuffer and framebuffers used to render to this view 112 | GLuint viewRenderbuffer, viewFramebuffer; 113 | 114 | // OpenGL name for the depth buffer that is attached to viewFramebuffer, if it exists (0 if it does not exist) 115 | GLuint depthRenderbuffer; 116 | 117 | textureInfo_t brushTexture; // brush texture 118 | GLfloat brushColor[4]; // brush color 119 | 120 | Boolean firstTouch; 121 | Boolean needsErase; 122 | 123 | // Shader objects 124 | GLuint vertexShader; 125 | GLuint fragmentShader; 126 | GLuint shaderProgram; 127 | 128 | // Buffer Objects 129 | GLuint vboId; 130 | 131 | BOOL initialized; 132 | } 133 | 134 | @end 135 | 136 | @implementation PaintingView 137 | 138 | @synthesize location; 139 | @synthesize previousLocation; 140 | 141 | // Implement this to override the default layer class (which is [CALayer class]). 142 | // We do this so that our view will be backed by a layer that is capable of OpenGL ES rendering. 143 | + (Class)layerClass 144 | { 145 | return [CAEAGLLayer class]; 146 | } 147 | 148 | // The GL view is stored in the nib file. When it's unarchived it's sent -initWithCoder: 149 | - (id)initWithCoder:(NSCoder*)coder { 150 | 151 | if ((self = [super initWithCoder:coder])) { 152 | CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer; 153 | 154 | eaglLayer.opaque = YES; 155 | // In this application, we want to retain the EAGLDrawable contents after a call to presentRenderbuffer. 156 | eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys: 157 | [NSNumber numberWithBool:YES], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil]; 158 | 159 | context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; 160 | 161 | if (!context || ![EAGLContext setCurrentContext:context]) { 162 | return nil; 163 | } 164 | 165 | // Set the view's scale factor as you wish 166 | self.contentScaleFactor = [[UIScreen mainScreen] scale]; 167 | 168 | // Make sure to start with a cleared buffer 169 | needsErase = YES; 170 | } 171 | 172 | return self; 173 | } 174 | 175 | // If our view is resized, we'll be asked to layout subviews. 176 | // This is the perfect opportunity to also update the framebuffer so that it is 177 | // the same size as our display area. 178 | -(void)layoutSubviews 179 | { 180 | [EAGLContext setCurrentContext:context]; 181 | 182 | if (!initialized) { 183 | initialized = [self initGL]; 184 | } 185 | else { 186 | [self resizeFromLayer:(CAEAGLLayer*)self.layer]; 187 | } 188 | 189 | // Clear the framebuffer the first time it is allocated 190 | if (needsErase) { 191 | [self erase]; 192 | needsErase = NO; 193 | } 194 | } 195 | 196 | - (void)setupShaders 197 | { 198 | for (int i = 0; i < NUM_PROGRAMS; i++) 199 | { 200 | char *vsrc = readFile(pathForResource(program[i].vert)); 201 | char *fsrc = readFile(pathForResource(program[i].frag)); 202 | GLsizei attribCt = 0; 203 | GLchar *attribUsed[NUM_ATTRIBS]; 204 | GLint attrib[NUM_ATTRIBS]; 205 | GLchar *attribName[NUM_ATTRIBS] = { 206 | "inVertex", 207 | }; 208 | const GLchar *uniformName[NUM_UNIFORMS] = { 209 | "MVP", "pointSize", "vertexColor", "texture", 210 | }; 211 | 212 | // auto-assign known attribs 213 | for (int j = 0; j < NUM_ATTRIBS; j++) 214 | { 215 | if (strstr(vsrc, attribName[j])) 216 | { 217 | attrib[attribCt] = j; 218 | attribUsed[attribCt++] = attribName[j]; 219 | } 220 | } 221 | 222 | glueCreateProgram(vsrc, fsrc, 223 | attribCt, (const GLchar **)&attribUsed[0], attrib, 224 | NUM_UNIFORMS, &uniformName[0], program[i].uniform, 225 | &program[i].id); 226 | free(vsrc); 227 | free(fsrc); 228 | 229 | // Set constant/initalize uniforms 230 | if (i == PROGRAM_POINT) 231 | { 232 | glUseProgram(program[PROGRAM_POINT].id); 233 | 234 | // the brush texture will be bound to texture unit 0 235 | glUniform1i(program[PROGRAM_POINT].uniform[UNIFORM_TEXTURE], 0); 236 | 237 | // viewing matrices 238 | GLKMatrix4 projectionMatrix = GLKMatrix4MakeOrtho(0, backingWidth, 0, backingHeight, -1, 1); 239 | GLKMatrix4 modelViewMatrix = GLKMatrix4Identity; // this sample uses a constant identity modelView matrix 240 | GLKMatrix4 MVPMatrix = GLKMatrix4Multiply(projectionMatrix, modelViewMatrix); 241 | 242 | glUniformMatrix4fv(program[PROGRAM_POINT].uniform[UNIFORM_MVP], 1, GL_FALSE, MVPMatrix.m); 243 | 244 | // point size 245 | glUniform1f(program[PROGRAM_POINT].uniform[UNIFORM_POINT_SIZE], brushTexture.width / kBrushScale); 246 | 247 | // initialize brush color 248 | glUniform4fv(program[PROGRAM_POINT].uniform[UNIFORM_VERTEX_COLOR], 1, brushColor); 249 | } 250 | } 251 | 252 | glError(); 253 | } 254 | 255 | // Create a texture from an image 256 | - (textureInfo_t)textureFromName:(NSString *)name 257 | { 258 | CGImageRef brushImage; 259 | CGContextRef brushContext; 260 | GLubyte *brushData; 261 | size_t width, height; 262 | GLuint texId; 263 | textureInfo_t texture; 264 | 265 | // First create a UIImage object from the data in a image file, and then extract the Core Graphics image 266 | brushImage = [UIImage imageNamed:name].CGImage; 267 | 268 | // Get the width and height of the image 269 | width = CGImageGetWidth(brushImage); 270 | height = CGImageGetHeight(brushImage); 271 | 272 | // Make sure the image exists 273 | if(brushImage) { 274 | // Allocate memory needed for the bitmap context 275 | brushData = (GLubyte *) calloc(width * height * 4, sizeof(GLubyte)); 276 | // Use the bitmatp creation function provided by the Core Graphics framework. 277 | brushContext = CGBitmapContextCreate(brushData, width, height, 8, width * 4, CGImageGetColorSpace(brushImage), kCGImageAlphaPremultipliedLast); 278 | // After you create the context, you can draw the image to the context. 279 | CGContextDrawImage(brushContext, CGRectMake(0.0, 0.0, (CGFloat)width, (CGFloat)height), brushImage); 280 | // You don't need the context at this point, so you need to release it to avoid memory leaks. 281 | CGContextRelease(brushContext); 282 | // Use OpenGL ES to generate a name for the texture. 283 | glGenTextures(1, &texId); 284 | // Bind the texture name. 285 | glBindTexture(GL_TEXTURE_2D, texId); 286 | // Set the texture parameters to use a minifying filter and a linear filer (weighted average) 287 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 288 | // Specify a 2D texture image, providing the a pointer to the image data in memory 289 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (int)width, (int)height, 0, GL_RGBA, GL_UNSIGNED_BYTE, brushData); 290 | // Release the image data; it's no longer needed 291 | free(brushData); 292 | 293 | texture.id = texId; 294 | texture.width = (int)width; 295 | texture.height = (int)height; 296 | } 297 | 298 | return texture; 299 | } 300 | 301 | - (BOOL)initGL 302 | { 303 | // Generate IDs for a framebuffer object and a color renderbuffer 304 | glGenFramebuffers(1, &viewFramebuffer); 305 | glGenRenderbuffers(1, &viewRenderbuffer); 306 | 307 | glBindFramebuffer(GL_FRAMEBUFFER, viewFramebuffer); 308 | glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer); 309 | // This call associates the storage for the current render buffer with the EAGLDrawable (our CAEAGLLayer) 310 | // allowing us to draw into a buffer that will later be rendered to screen wherever the layer is (which corresponds with our view). 311 | [context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(id)self.layer]; 312 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, viewRenderbuffer); 313 | 314 | glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &backingWidth); 315 | glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &backingHeight); 316 | 317 | // For this sample, we do not need a depth buffer. If you do, this is how you can create one and attach it to the framebuffer: 318 | // glGenRenderbuffers(1, &depthRenderbuffer); 319 | // glBindRenderbuffer(GL_RENDERBUFFER, depthRenderbuffer); 320 | // glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, backingWidth, backingHeight); 321 | // glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRenderbuffer); 322 | 323 | if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) 324 | { 325 | NSLog(@"failed to make complete framebuffer object %x", glCheckFramebufferStatus(GL_FRAMEBUFFER)); 326 | return NO; 327 | } 328 | 329 | // Setup the view port in Pixels 330 | glViewport(0, 0, backingWidth, backingHeight); 331 | 332 | // Create a Vertex Buffer Object to hold our data 333 | glGenBuffers(1, &vboId); 334 | 335 | // Load the brush texture 336 | brushTexture = [self textureFromName:@"Particle.png"]; 337 | 338 | // Load shaders 339 | [self setupShaders]; 340 | 341 | // Enable blending and set a blending function appropriate for premultiplied alpha pixel data 342 | glEnable(GL_BLEND); 343 | glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); 344 | 345 | // Playback recorded path, which is "Shake Me" 346 | NSMutableArray* recordedPaths = [NSMutableArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Recording" ofType:@"data"]]; 347 | if([recordedPaths count]) 348 | [self performSelector:@selector(playback:) withObject:recordedPaths afterDelay:0.2]; 349 | 350 | return YES; 351 | } 352 | 353 | - (BOOL)resizeFromLayer:(CAEAGLLayer *)layer 354 | { 355 | // Allocate color buffer backing based on the current layer size 356 | glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer); 357 | [context renderbufferStorage:GL_RENDERBUFFER fromDrawable:layer]; 358 | glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &backingWidth); 359 | glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &backingHeight); 360 | 361 | // For this sample, we do not need a depth buffer. If you do, this is how you can allocate depth buffer backing: 362 | // glBindRenderbuffer(GL_RENDERBUFFER, depthRenderbuffer); 363 | // glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, backingWidth, backingHeight); 364 | // glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRenderbuffer); 365 | 366 | if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) 367 | { 368 | NSLog(@"Failed to make complete framebuffer objectz %x", glCheckFramebufferStatus(GL_FRAMEBUFFER)); 369 | return NO; 370 | } 371 | 372 | // Update projection matrix 373 | GLKMatrix4 projectionMatrix = GLKMatrix4MakeOrtho(0, backingWidth, 0, backingHeight, -1, 1); 374 | GLKMatrix4 modelViewMatrix = GLKMatrix4Identity; // this sample uses a constant identity modelView matrix 375 | GLKMatrix4 MVPMatrix = GLKMatrix4Multiply(projectionMatrix, modelViewMatrix); 376 | 377 | glUseProgram(program[PROGRAM_POINT].id); 378 | glUniformMatrix4fv(program[PROGRAM_POINT].uniform[UNIFORM_MVP], 1, GL_FALSE, MVPMatrix.m); 379 | 380 | // Update viewport 381 | glViewport(0, 0, backingWidth, backingHeight); 382 | 383 | return YES; 384 | } 385 | 386 | // Releases resources when they are not longer needed. 387 | - (void)dealloc 388 | { 389 | // Destroy framebuffers and renderbuffers 390 | if (viewFramebuffer) { 391 | glDeleteFramebuffers(1, &viewFramebuffer); 392 | viewFramebuffer = 0; 393 | } 394 | if (viewRenderbuffer) { 395 | glDeleteRenderbuffers(1, &viewRenderbuffer); 396 | viewRenderbuffer = 0; 397 | } 398 | if (depthRenderbuffer) 399 | { 400 | glDeleteRenderbuffers(1, &depthRenderbuffer); 401 | depthRenderbuffer = 0; 402 | } 403 | // texture 404 | if (brushTexture.id) { 405 | glDeleteTextures(1, &brushTexture.id); 406 | brushTexture.id = 0; 407 | } 408 | // vbo 409 | if (vboId) { 410 | glDeleteBuffers(1, &vboId); 411 | vboId = 0; 412 | } 413 | 414 | // tear down context 415 | if ([EAGLContext currentContext] == context) 416 | [EAGLContext setCurrentContext:nil]; 417 | } 418 | 419 | // Erases the screen 420 | - (void)erase 421 | { 422 | [EAGLContext setCurrentContext:context]; 423 | 424 | // Clear the buffer 425 | glBindFramebuffer(GL_FRAMEBUFFER, viewFramebuffer); 426 | glClearColor(0.0, 0.0, 0.0, 0.0); 427 | glClear(GL_COLOR_BUFFER_BIT); 428 | 429 | // Display the buffer 430 | glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer); 431 | [context presentRenderbuffer:GL_RENDERBUFFER]; 432 | } 433 | 434 | // Drawings a line onscreen based on where the user touches 435 | - (void)renderLineFromPoint:(CGPoint)start toPoint:(CGPoint)end 436 | { 437 | static GLfloat* vertexBuffer = NULL; 438 | static NSUInteger vertexMax = 64; 439 | NSUInteger vertexCount = 0, 440 | count, 441 | i; 442 | 443 | [EAGLContext setCurrentContext:context]; 444 | glBindFramebuffer(GL_FRAMEBUFFER, viewFramebuffer); 445 | 446 | // Convert locations from Points to Pixels 447 | CGFloat scale = self.contentScaleFactor; 448 | start.x *= scale; 449 | start.y *= scale; 450 | end.x *= scale; 451 | end.y *= scale; 452 | 453 | // Allocate vertex array buffer 454 | if(vertexBuffer == NULL) 455 | vertexBuffer = malloc(vertexMax * 2 * sizeof(GLfloat)); 456 | 457 | // Add points to the buffer so there are drawing points every X pixels 458 | count = MAX(ceilf(sqrtf((end.x - start.x) * (end.x - start.x) + (end.y - start.y) * (end.y - start.y)) / kBrushPixelStep), 1); 459 | for(i = 0; i < count; ++i) { 460 | if(vertexCount == vertexMax) { 461 | vertexMax = 2 * vertexMax; 462 | vertexBuffer = realloc(vertexBuffer, vertexMax * 2 * sizeof(GLfloat)); 463 | } 464 | 465 | vertexBuffer[2 * vertexCount + 0] = start.x + (end.x - start.x) * ((GLfloat)i / (GLfloat)count); 466 | vertexBuffer[2 * vertexCount + 1] = start.y + (end.y - start.y) * ((GLfloat)i / (GLfloat)count); 467 | vertexCount += 1; 468 | } 469 | 470 | // Load data to the Vertex Buffer Object 471 | glBindBuffer(GL_ARRAY_BUFFER, vboId); 472 | glBufferData(GL_ARRAY_BUFFER, vertexCount*2*sizeof(GLfloat), vertexBuffer, GL_DYNAMIC_DRAW); 473 | 474 | glEnableVertexAttribArray(ATTRIB_VERTEX); 475 | glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, GL_FALSE, 0, 0); 476 | 477 | // Draw 478 | glUseProgram(program[PROGRAM_POINT].id); 479 | glDrawArrays(GL_POINTS, 0, (int)vertexCount); 480 | 481 | // Display the buffer 482 | glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer); 483 | [context presentRenderbuffer:GL_RENDERBUFFER]; 484 | } 485 | 486 | // Reads previously recorded points and draws them onscreen. This is the Shake Me message that appears when the application launches. 487 | - (void)playback:(NSMutableArray*)recordedPaths 488 | { 489 | // NOTE: Recording.data is stored with 32-bit floats 490 | // To make it work on both 32-bit and 64-bit devices, we make sure we read back 32 bits each time. 491 | 492 | Float32 x[1], y[1]; 493 | CGPoint point1, point2; 494 | 495 | NSData* data = [recordedPaths objectAtIndex:0]; 496 | NSUInteger count = [data length] / (sizeof(Float32)*2), // each point contains 64 bits (32-bit x and 32-bit y) 497 | i; 498 | 499 | // Render the current path 500 | for(i = 0; i < count - 1; i++) { 501 | 502 | [data getBytes:&x range:NSMakeRange(8*i, sizeof(Float32))]; // read 32 bits each time 503 | [data getBytes:&y range:NSMakeRange(8*i+sizeof(Float32), sizeof(Float32))]; 504 | point1 = CGPointMake(x[0], y[0]); 505 | 506 | [data getBytes:&x range:NSMakeRange(8*(i+1), sizeof(Float32))]; 507 | [data getBytes:&y range:NSMakeRange(8*(i+1)+sizeof(Float32), sizeof(Float32))]; 508 | point2 = CGPointMake(x[0], y[0]); 509 | 510 | [self renderLineFromPoint:point1 toPoint:point2]; 511 | } 512 | 513 | // Render the next path after a short delay 514 | [recordedPaths removeObjectAtIndex:0]; 515 | if([recordedPaths count]) 516 | [self performSelector:@selector(playback:) withObject:recordedPaths afterDelay:0.01]; 517 | } 518 | 519 | 520 | // Handles the start of a touch 521 | - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 522 | { 523 | CGRect bounds = [self bounds]; 524 | UITouch* touch = [[event touchesForView:self] anyObject]; 525 | firstTouch = YES; 526 | // Convert touch point from UIView referential to OpenGL one (upside-down flip) 527 | location = [touch locationInView:self]; 528 | location.y = bounds.size.height - location.y; 529 | } 530 | 531 | // Handles the continuation of a touch. 532 | - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 533 | { 534 | CGRect bounds = [self bounds]; 535 | UITouch* touch = [[event touchesForView:self] anyObject]; 536 | 537 | // Convert touch point from UIView referential to OpenGL one (upside-down flip) 538 | if (firstTouch) { 539 | firstTouch = NO; 540 | previousLocation = [touch previousLocationInView:self]; 541 | previousLocation.y = bounds.size.height - previousLocation.y; 542 | } else { 543 | location = [touch locationInView:self]; 544 | location.y = bounds.size.height - location.y; 545 | previousLocation = [touch previousLocationInView:self]; 546 | previousLocation.y = bounds.size.height - previousLocation.y; 547 | } 548 | 549 | // Render the stroke 550 | [self renderLineFromPoint:previousLocation toPoint:location]; 551 | } 552 | 553 | // Handles the end of a touch event when the touch is a tap. 554 | - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 555 | { 556 | CGRect bounds = [self bounds]; 557 | UITouch* touch = [[event touchesForView:self] anyObject]; 558 | if (firstTouch) { 559 | firstTouch = NO; 560 | previousLocation = [touch previousLocationInView:self]; 561 | previousLocation.y = bounds.size.height - previousLocation.y; 562 | [self renderLineFromPoint:previousLocation toPoint:location]; 563 | } 564 | } 565 | 566 | // Handles the end of a touch event. 567 | - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event 568 | { 569 | // If appropriate, add code necessary to save the state of the application. 570 | // This application is not saving state. 571 | } 572 | 573 | - (void)setBrushColorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue 574 | { 575 | // Update the brush color 576 | brushColor[0] = red * kBrushOpacity; 577 | brushColor[1] = green * kBrushOpacity; 578 | brushColor[2] = blue * kBrushOpacity; 579 | brushColor[3] = kBrushOpacity; 580 | 581 | if (initialized) { 582 | glUseProgram(program[PROGRAM_POINT].id); 583 | glUniform4fv(program[PROGRAM_POINT].uniform[UNIFORM_VERTEX_COLOR], 1, brushColor); 584 | } 585 | } 586 | 587 | 588 | - (BOOL)canBecomeFirstResponder { 589 | return YES; 590 | } 591 | 592 | @end 593 | -------------------------------------------------------------------------------- /Classes/PaintingView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PaintingView.swift 3 | // GLPaint 4 | // 5 | // Translated by OOPer in cooperation with shlab.jp, on 2015/1/4. 6 | // 7 | // 8 | /* 9 | File: PaintingView.h 10 | File: PaintingView.m 11 | Abstract: The class responsible for the finger painting. The class wraps the 12 | CAEAGLLayer from CoreAnimation into a convenient UIView subclass. The view 13 | content is basically an EAGL surface you render your OpenGL scene into. 14 | Version: 1.13 15 | 16 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 17 | Inc. ("Apple") in consideration of your agreement to the following 18 | terms, and your use, installation, modification or redistribution of 19 | this Apple software constitutes acceptance of these terms. If you do 20 | not agree with these terms, please do not use, install, modify or 21 | redistribute this Apple software. 22 | 23 | In consideration of your agreement to abide by the following terms, and 24 | subject to these terms, Apple grants you a personal, non-exclusive 25 | license, under Apple's copyrights in this original Apple software (the 26 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 27 | Software, with or without modifications, in source and/or binary forms; 28 | provided that if you redistribute the Apple Software in its entirety and 29 | without modifications, you must retain this notice and the following 30 | text and disclaimers in all such redistributions of the Apple Software. 31 | Neither the name, trademarks, service marks or logos of Apple Inc. may 32 | be used to endorse or promote products derived from the Apple Software 33 | without specific prior written permission from Apple. Except as 34 | expressly stated in this notice, no other rights or licenses, express or 35 | implied, are granted by Apple herein, including but not limited to any 36 | patent rights that may be infringed by your derivative works or by other 37 | works in which the Apple Software may be incorporated. 38 | 39 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 40 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 41 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 42 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 43 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 44 | 45 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 46 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 47 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 48 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 49 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 50 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 51 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 52 | POSSIBILITY OF SUCH DAMAGE. 53 | 54 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 55 | 56 | */ 57 | 58 | import UIKit 59 | import GLKit 60 | 61 | //CONSTANTS: 62 | 63 | let kBrushOpacity = (1.0 / 3.0) 64 | let kBrushPixelStep = 3 65 | let kBrushScale = 2 66 | 67 | 68 | // Shaders 69 | let PROGRAM_POINT = 0 70 | 71 | let UNIFORM_MVP = 0 72 | let UNIFORM_POINT_SIZE = 1 73 | let UNIFORM_VERTEX_COLOR = 2 74 | let UNIFORM_TEXTURE = 3 75 | let NUM_UNIFORMS = 4 76 | 77 | let ATTRIB_VERTEX = 0 78 | let NUM_ATTRIBS = 1 79 | 80 | typealias programInfo_t = ( 81 | vert: String, frag: String, 82 | uniform: [GLint], 83 | id: GLuint) 84 | 85 | var program: [programInfo_t] = [ 86 | ("point.vsh", "point.fsh", Array(repeating: 0, count: NUM_UNIFORMS), 0), // PROGRAM_POINT 87 | ] 88 | let NUM_PROGRAMS = program.count 89 | 90 | 91 | // Texture 92 | typealias textureInfo_t = ( 93 | id: GLuint, 94 | width: GLsizei, height: GLsizei) 95 | 96 | 97 | @objc(PaintingView) 98 | class PaintingView: UIView { 99 | // The pixel dimensions of the backbuffer 100 | private var backingWidth: GLint = 0 101 | private var backingHeight: GLint = 0 102 | 103 | private var context: EAGLContext! 104 | 105 | // OpenGL names for the renderbuffer and framebuffers used to render to this view 106 | private var viewRenderbuffer: GLuint = 0, viewFramebuffer: GLuint = 0 107 | 108 | // OpenGL name for the depth buffer that is attached to viewFramebuffer, if it exists (0 if it does not exist) 109 | private var depthRenderbuffer: GLuint = 0 110 | 111 | private var brushTexture: textureInfo_t = (0, 0, 0) // brush texture 112 | private var brushColor: [GLfloat] = [0, 0, 0, 0] // brush color 113 | 114 | private var firstTouch: Bool = false 115 | private var needsErase: Bool = false 116 | 117 | // Shader objects 118 | private var vertexShader: GLuint = 0 119 | private var fragmentShader: GLuint = 0 120 | private var shaderProgram: GLuint = 0 121 | 122 | // Buffer Objects 123 | private var vboId: GLuint = 0 124 | 125 | private var initialized: Bool = false 126 | 127 | var location: CGPoint = CGPoint() 128 | var previousLocation: CGPoint = CGPoint() 129 | 130 | // Implement this to override the default layer class (which is [CALayer class]). 131 | // We do this so that our view will be backed by a layer that is capable of OpenGL ES rendering. 132 | override class var layerClass : AnyClass { 133 | return CAEAGLLayer.self 134 | } 135 | 136 | // The GL view is stored in the nib file. When it's unarchived it's sent -initWithCoder: 137 | required init?(coder: NSCoder) { 138 | 139 | super.init(coder: coder) 140 | let eaglLayer = self.layer as! CAEAGLLayer 141 | 142 | eaglLayer.isOpaque = true 143 | // In this application, we want to retain the EAGLDrawable contents after a call to presentRenderbuffer. 144 | eaglLayer.drawableProperties = [ 145 | kEAGLDrawablePropertyRetainedBacking: true, 146 | kEAGLDrawablePropertyColorFormat: kEAGLColorFormatRGBA8 147 | ] 148 | 149 | context = EAGLContext(api: .openGLES2) 150 | 151 | if context == nil || !EAGLContext.setCurrent(context) { 152 | fatalError("EAGLContext cannot be created") 153 | } 154 | 155 | // Set the view's scale factor as you wish 156 | self.contentScaleFactor = UIScreen.main.scale 157 | 158 | // Make sure to start with a cleared buffer 159 | needsErase = true 160 | 161 | } 162 | 163 | // If our view is resized, we'll be asked to layout subviews. 164 | // This is the perfect opportunity to also update the framebuffer so that it is 165 | // the same size as our display area. 166 | override func layoutSubviews() { 167 | EAGLContext.setCurrent(context) 168 | 169 | if !initialized { 170 | initialized = self.initGL() 171 | } else { 172 | self.resize(from: self.layer as! CAEAGLLayer) 173 | } 174 | 175 | // Clear the framebuffer the first time it is allocated 176 | if needsErase { 177 | self.erase() 178 | needsErase = false 179 | } 180 | } 181 | 182 | private func setupShaders() { 183 | for i in 0.. textureInfo_t { 248 | var texId: GLuint = 0 249 | var texture: textureInfo_t = (0, 0, 0) 250 | 251 | // First create a UIImage object from the data in a image file, and then extract the Core Graphics image 252 | let brushImage = UIImage(named: name)?.cgImage 253 | 254 | // Get the width and height of the image 255 | let width: size_t = brushImage!.width 256 | let height: size_t = brushImage!.height 257 | 258 | // Make sure the image exists 259 | if brushImage != nil { 260 | // Allocate memory needed for the bitmap context 261 | var brushData = [GLubyte](repeating: 0, count: width * height * 4) 262 | // Use the bitmatp creation function provided by the Core Graphics framework. 263 | let bitmapInfo = CGImageAlphaInfo.premultipliedLast.rawValue 264 | let brushContext = CGContext(data: &brushData, width: width, height: height, bitsPerComponent: 8, bytesPerRow: width * 4, space: (brushImage?.colorSpace!)!, bitmapInfo: bitmapInfo) 265 | // After you create the context, you can draw the image to the context. 266 | brushContext?.draw(brushImage!, in: CGRect(x: 0.0, y: 0.0, width: width.g, height: height.g)) 267 | // You don't need the context at this point, so you need to release it to avoid memory leaks. 268 | // Use OpenGL ES to generate a name for the texture. 269 | glGenTextures(1, &texId) 270 | // Bind the texture name. 271 | glBindTexture(GL_TEXTURE_2D.ui, texId) 272 | // Set the texture parameters to use a minifying filter and a linear filer (weighted average) 273 | glTexParameteri(GL_TEXTURE_2D.ui, GL_TEXTURE_MIN_FILTER.ui, GL_LINEAR) 274 | // Specify a 2D texture image, providing the a pointer to the image data in memory 275 | glTexImage2D(GL_TEXTURE_2D.ui, 0, GL_RGBA, width.i, height.i, 0, GL_RGBA.ui, GL_UNSIGNED_BYTE.ui, brushData) 276 | // Release the image data; it's no longer needed 277 | 278 | texture.id = texId 279 | texture.width = width.i 280 | texture.height = height.i 281 | } 282 | 283 | return texture 284 | } 285 | 286 | private func initGL() -> Bool { 287 | // Generate IDs for a framebuffer object and a color renderbuffer 288 | glGenFramebuffers(1, &viewFramebuffer) 289 | glGenRenderbuffers(1, &viewRenderbuffer) 290 | 291 | glBindFramebuffer(GL_FRAMEBUFFER.ui, viewFramebuffer) 292 | glBindRenderbuffer(GL_RENDERBUFFER.ui, viewRenderbuffer) 293 | // This call associates the storage for the current render buffer with the EAGLDrawable (our CAEAGLLayer) 294 | // allowing us to draw into a buffer that will later be rendered to screen wherever the layer is (which corresponds with our view). 295 | context.renderbufferStorage(GL_RENDERBUFFER.l, from: (self.layer as! EAGLDrawable)) 296 | glFramebufferRenderbuffer(GL_FRAMEBUFFER.ui, GL_COLOR_ATTACHMENT0.ui, GL_RENDERBUFFER.ui, viewRenderbuffer) 297 | 298 | glGetRenderbufferParameteriv(GL_RENDERBUFFER.ui, GL_RENDERBUFFER_WIDTH.ui, &backingWidth) 299 | glGetRenderbufferParameteriv(GL_RENDERBUFFER.ui, GL_RENDERBUFFER_HEIGHT.ui, &backingHeight) 300 | 301 | // For this sample, we do not need a depth buffer. If you do, this is how you can create one and attach it to the framebuffer: 302 | // glGenRenderbuffers(1, &depthRenderbuffer); 303 | // glBindRenderbuffer(GL_RENDERBUFFER, depthRenderbuffer); 304 | // glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, backingWidth, backingHeight); 305 | // glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRenderbuffer); 306 | 307 | if glCheckFramebufferStatus(GL_FRAMEBUFFER.ui) != GL_FRAMEBUFFER_COMPLETE.ui { 308 | NSLog("failed to make complete framebuffer object %x", glCheckFramebufferStatus(GL_FRAMEBUFFER.ui)) 309 | return false 310 | } 311 | 312 | // Setup the view port in Pixels 313 | glViewport(0, 0, backingWidth, backingHeight) 314 | 315 | // Create a Vertex Buffer Object to hold our data 316 | glGenBuffers(1, &vboId) 317 | 318 | // Load the brush texture 319 | brushTexture = self.texture(fromName: "Particle.png") 320 | 321 | // Load shaders 322 | self.setupShaders() 323 | 324 | // Enable blending and set a blending function appropriate for premultiplied alpha pixel data 325 | glEnable(GL_BLEND.ui) 326 | glBlendFunc(GL_ONE.ui, GL_ONE_MINUS_SRC_ALPHA.ui) 327 | 328 | // Playback recorded path, which is "Shake Me" 329 | let recordedPaths = NSArray(contentsOfFile: Bundle.main.path(forResource: "Recording", ofType: "data")!)! as! [Data] 330 | if recordedPaths.count != 0 { 331 | DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 200 * NSEC_PER_MSEC.d / NSEC_PER_SEC.d) { 332 | self.playback(recordedPaths, fromIndex: 0) 333 | } 334 | } 335 | 336 | return true 337 | } 338 | 339 | @discardableResult 340 | private func resize(from layer: CAEAGLLayer) -> Bool { 341 | // Allocate color buffer backing based on the current layer size 342 | glBindRenderbuffer(GL_RENDERBUFFER.ui, viewRenderbuffer) 343 | context.renderbufferStorage(GL_RENDERBUFFER.l, from: layer) 344 | glGetRenderbufferParameteriv(GL_RENDERBUFFER.ui, GL_RENDERBUFFER_WIDTH.ui, &backingWidth) 345 | glGetRenderbufferParameteriv(GL_RENDERBUFFER.ui, GL_RENDERBUFFER_HEIGHT.ui, &backingHeight) 346 | 347 | // For this sample, we do not need a depth buffer. If you do, this is how you can allocate depth buffer backing: 348 | // glBindRenderbuffer(GL_RENDERBUFFER, depthRenderbuffer); 349 | // glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, backingWidth, backingHeight); 350 | // glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRenderbuffer); 351 | 352 | if glCheckFramebufferStatus(GL_FRAMEBUFFER.ui) != GL_FRAMEBUFFER_COMPLETE.ui { 353 | NSLog("Failed to make complete framebuffer objectz %x", glCheckFramebufferStatus(GL_FRAMEBUFFER.ui)) 354 | return false 355 | } 356 | 357 | // Update projection matrix 358 | let projectionMatrix = GLKMatrix4MakeOrtho(0, backingWidth.f, 0, backingHeight.f, -1, 1) 359 | let modelViewMatrix = GLKMatrix4Identity // this sample uses a constant identity modelView matrix 360 | var MVPMatrix = GLKMatrix4Multiply(projectionMatrix, modelViewMatrix) 361 | 362 | glUseProgram(program[PROGRAM_POINT].id) 363 | withUnsafePointer(to: &MVPMatrix) {ptrMVP in 364 | ptrMVP.withMemoryRebound(to: GLfloat.self, capacity: 16) {ptrGLfloat in 365 | glUniformMatrix4fv(program[PROGRAM_POINT].uniform[UNIFORM_MVP], 1, GL_FALSE.ub, ptrGLfloat) 366 | } 367 | } 368 | 369 | // Update viewport 370 | glViewport(0, 0, backingWidth, backingHeight) 371 | 372 | return true 373 | } 374 | 375 | // Releases resources when they are not longer needed. 376 | deinit { 377 | // Destroy framebuffers and renderbuffers 378 | if viewFramebuffer != 0 { 379 | glDeleteFramebuffers(1, &viewFramebuffer) 380 | } 381 | if viewRenderbuffer != 0 { 382 | glDeleteRenderbuffers(1, &viewRenderbuffer) 383 | } 384 | if depthRenderbuffer != 0 { 385 | glDeleteRenderbuffers(1, &depthRenderbuffer) 386 | } 387 | // texture 388 | if brushTexture.id != 0 { 389 | glDeleteTextures(1, &brushTexture.id) 390 | } 391 | // vbo 392 | if vboId != 0 { 393 | glDeleteBuffers(1, &vboId) 394 | } 395 | 396 | // tear down context 397 | if EAGLContext.current() === context { 398 | EAGLContext.setCurrent(context) 399 | } 400 | } 401 | 402 | // Erases the screen 403 | func erase() { 404 | EAGLContext.setCurrent(context) 405 | 406 | // Clear the buffer 407 | glBindFramebuffer(GL_FRAMEBUFFER.ui, viewFramebuffer) 408 | glClearColor(0.0, 0.0, 0.0, 0.0) 409 | glClear(GL_COLOR_BUFFER_BIT.ui) 410 | 411 | // Display the buffer 412 | glBindRenderbuffer(GL_RENDERBUFFER.ui, viewRenderbuffer) 413 | context.presentRenderbuffer(GL_RENDERBUFFER.l) 414 | } 415 | 416 | // Drawings a line onscreen based on where the user touches 417 | private func renderLine(from _start: CGPoint, to _end: CGPoint) { 418 | struct Static { 419 | static var vertexBuffer: [GLfloat] = [] 420 | } 421 | var count = 0 422 | 423 | EAGLContext.setCurrent(context) 424 | glBindFramebuffer(GL_FRAMEBUFFER.ui, viewFramebuffer) 425 | 426 | // Convert locations from Points to Pixels 427 | let scale = self.contentScaleFactor 428 | var start = _start 429 | start.x *= scale 430 | start.y *= scale 431 | var end = _end 432 | end.x *= scale 433 | end.y *= scale 434 | 435 | // Allocate vertex array buffer 436 | 437 | // Add points to the buffer so there are drawing points every X pixels 438 | count = max(Int(ceilf(sqrtf((end.x - start.x).f * (end.x - start.x).f + (end.y - start.y).f * (end.y - start.y).f) / kBrushPixelStep.f)), 1) 439 | Static.vertexBuffer.reserveCapacity(count * 2) 440 | Static.vertexBuffer.removeAll(keepingCapacity: true) 441 | for i in 0...size, Static.vertexBuffer, GL_DYNAMIC_DRAW.ui) 450 | 451 | glEnableVertexAttribArray(ATTRIB_VERTEX.ui) 452 | glVertexAttribPointer(ATTRIB_VERTEX.ui, 2, GL_FLOAT.ui, GL_FALSE.ub, 0, nil) 453 | 454 | // Draw 455 | glUseProgram(program[PROGRAM_POINT].id) 456 | glDrawArrays(GL_POINTS.ui, 0, count.i) 457 | 458 | // Display the buffer 459 | glBindRenderbuffer(GL_RENDERBUFFER.ui, viewRenderbuffer) 460 | context.presentRenderbuffer(GL_RENDERBUFFER.l) 461 | } 462 | 463 | // Reads previously recorded points and draws them onscreen. This is the Shake Me message that appears when the application launches. 464 | 465 | private func playback(_ recordedPaths: [Data], fromIndex index: Int) { 466 | // NOTE: Recording.data is stored with 32-bit floats 467 | // To make it work on both 32-bit and 64-bit devices, we make sure we read back 32 bits each time. 468 | 469 | let data = recordedPaths[index] 470 | let count = data.count / (MemoryLayout.size*2) // each point contains 64 bits (32-bit x and 32-bit y) 471 | 472 | // Render the current path 473 | data.withUnsafeBytes { bytes in 474 | let floats = bytes.bindMemory(to: Float32.self).baseAddress! 475 | for i in 0.. index+1 { 491 | DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 10 * NSEC_PER_MSEC.d / NSEC_PER_SEC.d) { 492 | self.playback(recordedPaths, fromIndex: index+1) 493 | } 494 | } 495 | } 496 | 497 | 498 | // Handles the start of a touch 499 | override func touchesBegan(_ touches: Set, with event: UIEvent?) { 500 | let bounds = self.bounds 501 | let touch = event!.touches(for: self)!.first! 502 | firstTouch = true 503 | // Convert touch point from UIView referential to OpenGL one (upside-down flip) 504 | location = touch.location(in: self) 505 | location.y = bounds.size.height - location.y 506 | } 507 | 508 | // Handles the continuation of a touch. 509 | override func touchesMoved(_ touches: Set, with event: UIEvent?) { 510 | let bounds = self.bounds 511 | let touch = event!.touches(for: self)!.first! 512 | 513 | // Convert touch point from UIView referential to OpenGL one (upside-down flip) 514 | if firstTouch { 515 | firstTouch = false 516 | previousLocation = touch.previousLocation(in: self) 517 | previousLocation.y = bounds.size.height - previousLocation.y 518 | } else { 519 | location = touch.location(in: self) 520 | location.y = bounds.size.height - location.y 521 | previousLocation = touch.previousLocation(in: self) 522 | previousLocation.y = bounds.size.height - previousLocation.y 523 | } 524 | 525 | // Render the stroke 526 | self.renderLine(from: previousLocation, to: location) 527 | } 528 | 529 | // Handles the end of a touch event when the touch is a tap. 530 | override func touchesEnded(_ touches: Set, with event: UIEvent?) { 531 | let bounds = self.bounds 532 | let touch = event!.touches(for: self)!.first! 533 | if firstTouch { 534 | firstTouch = false 535 | previousLocation = touch.previousLocation(in: self) 536 | previousLocation.y = bounds.size.height - previousLocation.y 537 | self.renderLine(from: previousLocation, to: location) 538 | } 539 | } 540 | 541 | // Handles the end of a touch event. 542 | override func touchesCancelled(_ touches: Set, with event: UIEvent?) { 543 | // If appropriate, add code necessary to save the state of the application. 544 | // This application is not saving state. 545 | } 546 | 547 | func setBrushColor(red: CGFloat, green: CGFloat, blue: CGFloat) { 548 | // Update the brush color 549 | brushColor[0] = red.f * kBrushOpacity.f 550 | brushColor[1] = green.f * kBrushOpacity.f 551 | brushColor[2] = blue.f * kBrushOpacity.f 552 | brushColor[3] = kBrushOpacity.f 553 | 554 | if initialized { 555 | glUseProgram(program[PROGRAM_POINT].id) 556 | glUniform4fv(program[PROGRAM_POINT].uniform[UNIFORM_VERTEX_COLOR], 1, brushColor) 557 | } 558 | } 559 | 560 | 561 | override var canBecomeFirstResponder : Bool { 562 | return true 563 | } 564 | 565 | } 566 | -------------------------------------------------------------------------------- /Classes/PaintingViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: PaintingViewController.h 3 | Abstract: The central controller of the application. 4 | Version: 1.13 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import 49 | 50 | @interface PaintingViewController : UIViewController 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /Classes/PaintingViewController.m: -------------------------------------------------------------------------------- 1 | /* 2 | File: PaintingViewController.m 3 | Abstract: The central controller of the application. 4 | Version: 1.13 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import "PaintingViewController.h" 49 | #import "PaintingView.h" 50 | #import "SoundEffect.h" 51 | 52 | //CONSTANTS: 53 | 54 | #define kBrightness 1.0 55 | #define kSaturation 0.45 56 | 57 | #define kPaletteHeight 30 58 | #define kPaletteSize 5 59 | #define kMinEraseInterval 0.5 60 | 61 | // Padding for margins 62 | #define kLeftMargin 10.0 63 | #define kTopMargin 10.0 64 | #define kRightMargin 10.0 65 | 66 | //CLASS IMPLEMENTATIONS: 67 | 68 | @interface PaintingViewController() 69 | { 70 | SoundEffect *erasingSound; 71 | SoundEffect *selectSound; 72 | CFTimeInterval lastTime; 73 | } 74 | @end 75 | 76 | @implementation PaintingViewController 77 | 78 | - (void)viewDidLoad 79 | { 80 | [super viewDidLoad]; 81 | 82 | // Create a segmented control so that the user can choose the brush color. 83 | // Create the UIImages with the UIImageRenderingModeAlwaysOriginal rendering mode. This allows us to show the actual image colors in the segmented control. 84 | UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems: 85 | [NSArray arrayWithObjects: 86 | [[UIImage imageNamed:@"Red"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal], 87 | [[UIImage imageNamed:@"Yellow"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal], 88 | [[UIImage imageNamed:@"Green"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal], 89 | [[UIImage imageNamed:@"Blue"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal], 90 | [[UIImage imageNamed:@"Purple"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal], 91 | nil]]; 92 | 93 | // Compute a rectangle that is positioned correctly for the segmented control you'll use as a brush color palette 94 | CGRect rect = [[UIScreen mainScreen] bounds]; 95 | CGRect frame = CGRectMake(rect.origin.x + kLeftMargin, rect.size.height - kPaletteHeight - kTopMargin, rect.size.width - (kLeftMargin + kRightMargin), kPaletteHeight); 96 | segmentedControl.frame = frame; 97 | // When the user chooses a color, the method changeBrushColor: is called. 98 | [segmentedControl addTarget:self action:@selector(changeBrushColor:) forControlEvents:UIControlEventValueChanged]; 99 | // Make sure the color of the color complements the black background 100 | segmentedControl.tintColor = [UIColor darkGrayColor]; 101 | // Set the third color (index values start at 0) 102 | segmentedControl.selectedSegmentIndex = 2; 103 | 104 | // Add the control to the window 105 | [self.view addSubview:segmentedControl]; 106 | // Now that the control is added, you can release it 107 | 108 | // Define a starting color 109 | CGColorRef color = [UIColor colorWithHue:(CGFloat)2.0 / (CGFloat)kPaletteSize 110 | saturation:kSaturation 111 | brightness:kBrightness 112 | alpha:1.0].CGColor; 113 | const CGFloat *components = CGColorGetComponents(color); 114 | 115 | // Defer to the OpenGL view to set the brush color 116 | [(PaintingView *)self.view setBrushColorWithRed:components[0] green:components[1] blue:components[2]]; 117 | 118 | // Load the sounds 119 | NSBundle *mainBundle = [NSBundle mainBundle]; 120 | erasingSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Erase" ofType:@"caf"]]; 121 | selectSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"Select" ofType:@"caf"]]; 122 | 123 | // Erase the view when recieving a notification named "shake" from the NSNotificationCenter object 124 | // The "shake" nofification is posted by the PaintingWindow object when user shakes the device 125 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(eraseView) name:@"shake" object:nil]; 126 | } 127 | 128 | - (void)viewDidAppear:(BOOL)animated 129 | { 130 | [super viewDidAppear:animated]; 131 | [self becomeFirstResponder]; 132 | } 133 | 134 | - (BOOL)canBecomeFirstResponder 135 | { 136 | return YES; 137 | } 138 | 139 | // Release resources when they are no longer needed, 140 | - (void)dealloc 141 | { 142 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 143 | } 144 | 145 | // Change the brush color 146 | - (void)changeBrushColor:(id)sender 147 | { 148 | // Play sound 149 | [selectSound play]; 150 | 151 | // Define a new brush color 152 | CGColorRef color = [UIColor colorWithHue:(CGFloat)[sender selectedSegmentIndex] / (CGFloat)kPaletteSize 153 | saturation:kSaturation 154 | brightness:kBrightness 155 | alpha:1.0].CGColor; 156 | const CGFloat *components = CGColorGetComponents(color); 157 | 158 | // Defer to the OpenGL view to set the brush color 159 | [(PaintingView *)self.view setBrushColorWithRed:components[0] green:components[1] blue:components[2]]; 160 | } 161 | 162 | // Called when receiving the "shake" notification; plays the erase sound and redraws the view 163 | - (void)eraseView 164 | { 165 | if(CFAbsoluteTimeGetCurrent() > lastTime + kMinEraseInterval) { 166 | [erasingSound play]; 167 | [(PaintingView *)self.view erase]; 168 | lastTime = CFAbsoluteTimeGetCurrent(); 169 | } 170 | } 171 | 172 | // We do not support auto-rotation in this sample 173 | - (BOOL)shouldAutorotate 174 | { 175 | return NO; 176 | } 177 | 178 | #pragma mark Motion 179 | 180 | - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event 181 | { 182 | if (motion == UIEventSubtypeMotionShake) 183 | { 184 | // User was shaking the device. Post a notification named "shake". 185 | [[NSNotificationCenter defaultCenter] postNotificationName:@"shake" object:self]; 186 | } 187 | } 188 | 189 | @end 190 | -------------------------------------------------------------------------------- /Classes/PaintingViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PaintingViewController.swift 3 | // GLPaint 4 | // 5 | // Translated by OOPer in cooperation with shlab.jp, on 2015/1/5. 6 | // 7 | // 8 | /* 9 | File: PaintingViewController.h 10 | File: PaintingViewController.m 11 | Abstract: The central controller of the application. 12 | Version: 1.13 13 | 14 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 15 | Inc. ("Apple") in consideration of your agreement to the following 16 | terms, and your use, installation, modification or redistribution of 17 | this Apple software constitutes acceptance of these terms. If you do 18 | not agree with these terms, please do not use, install, modify or 19 | redistribute this Apple software. 20 | 21 | In consideration of your agreement to abide by the following terms, and 22 | subject to these terms, Apple grants you a personal, non-exclusive 23 | license, under Apple's copyrights in this original Apple software (the 24 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 25 | Software, with or without modifications, in source and/or binary forms; 26 | provided that if you redistribute the Apple Software in its entirety and 27 | without modifications, you must retain this notice and the following 28 | text and disclaimers in all such redistributions of the Apple Software. 29 | Neither the name, trademarks, service marks or logos of Apple Inc. may 30 | be used to endorse or promote products derived from the Apple Software 31 | without specific prior written permission from Apple. Except as 32 | expressly stated in this notice, no other rights or licenses, express or 33 | implied, are granted by Apple herein, including but not limited to any 34 | patent rights that may be infringed by your derivative works or by other 35 | works in which the Apple Software may be incorporated. 36 | 37 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 38 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 39 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 40 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 41 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 42 | 43 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 44 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 45 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 46 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 47 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 48 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 49 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 50 | POSSIBILITY OF SUCH DAMAGE. 51 | 52 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 53 | 54 | */ 55 | 56 | import UIKit 57 | 58 | //CONSTANTS: 59 | 60 | let kBrightness = 1.0 61 | let kSaturation = 0.45 62 | 63 | let kPaletteHeight = 30 64 | let kPaletteSize = 5 65 | let kMinEraseInterval = 0.5 66 | 67 | // Padding for margins 68 | let kLeftMargin = 10.0 69 | let kTopMargin = 10.0 70 | let kRightMargin = 10.0 71 | 72 | extension Notification.Name { 73 | static let shake = Notification.Name(rawValue: "shake") 74 | } 75 | 76 | //CLASS IMPLEMENTATIONS: 77 | 78 | @objc(PaintingViewController) 79 | class PaintingViewController: UIViewController { 80 | private var erasingSound: SoundEffect! 81 | private var selectSound: SoundEffect! 82 | private var lastTime: CFTimeInterval = 0 83 | 84 | override func viewDidLoad() { 85 | super.viewDidLoad() 86 | 87 | // Create a segmented control so that the user can choose the brush color. 88 | // Create the UIImages with the UIImageRenderingModeAlwaysOriginal rendering mode. This allows us to show the actual image colors in the segmented control. 89 | let segmentedControl = UISegmentedControl(items: [ 90 | 91 | UIImage(named: "Red")!.withRenderingMode(.alwaysOriginal), 92 | UIImage(named: "Yellow")!.withRenderingMode(.alwaysOriginal), 93 | UIImage(named: "Green")!.withRenderingMode(.alwaysOriginal), 94 | UIImage(named: "Blue")!.withRenderingMode(.alwaysOriginal), 95 | UIImage(named: "Purple")!.withRenderingMode(.alwaysOriginal), 96 | ]) 97 | 98 | // Compute a rectangle that is positioned correctly for the segmented control you'll use as a brush color palette 99 | let rect = UIScreen.main.bounds 100 | let frame = CGRect(x: rect.origin.x + kLeftMargin.g, y: rect.size.height - kPaletteHeight.g - kTopMargin.g, width: rect.size.width - (kLeftMargin + kRightMargin).g, height: kPaletteHeight.g) 101 | segmentedControl.frame = frame 102 | // When the user chooses a color, the method changeBrushColor: is called. 103 | segmentedControl.addTarget(self, action: #selector(PaintingViewController.changeBrushColor(_:)), for: .valueChanged) 104 | // Make sure the color of the color complements the black background 105 | segmentedControl.tintColor = UIColor.darkGray 106 | // Set the third color (index values start at 0) 107 | segmentedControl.selectedSegmentIndex = 2 108 | 109 | // Add the control to the window 110 | self.view.addSubview(segmentedControl) 111 | // Now that the control is added, you can release it 112 | 113 | // Define a starting color 114 | let color = UIColor(hue: 2.0.g / kPaletteSize.g, 115 | saturation: kSaturation.g, 116 | brightness: kBrightness.g, 117 | alpha: 1.0).cgColor 118 | if let components = color.components { 119 | 120 | // Defer to the OpenGL view to set the brush color 121 | (self.view as! PaintingView).setBrushColor(red: components[0], green: components[1], blue: components[2]) 122 | } else { 123 | print("CGColor.components unavailable") 124 | } 125 | 126 | // Load the sounds 127 | let mainBundle = Bundle.main 128 | erasingSound = SoundEffect(contentsOfFile: mainBundle.path(forResource: "Erase", ofType: "caf")!)! 129 | selectSound = SoundEffect(contentsOfFile: mainBundle.path(forResource: "Select", ofType: "caf")!)! 130 | 131 | // Erase the view when recieving a notification named "shake" from the NSNotificationCenter object 132 | // The "shake" nofification is posted by the PaintingWindow object when user shakes the device 133 | NotificationCenter.default.addObserver(self, selector: #selector(PaintingViewController.eraseView), name: .shake, object: nil) 134 | } 135 | 136 | override func viewDidAppear(_ animated: Bool) { 137 | super.viewDidAppear(animated) 138 | self.becomeFirstResponder() 139 | } 140 | 141 | override var canBecomeFirstResponder : Bool { 142 | return true 143 | } 144 | 145 | // Release resources when they are no longer needed, 146 | deinit { 147 | NotificationCenter.default.removeObserver(self) 148 | } 149 | 150 | // Change the brush color 151 | @objc func changeBrushColor(_ senderSegment: UISegmentedControl) { 152 | // Play sound 153 | selectSound.play() 154 | 155 | // Define a new brush color 156 | let color = UIColor(hue: senderSegment.selectedSegmentIndex.g / kPaletteSize.g, 157 | saturation: kSaturation.g, 158 | brightness: kBrightness.g, 159 | alpha: 1.0).cgColor 160 | if let components = color.components { 161 | 162 | // Defer to the OpenGL view to set the brush color 163 | (self.view as! PaintingView).setBrushColor(red: components[0], green: components[1], blue: components[2]) 164 | } else { 165 | print("CGColor.components unavailable") 166 | } 167 | } 168 | 169 | // Called when receiving the "shake" notification; plays the erase sound and redraws the view 170 | @objc func eraseView() { 171 | if CFAbsoluteTimeGetCurrent() > lastTime + kMinEraseInterval { 172 | erasingSound.play() 173 | (self.view as! PaintingView).erase() 174 | lastTime = CFAbsoluteTimeGetCurrent() 175 | } 176 | } 177 | 178 | // We do not support auto-rotation in this sample 179 | override var shouldAutorotate : Bool { 180 | return false 181 | } 182 | 183 | //MARK: Motion 184 | 185 | override func motionEnded(_ motion: UIEvent.EventSubtype, with event: UIEvent?) { 186 | if motion == UIEvent.EventSubtype.motionShake { 187 | // User was shaking the device. Post a notification named "shake". 188 | NotificationCenter.default.post(name: .shake, object: self) 189 | } 190 | } 191 | 192 | } 193 | -------------------------------------------------------------------------------- /Classes/SoundEffect.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: SoundEffect.h 3 | Abstract: SoundEffect is a class that loads and plays sound files. 4 | Version: 1.13 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import 49 | #import 50 | 51 | @interface SoundEffect : NSObject { 52 | SystemSoundID _soundID; 53 | } 54 | 55 | + (id)soundEffectWithContentsOfFile:(NSString *)aPath; 56 | - (id)initWithContentsOfFile:(NSString *)path; 57 | - (void)play; 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /Classes/SoundEffect.m: -------------------------------------------------------------------------------- 1 | /* 2 | File: SoundEffect.m 3 | Abstract: SoundEffect is a class that loads and plays sound files. 4 | Version: 1.13 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import "SoundEffect.h" 49 | 50 | @implementation SoundEffect 51 | 52 | // Creates a sound effect object from the specified sound file 53 | + (id)soundEffectWithContentsOfFile:(NSString *)aPath { 54 | if (aPath) { 55 | return [[SoundEffect alloc] initWithContentsOfFile:aPath]; 56 | } 57 | return nil; 58 | } 59 | 60 | // Initializes a sound effect object with the contents of the specified sound file 61 | - (id)initWithContentsOfFile:(NSString *)path { 62 | self = [super init]; 63 | 64 | // Gets the file located at the specified path. 65 | if (self != nil) { 66 | NSURL *aFileURL = [NSURL fileURLWithPath:path isDirectory:NO]; 67 | 68 | // If the file exists, calls Core Audio to create a system sound ID. 69 | if (aFileURL != nil) { 70 | SystemSoundID aSoundID; 71 | OSStatus error = AudioServicesCreateSystemSoundID((__bridge CFURLRef)aFileURL, &aSoundID); 72 | 73 | if (error == kAudioServicesNoError) { // success 74 | _soundID = aSoundID; 75 | } else { 76 | NSLog(@"Error %d loading sound at path: %@", (int)error, path); 77 | self = nil; 78 | } 79 | } else { 80 | NSLog(@"NSURL is nil for path: %@", path); 81 | self = nil; 82 | } 83 | } 84 | return self; 85 | } 86 | 87 | // Releases resouces when no longer needed. 88 | -(void)dealloc { 89 | AudioServicesDisposeSystemSoundID(_soundID); 90 | } 91 | 92 | // Plays the sound associated with a sound effect object. 93 | -(void)play { 94 | // Calls Core Audio to play the sound for the specified sound ID. 95 | AudioServicesPlaySystemSound(_soundID); 96 | } 97 | 98 | @end 99 | -------------------------------------------------------------------------------- /Classes/SoundEffect.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SoundEffect.swift 3 | // GLPaint 4 | // 5 | // Translated by OOPer in cooperation with shlab.jp, on 2015/1/4. 6 | // 7 | // 8 | /* 9 | File: SoundEffect.h 10 | File: SoundEffect.m 11 | Abstract: SoundEffect is a class that loads and plays sound files. 12 | Version: 1.13 13 | 14 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 15 | Inc. ("Apple") in consideration of your agreement to the following 16 | terms, and your use, installation, modification or redistribution of 17 | this Apple software constitutes acceptance of these terms. If you do 18 | not agree with these terms, please do not use, install, modify or 19 | redistribute this Apple software. 20 | 21 | In consideration of your agreement to abide by the following terms, and 22 | subject to these terms, Apple grants you a personal, non-exclusive 23 | license, under Apple's copyrights in this original Apple software (the 24 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 25 | Software, with or without modifications, in source and/or binary forms; 26 | provided that if you redistribute the Apple Software in its entirety and 27 | without modifications, you must retain this notice and the following 28 | text and disclaimers in all such redistributions of the Apple Software. 29 | Neither the name, trademarks, service marks or logos of Apple Inc. may 30 | be used to endorse or promote products derived from the Apple Software 31 | without specific prior written permission from Apple. Except as 32 | expressly stated in this notice, no other rights or licenses, express or 33 | implied, are granted by Apple herein, including but not limited to any 34 | patent rights that may be infringed by your derivative works or by other 35 | works in which the Apple Software may be incorporated. 36 | 37 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 38 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 39 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 40 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 41 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 42 | 43 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 44 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 45 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 46 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 47 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 48 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 49 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 50 | POSSIBILITY OF SUCH DAMAGE. 51 | 52 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 53 | 54 | */ 55 | 56 | import UIKit 57 | import AudioToolbox 58 | 59 | @objc(SoundEffect) 60 | class SoundEffect: NSObject { 61 | private var _soundID: SystemSoundID = 0 62 | 63 | // Creates a sound effect object from the specified sound file 64 | // Initializes a sound effect object with the contents of the specified sound file 65 | init?(contentsOfFile path: String) { 66 | super.init() 67 | 68 | // Gets the file located at the specified path. 69 | let aFileURL = URL(fileURLWithPath: path) 70 | 71 | // If the file exists, calls Core Audio to create a system sound ID. 72 | var aSoundID: SystemSoundID = 0 73 | let error = AudioServicesCreateSystemSoundID(aFileURL as CFURL, &aSoundID) 74 | 75 | if error == kAudioServicesNoError { 76 | _soundID = aSoundID 77 | } else { 78 | NSLog("Error %d loading sound at path: %@", error, path) 79 | return nil 80 | } 81 | } 82 | 83 | // Releases resouces when no longer needed. 84 | deinit { 85 | AudioServicesDisposeSystemSoundID(_soundID) 86 | } 87 | 88 | // Plays the sound associated with a sound effect object. 89 | func play() { 90 | // Calls Core Audio to play the sound for the specified sound ID. 91 | AudioServicesPlaySystemSound(_soundID) 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /Classes/UtilSrc/debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: debug.h 3 | Abstract: Utility functions for debugging. 4 | Version: 1.13 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #define glError() { \ 49 | GLenum err = glGetError(); \ 50 | if (err != GL_NO_ERROR) { \ 51 | printf("glError: %04x caught at %s:%u\n", err, __FILE__, __LINE__); \ 52 | } \ 53 | } 54 | 55 | -------------------------------------------------------------------------------- /Classes/UtilSrc/debug.swift: -------------------------------------------------------------------------------- 1 | // 2 | // debug.swift 3 | // GLPaint 4 | // 5 | // Translated by OOPer in cooperation with shlab.jp, on 2015/1/4. 6 | // 7 | // 8 | /* 9 | File: debug.h 10 | Abstract: Utility functions for debugging. 11 | Version: 1.13 12 | 13 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 14 | Inc. ("Apple") in consideration of your agreement to the following 15 | terms, and your use, installation, modification or redistribution of 16 | this Apple software constitutes acceptance of these terms. If you do 17 | not agree with these terms, please do not use, install, modify or 18 | redistribute this Apple software. 19 | 20 | In consideration of your agreement to abide by the following terms, and 21 | subject to these terms, Apple grants you a personal, non-exclusive 22 | license, under Apple's copyrights in this original Apple software (the 23 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 24 | Software, with or without modifications, in source and/or binary forms; 25 | provided that if you redistribute the Apple Software in its entirety and 26 | without modifications, you must retain this notice and the following 27 | text and disclaimers in all such redistributions of the Apple Software. 28 | Neither the name, trademarks, service marks or logos of Apple Inc. may 29 | be used to endorse or promote products derived from the Apple Software 30 | without specific prior written permission from Apple. Except as 31 | expressly stated in this notice, no other rights or licenses, express or 32 | implied, are granted by Apple herein, including but not limited to any 33 | patent rights that may be infringed by your derivative works or by other 34 | works in which the Apple Software may be incorporated. 35 | 36 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 37 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 38 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 39 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 40 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 41 | 42 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 43 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 44 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 45 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 46 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 47 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 48 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 49 | POSSIBILITY OF SUCH DAMAGE. 50 | 51 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 52 | 53 | */ 54 | import UIKit 55 | 56 | func glError(_ file: String = #file, line: Int = #line) { 57 | let err = glGetError() 58 | if err != GL_NO_ERROR.ui { 59 | print("glError: \(String(err, radix: 16)) caught at \(file):\(line)") 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Classes/UtilSrc/fileUtil.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: fileUtil.h 3 | Abstract: Functions for loading source files. 4 | Version: 1.13 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #ifndef FILEUTIL_H 49 | #define FILEUTIL_H 50 | 51 | const char *pathForResource(const char *name); 52 | char *readFile(const char *name); 53 | 54 | #endif /* FILEUTIL_H */ 55 | -------------------------------------------------------------------------------- /Classes/UtilSrc/fileUtil.m: -------------------------------------------------------------------------------- 1 | /* 2 | File: fileUtil.m 3 | Abstract: Functions for loading source files. 4 | Version: 1.13 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import 49 | #import 50 | 51 | const char *pathForResource(const char *name) 52 | { 53 | NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithUTF8String:name] ofType: nil]; 54 | return [path fileSystemRepresentation]; 55 | } 56 | 57 | char *readFile(const char *name) 58 | { 59 | struct stat statbuf; 60 | FILE *fh; 61 | char *source; 62 | 63 | fh = fopen(name, "r"); 64 | if (fh == 0) 65 | return 0; 66 | 67 | stat(name, &statbuf); 68 | source = (char *) malloc(statbuf.st_size + 1); 69 | fread(source, statbuf.st_size, 1, fh); 70 | source[statbuf.st_size] = '\0'; 71 | fclose(fh); 72 | 73 | return source; 74 | } 75 | -------------------------------------------------------------------------------- /Classes/UtilSrc/fileUtil.swift: -------------------------------------------------------------------------------- 1 | // 2 | // fileUtil.swift 3 | // GLPaint 4 | // 5 | // Translated by OOPer in cooperation with shlab.jp, on 2015/1/4. 6 | // 7 | // 8 | /* 9 | File: fileUtil.h 10 | File: fileUtil.m 11 | Abstract: Functions for loading source files. 12 | Version: 1.13 13 | 14 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 15 | Inc. ("Apple") in consideration of your agreement to the following 16 | terms, and your use, installation, modification or redistribution of 17 | this Apple software constitutes acceptance of these terms. If you do 18 | not agree with these terms, please do not use, install, modify or 19 | redistribute this Apple software. 20 | 21 | In consideration of your agreement to abide by the following terms, and 22 | subject to these terms, Apple grants you a personal, non-exclusive 23 | license, under Apple's copyrights in this original Apple software (the 24 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 25 | Software, with or without modifications, in source and/or binary forms; 26 | provided that if you redistribute the Apple Software in its entirety and 27 | without modifications, you must retain this notice and the following 28 | text and disclaimers in all such redistributions of the Apple Software. 29 | Neither the name, trademarks, service marks or logos of Apple Inc. may 30 | be used to endorse or promote products derived from the Apple Software 31 | without specific prior written permission from Apple. Except as 32 | expressly stated in this notice, no other rights or licenses, express or 33 | implied, are granted by Apple herein, including but not limited to any 34 | patent rights that may be infringed by your derivative works or by other 35 | works in which the Apple Software may be incorporated. 36 | 37 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 38 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 39 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 40 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 41 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 42 | 43 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 44 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 45 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 46 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 47 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 48 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 49 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 50 | POSSIBILITY OF SUCH DAMAGE. 51 | 52 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 53 | 54 | */ 55 | 56 | import UIKit 57 | 58 | func readData(forResource name: String, withExtension ext: String? = nil) -> Data { 59 | let url = Bundle.main.url(forResource: name, withExtension: ext)! 60 | var source = try! Data(contentsOf: url) 61 | var trailingNul: UInt8 = 0 62 | source.append(&trailingNul, count: 1) 63 | return source 64 | } 65 | -------------------------------------------------------------------------------- /Classes/UtilSrc/shaderUtil.c: -------------------------------------------------------------------------------- 1 | /* 2 | File: shaderUtil.c 3 | Abstract: Functions that compile, link and validate shader programs. 4 | Version: 1.13 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include "ShaderUtil.h" 53 | #include "debug.h" 54 | 55 | 56 | #define LogInfo printf 57 | #define LogError printf 58 | 59 | 60 | /* Compile a shader from the provided source(s) */ 61 | GLint glueCompileShader(GLenum target, GLsizei count, const GLchar **sources, GLuint *shader) 62 | { 63 | GLint logLength, status; 64 | 65 | *shader = glCreateShader(target); 66 | glShaderSource(*shader, count, sources, NULL); 67 | glCompileShader(*shader); 68 | glGetShaderiv(*shader, GL_INFO_LOG_LENGTH, &logLength); 69 | if (logLength > 0) 70 | { 71 | GLchar *log = (GLchar *)malloc(logLength); 72 | glGetShaderInfoLog(*shader, logLength, &logLength, log); 73 | LogInfo("Shader compile log:\n%s", log); 74 | free(log); 75 | } 76 | 77 | glGetShaderiv(*shader, GL_COMPILE_STATUS, &status); 78 | if (status == 0) 79 | { 80 | int i; 81 | 82 | LogError("Failed to compile shader:\n"); 83 | for (i = 0; i < count; i++) 84 | LogInfo("%s", sources[i]); 85 | } 86 | glError(); 87 | 88 | return status; 89 | } 90 | 91 | 92 | /* Link a program with all currently attached shaders */ 93 | GLint glueLinkProgram(GLuint program) 94 | { 95 | GLint logLength, status; 96 | 97 | glLinkProgram(program); 98 | glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength); 99 | if (logLength > 0) 100 | { 101 | GLchar *log = (GLchar *)malloc(logLength); 102 | glGetProgramInfoLog(program, logLength, &logLength, log); 103 | LogInfo("Program link log:\n%s", log); 104 | free(log); 105 | } 106 | 107 | glGetProgramiv(program, GL_LINK_STATUS, &status); 108 | if (status == 0) 109 | LogError("Failed to link program %d", program); 110 | glError(); 111 | 112 | return status; 113 | } 114 | 115 | 116 | /* Validate a program (for i.e. inconsistent samplers) */ 117 | GLint glueValidateProgram(GLuint program) 118 | { 119 | GLint logLength, status; 120 | 121 | glValidateProgram(program); 122 | glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength); 123 | if (logLength > 0) 124 | { 125 | GLchar *log = (GLchar *)malloc(logLength); 126 | glGetProgramInfoLog(program, logLength, &logLength, log); 127 | LogInfo("Program validate log:\n%s", log); 128 | free(log); 129 | } 130 | 131 | glGetProgramiv(program, GL_VALIDATE_STATUS, &status); 132 | if (status == 0) 133 | LogError("Failed to validate program %d", program); 134 | glError(); 135 | 136 | return status; 137 | } 138 | 139 | 140 | /* Return named uniform location after linking */ 141 | GLint glueGetUniformLocation(GLuint program, const GLchar *uniformName) 142 | { 143 | GLint loc; 144 | 145 | loc = glGetUniformLocation(program, uniformName); 146 | 147 | return loc; 148 | } 149 | 150 | 151 | /* Convenience wrapper that compiles, links, enumerates uniforms and attribs */ 152 | GLint glueCreateProgram(const GLchar *vertSource, const GLchar *fragSource, 153 | GLsizei attribNameCt, const GLchar **attribNames, 154 | const GLint *attribLocations, 155 | GLsizei uniformNameCt, const GLchar **uniformNames, 156 | GLint *uniformLocations, 157 | GLuint *program) 158 | { 159 | GLuint vertShader = 0, fragShader = 0, prog = 0, status = 1, i; 160 | 161 | prog = glCreateProgram(); 162 | 163 | status *= glueCompileShader(GL_VERTEX_SHADER, 1, &vertSource, &vertShader); 164 | status *= glueCompileShader(GL_FRAGMENT_SHADER, 1, &fragSource, &fragShader); 165 | glAttachShader(prog, vertShader); 166 | glAttachShader(prog, fragShader); 167 | 168 | for (i = 0; i < attribNameCt; i++) 169 | { 170 | if(strlen(attribNames[i])) 171 | glBindAttribLocation(prog, attribLocations[i], attribNames[i]); 172 | } 173 | 174 | status *= glueLinkProgram(prog); 175 | status *= glueValidateProgram(prog); 176 | 177 | if (status) 178 | { 179 | for(i = 0; i < uniformNameCt; i++) 180 | { 181 | if(strlen(uniformNames[i])) 182 | uniformLocations[i] = glueGetUniformLocation(prog, uniformNames[i]); 183 | } 184 | *program = prog; 185 | } 186 | if (vertShader) 187 | glDeleteShader(vertShader); 188 | if (fragShader) 189 | glDeleteShader(fragShader); 190 | glError(); 191 | 192 | return status; 193 | } 194 | -------------------------------------------------------------------------------- /Classes/UtilSrc/shaderUtil.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: shaderUtil.h 3 | Abstract: Functions that compile, link and validate shader programs. 4 | Version: 1.13 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #ifndef SHADERUTIL_H 49 | #define SHADERUTIL_H 50 | 51 | #import 52 | 53 | /* Shader Utilities */ 54 | GLint glueCompileShader(GLenum target, GLsizei count, const GLchar **sources, GLuint *shader); 55 | GLint glueLinkProgram(GLuint program); 56 | GLint glueValidateProgram(GLuint program); 57 | GLint glueGetUniformLocation(GLuint program, const GLchar *name); 58 | 59 | /* Shader Conveniences */ 60 | GLint glueCreateProgram(const GLchar *vertSource, const GLchar *fragSource, 61 | GLsizei attribNameCt, const GLchar **attribNames, 62 | const GLint *attribLocations, 63 | GLsizei uniformNameCt, const GLchar **uniformNames, 64 | GLint *uniformLocations, 65 | GLuint *program); 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif /* SHADERUTIL_H */ 72 | -------------------------------------------------------------------------------- /Classes/UtilSrc/shaderUtil.swift: -------------------------------------------------------------------------------- 1 | // 2 | // shaderUtil.swift 3 | // GLPaint 4 | // 5 | // Translated by OOPer in cooperation with shlab.jp, on 2015/1/4. 6 | // 7 | // 8 | /* 9 | File: shaderUtil.h 10 | File: shaderUtil.c 11 | Abstract: Functions that compile, link and validate shader programs. 12 | Version: 1.13 13 | 14 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 15 | Inc. ("Apple") in consideration of your agreement to the following 16 | terms, and your use, installation, modification or redistribution of 17 | this Apple software constitutes acceptance of these terms. If you do 18 | not agree with these terms, please do not use, install, modify or 19 | redistribute this Apple software. 20 | 21 | In consideration of your agreement to abide by the following terms, and 22 | subject to these terms, Apple grants you a personal, non-exclusive 23 | license, under Apple's copyrights in this original Apple software (the 24 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 25 | Software, with or without modifications, in source and/or binary forms; 26 | provided that if you redistribute the Apple Software in its entirety and 27 | without modifications, you must retain this notice and the following 28 | text and disclaimers in all such redistributions of the Apple Software. 29 | Neither the name, trademarks, service marks or logos of Apple Inc. may 30 | be used to endorse or promote products derived from the Apple Software 31 | without specific prior written permission from Apple. Except as 32 | expressly stated in this notice, no other rights or licenses, express or 33 | implied, are granted by Apple herein, including but not limited to any 34 | patent rights that may be infringed by your derivative works or by other 35 | works in which the Apple Software may be incorporated. 36 | 37 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 38 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 39 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 40 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 41 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 42 | 43 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 44 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 45 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 46 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 47 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 48 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 49 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 50 | POSSIBILITY OF SUCH DAMAGE. 51 | 52 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 53 | 54 | */ 55 | 56 | import UIKit 57 | import OpenGLES 58 | 59 | 60 | private func printf(_ format: String, args: [CVarArg]) { 61 | print(String(format: format, arguments: args), terminator: "") 62 | } 63 | private func printf(_ format: String, args: CVarArg...) { 64 | printf(format, args: args) 65 | } 66 | func LogInfo(_ format: String, args: CVarArg...) { 67 | printf(format, args: args) 68 | } 69 | func LogError(_ format: String, args: CVarArg...) { 70 | printf(format, args: args) 71 | } 72 | 73 | 74 | struct glue { 75 | 76 | /* Shader Utilities */ 77 | 78 | /* Compile a shader from the provided source(s) */ 79 | static func compileShader(_ target: GLenum, 80 | _ count: GLsizei, 81 | _ sources: UnsafePointer?>, 82 | _ shader: inout GLuint) -> GLint 83 | { 84 | var logLength: GLint = 0, status: GLint = 0 85 | 86 | shader = glCreateShader(target) 87 | glShaderSource(shader, count, sources, nil) 88 | glCompileShader(shader) 89 | glGetShaderiv(shader, GL_INFO_LOG_LENGTH.ui, &logLength) 90 | if logLength > 0 { 91 | let log = UnsafeMutablePointer.allocate(capacity: logLength.l) 92 | glGetShaderInfoLog(shader, logLength, &logLength, log) 93 | LogInfo("Shader compile log:\n%@", args: String(cString: log)) 94 | log.deallocate() 95 | } 96 | 97 | glGetShaderiv(shader, GL_COMPILE_STATUS.ui, &status) 98 | if status == 0 { 99 | 100 | LogError("Failed to compile shader:\n") 101 | for i in 0.. GLint { 113 | var logLength: GLint = 0, status: GLint = 0 114 | 115 | glLinkProgram(program) 116 | glGetProgramiv(program, GL_INFO_LOG_LENGTH.ui, &logLength) 117 | if logLength > 0 { 118 | let log = UnsafeMutablePointer.allocate(capacity: logLength.l) 119 | glGetProgramInfoLog(program, logLength, &logLength, log) 120 | LogInfo("Program link log:\n%@", args: String(cString: log)) 121 | log.deallocate() 122 | } 123 | 124 | glGetProgramiv(program, GL_LINK_STATUS.ui, &status) 125 | if status == 0 { 126 | LogError("Failed to link program %d", args: program) 127 | } 128 | glError() 129 | 130 | return status 131 | } 132 | 133 | 134 | /* Validate a program (for i.e. inconsistent samplers) */ 135 | static func validateProgram(_ program: GLuint) -> GLint { 136 | var logLength: GLint = 0, status: GLint = 0 137 | 138 | glValidateProgram(program) 139 | glGetProgramiv(program, GL_INFO_LOG_LENGTH.ui, &logLength) 140 | if logLength > 0 { 141 | let log = UnsafeMutablePointer.allocate(capacity: logLength.l) 142 | glGetProgramInfoLog(program, logLength, &logLength, log) 143 | LogInfo("Program validate log:\n%@", args: String(cString: log)) 144 | log.deallocate() 145 | } 146 | 147 | glGetProgramiv(program, GL_VALIDATE_STATUS.ui, &status) 148 | if status == 0 { 149 | LogError("Failed to validate program %d", args: program) 150 | } 151 | glError() 152 | 153 | return status 154 | } 155 | 156 | 157 | /* Return named uniform location after linking */ 158 | static func getUniformLocation(_ program: GLuint, _ uniformName: UnsafePointer) -> GLint { 159 | 160 | return glGetUniformLocation(program, uniformName) 161 | 162 | } 163 | 164 | 165 | /* Shader Conveniences */ 166 | 167 | /* Convenience wrapper that compiles, links, enumerates uniforms and attribs */ 168 | @discardableResult 169 | static func createProgram(_ _vertSource: UnsafePointer, 170 | _ _fragSource: UnsafePointer, 171 | _ attribNames: [String], 172 | _ attribLocations: [GLuint], 173 | _ uniformNames: [String], 174 | _ uniformLocations: inout [GLint], 175 | _ program: inout GLuint) -> GLint 176 | { 177 | var vertShader: GLuint = 0, fragShader: GLuint = 0, prog: GLuint = 0, status: GLint = 1 178 | 179 | prog = glCreateProgram() 180 | 181 | var vertSource: UnsafePointer? = _vertSource 182 | status *= compileShader(GL_VERTEX_SHADER.ui, 1, &vertSource, &vertShader) 183 | var fragSource: UnsafePointer? = _fragSource 184 | status *= compileShader(GL_FRAGMENT_SHADER.ui, 1, &fragSource, &fragShader) 185 | glAttachShader(prog, vertShader) 186 | glAttachShader(prog, fragShader) 187 | 188 | for i in 0.. 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | 13 | CFBundleIconFiles 14 | 15 | Icon.png 16 | Icon@2x.png 17 | Icon-72.png 18 | Icon-Small.png 19 | Icon-Small-50.png 20 | Icon-Small@2x.png 21 | 22 | CFBundleIdentifier 23 | $(PRODUCT_BUNDLE_IDENTIFIER) 24 | CFBundleInfoDictionaryVersion 25 | 6.0 26 | CFBundleName 27 | ${PRODUCT_NAME} 28 | CFBundlePackageType 29 | APPL 30 | CFBundleSignature 31 | ???? 32 | CFBundleVersion 33 | 1.13 34 | LSRequiresIPhoneOS 35 | 36 | NSMainNibFile 37 | MainWindow 38 | UILaunchStoryboardName 39 | LaunchScreen 40 | UIStatusBarHidden 41 | 42 | UIViewControllerBasedStatusBarAppearance 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /GLPaint.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 1B612B1F0DDCF277003A5CC7 /* Particle.png in Resources */ = {isa = PBXBuildFile; fileRef = 1B612B1E0DDCF277003A5CC7 /* Particle.png */; }; 11 | 1BBE306C0DD273B90012773B /* Blue.png in Resources */ = {isa = PBXBuildFile; fileRef = 1BBE30670DD273B90012773B /* Blue.png */; }; 12 | 1BBE306D0DD273B90012773B /* Green.png in Resources */ = {isa = PBXBuildFile; fileRef = 1BBE30680DD273B90012773B /* Green.png */; }; 13 | 1BBE306E0DD273B90012773B /* Purple.png in Resources */ = {isa = PBXBuildFile; fileRef = 1BBE30690DD273B90012773B /* Purple.png */; }; 14 | 1BBE306F0DD273B90012773B /* Red.png in Resources */ = {isa = PBXBuildFile; fileRef = 1BBE306A0DD273B90012773B /* Red.png */; }; 15 | 1BBE30700DD273B90012773B /* Yellow.png in Resources */ = {isa = PBXBuildFile; fileRef = 1BBE306B0DD273B90012773B /* Yellow.png */; }; 16 | 1D3623EC0D0F72F000981E51 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D3623EB0D0F72F000981E51 /* CoreGraphics.framework */; }; 17 | 1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; }; 18 | 1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; }; 19 | 28F25BC20D64BF0B00158CCD /* Recording.data in Resources */ = {isa = PBXBuildFile; fileRef = 28F25BBF0D64BF0B00158CCD /* Recording.data */; }; 20 | 28F25BC30D64BF0B00158CCD /* Select.caf in Resources */ = {isa = PBXBuildFile; fileRef = 28F25BC00D64BF0B00158CCD /* Select.caf */; }; 21 | 28F25BC40D64BF0B00158CCD /* Erase.caf in Resources */ = {isa = PBXBuildFile; fileRef = 28F25BC10D64BF0B00158CCD /* Erase.caf */; }; 22 | 2D500B940D5A79C200DBA0E3 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2D500B920D5A79C200DBA0E3 /* OpenGLES.framework */; }; 23 | 2D500B9A0D5A79CF00DBA0E3 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2D500B990D5A79CF00DBA0E3 /* QuartzCore.framework */; }; 24 | 2D500C820D5A7DAE00DBA0E3 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2D500C810D5A7DAE00DBA0E3 /* AudioToolbox.framework */; }; 25 | AF7492AB1728A9E50013253B /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = AF7492A91728A9E50013253B /* MainWindow.xib */; }; 26 | AF7E20421728A2C600728423 /* PaintingViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = AF7E203F1728A2C600728423 /* PaintingViewController.xib */; }; 27 | AF877F9117272B68002D08B8 /* point.fsh in Resources */ = {isa = PBXBuildFile; fileRef = AF877F8F17272B68002D08B8 /* point.fsh */; }; 28 | AF877F9217272B68002D08B8 /* point.vsh in Resources */ = {isa = PBXBuildFile; fileRef = AF877F9017272B68002D08B8 /* point.vsh */; }; 29 | AF877F9417272C2F002D08B8 /* GLKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AF877F9317272C2F002D08B8 /* GLKit.framework */; }; 30 | AFCEBA2111D96215001AA22A /* Icon-72.png in Resources */ = {isa = PBXBuildFile; fileRef = AFCEBA1A11D96215001AA22A /* Icon-72.png */; }; 31 | AFCEBA2211D96215001AA22A /* Icon-Small-50.png in Resources */ = {isa = PBXBuildFile; fileRef = AFCEBA1B11D96215001AA22A /* Icon-Small-50.png */; }; 32 | AFCEBA2311D96215001AA22A /* Icon-Small.png in Resources */ = {isa = PBXBuildFile; fileRef = AFCEBA1C11D96215001AA22A /* Icon-Small.png */; }; 33 | AFCEBA2411D96215001AA22A /* Icon-Small@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = AFCEBA1D11D96215001AA22A /* Icon-Small@2x.png */; }; 34 | AFCEBA2511D96215001AA22A /* Icon.png in Resources */ = {isa = PBXBuildFile; fileRef = AFCEBA1E11D96215001AA22A /* Icon.png */; }; 35 | AFCEBA2611D96215001AA22A /* Icon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = AFCEBA1F11D96215001AA22A /* Icon@2x.png */; }; 36 | AFCEBA2711D96215001AA22A /* iTunesArtwork in Resources */ = {isa = PBXBuildFile; fileRef = AFCEBA2011D96215001AA22A /* iTunesArtwork */; }; 37 | D7A0FDC3226D964900D53FA1 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D7A0FDC2226D964900D53FA1 /* LaunchScreen.storyboard */; }; 38 | D7AE538B1A8645390085AA3B /* NumTypes+Conversion.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7AE53891A8645390085AA3B /* NumTypes+Conversion.swift */; }; 39 | D7B915861A767513002949C6 /* AppController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7B915821A767513002949C6 /* AppController.swift */; }; 40 | D7B915871A767513002949C6 /* PaintingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7B915831A767513002949C6 /* PaintingView.swift */; }; 41 | D7B915881A767513002949C6 /* PaintingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7B915841A767513002949C6 /* PaintingViewController.swift */; }; 42 | D7B915891A767513002949C6 /* SoundEffect.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7B915851A767513002949C6 /* SoundEffect.swift */; }; 43 | D7B9158F1A767532002949C6 /* debug.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7B9158A1A767532002949C6 /* debug.swift */; }; 44 | D7B915901A767532002949C6 /* fileUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7B9158B1A767532002949C6 /* fileUtil.swift */; }; 45 | D7B915931A767532002949C6 /* shaderUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7B9158E1A767532002949C6 /* shaderUtil.swift */; }; 46 | /* End PBXBuildFile section */ 47 | 48 | /* Begin PBXFileReference section */ 49 | 1B612B1E0DDCF277003A5CC7 /* Particle.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Particle.png; sourceTree = ""; }; 50 | 1BBE30670DD273B90012773B /* Blue.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Blue.png; path = Images/Blue.png; sourceTree = ""; }; 51 | 1BBE30680DD273B90012773B /* Green.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Green.png; path = Images/Green.png; sourceTree = ""; }; 52 | 1BBE30690DD273B90012773B /* Purple.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Purple.png; path = Images/Purple.png; sourceTree = ""; }; 53 | 1BBE306A0DD273B90012773B /* Red.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Red.png; path = Images/Red.png; sourceTree = ""; }; 54 | 1BBE306B0DD273B90012773B /* Yellow.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Yellow.png; path = Images/Yellow.png; sourceTree = ""; }; 55 | 1BEB7DB40DA5967E00271C96 /* ReadMe.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ReadMe.txt; sourceTree = ""; }; 56 | 1D30AB110D05D00D00671497 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 57 | 1D3623EB0D0F72F000981E51 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 58 | 1D6058910D05DD3D006BFB54 /* GLPaint.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GLPaint.app; sourceTree = BUILT_PRODUCTS_DIR; }; 59 | 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 60 | 28F25BBF0D64BF0B00158CCD /* Recording.data */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = Recording.data; sourceTree = ""; }; 61 | 28F25BC00D64BF0B00158CCD /* Select.caf */ = {isa = PBXFileReference; lastKnownFileType = file; path = Select.caf; sourceTree = ""; }; 62 | 28F25BC10D64BF0B00158CCD /* Erase.caf */ = {isa = PBXFileReference; lastKnownFileType = file; path = Erase.caf; sourceTree = ""; }; 63 | 2D500B920D5A79C200DBA0E3 /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; }; 64 | 2D500B990D5A79CF00DBA0E3 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; 65 | 2D500C810D5A7DAE00DBA0E3 /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; }; 66 | 8D1107310486CEB800E47090 /* GLPaint-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GLPaint-Info.plist"; sourceTree = ""; }; 67 | AF877F8F17272B68002D08B8 /* point.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = point.fsh; sourceTree = ""; }; 68 | AF877F9017272B68002D08B8 /* point.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = point.vsh; sourceTree = ""; }; 69 | AF877F9317272C2F002D08B8 /* GLKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GLKit.framework; path = System/Library/Frameworks/GLKit.framework; sourceTree = SDKROOT; }; 70 | AFCEBA1A11D96215001AA22A /* Icon-72.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Icon-72.png"; path = "Images/Icon-72.png"; sourceTree = ""; }; 71 | AFCEBA1B11D96215001AA22A /* Icon-Small-50.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Icon-Small-50.png"; path = "Images/Icon-Small-50.png"; sourceTree = ""; }; 72 | AFCEBA1C11D96215001AA22A /* Icon-Small.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Icon-Small.png"; path = "Images/Icon-Small.png"; sourceTree = ""; }; 73 | AFCEBA1D11D96215001AA22A /* Icon-Small@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Icon-Small@2x.png"; path = "Images/Icon-Small@2x.png"; sourceTree = ""; }; 74 | AFCEBA1E11D96215001AA22A /* Icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Icon.png; path = Images/Icon.png; sourceTree = ""; }; 75 | AFCEBA1F11D96215001AA22A /* Icon@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Icon@2x.png"; path = "Images/Icon@2x.png"; sourceTree = ""; }; 76 | AFCEBA2011D96215001AA22A /* iTunesArtwork */ = {isa = PBXFileReference; lastKnownFileType = file; name = iTunesArtwork; path = Images/iTunesArtwork; sourceTree = ""; }; 77 | D7A0FDC2226D964900D53FA1 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = ""; }; 78 | D7AE53871A8644770085AA3B /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 79 | D7AE53891A8645390085AA3B /* NumTypes+Conversion.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "NumTypes+Conversion.swift"; path = "Classes/OOPUtils/NumTypes+Conversion.swift"; sourceTree = ""; }; 80 | D7B915821A767513002949C6 /* AppController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AppController.swift; path = Classes/AppController.swift; sourceTree = ""; }; 81 | D7B915831A767513002949C6 /* PaintingView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PaintingView.swift; path = Classes/PaintingView.swift; sourceTree = ""; }; 82 | D7B915841A767513002949C6 /* PaintingViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PaintingViewController.swift; path = Classes/PaintingViewController.swift; sourceTree = ""; }; 83 | D7B915851A767513002949C6 /* SoundEffect.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SoundEffect.swift; path = Classes/SoundEffect.swift; sourceTree = ""; }; 84 | D7B9158A1A767532002949C6 /* debug.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = debug.swift; path = Classes/UtilSrc/debug.swift; sourceTree = ""; }; 85 | D7B9158B1A767532002949C6 /* fileUtil.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = fileUtil.swift; path = Classes/UtilSrc/fileUtil.swift; sourceTree = ""; }; 86 | D7B9158E1A767532002949C6 /* shaderUtil.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = shaderUtil.swift; path = Classes/UtilSrc/shaderUtil.swift; sourceTree = ""; }; 87 | D7BE0FDC226D91A20036E5D0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainWindow.xib; sourceTree = ""; }; 88 | D7BE0FDD226D91A30036E5D0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/PaintingViewController.xib; sourceTree = ""; }; 89 | /* End PBXFileReference section */ 90 | 91 | /* Begin PBXFrameworksBuildPhase section */ 92 | 1D60588F0D05DD3D006BFB54 /* Frameworks */ = { 93 | isa = PBXFrameworksBuildPhase; 94 | buildActionMask = 2147483647; 95 | files = ( 96 | AF877F9417272C2F002D08B8 /* GLKit.framework in Frameworks */, 97 | 1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */, 98 | 1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */, 99 | 1D3623EC0D0F72F000981E51 /* CoreGraphics.framework in Frameworks */, 100 | 2D500B940D5A79C200DBA0E3 /* OpenGLES.framework in Frameworks */, 101 | 2D500B9A0D5A79CF00DBA0E3 /* QuartzCore.framework in Frameworks */, 102 | 2D500C820D5A7DAE00DBA0E3 /* AudioToolbox.framework in Frameworks */, 103 | ); 104 | runOnlyForDeploymentPostprocessing = 0; 105 | }; 106 | /* End PBXFrameworksBuildPhase section */ 107 | 108 | /* Begin PBXGroup section */ 109 | 19C28FACFE9D520D11CA2CBB /* Products */ = { 110 | isa = PBXGroup; 111 | children = ( 112 | 1D6058910D05DD3D006BFB54 /* GLPaint.app */, 113 | ); 114 | name = Products; 115 | sourceTree = ""; 116 | }; 117 | 29B97314FDCFA39411CA2CEA /* CustomTemplate */ = { 118 | isa = PBXGroup; 119 | children = ( 120 | D7AE53871A8644770085AA3B /* README.md */, 121 | 1BEB7DB40DA5967E00271C96 /* ReadMe.txt */, 122 | 2D500B1D0D5A766B00DBA0E3 /* Classes */, 123 | 29B97315FDCFA39411CA2CEA /* Other Sources */, 124 | AF877F8E17272B68002D08B8 /* Shaders */, 125 | 29B97317FDCFA39411CA2CEA /* Resources */, 126 | 29B97323FDCFA39411CA2CEA /* Frameworks */, 127 | 19C28FACFE9D520D11CA2CBB /* Products */, 128 | ); 129 | name = CustomTemplate; 130 | sourceTree = ""; 131 | }; 132 | 29B97315FDCFA39411CA2CEA /* Other Sources */ = { 133 | isa = PBXGroup; 134 | children = ( 135 | D7AE53891A8645390085AA3B /* NumTypes+Conversion.swift */, 136 | D7B9158A1A767532002949C6 /* debug.swift */, 137 | D7B9158B1A767532002949C6 /* fileUtil.swift */, 138 | D7B9158E1A767532002949C6 /* shaderUtil.swift */, 139 | ); 140 | name = "Other Sources"; 141 | sourceTree = ""; 142 | }; 143 | 29B97317FDCFA39411CA2CEA /* Resources */ = { 144 | isa = PBXGroup; 145 | children = ( 146 | AF7492A91728A9E50013253B /* MainWindow.xib */, 147 | AF7E203F1728A2C600728423 /* PaintingViewController.xib */, 148 | D7A0FDC2226D964900D53FA1 /* LaunchScreen.storyboard */, 149 | AFCEBA1D11D96215001AA22A /* Icon-Small@2x.png */, 150 | AFCEBA1A11D96215001AA22A /* Icon-72.png */, 151 | AFCEBA1B11D96215001AA22A /* Icon-Small-50.png */, 152 | AFCEBA1C11D96215001AA22A /* Icon-Small.png */, 153 | AFCEBA1E11D96215001AA22A /* Icon.png */, 154 | AFCEBA1F11D96215001AA22A /* Icon@2x.png */, 155 | AFCEBA2011D96215001AA22A /* iTunesArtwork */, 156 | 1B612B1E0DDCF277003A5CC7 /* Particle.png */, 157 | 28F25BBF0D64BF0B00158CCD /* Recording.data */, 158 | 28F25BC00D64BF0B00158CCD /* Select.caf */, 159 | 28F25BC10D64BF0B00158CCD /* Erase.caf */, 160 | 8D1107310486CEB800E47090 /* GLPaint-Info.plist */, 161 | 1BBE30670DD273B90012773B /* Blue.png */, 162 | 1BBE30680DD273B90012773B /* Green.png */, 163 | 1BBE30690DD273B90012773B /* Purple.png */, 164 | 1BBE306A0DD273B90012773B /* Red.png */, 165 | 1BBE306B0DD273B90012773B /* Yellow.png */, 166 | ); 167 | name = Resources; 168 | sourceTree = ""; 169 | }; 170 | 29B97323FDCFA39411CA2CEA /* Frameworks */ = { 171 | isa = PBXGroup; 172 | children = ( 173 | AF877F9317272C2F002D08B8 /* GLKit.framework */, 174 | 2D500C810D5A7DAE00DBA0E3 /* AudioToolbox.framework */, 175 | 1D3623EB0D0F72F000981E51 /* CoreGraphics.framework */, 176 | 2D500B990D5A79CF00DBA0E3 /* QuartzCore.framework */, 177 | 2D500B920D5A79C200DBA0E3 /* OpenGLES.framework */, 178 | 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */, 179 | 1D30AB110D05D00D00671497 /* Foundation.framework */, 180 | ); 181 | name = Frameworks; 182 | sourceTree = ""; 183 | }; 184 | 2D500B1D0D5A766B00DBA0E3 /* Classes */ = { 185 | isa = PBXGroup; 186 | children = ( 187 | D7B915821A767513002949C6 /* AppController.swift */, 188 | D7B915831A767513002949C6 /* PaintingView.swift */, 189 | D7B915841A767513002949C6 /* PaintingViewController.swift */, 190 | D7B915851A767513002949C6 /* SoundEffect.swift */, 191 | ); 192 | name = Classes; 193 | sourceTree = ""; 194 | }; 195 | AF877F8E17272B68002D08B8 /* Shaders */ = { 196 | isa = PBXGroup; 197 | children = ( 198 | AF877F9017272B68002D08B8 /* point.vsh */, 199 | AF877F8F17272B68002D08B8 /* point.fsh */, 200 | ); 201 | path = Shaders; 202 | sourceTree = ""; 203 | }; 204 | /* End PBXGroup section */ 205 | 206 | /* Begin PBXNativeTarget section */ 207 | 1D6058900D05DD3D006BFB54 /* GLPaint */ = { 208 | isa = PBXNativeTarget; 209 | buildConfigurationList = 1D6058960D05DD3E006BFB54 /* Build configuration list for PBXNativeTarget "GLPaint" */; 210 | buildPhases = ( 211 | 1D60588D0D05DD3D006BFB54 /* Resources */, 212 | 1D60588E0D05DD3D006BFB54 /* Sources */, 213 | 1D60588F0D05DD3D006BFB54 /* Frameworks */, 214 | ); 215 | buildRules = ( 216 | ); 217 | dependencies = ( 218 | ); 219 | name = GLPaint; 220 | productName = foo; 221 | productReference = 1D6058910D05DD3D006BFB54 /* GLPaint.app */; 222 | productType = "com.apple.product-type.application"; 223 | }; 224 | /* End PBXNativeTarget section */ 225 | 226 | /* Begin PBXProject section */ 227 | 29B97313FDCFA39411CA2CEA /* Project object */ = { 228 | isa = PBXProject; 229 | attributes = { 230 | LastSwiftUpdateCheck = 0700; 231 | LastUpgradeCheck = 1020; 232 | TargetAttributes = { 233 | 1D6058900D05DD3D006BFB54 = { 234 | LastSwiftMigration = 1020; 235 | }; 236 | }; 237 | }; 238 | buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "GLPaint" */; 239 | compatibilityVersion = "Xcode 3.2"; 240 | developmentRegion = en; 241 | hasScannedForEncodings = 1; 242 | knownRegions = ( 243 | en, 244 | Base, 245 | ); 246 | mainGroup = 29B97314FDCFA39411CA2CEA /* CustomTemplate */; 247 | projectDirPath = ""; 248 | projectRoot = ""; 249 | targets = ( 250 | 1D6058900D05DD3D006BFB54 /* GLPaint */, 251 | ); 252 | }; 253 | /* End PBXProject section */ 254 | 255 | /* Begin PBXResourcesBuildPhase section */ 256 | 1D60588D0D05DD3D006BFB54 /* Resources */ = { 257 | isa = PBXResourcesBuildPhase; 258 | buildActionMask = 2147483647; 259 | files = ( 260 | 28F25BC20D64BF0B00158CCD /* Recording.data in Resources */, 261 | 28F25BC30D64BF0B00158CCD /* Select.caf in Resources */, 262 | 28F25BC40D64BF0B00158CCD /* Erase.caf in Resources */, 263 | 1BBE306C0DD273B90012773B /* Blue.png in Resources */, 264 | 1BBE306D0DD273B90012773B /* Green.png in Resources */, 265 | 1BBE306E0DD273B90012773B /* Purple.png in Resources */, 266 | 1BBE306F0DD273B90012773B /* Red.png in Resources */, 267 | 1BBE30700DD273B90012773B /* Yellow.png in Resources */, 268 | 1B612B1F0DDCF277003A5CC7 /* Particle.png in Resources */, 269 | AFCEBA2111D96215001AA22A /* Icon-72.png in Resources */, 270 | AFCEBA2211D96215001AA22A /* Icon-Small-50.png in Resources */, 271 | AFCEBA2311D96215001AA22A /* Icon-Small.png in Resources */, 272 | AFCEBA2411D96215001AA22A /* Icon-Small@2x.png in Resources */, 273 | AFCEBA2511D96215001AA22A /* Icon.png in Resources */, 274 | AFCEBA2611D96215001AA22A /* Icon@2x.png in Resources */, 275 | AFCEBA2711D96215001AA22A /* iTunesArtwork in Resources */, 276 | AF877F9117272B68002D08B8 /* point.fsh in Resources */, 277 | AF877F9217272B68002D08B8 /* point.vsh in Resources */, 278 | D7A0FDC3226D964900D53FA1 /* LaunchScreen.storyboard in Resources */, 279 | AF7E20421728A2C600728423 /* PaintingViewController.xib in Resources */, 280 | AF7492AB1728A9E50013253B /* MainWindow.xib in Resources */, 281 | ); 282 | runOnlyForDeploymentPostprocessing = 0; 283 | }; 284 | /* End PBXResourcesBuildPhase section */ 285 | 286 | /* Begin PBXSourcesBuildPhase section */ 287 | 1D60588E0D05DD3D006BFB54 /* Sources */ = { 288 | isa = PBXSourcesBuildPhase; 289 | buildActionMask = 2147483647; 290 | files = ( 291 | D7B915861A767513002949C6 /* AppController.swift in Sources */, 292 | D7B915871A767513002949C6 /* PaintingView.swift in Sources */, 293 | D7B915931A767532002949C6 /* shaderUtil.swift in Sources */, 294 | D7B915901A767532002949C6 /* fileUtil.swift in Sources */, 295 | D7AE538B1A8645390085AA3B /* NumTypes+Conversion.swift in Sources */, 296 | D7B9158F1A767532002949C6 /* debug.swift in Sources */, 297 | D7B915881A767513002949C6 /* PaintingViewController.swift in Sources */, 298 | D7B915891A767513002949C6 /* SoundEffect.swift in Sources */, 299 | ); 300 | runOnlyForDeploymentPostprocessing = 0; 301 | }; 302 | /* End PBXSourcesBuildPhase section */ 303 | 304 | /* Begin PBXVariantGroup section */ 305 | AF7492A91728A9E50013253B /* MainWindow.xib */ = { 306 | isa = PBXVariantGroup; 307 | children = ( 308 | D7BE0FDC226D91A20036E5D0 /* Base */, 309 | ); 310 | name = MainWindow.xib; 311 | sourceTree = ""; 312 | }; 313 | AF7E203F1728A2C600728423 /* PaintingViewController.xib */ = { 314 | isa = PBXVariantGroup; 315 | children = ( 316 | D7BE0FDD226D91A30036E5D0 /* Base */, 317 | ); 318 | name = PaintingViewController.xib; 319 | sourceTree = ""; 320 | }; 321 | /* End PBXVariantGroup section */ 322 | 323 | /* Begin XCBuildConfiguration section */ 324 | 1D6058940D05DD3E006BFB54 /* Debug */ = { 325 | isa = XCBuildConfiguration; 326 | buildSettings = { 327 | ALWAYS_SEARCH_USER_PATHS = NO; 328 | CLANG_ENABLE_MODULES = YES; 329 | CLANG_ENABLE_OBJC_ARC = YES; 330 | COPY_PHASE_STRIP = NO; 331 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 332 | DEVELOPMENT_TEAM = ""; 333 | GCC_DYNAMIC_NO_PIC = NO; 334 | GCC_OPTIMIZATION_LEVEL = 0; 335 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 336 | GCC_PREFIX_HEADER = Prefix.pch; 337 | INFOPLIST_FILE = "GLPaint-Info.plist"; 338 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 339 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 340 | ONLY_ACTIVE_ARCH = YES; 341 | PRODUCT_BUNDLE_IDENTIFIER = "com.example.apple-samplecode.${PRODUCT_NAME:identifier}"; 342 | PRODUCT_NAME = GLPaint; 343 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 344 | SWIFT_VERSION = 5.0; 345 | WARNING_CFLAGS = "-Wall"; 346 | }; 347 | name = Debug; 348 | }; 349 | 1D6058950D05DD3E006BFB54 /* Release */ = { 350 | isa = XCBuildConfiguration; 351 | buildSettings = { 352 | ALWAYS_SEARCH_USER_PATHS = NO; 353 | CLANG_ENABLE_MODULES = YES; 354 | CLANG_ENABLE_OBJC_ARC = YES; 355 | COPY_PHASE_STRIP = YES; 356 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 357 | DEVELOPMENT_TEAM = ""; 358 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 359 | GCC_PREFIX_HEADER = Prefix.pch; 360 | INFOPLIST_FILE = "GLPaint-Info.plist"; 361 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 362 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 363 | ONLY_ACTIVE_ARCH = NO; 364 | PRODUCT_BUNDLE_IDENTIFIER = "com.example.apple-samplecode.${PRODUCT_NAME:identifier}"; 365 | PRODUCT_NAME = GLPaint; 366 | SWIFT_VERSION = 5.0; 367 | WARNING_CFLAGS = "-Wall"; 368 | }; 369 | name = Release; 370 | }; 371 | C01FCF4F08A954540054247B /* Debug */ = { 372 | isa = XCBuildConfiguration; 373 | buildSettings = { 374 | ALWAYS_SEARCH_USER_PATHS = NO; 375 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 376 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 377 | CLANG_WARN_BOOL_CONVERSION = YES; 378 | CLANG_WARN_COMMA = YES; 379 | CLANG_WARN_CONSTANT_CONVERSION = YES; 380 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 381 | CLANG_WARN_EMPTY_BODY = YES; 382 | CLANG_WARN_ENUM_CONVERSION = YES; 383 | CLANG_WARN_INFINITE_RECURSION = YES; 384 | CLANG_WARN_INT_CONVERSION = YES; 385 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 386 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 387 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 388 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 389 | CLANG_WARN_STRICT_PROTOTYPES = YES; 390 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 391 | CLANG_WARN_UNREACHABLE_CODE = YES; 392 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 393 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 394 | ENABLE_STRICT_OBJC_MSGSEND = YES; 395 | ENABLE_TESTABILITY = YES; 396 | GCC_C_LANGUAGE_STANDARD = c99; 397 | GCC_NO_COMMON_BLOCKS = YES; 398 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 399 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 400 | GCC_WARN_UNDECLARED_SELECTOR = YES; 401 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 402 | GCC_WARN_UNUSED_FUNCTION = YES; 403 | GCC_WARN_UNUSED_PARAMETER = NO; 404 | GCC_WARN_UNUSED_VARIABLE = YES; 405 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 406 | ONLY_ACTIVE_ARCH = YES; 407 | SDKROOT = iphoneos; 408 | }; 409 | name = Debug; 410 | }; 411 | C01FCF5008A954540054247B /* Release */ = { 412 | isa = XCBuildConfiguration; 413 | buildSettings = { 414 | ALWAYS_SEARCH_USER_PATHS = NO; 415 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 416 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 417 | CLANG_WARN_BOOL_CONVERSION = YES; 418 | CLANG_WARN_COMMA = YES; 419 | CLANG_WARN_CONSTANT_CONVERSION = YES; 420 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 421 | CLANG_WARN_EMPTY_BODY = YES; 422 | CLANG_WARN_ENUM_CONVERSION = YES; 423 | CLANG_WARN_INFINITE_RECURSION = YES; 424 | CLANG_WARN_INT_CONVERSION = YES; 425 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 426 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 427 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 428 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 429 | CLANG_WARN_STRICT_PROTOTYPES = YES; 430 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 431 | CLANG_WARN_UNREACHABLE_CODE = YES; 432 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 433 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 434 | ENABLE_STRICT_OBJC_MSGSEND = YES; 435 | GCC_C_LANGUAGE_STANDARD = c99; 436 | GCC_NO_COMMON_BLOCKS = YES; 437 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 438 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 439 | GCC_WARN_UNDECLARED_SELECTOR = YES; 440 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 441 | GCC_WARN_UNUSED_VARIABLE = YES; 442 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 443 | SDKROOT = iphoneos; 444 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 445 | }; 446 | name = Release; 447 | }; 448 | /* End XCBuildConfiguration section */ 449 | 450 | /* Begin XCConfigurationList section */ 451 | 1D6058960D05DD3E006BFB54 /* Build configuration list for PBXNativeTarget "GLPaint" */ = { 452 | isa = XCConfigurationList; 453 | buildConfigurations = ( 454 | 1D6058940D05DD3E006BFB54 /* Debug */, 455 | 1D6058950D05DD3E006BFB54 /* Release */, 456 | ); 457 | defaultConfigurationIsVisible = 0; 458 | defaultConfigurationName = Release; 459 | }; 460 | C01FCF4E08A954540054247B /* Build configuration list for PBXProject "GLPaint" */ = { 461 | isa = XCConfigurationList; 462 | buildConfigurations = ( 463 | C01FCF4F08A954540054247B /* Debug */, 464 | C01FCF5008A954540054247B /* Release */, 465 | ); 466 | defaultConfigurationIsVisible = 0; 467 | defaultConfigurationName = Release; 468 | }; 469 | /* End XCConfigurationList section */ 470 | }; 471 | rootObject = 29B97313FDCFA39411CA2CEA /* Project object */; 472 | } 473 | -------------------------------------------------------------------------------- /GLPaint.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /GLPaint.xcodeproj/project.xcworkspace/xcuserdata/dev.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ooper-shlab/GLPaint1.13-Swift/e9efa2e9db24d47e85d16911aa56d2c09c034b88/GLPaint.xcodeproj/project.xcworkspace/xcuserdata/dev.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /GLPaint.xcodeproj/xcuserdata/dev.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 20 | 21 | 22 | 24 | 36 | 37 | 38 | 40 | 52 | 53 | 54 | 56 | 68 | 69 | 70 | 72 | 84 | 85 | 86 | 88 | 100 | 101 | 102 | 104 | 116 | 117 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /GLPaint.xcodeproj/xcuserdata/dev.xcuserdatad/xcschemes/GLPaint.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /GLPaint.xcodeproj/xcuserdata/dev.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | GLPaint.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 1D6058900D05DD3D006BFB54 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Images/Blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ooper-shlab/GLPaint1.13-Swift/e9efa2e9db24d47e85d16911aa56d2c09c034b88/Images/Blue.png -------------------------------------------------------------------------------- /Images/Green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ooper-shlab/GLPaint1.13-Swift/e9efa2e9db24d47e85d16911aa56d2c09c034b88/Images/Green.png -------------------------------------------------------------------------------- /Images/Icon-72.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ooper-shlab/GLPaint1.13-Swift/e9efa2e9db24d47e85d16911aa56d2c09c034b88/Images/Icon-72.png -------------------------------------------------------------------------------- /Images/Icon-Small-50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ooper-shlab/GLPaint1.13-Swift/e9efa2e9db24d47e85d16911aa56d2c09c034b88/Images/Icon-Small-50.png -------------------------------------------------------------------------------- /Images/Icon-Small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ooper-shlab/GLPaint1.13-Swift/e9efa2e9db24d47e85d16911aa56d2c09c034b88/Images/Icon-Small.png -------------------------------------------------------------------------------- /Images/Icon-Small@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ooper-shlab/GLPaint1.13-Swift/e9efa2e9db24d47e85d16911aa56d2c09c034b88/Images/Icon-Small@2x.png -------------------------------------------------------------------------------- /Images/Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ooper-shlab/GLPaint1.13-Swift/e9efa2e9db24d47e85d16911aa56d2c09c034b88/Images/Icon.png -------------------------------------------------------------------------------- /Images/Icon@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ooper-shlab/GLPaint1.13-Swift/e9efa2e9db24d47e85d16911aa56d2c09c034b88/Images/Icon@2x.png -------------------------------------------------------------------------------- /Images/Purple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ooper-shlab/GLPaint1.13-Swift/e9efa2e9db24d47e85d16911aa56d2c09c034b88/Images/Purple.png -------------------------------------------------------------------------------- /Images/Red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ooper-shlab/GLPaint1.13-Swift/e9efa2e9db24d47e85d16911aa56d2c09c034b88/Images/Red.png -------------------------------------------------------------------------------- /Images/Yellow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ooper-shlab/GLPaint1.13-Swift/e9efa2e9db24d47e85d16911aa56d2c09c034b88/Images/Yellow.png -------------------------------------------------------------------------------- /Images/iTunesArtwork: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ooper-shlab/GLPaint1.13-Swift/e9efa2e9db24d47e85d16911aa56d2c09c034b88/Images/iTunesArtwork -------------------------------------------------------------------------------- /LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 30 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /Particle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ooper-shlab/GLPaint1.13-Swift/e9efa2e9db24d47e85d16911aa56d2c09c034b88/Particle.png -------------------------------------------------------------------------------- /Prefix.pch: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | 4 | #ifdef __OBJC__ 5 | #import 6 | #endif 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GLPaint 2 | 3 | Translated by OOPer in cooperation with shlab.jp, on 2015/1/5. 4 | 5 | Based on 6 | 7 | 2014-05-19. 8 | 9 | As this is a line-by-line translation from the original sample code, "redistribute the Apple Software in its entirety and without modifications" would apply. See license terms in each file . 10 | Some faults caused by my translation may exist. Not all features tested. 11 | You should not contact to Apple or SHLab(jp) about any faults caused by my translation. 12 | 13 | =========================================================================== 14 | ### BUILD REQUIREMENTS: 15 | 16 | Xcode 10.2, iOS SDK 12.2 17 | 18 | ================================================================================ 19 | ### RUNTIME REQUIREMENTS: 20 | 21 | iOS 8.0 or later 22 | 23 | =========================================================================== 24 | Some utility files are used to make line-by-line translation easier. They have another license terms. 25 | See license terms in each file. 26 | -------------------------------------------------------------------------------- /ReadMe.txt: -------------------------------------------------------------------------------- 1 | ### GLPaint ### 2 | 3 | ================================================================================ 4 | DESCRIPTION: 5 | 6 | The GLPaint sample application demonstrates how to support single finger painting using OpenGL ES. This sample also shows how to detect a "shake" motion of the device. 7 | 8 | By looking at the code you'll see how to set up an OpenGL ES view and use it for rendering painting strokes. The application creates a brush texture from an image by first drawing the image into a Core Graphics bitmap context. It then uses the bitmap data for the texture. 9 | 10 | To use this sample, open it in Xcode and click Build and Go. After the application paints "Shake Me", shake the device to erase the words. Touch a color to choose it. Paint by dragging a finger. 11 | 12 | NOTE: When you run the application in the simulator, you can use the Shake Gesture key under Hardware to simulate the shake motion. 13 | 14 | ================================================================================ 15 | BUILD REQUIREMENTS: 16 | 17 | iOS 7.0 SDK 18 | 19 | ================================================================================ 20 | RUNTIME REQUIREMENTS: 21 | 22 | iOS 5.0 or later 23 | 24 | ================================================================================ 25 | PACKAGING LIST: 26 | 27 | AppController.h 28 | AppController.m 29 | UIApplication's delegate class. 30 | 31 | PaintingViewController.h 32 | PaintingViewController.m 33 | The central controller of the application. Handles shake and other motion events. 34 | 35 | PaintingView.h 36 | PaintingView.m 37 | The class responsible for the finger painting. The class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass. The view content is basically an EAGL surface you render your OpenGL scene into. 38 | 39 | SoundEffect.h 40 | SoundEffect.m 41 | A simple Objective-C wrapper around Audio Services functions that allow the loading and playing of sound files. 42 | 43 | main.m 44 | The main entry point for the GLPaint application. 45 | 46 | Recording.data 47 | Contains the path used to display "Shake Me" after the application launches. 48 | 49 | Particle.png 50 | The texture used for the paint brush. 51 | 52 | ================================================================================ 53 | CHANGES FROM PREVIOUS VERSIONS: 54 | 55 | Version 1.13 56 | Updated for iOS 7 and 64-bit. 57 | 58 | Version 1.12 59 | Updated with OpenGL ES 2.0. Added a root view controller. Moved main controls from the UIApplication delegate to the new PaintingViewController class. Replaced the HSL2RGB() function with UIColor's +colorWithHue:saturation:brightness:alpha:. 60 | 61 | Version 1.11 62 | Updated to take into account the view's contentScaleFactor. 63 | Updated to draw strictly with premultiplied alpha pixel data. 64 | 65 | Version 1.9 66 | Upgraded project to build with the iOS 4.0 SDK. 67 | Fixed minor bugs. 68 | 69 | Version 1.8 70 | Removed duplicate lines in setting up OpenGL blending. 71 | 72 | Version 1.7 73 | Updated for iPhone OS 3.1. Set texture parameters before creating the texture. This will save texture memory and texture loading time. 74 | Use the shake API available in iPhone OS 3.0 and later. 75 | Made the sample xib-based. 76 | 77 | Version 1.6 78 | Updated for and tested with iPhone OS 2.0. First public release. 79 | 80 | Version 1.5 81 | Minor changes to the comments. 82 | There are no code changes in this version. 83 | 84 | Version 1.4 85 | Updated for Beta 6. 86 | Updated code to use revised EAGL API. 87 | Removed TouchView and Texture2D classes. 88 | Replaced the views used to choose brush color with a segmented control. 89 | Replace the Texture2D class with code that creates a texture using a Core Graphic bitmap graphics context. 90 | Speeded up the "Shake Me" instructions that appear at the start of the application. 91 | Revised touch handling to use the begin, moved, end, and cancelled methods instead of touchesChanged:withEvent; 92 | 93 | Version 1.3 94 | Updated for Beta 4. 95 | Changed project setting related to code signing. 96 | Replaced pixel buffer objects with framebuffer objects. 97 | 98 | Version 1.2 99 | Added an icon and a default.png file. 100 | 101 | Version 1.1 102 | Updated for Beta 2. 103 | 104 | ================================================================================ 105 | Copyright (C) 2009-2014 Apple Inc. All rights reserved. -------------------------------------------------------------------------------- /Recording.data: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | AAB4QgAAt0MAAFBCAIC1QwAAMEIAgLRDAAAUQgAAskMAAOhBAACvQwAAwEEAgKxDAAC4 7 | QQCAqkMAALhBAICnQwAAPEIAAKRDAABsQgCAokMAAIxCAIChQwAAlEIAgJ9DAACWQgCA 8 | nkMAAI5CAICbQwAAbEIAAJhDAAAkQgAAlEMAAKBBAACOQwAAgEEAgIxDAABwQQAAjEMA 9 | AGBBAICLQwAAYEEAgItD 10 | 11 | 12 | AAC8QgAAsEMAAMJCAICoQwAAwkIAAKRDAADCQgCAnUMAAMJCAACYQwAAwEIAgJRDAADA 13 | QgCAkkMAAMBCAACRQwAAwEIAgJBDAADAQgCAkEM= 14 | 15 | 16 | AACoQgAAnEMAALpCAACdQwAAxEIAAJ1DAADQQgAAnUMAANpCAICdQwAA4kIAgJ5DAADs 17 | QgCAn0MAAOxCAICfQw== 18 | 19 | 20 | AAACQwAAsEMAAANDAACpQwAAA0MAAKVDAAADQwAAn0MAAANDAICZQwAAA0MAAJVDAAAD 21 | QwAAkkMAAANDAACSQw== 22 | 23 | 24 | AAAVQwCAiUMAABdDAICMQwAAF0MAAJBDAAAYQwCAlUMAABtDAACcQwAAI0MAAKRDAAAr 25 | QwAArEMAADFDAICxQwAANkMAgLRDAAA6QwAAtkMAAD1DAIC2QwAAP0MAgLVDAABAQwAA 26 | skMAAEFDAACuQwAAQkMAgKhDAABCQwAApEMAAEJDAACeQwAAQkMAgJhDAABCQwCAlkMA 27 | AD5DAICTQwAAPkMAgJND 28 | 29 | 30 | AAAhQwCAoEMAADRDAIChQwAAO0MAAKJDAABAQwCAokMAAEZDAICiQwAARkMAgKJD 31 | 32 | 33 | AABbQwAAs0MAAFtDAICsQwAAW0MAAKhDAABbQwAAokMAAFpDAICaQwAAWEMAgJVDAABX 34 | QwAAkkMAAFdDAACQQwAAV0MAAI9DAABXQwAAjkMAAFdDAACQQwAAWUMAAJRDAABfQwAA 35 | mUMAAGVDAACfQwAAa0MAAKNDAABxQwCApkMAAHZDAACpQwAAeUMAAKtDAAB9QwCArEMA 36 | AH9DAICtQwCAgEMAgK5DAACBQwAAr0MAgIFDAACvQwCAgUMAAK9D 37 | 38 | 39 | AABlQwAAn0MAAG5DAICbQwAAckMAgJtDAAB3QwAAm0MAAHtDAACaQwAAf0MAAJlDAICA 40 | QwCAmEMAgIFDAACYQwCAgkMAAJdDAACEQwCAlUMAAIRDAICVQw== 41 | 42 | 43 | AACOQwAAsUMAAI1DAACtQwAAjUMAgKlDAACMQwAApkMAgIpDAAChQwAAiUMAAJxDAICI 44 | QwAAmUMAgIhDAICWQwCAiEMAgJRDAICIQwAAk0MAAIlDAACSQwAAi0MAgJFDAICNQwCA 45 | kUMAgJJDAICRQwCAlEMAgJJDAICWQwCAk0MAAJlDAICUQwAAmkMAAJVDAICaQwAAlUMA 46 | gJpDAACVQw== 47 | 48 | 49 | AICJQwCAoUMAgI1DAACiQwCAj0MAAKJDAACSQwAAokMAgJNDAICiQwAAlUMAgKJDAACV 50 | QwCAokM= 51 | 52 | 53 | AICNQwCAr0MAgJNDAACyQwAAl0MAgLJDAACaQwAAtEMAAJxDAIC0QwAAnEMAgLRD 54 | 55 | 56 | AABcQgAAJUMAAFRCAAAeQwAAVEIAABNDAABUQgAACEMAAFRCAAD+QgAAVEIAAPBCAABU 57 | QgAA5EIAAFRCAADcQgAAVEIAANpCAABUQgAA2EIAAFRCAADaQgAAVEIAAOZCAABYQgAA 58 | A0MAAGRCAAAfQwAAaEIAADFDAABsQgAAPUMAAGxCAABEQwAAdEIAAElDAACAQgAASEMA 59 | AI5CAABCQwAAoEIAAD1DAAC0QgAAOUMAAMZCAAA4QwAA3EIAADhDAADsQgAAPUMAAPRC 60 | AABBQwAA/kIAAEZDAAAAQwAARkMAAABDAAA/QwAAAEMAADNDAAAAQwAAIUMAAP5CAAAP 61 | QwAA/kIAAP5CAAD+QgAA5EIAAP5CAADUQgAA/kIAAMhCAAAAQwAAxkIAAABDAADGQg== 62 | 63 | 64 | AAAvQwAATEMAACxDAABDQwAALEMAADpDAAArQwAALUMAACpDAAAgQwAAKUMAABFDAAAo 65 | QwAABkMAACZDAAD8QgAAJUMAAOpCAAAlQwAA3kIAACVDAADWQgAAKkMAANJCAAAzQwAA 66 | 0kIAADxDAADcQgAARkMAAOZCAABQQwAA7kIAAFhDAAD0QgAAXUMAAPZCAABjQwAA+kIA 67 | AGNDAAD6Qg== 68 | 69 | 70 | AAA0QwAAFUMAAEFDAAAYQwAATUMAABpDAABaQwAAHkMAAGZDAAAkQwAAcEMAACpDAAB0 71 | QwAAL0MAAHRDAAAvQw== 72 | 73 | 74 | AAAxQwAAPUMAAD9DAABAQwAATUMAAEFDAABbQwAARUMAAGhDAABKQwAAcUMAAE1DAAB5 75 | QwAAUEMAAHlDAABQQw== 76 | 77 | 78 | AICEQwAAb0MAAIZDAABjQwCAhkMAAFdDAACHQwAARkMAgIdDAAAyQwCAiEMAACBDAACJ 79 | QwAAFkMAgIlDAAAOQwCAikMAAAVDAICKQwAABUM= 80 | 81 | 82 | AICNQwAAukIAgI1DAAC6Qg== 83 | 84 | 85 | AACTQwAArkIAgI5DAACiQgAAjkMAAKJCAACOQwAAoEIAAI5DAACeQgCAjkMAAKBCAICO 86 | QwAApEIAgI5DAACmQgCAjkMAAKhCAACOQwAAqEIAAI1DAACoQgAAjUMAAKZCAACNQwAA 87 | pEIAAI1DAACkQg== 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /Select.caf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ooper-shlab/GLPaint1.13-Swift/e9efa2e9db24d47e85d16911aa56d2c09c034b88/Select.caf -------------------------------------------------------------------------------- /Shaders/point.fsh: -------------------------------------------------------------------------------- 1 | /* 2 | File: color.fsh 3 | Abstract: A fragment shader that draws points with assigned color and 4 | texture. 5 | Version: 1.13 6 | 7 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 8 | Inc. ("Apple") in consideration of your agreement to the following 9 | terms, and your use, installation, modification or redistribution of 10 | this Apple software constitutes acceptance of these terms. If you do 11 | not agree with these terms, please do not use, install, modify or 12 | redistribute this Apple software. 13 | 14 | In consideration of your agreement to abide by the following terms, and 15 | subject to these terms, Apple grants you a personal, non-exclusive 16 | license, under Apple's copyrights in this original Apple software (the 17 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 18 | Software, with or without modifications, in source and/or binary forms; 19 | provided that if you redistribute the Apple Software in its entirety and 20 | without modifications, you must retain this notice and the following 21 | text and disclaimers in all such redistributions of the Apple Software. 22 | Neither the name, trademarks, service marks or logos of Apple Inc. may 23 | be used to endorse or promote products derived from the Apple Software 24 | without specific prior written permission from Apple. Except as 25 | expressly stated in this notice, no other rights or licenses, express or 26 | implied, are granted by Apple herein, including but not limited to any 27 | patent rights that may be infringed by your derivative works or by other 28 | works in which the Apple Software may be incorporated. 29 | 30 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 31 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 32 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 33 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 34 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 35 | 36 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 37 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 38 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 39 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 40 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 41 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 42 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 43 | POSSIBILITY OF SUCH DAMAGE. 44 | 45 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 46 | 47 | */ 48 | 49 | uniform sampler2D texture; 50 | varying lowp vec4 color; 51 | 52 | void main() 53 | { 54 | gl_FragColor = color * texture2D(texture, gl_PointCoord); 55 | } 56 | -------------------------------------------------------------------------------- /Shaders/point.vsh: -------------------------------------------------------------------------------- 1 | /* 2 | File: color.vsh 3 | Abstract: A vertex shader that draws points with assigned color. 4 | Version: 1.13 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | attribute vec4 inVertex; 49 | 50 | uniform mat4 MVP; 51 | uniform float pointSize; 52 | uniform lowp vec4 vertexColor; 53 | 54 | varying lowp vec4 color; 55 | 56 | void main() 57 | { 58 | gl_Position = MVP * inVertex; 59 | gl_PointSize = pointSize; 60 | color = vertexColor; 61 | } 62 | -------------------------------------------------------------------------------- /main.m: -------------------------------------------------------------------------------- 1 | /* 2 | File: main.m 3 | Abstract: The main entry point for GLPaint. 4 | Version: 1.13 5 | 6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 7 | Inc. ("Apple") in consideration of your agreement to the following 8 | terms, and your use, installation, modification or redistribution of 9 | this Apple software constitutes acceptance of these terms. If you do 10 | not agree with these terms, please do not use, install, modify or 11 | redistribute this Apple software. 12 | 13 | In consideration of your agreement to abide by the following terms, and 14 | subject to these terms, Apple grants you a personal, non-exclusive 15 | license, under Apple's copyrights in this original Apple software (the 16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 17 | Software, with or without modifications, in source and/or binary forms; 18 | provided that if you redistribute the Apple Software in its entirety and 19 | without modifications, you must retain this notice and the following 20 | text and disclaimers in all such redistributions of the Apple Software. 21 | Neither the name, trademarks, service marks or logos of Apple Inc. may 22 | be used to endorse or promote products derived from the Apple Software 23 | without specific prior written permission from Apple. Except as 24 | expressly stated in this notice, no other rights or licenses, express or 25 | implied, are granted by Apple herein, including but not limited to any 26 | patent rights that may be infringed by your derivative works or by other 27 | works in which the Apple Software may be incorporated. 28 | 29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 34 | 35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 42 | POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2014 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | #import 49 | 50 | int main(int argc, char *argv[]) 51 | { 52 | @autoreleasepool { 53 | int retVal = UIApplicationMain(argc, argv, nil, nil); 54 | return retVal; 55 | } 56 | } 57 | --------------------------------------------------------------------------------