Skip to content

Commit 5fdd454

Browse files
committed
First push
1 parent 9b049a0 commit 5fdd454

File tree

9 files changed

+400
-8
lines changed

9 files changed

+400
-8
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#OpenGL for iOS using Swift
2+
3+
![example output]()
4+
5+
A basic example of using OpenGL and GLSL Shaders in iOS using Swift.
6+
7+
*The code in this project is a direct port of of the Objective-C code for OpenGL in iOS outlined by Ray Wenderlich in his [OpenGL for iOS Tutorial](http://www.raywenderlich.com/3664/opengl-tutorial-for-ios-opengl-es-2-0).*

SimpleFragment.glsl

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
varying lowp vec4 DestinationColor;
2+
3+
void main(void) {
4+
gl_FragColor = DestinationColor;
5+
}

SimpleVertex.glsl

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
attribute vec4 Position;
2+
attribute vec4 SourceColor;
3+
4+
varying vec4 DestinationColor;
5+
6+
void main(void) {
7+
DestinationColor = SourceColor;
8+
gl_Position = Position;
9+
}

example.png

70.2 KB
Loading

iOSSwiftOpenGL.xcodeproj/project.pbxproj

+23-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
AD8814701960EEBF005F2E41 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = AD88146E1960EEBF005F2E41 /* Main.storyboard */; };
1414
AD8814721960EEBF005F2E41 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = AD8814711960EEBF005F2E41 /* Images.xcassets */; };
1515
AD88147E1960EEBF005F2E41 /* iOSSwiftOpenGLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD88147D1960EEBF005F2E41 /* iOSSwiftOpenGLTests.swift */; };
16+
AD88148A1960EF38005F2E41 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AD8814891960EF38005F2E41 /* OpenGLES.framework */; };
17+
AD88148C1960EFBA005F2E41 /* SimpleVertex.glsl in Resources */ = {isa = PBXBuildFile; fileRef = AD88148B1960EFBA005F2E41 /* SimpleVertex.glsl */; };
18+
AD88148E1960EFCE005F2E41 /* SimpleFragment.glsl in Resources */ = {isa = PBXBuildFile; fileRef = AD88148D1960EFCE005F2E41 /* SimpleFragment.glsl */; };
19+
AD8814901960F047005F2E41 /* Images.xcassets in Sources */ = {isa = PBXBuildFile; fileRef = AD8814711960EEBF005F2E41 /* Images.xcassets */; };
20+
AD8814911960F27B005F2E41 /* OpenGLView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD8814871960EEDA005F2E41 /* OpenGLView.swift */; };
1621
/* End PBXBuildFile section */
1722

1823
/* Begin PBXContainerItemProxy section */
@@ -36,13 +41,18 @@
3641
AD8814771960EEBF005F2E41 /* iOSSwiftOpenGLTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = iOSSwiftOpenGLTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
3742
AD88147C1960EEBF005F2E41 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3843
AD88147D1960EEBF005F2E41 /* iOSSwiftOpenGLTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iOSSwiftOpenGLTests.swift; sourceTree = "<group>"; };
44+
AD8814871960EEDA005F2E41 /* OpenGLView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenGLView.swift; sourceTree = "<group>"; };
45+
AD8814891960EF38005F2E41 /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; };
46+
AD88148B1960EFBA005F2E41 /* SimpleVertex.glsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = SimpleVertex.glsl; path = ../SimpleVertex.glsl; sourceTree = "<group>"; };
47+
AD88148D1960EFCE005F2E41 /* SimpleFragment.glsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = SimpleFragment.glsl; path = ../SimpleFragment.glsl; sourceTree = "<group>"; };
3948
/* End PBXFileReference section */
4049

4150
/* Begin PBXFrameworksBuildPhase section */
4251
AD88145F1960EEBF005F2E41 /* Frameworks */ = {
4352
isa = PBXFrameworksBuildPhase;
4453
buildActionMask = 2147483647;
4554
files = (
55+
AD88148A1960EF38005F2E41 /* OpenGLES.framework in Frameworks */,
4656
);
4757
runOnlyForDeploymentPostprocessing = 0;
4858
};
@@ -59,6 +69,7 @@
5969
AD8814591960EEBF005F2E41 = {
6070
isa = PBXGroup;
6171
children = (
72+
AD8814891960EF38005F2E41 /* OpenGLES.framework */,
6273
AD8814641960EEBF005F2E41 /* iOSSwiftOpenGL */,
6374
AD88147A1960EEBF005F2E41 /* iOSSwiftOpenGLTests */,
6475
AD8814631960EEBF005F2E41 /* Products */,
@@ -79,9 +90,7 @@
7990
children = (
8091
AD8814671960EEBF005F2E41 /* AppDelegate.swift */,
8192
AD88146C1960EEBF005F2E41 /* ViewController.swift */,
82-
AD88146E1960EEBF005F2E41 /* Main.storyboard */,
83-
AD8814711960EEBF005F2E41 /* Images.xcassets */,
84-
AD8814691960EEBF005F2E41 /* iOSSwiftOpenGL.xcdatamodeld */,
93+
AD8814871960EEDA005F2E41 /* OpenGLView.swift */,
8594
AD8814651960EEBF005F2E41 /* Supporting Files */,
8695
);
8796
path = iOSSwiftOpenGL;
@@ -90,6 +99,11 @@
9099
AD8814651960EEBF005F2E41 /* Supporting Files */ = {
91100
isa = PBXGroup;
92101
children = (
102+
AD88146E1960EEBF005F2E41 /* Main.storyboard */,
103+
AD88148D1960EFCE005F2E41 /* SimpleFragment.glsl */,
104+
AD88148B1960EFBA005F2E41 /* SimpleVertex.glsl */,
105+
AD8814711960EEBF005F2E41 /* Images.xcassets */,
106+
AD8814691960EEBF005F2E41 /* iOSSwiftOpenGL.xcdatamodeld */,
93107
AD8814661960EEBF005F2E41 /* Info.plist */,
94108
);
95109
name = "Supporting Files";
@@ -193,7 +207,9 @@
193207
buildActionMask = 2147483647;
194208
files = (
195209
AD8814701960EEBF005F2E41 /* Main.storyboard in Resources */,
210+
AD88148E1960EFCE005F2E41 /* SimpleFragment.glsl in Resources */,
196211
AD8814721960EEBF005F2E41 /* Images.xcassets in Resources */,
212+
AD88148C1960EFBA005F2E41 /* SimpleVertex.glsl in Resources */,
197213
);
198214
runOnlyForDeploymentPostprocessing = 0;
199215
};
@@ -211,8 +227,10 @@
211227
isa = PBXSourcesBuildPhase;
212228
buildActionMask = 2147483647;
213229
files = (
230+
AD8814901960F047005F2E41 /* Images.xcassets in Sources */,
214231
AD88146D1960EEBF005F2E41 /* ViewController.swift in Sources */,
215232
AD88146B1960EEBF005F2E41 /* iOSSwiftOpenGL.xcdatamodeld in Sources */,
233+
AD8814911960F27B005F2E41 /* OpenGLView.swift in Sources */,
216234
AD8814681960EEBF005F2E41 /* AppDelegate.swift in Sources */,
217235
);
218236
runOnlyForDeploymentPostprocessing = 0;
@@ -401,6 +419,7 @@
401419
AD8814831960EEBF005F2E41 /* Release */,
402420
);
403421
defaultConfigurationIsVisible = 0;
422+
defaultConfigurationName = Release;
404423
};
405424
AD8814841960EEBF005F2E41 /* Build configuration list for PBXNativeTarget "iOSSwiftOpenGLTests" */ = {
406425
isa = XCConfigurationList;
@@ -409,6 +428,7 @@
409428
AD8814861960EEBF005F2E41 /* Release */,
410429
);
411430
defaultConfigurationIsVisible = 0;
431+
defaultConfigurationName = Release;
412432
};
413433
/* End XCConfigurationList section */
414434

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "0600"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "AD8814611960EEBF005F2E41"
18+
BuildableName = "iOSSwiftOpenGL.app"
19+
BlueprintName = "iOSSwiftOpenGL"
20+
ReferencedContainer = "container:iOSSwiftOpenGL.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
27+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
28+
shouldUseLaunchSchemeArgsEnv = "YES"
29+
buildConfiguration = "Debug">
30+
<Testables>
31+
<TestableReference
32+
skipped = "NO">
33+
<BuildableReference
34+
BuildableIdentifier = "primary"
35+
BlueprintIdentifier = "AD8814761960EEBF005F2E41"
36+
BuildableName = "iOSSwiftOpenGLTests.xctest"
37+
BlueprintName = "iOSSwiftOpenGLTests"
38+
ReferencedContainer = "container:iOSSwiftOpenGL.xcodeproj">
39+
</BuildableReference>
40+
</TestableReference>
41+
</Testables>
42+
<MacroExpansion>
43+
<BuildableReference
44+
BuildableIdentifier = "primary"
45+
BlueprintIdentifier = "AD8814611960EEBF005F2E41"
46+
BuildableName = "iOSSwiftOpenGL.app"
47+
BlueprintName = "iOSSwiftOpenGL"
48+
ReferencedContainer = "container:iOSSwiftOpenGL.xcodeproj">
49+
</BuildableReference>
50+
</MacroExpansion>
51+
</TestAction>
52+
<LaunchAction
53+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
54+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
55+
launchStyle = "0"
56+
useCustomWorkingDirectory = "NO"
57+
buildConfiguration = "Debug"
58+
ignoresPersistentStateOnLaunch = "NO"
59+
debugDocumentVersioning = "YES"
60+
allowLocationSimulation = "YES">
61+
<BuildableProductRunnable>
62+
<BuildableReference
63+
BuildableIdentifier = "primary"
64+
BlueprintIdentifier = "AD8814611960EEBF005F2E41"
65+
BuildableName = "iOSSwiftOpenGL.app"
66+
BlueprintName = "iOSSwiftOpenGL"
67+
ReferencedContainer = "container:iOSSwiftOpenGL.xcodeproj">
68+
</BuildableReference>
69+
</BuildableProductRunnable>
70+
<AdditionalOptions>
71+
</AdditionalOptions>
72+
</LaunchAction>
73+
<ProfileAction
74+
shouldUseLaunchSchemeArgsEnv = "YES"
75+
savedToolIdentifier = ""
76+
useCustomWorkingDirectory = "NO"
77+
buildConfiguration = "Release"
78+
debugDocumentVersioning = "YES">
79+
<BuildableProductRunnable>
80+
<BuildableReference
81+
BuildableIdentifier = "primary"
82+
BlueprintIdentifier = "AD8814611960EEBF005F2E41"
83+
BuildableName = "iOSSwiftOpenGL.app"
84+
BlueprintName = "iOSSwiftOpenGL"
85+
ReferencedContainer = "container:iOSSwiftOpenGL.xcodeproj">
86+
</BuildableReference>
87+
</BuildableProductRunnable>
88+
</ProfileAction>
89+
<AnalyzeAction
90+
buildConfiguration = "Debug">
91+
</AnalyzeAction>
92+
<ArchiveAction
93+
buildConfiguration = "Release"
94+
revealArchiveInOrganizer = "YES">
95+
</ArchiveAction>
96+
</Scheme>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>SchemeUserState</key>
6+
<dict>
7+
<key>iOSSwiftOpenGL.xcscheme</key>
8+
<dict>
9+
<key>orderHint</key>
10+
<integer>0</integer>
11+
</dict>
12+
</dict>
13+
<key>SuppressBuildableAutocreation</key>
14+
<dict>
15+
<key>AD8814611960EEBF005F2E41</key>
16+
<dict>
17+
<key>primary</key>
18+
<true/>
19+
</dict>
20+
<key>AD8814761960EEBF005F2E41</key>
21+
<dict>
22+
<key>primary</key>
23+
<true/>
24+
</dict>
25+
</dict>
26+
</dict>
27+
</plist>

iOSSwiftOpenGL/Base.lproj/Main.storyboard

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6162" systemVersion="14A238h" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6154.21" systemVersion="14A261i" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
33
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6160"/>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6153.13"/>
55
</dependencies>
66
<scenes>
77
<!--View Controller-->
88
<scene sceneID="ufC-wZ-h7g">
99
<objects>
10-
<viewController id="vXZ-lx-hvc" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
10+
<viewController id="vXZ-lx-hvc" customClass="ViewController" customModule="iOSSwiftOpenGL" customModuleProvider="target" sceneMemberID="viewController">
1111
<layoutGuides>
1212
<viewControllerLayoutGuide type="top" id="jyV-Pf-zRb"/>
1313
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
1414
</layoutGuides>
15-
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
15+
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS" customClass="OpenGLView" customModule="iOSSwiftOpenGL" customModuleProvider="target">
1616
<rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
1717
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
18-
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
18+
<color key="backgroundColor" red="1" green="0.52648174316488017" blue="0.48974023977280912" alpha="1" colorSpace="calibratedRGB"/>
19+
<simulatedOrientationMetrics key="simulatedOrientationMetrics" orientation="landscapeRight"/>
1920
</view>
2021
</viewController>
2122
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>

0 commit comments

Comments
 (0)