diff --git a/GLSLBasicsCocoaDL.zip b/GLSLBasicsCocoaDL.zip new file mode 100644 index 00000000..e7eb3a90 Binary files /dev/null and b/GLSLBasicsCocoaDL.zip differ diff --git a/GLSLBasicsCocoaDL/English.lproj/InfoPlist.strings b/GLSLBasicsCocoaDL/English.lproj/InfoPlist.strings new file mode 100755 index 00000000..e0938285 Binary files /dev/null and b/GLSLBasicsCocoaDL/English.lproj/InfoPlist.strings differ diff --git a/GLSLBasicsCocoaDL/English.lproj/MainMenu.nib/designable.nib b/GLSLBasicsCocoaDL/English.lproj/MainMenu.nib/designable.nib new file mode 100644 index 00000000..d710d4a8 --- /dev/null +++ b/GLSLBasicsCocoaDL/English.lproj/MainMenu.nib/designable.nib @@ -0,0 +1,719 @@ + + + + 1050 + 9E17 + 670 + 949.33 + 352.00 + + YES + + + + + YES + com.apple.InterfaceBuilder.CocoaPlugin + + + YES + + + NSApplication + + + + FirstResponder + + + NSApplication + + + 13 + 2 + {{138, 511}, {512, 512}} + 1886912512 + GLSL Basics + NSWindow + + View + + {1024, 1024} + {256, 256} + + + 256 + + YES + + + 319 + {512, 512} + + GLSLBasicsView + NSOpenGLView + + + {512, 512} + + + {{0, 0}, {1680, 1028}} + {256, 278} + {1024, 1046} + + + MainMenu + + YES + + + GLSL Basics + + 1048576 + 2147483647 + + NSImage + NSMenuCheckmark + + + NSImage + NSMenuMixedState + + submenuAction: + + GLSL Basics + + YES + + + About GLSL Basics + + 2147483647 + + + + + + YES + YES + + + 1048576 + 2147483647 + + + + + + UHJlZmVyZW5jZXPigKY + , + 1048576 + 2147483647 + + + + + + YES + YES + + + 1048576 + 2147483647 + + + + + + Services + + 1048576 + 2147483647 + + + submenuAction: + + + Services + + + YES + + _NSServicesMenu + + + + + YES + YES + + + 1048576 + 2147483647 + + + + + + Hide GLSL Basics + h + 1048576 + 2147483647 + + + + + + Hide Others + h + 1572864 + 2147483647 + + + + + + Show All + + 1048576 + 2147483647 + + + + + + YES + YES + + + 1048576 + 2147483647 + + + + + + Quit GLSL Basics + q + 1048576 + 2147483647 + + + + + _NSAppleMenu + + + + + Window + + 1048576 + 2147483647 + + + submenuAction: + + + Window + + + YES + + + Minimize + m + 1048576 + 2147483647 + + + + + + Zoom + + 1048576 + 2147483647 + + + + + + YES + YES + + + 1048576 + 2147483647 + + + + + + Bring All to Front + + 1048576 + 2147483647 + + + + + _NSWindowsMenu + + + + _NSMainMenu + + + + + YES + + + performMiniaturize: + + + + 37 + + + + arrangeInFront: + + + + 39 + + + + terminate: + + + + 139 + + + + orderFrontStandardAboutPanel: + + + + 142 + + + + hideOtherApplications: + + + + 146 + + + + hide: + + + + 152 + + + + unhideAllApplications: + + + + 153 + + + + performZoom: + + + + 198 + + + + + YES + + 0 + + YES + + + + + + -2 + + + RmlsZSdzIE93bmVyA + + + -1 + + + First Responder + + + -3 + + + Application + + + 21 + + + YES + + + + Window + + + 2 + + + YES + + + + + + 206 + + + + + 29 + + + YES + + + + + MainMenu + + + 19 + + + YES + + + + + + 24 + + + YES + + + + + + + + + 5 + + + + + 23 + + + + + 92 + + + + + 197 + + + + + 56 + + + YES + + + + + + 57 + + + YES + + + + + + + + + + + + + + + + 58 + + + + + 129 + + + + + 131 + + + YES + + + + + + 130 + + + + + 134 + + + + + 136 + + + + + 143 + + + + + 144 + + + + + 145 + + + + + 149 + + + + + 150 + + + + + 196 + + + + + + + YES + + YES + -1.IBPluginDependency + -2.IBPluginDependency + -3.IBPluginDependency + -3.ImportedFromIB2 + 129.IBPluginDependency + 129.ImportedFromIB2 + 130.IBPluginDependency + 130.ImportedFromIB2 + 131.IBPluginDependency + 131.ImportedFromIB2 + 134.IBPluginDependency + 134.ImportedFromIB2 + 136.IBPluginDependency + 136.ImportedFromIB2 + 143.IBPluginDependency + 143.ImportedFromIB2 + 144.IBPluginDependency + 144.ImportedFromIB2 + 145.IBPluginDependency + 145.ImportedFromIB2 + 149.IBPluginDependency + 149.ImportedFromIB2 + 150.IBPluginDependency + 150.ImportedFromIB2 + 19.IBPluginDependency + 19.ImportedFromIB2 + 196.IBPluginDependency + 196.ImportedFromIB2 + 197.IBPluginDependency + 197.ImportedFromIB2 + 2.IBPluginDependency + 2.ImportedFromIB2 + 206.IBPluginDependency + 206.ImportedFromIB2 + 21.IBEditorWindowLastContentRect + 21.IBPluginDependency + 21.IBWindowTemplateEditedContentRect + 21.ImportedFromIB2 + 21.NSWindowTemplate.visibleAtLaunch + 21.windowTemplate.hasMaxSize + 21.windowTemplate.hasMinSize + 21.windowTemplate.maxSize + 21.windowTemplate.minSize + 23.IBPluginDependency + 23.ImportedFromIB2 + 24.IBPluginDependency + 24.ImportedFromIB2 + 29.IBEditorWindowLastContentRect + 29.IBPluginDependency + 29.ImportedFromIB2 + 5.IBPluginDependency + 5.ImportedFromIB2 + 56.IBPluginDependency + 56.ImportedFromIB2 + 57.IBPluginDependency + 57.ImportedFromIB2 + 58.IBPluginDependency + 58.ImportedFromIB2 + 92.IBPluginDependency + 92.ImportedFromIB2 + + + YES + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + {{0, 472}, {512, 512}} + com.apple.InterfaceBuilder.CocoaPlugin + {{0, 472}, {512, 512}} + + + + + {1024, 1024} + {256, 256} + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + {{0, 975}, {198, 20}} + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + + + + YES + + YES + + + YES + + + + + YES + + YES + + + YES + + + + 208 + + + + YES + + FirstResponder + NSObject + + IBUserSource + + + + + GLSLBasicsView + NSOpenGLView + + IBProjectSource + GLSLBasicsView.h + + + + GLSLBasicsView + NSOpenGLView + + IBUserSource + + + + + + 0 + ../GLSLBasicsCocoaDL.xcodeproj + 3 + + diff --git a/GLSLBasicsCocoaDL/English.lproj/MainMenu.nib/keyedobjects.nib b/GLSLBasicsCocoaDL/English.lproj/MainMenu.nib/keyedobjects.nib new file mode 100644 index 00000000..52d228e7 Binary files /dev/null and b/GLSLBasicsCocoaDL/English.lproj/MainMenu.nib/keyedobjects.nib differ diff --git a/GLSLBasicsCocoaDL/GLSLBasicsCocoaDL.xcodeproj/project.pbxproj b/GLSLBasicsCocoaDL/GLSLBasicsCocoaDL.xcodeproj/project.pbxproj new file mode 100755 index 00000000..dff69a3d --- /dev/null +++ b/GLSLBasicsCocoaDL/GLSLBasicsCocoaDL.xcodeproj/project.pbxproj @@ -0,0 +1,336 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 44; + objects = { + +/* Begin PBXBuildFile section */ + 36B67AAF0E3657D600695250 /* TranguloidTrefoilGeometry.mm in Sources */ = {isa = PBXBuildFile; fileRef = 36B67AA30E3657D500695250 /* TranguloidTrefoilGeometry.mm */; }; + 36B67AB00E3657D600695250 /* GLUTString.m in Sources */ = {isa = PBXBuildFile; fileRef = 36B67AA60E3657D500695250 /* GLUTString.m */; }; + 36B67AB10E3657D600695250 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 36B67AA80E3657D500695250 /* main.m */; }; + 36B67AB20E3657D600695250 /* Plasma.fs in Resources */ = {isa = PBXBuildFile; fileRef = 36B67AAA0E3657D600695250 /* Plasma.fs */; }; + 36B67AB30E3657D600695250 /* Plasma.vs in Resources */ = {isa = PBXBuildFile; fileRef = 36B67AAB0E3657D600695250 /* Plasma.vs */; }; + 36B67AB40E3657D600695250 /* GLSLBasicsView.m in Sources */ = {isa = PBXBuildFile; fileRef = 36B67AAE0E3657D600695250 /* GLSLBasicsView.m */; }; + 36B67AD80E36590900695250 /* GLUT.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 36B67AD70E36590900695250 /* GLUT.framework */; }; + 36B67AFA0E365D1900695250 /* Shader.m in Sources */ = {isa = PBXBuildFile; fileRef = 36B67AF90E365D1900695250 /* Shader.m */; }; + 36C820A60E3FDB4E00049C5E /* GLSLHardwareSupport.c in Sources */ = {isa = PBXBuildFile; fileRef = 36C820A40E3FDB4E00049C5E /* GLSLHardwareSupport.c */; }; + 74E028770B819B0400B15674 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 74E028760B819B0400B15674 /* OpenGL.framework */; }; + 8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */ = {isa = PBXBuildFile; fileRef = 29B97318FDCFA39411CA2CEA /* MainMenu.nib */; }; + 8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; }; + 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 089C165DFE840E0CC02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = ""; }; + 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = ""; }; + 29B97319FDCFA39411CA2CEA /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/MainMenu.nib; sourceTree = ""; }; + 360B79C20C3D8C350085BCCF /* info.plist */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.plist.xml; path = info.plist; sourceTree = ""; }; + 36B67AA20E3657D500695250 /* TranguloidTrefoilGeometry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TranguloidTrefoilGeometry.h; sourceTree = ""; }; + 36B67AA30E3657D500695250 /* TranguloidTrefoilGeometry.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TranguloidTrefoilGeometry.mm; sourceTree = ""; }; + 36B67AA50E3657D500695250 /* GLUTString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GLUTString.h; sourceTree = ""; }; + 36B67AA60E3657D500695250 /* GLUTString.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GLUTString.m; sourceTree = ""; }; + 36B67AA80E3657D500695250 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 36B67AAA0E3657D600695250 /* Plasma.fs */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Plasma.fs; sourceTree = ""; }; + 36B67AAB0E3657D600695250 /* Plasma.vs */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Plasma.vs; sourceTree = ""; }; + 36B67AAD0E3657D600695250 /* GLSLBasicsView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GLSLBasicsView.h; sourceTree = ""; }; + 36B67AAE0E3657D600695250 /* GLSLBasicsView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GLSLBasicsView.m; sourceTree = ""; }; + 36B67AD70E36590900695250 /* GLUT.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GLUT.framework; path = /System/Library/Frameworks/GLUT.framework; sourceTree = ""; }; + 36B67AF80E365D1900695250 /* Shader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Shader.h; sourceTree = ""; }; + 36B67AF90E365D1900695250 /* Shader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Shader.m; sourceTree = ""; }; + 36C820A40E3FDB4E00049C5E /* GLSLHardwareSupport.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = GLSLHardwareSupport.c; sourceTree = ""; }; + 36C820A50E3FDB4E00049C5E /* GLSLHardwareSupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GLSLHardwareSupport.h; sourceTree = ""; }; + 74E028760B819B0400B15674 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = /System/Library/Frameworks/OpenGL.framework; sourceTree = ""; }; + 8D1107320486CEB800E47090 /* GLSLBasicsCocoaDL.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GLSLBasicsCocoaDL.app; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 8D11072E0486CEB800E47090 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */, + 74E028770B819B0400B15674 /* OpenGL.framework in Frameworks */, + 36B67AD80E36590900695250 /* GLUT.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 19C28FACFE9D520D11CA2CBB /* Products */ = { + isa = PBXGroup; + children = ( + 8D1107320486CEB800E47090 /* GLSLBasicsCocoaDL.app */, + ); + name = Products; + sourceTree = ""; + }; + 29B97314FDCFA39411CA2CEA /* SimpleFBO */ = { + isa = PBXGroup; + children = ( + 36B67AA00E3657D500695250 /* Sources */, + 29B97317FDCFA39411CA2CEA /* Resources */, + 29B97323FDCFA39411CA2CEA /* Frameworks */, + 19C28FACFE9D520D11CA2CBB /* Products */, + ); + name = SimpleFBO; + sourceTree = ""; + }; + 29B97317FDCFA39411CA2CEA /* Resources */ = { + isa = PBXGroup; + children = ( + 360B79C20C3D8C350085BCCF /* info.plist */, + 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */, + 29B97318FDCFA39411CA2CEA /* MainMenu.nib */, + ); + name = Resources; + sourceTree = ""; + }; + 29B97323FDCFA39411CA2CEA /* Frameworks */ = { + isa = PBXGroup; + children = ( + 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */, + 36B67AD70E36590900695250 /* GLUT.framework */, + 74E028760B819B0400B15674 /* OpenGL.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; + 36B67AA00E3657D500695250 /* Sources */ = { + isa = PBXGroup; + children = ( + 36B67AA10E3657D500695250 /* Geometry */, + 36B67AA40E3657D500695250 /* GLUT */, + 36C820A30E3FDB4E00049C5E /* Hardware */, + 36B67AA70E3657D500695250 /* Other */, + 36B67AA90E3657D500695250 /* Plasma */, + 36B67AF70E365D1900695250 /* Shader */, + 36B67AAC0E3657D600695250 /* View */, + ); + path = Sources; + sourceTree = ""; + }; + 36B67AA10E3657D500695250 /* Geometry */ = { + isa = PBXGroup; + children = ( + 36B67AA20E3657D500695250 /* TranguloidTrefoilGeometry.h */, + 36B67AA30E3657D500695250 /* TranguloidTrefoilGeometry.mm */, + ); + path = Geometry; + sourceTree = ""; + }; + 36B67AA40E3657D500695250 /* GLUT */ = { + isa = PBXGroup; + children = ( + 36B67AA50E3657D500695250 /* GLUTString.h */, + 36B67AA60E3657D500695250 /* GLUTString.m */, + ); + path = GLUT; + sourceTree = ""; + }; + 36B67AA70E3657D500695250 /* Other */ = { + isa = PBXGroup; + children = ( + 36B67AA80E3657D500695250 /* main.m */, + ); + path = Other; + sourceTree = ""; + }; + 36B67AA90E3657D500695250 /* Plasma */ = { + isa = PBXGroup; + children = ( + 36B67AAA0E3657D600695250 /* Plasma.fs */, + 36B67AAB0E3657D600695250 /* Plasma.vs */, + ); + path = Plasma; + sourceTree = ""; + }; + 36B67AAC0E3657D600695250 /* View */ = { + isa = PBXGroup; + children = ( + 36B67AAD0E3657D600695250 /* GLSLBasicsView.h */, + 36B67AAE0E3657D600695250 /* GLSLBasicsView.m */, + ); + path = View; + sourceTree = ""; + }; + 36B67AF70E365D1900695250 /* Shader */ = { + isa = PBXGroup; + children = ( + 36B67AF80E365D1900695250 /* Shader.h */, + 36B67AF90E365D1900695250 /* Shader.m */, + ); + path = Shader; + sourceTree = ""; + }; + 36C820A30E3FDB4E00049C5E /* Hardware */ = { + isa = PBXGroup; + children = ( + 36C820A40E3FDB4E00049C5E /* GLSLHardwareSupport.c */, + 36C820A50E3FDB4E00049C5E /* GLSLHardwareSupport.h */, + ); + path = Hardware; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 8D1107260486CEB800E47090 /* GLSL Basics Cocoa */ = { + isa = PBXNativeTarget; + buildConfigurationList = C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "GLSL Basics Cocoa" */; + buildPhases = ( + 8D1107290486CEB800E47090 /* Resources */, + 8D11072C0486CEB800E47090 /* Sources */, + 8D11072E0486CEB800E47090 /* Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "GLSL Basics Cocoa"; + productInstallPath = "$(HOME)/Applications"; + productName = SimpleFBO; + productReference = 8D1107320486CEB800E47090 /* GLSLBasicsCocoaDL.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 29B97313FDCFA39411CA2CEA /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = YES; + }; + buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "GLSLBasicsCocoaDL" */; + compatibilityVersion = "Xcode 3.0"; + hasScannedForEncodings = 1; + mainGroup = 29B97314FDCFA39411CA2CEA /* SimpleFBO */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 8D1107260486CEB800E47090 /* GLSL Basics Cocoa */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 8D1107290486CEB800E47090 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */, + 8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */, + 36B67AB20E3657D600695250 /* Plasma.fs in Resources */, + 36B67AB30E3657D600695250 /* Plasma.vs in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 8D11072C0486CEB800E47090 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 36B67AAF0E3657D600695250 /* TranguloidTrefoilGeometry.mm in Sources */, + 36B67AB00E3657D600695250 /* GLUTString.m in Sources */, + 36B67AB10E3657D600695250 /* main.m in Sources */, + 36B67AB40E3657D600695250 /* GLSLBasicsView.m in Sources */, + 36B67AFA0E365D1900695250 /* Shader.m in Sources */, + 36C820A60E3FDB4E00049C5E /* GLSLHardwareSupport.c in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */ = { + isa = PBXVariantGroup; + children = ( + 089C165DFE840E0CC02AAC07 /* English */, + ); + name = InfoPlist.strings; + sourceTree = ""; + }; + 29B97318FDCFA39411CA2CEA /* MainMenu.nib */ = { + isa = PBXVariantGroup; + children = ( + 29B97319FDCFA39411CA2CEA /* English */, + ); + name = MainMenu.nib; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + C01FCF4B08A954540054247B /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + INFOPLIST_FILE = info.plist; + PRODUCT_NAME = GLSLBasicsCocoaDL; + }; + name = Debug; + }; + C01FCF4C08A954540054247B /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = "$(ARCHS_STANDARD_32_64_BIT_PRE_XCODE_3_1)"; + ARCHS_STANDARD_32_64_BIT_PRE_XCODE_3_1 = "ppc i386 ppc64 x86_64"; + INFOPLIST_FILE = info.plist; + PRODUCT_NAME = GLSLBasicsCocoaDL; + }; + name = Release; + }; + C01FCF4F08A954540054247B /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + GCC_PRECOMPILE_PREFIX_HEADER = NO; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + PREBINDING = NO; + SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk"; + }; + name = Debug; + }; + C01FCF5008A954540054247B /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = ( + ppc, + i386, + ); + GCC_PRECOMPILE_PREFIX_HEADER = NO; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + PREBINDING = NO; + SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "GLSL Basics Cocoa" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + C01FCF4B08A954540054247B /* Debug */, + C01FCF4C08A954540054247B /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + C01FCF4E08A954540054247B /* Build configuration list for PBXProject "GLSLBasicsCocoaDL" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + C01FCF4F08A954540054247B /* Debug */, + C01FCF5008A954540054247B /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 29B97313FDCFA39411CA2CEA /* Project object */; +} diff --git a/GLSLBasicsCocoaDL/ReadMe.txt b/GLSLBasicsCocoaDL/ReadMe.txt new file mode 100644 index 00000000..7d71fd9c --- /dev/null +++ b/GLSLBasicsCocoaDL/ReadMe.txt @@ -0,0 +1,28 @@ +Introduction: + +This sample code demonstrates how to load, compile, and link GLSL fragment and vertex shaders from within a simple Cocoa application. + +The Fragment and vertex shaders have c like syntax and reside in the files with ".vs" and ".fs" extensions respectively, inside the main application bundle. They're loaded, compiled, linked and bound to a program object using OpenGL APIs and instantiated through the Shader class. The shader class here does not validate the program object. + +This project further contains a simple class for displaying strings in an OpenGL view using GLUT's built-in bitmap fonts. + +This application further demonstrates a simple timer based OpenGL animation from within a Cocoa application. + +It is also worth noting that the Tranguloid Trefoil geometry here is a parametric surface, created using a display list. + +Mouse support: + +¥ For zooming the object, hold the right-mouse down and move mouse up or down. +¥ For updating the pitch, hold the left-mouse key down and change the angle. + +Revision History: + +¥ Refactored the sample code to better demonstrate the interaction of OpenGL APIs with an OpenGL view. +¥ Moved the GLSL program object instantiation into its own basic class. +¥ Moved the GLSL hardware check code into its a separate file. +¥ Consistent use of float math library functions for pattern and palette generation. +¥ Animation continues during window resizing. +¥ Consistent use of doubles and their OpenGL equivalents during geometry generation. +¥ Updated the Xcode project to use the new format. +¥ Updated the NIB to use the new format. +¥ Added a simple GLUT string class. \ No newline at end of file diff --git a/GLSLBasicsCocoaDL/Sources/GLUT/GLUTString.h b/GLSLBasicsCocoaDL/Sources/GLUT/GLUTString.h new file mode 100755 index 00000000..3f95ea68 --- /dev/null +++ b/GLSLBasicsCocoaDL/Sources/GLUT/GLUTString.h @@ -0,0 +1,82 @@ +//--------------------------------------------------------------------------------- +// +// File: GLUTString.h +// +// Abstract: A simple utility class for drawing strings using glut +// +// Disclaimer: IMPORTANT: This Apple software is supplied to you by +// Inc. ("Apple") in consideration of your agreement to the following terms, +// and your use, installation, modification or redistribution of this Apple +// software constitutes acceptance of these terms. If you do not agree with +// these terms, please do not use, install, modify or redistribute this +// Apple software. +// +// In consideration of your agreement to abide by the following terms, and +// subject to these terms, Apple grants you a personal, non-exclusive +// license, under Apple's copyrights in this original Apple software (the +// "Apple Software"), to use, reproduce, modify and redistribute the Apple +// Software, with or without modifications, in source and/or binary forms; +// provided that if you redistribute the Apple Software in its entirety and +// without modifications, you must retain this notice and the following +// text and disclaimers in all such redistributions of the Apple Software. +// Neither the name, trademarks, service marks or logos of Apple Inc. may +// be used to endorse or promote products derived from the Apple Software +// without specific prior written permission from Apple. Except as +// expressly stated in this notice, no other rights or licenses, express +// or implied, are granted by Apple herein, including but not limited to +// any patent rights that may be infringed by your derivative works or by +// other works in which the Apple Software may be incorporated. +// +// The Apple Software is provided by Apple on an "AS IS" basis. APPLE +// MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION +// THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND +// OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. +// +// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL +// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, +// MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED +// AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), +// STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Copyright (c) 2008 Apple Inc., All rights reserved. +// +//--------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------- + +#import +#import + +//--------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------- + +@interface GLUTString : NSObject +{ + @private + void *font; + GLsizei width; + GLsizei height; + GLint drawX; + GLint drawY; + GLfloat red; + GLfloat green; + GLfloat blue; +} // GLUTString + +- (id) initWithViewSizeAndDrawCoordinates:(const NSSize *)theSize + coordinates:(const NSPoint *)theCoordinates; + +- (void) setGLUTFont:(void *)theFont; +- (void) setGLUTFontColor:(const GLfloat *)theColors; + +- (void) setViewSize:(const NSSize *)theSize; +- (void) setDrawCoordinates:(const NSPoint *)theCoordinates; + +- (void) drawString:(NSString *)theString; + +@end diff --git a/GLSLBasicsCocoaDL/Sources/GLUT/GLUTString.m b/GLSLBasicsCocoaDL/Sources/GLUT/GLUTString.m new file mode 100644 index 00000000..1fda8a09 --- /dev/null +++ b/GLSLBasicsCocoaDL/Sources/GLUT/GLUTString.m @@ -0,0 +1,195 @@ +//--------------------------------------------------------------------------------------- +// +// File: GLUTString.m +// +// Abstract: A simple utility class for drawing strings using glut +// +// Disclaimer: IMPORTANT: This Apple software is supplied to you by +// Inc. ("Apple") in consideration of your agreement to the following terms, +// and your use, installation, modification or redistribution of this Apple +// software constitutes acceptance of these terms. If you do not agree with +// these terms, please do not use, install, modify or redistribute this +// Apple software. +// +// In consideration of your agreement to abide by the following terms, and +// subject to these terms, Apple grants you a personal, non-exclusive +// license, under Apple's copyrights in this original Apple software (the +// "Apple Software"), to use, reproduce, modify and redistribute the Apple +// Software, with or without modifications, in source and/or binary forms; +// provided that if you redistribute the Apple Software in its entirety and +// without modifications, you must retain this notice and the following +// text and disclaimers in all such redistributions of the Apple Software. +// Neither the name, trademarks, service marks or logos of Apple Inc. may +// be used to endorse or promote products derived from the Apple Software +// without specific prior written permission from Apple. Except as +// expressly stated in this notice, no other rights or licenses, express +// or implied, are granted by Apple herein, including but not limited to +// any patent rights that may be infringed by your derivative works or by +// other works in which the Apple Software may be incorporated. +// +// The Apple Software is provided by Apple on an "AS IS" basis. APPLE +// MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION +// THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND +// OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. +// +// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL +// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, +// MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED +// AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), +// STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Copyright (c) 2008 Apple Inc., All rights reserved. +// +//--------------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------------- + +#import + +#import "GLUTString.h" + +//--------------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------------- + +#define kNibble 4 + +static const GLuint kDoubleDecimals = kNibble * sizeof(GLdouble); +static const GLuint kFloatDecimals = kNibble * sizeof(GLfloat); + +static const GLuint kCharSize = sizeof(GLchar); + +//--------------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------------- + +@implementation GLUTString + +//--------------------------------------------------------------------------------------- + +- (id) initWithViewSizeAndDrawCoordinates:(const NSSize *)theSize + coordinates:(const NSPoint *)theCoordinates +{ + self = [super init]; + + if( self ) + { + font = GLUT_BITMAP_9_BY_15; + width = (GLsizei)theSize->width; + height = (GLsizei)theSize->height; + drawX = (GLint)theCoordinates->x; + drawY = (GLint)theCoordinates->y; + red = 1.0f; + green = 1.0f; + blue = 1.0f; + } // if + + return self; +} // init + +//--------------------------------------------------------------------------------------- + +- (void) dealloc +{ + [super dealloc]; +} // dealloc + +//--------------------------------------------------------------------------------------- + +- (void) setGLUTFont:(void *)theFont +{ + font = theFont; +} // setGLUTFont + +//--------------------------------------------------------------------------------------- + +- (void) setGLUTFontColor:(const GLfloat *)theColors +{ + red = theColors[0]; + green = theColors[1]; + blue = theColors[2]; +} // setGLUTFontColor + +//--------------------------------------------------------------------------------------- + +- (void) setViewSize:(const NSSize *)theSize +{ + width = (GLsizei)theSize->width; + height = (GLsizei)theSize->height; +} // setViewSize + +//--------------------------------------------------------------------------------------- + +- (void) setDrawCoordinates:(const NSPoint *)theCoordinates +{ + drawX = (GLint)theCoordinates->x; + drawY = (GLint)theCoordinates->y; +} // setDrawCoordinates + +//--------------------------------------------------------------------------------------- + +- (void) drawUTF8StringUsingGLUT:(const GLchar *)theString +{ + GLuint stringLength = strlen(theString); + + GLuint i; + + glPushAttrib(GL_TRANSFORM_BIT | GL_CURRENT_BIT); + + glMatrixMode(GL_PROJECTION); + + glPushMatrix(); + + glLoadIdentity(); + + glBindTexture(GL_TEXTURE_RECTANGLE_EXT,0); + glOrtho(0, width, 0, height, -10.0, 10.0); + + glMatrixMode(GL_MODELVIEW); + + glPushMatrix(); + + glLoadIdentity(); + + glColor3f(red, green, blue); + + glRasterPos2i(drawX, drawY); + + for( i = 0; i < stringLength; i++ ) + { + glutBitmapCharacter( font, theString[i] ); + } // for + + glPopMatrix(); + + glMatrixMode(GL_PROJECTION); + + glPopMatrix(); + + glPopAttrib(); +} // drawUTF8StringUsingGLUT + +//--------------------------------------------------------------------------------------- + +- (void) drawString:(NSString *)theString +{ + const char *str =[theString UTF8String]; + + if( str != NULL ) + { + [self drawUTF8StringUsingGLUT:str]; + } // if +} // drawString + +//--------------------------------------------------------------------------------------- + +@end + +//--------------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------------- + diff --git a/GLSLBasicsCocoaDL/Sources/Geometry/TranguloidTrefoilGeometry.h b/GLSLBasicsCocoaDL/Sources/Geometry/TranguloidTrefoilGeometry.h new file mode 100755 index 00000000..a5224dcc --- /dev/null +++ b/GLSLBasicsCocoaDL/Sources/Geometry/TranguloidTrefoilGeometry.h @@ -0,0 +1,64 @@ +//--------------------------------------------------------------------------- +// +// File: TranguloidTrefoilGeometry.h +// +// Abstract: Tranguloid Trefoil geometry class +// +// Disclaimer: IMPORTANT: This Apple software is supplied to you by +// Inc. ("Apple") in consideration of your agreement to the following terms, +// and your use, installation, modification or redistribution of this Apple +// software constitutes acceptance of these terms. If you do not agree with +// these terms, please do not use, install, modify or redistribute this +// Apple software. +// +// In consideration of your agreement to abide by the following terms, and +// subject to these terms, Apple grants you a personal, non-exclusive +// license, under Apple's copyrights in this original Apple software (the +// "Apple Software"), to use, reproduce, modify and redistribute the Apple +// Software, with or without modifications, in source and/or binary forms; +// provided that if you redistribute the Apple Software in its entirety and +// without modifications, you must retain this notice and the following +// text and disclaimers in all such redistributions of the Apple Software. +// Neither the name, trademarks, service marks or logos of Apple Inc. may +// be used to endorse or promote products derived from the Apple Software +// without specific prior written permission from Apple. Except as +// expressly stated in this notice, no other rights or licenses, express +// or implied, are granted by Apple herein, including but not limited to +// any patent rights that may be infringed by your derivative works or by +// other works in which the Apple Software may be incorporated. +// +// The Apple Software is provided by Apple on an "AS IS" basis. APPLE +// MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION +// THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND +// OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. +// +// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL +// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, +// MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED +// AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), +// STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Copyright (c) 2007-2008 Apple Inc., All rights reserved. +// +//--------------------------------------------------------------------------- + +#import +#import +#import + +@interface TranguloidTrefoil : NSObject +{ + @private + GLuint displayList; +} // TranguloidTrefoil + +- (id) initTranguloidTrefoilWithAttribbutes:(const GLuint)theSubdivisions + ratio:(const GLuint)theRatio; + +- (GLuint) displayList; + +@end diff --git a/GLSLBasicsCocoaDL/Sources/Geometry/TranguloidTrefoilGeometry.mm b/GLSLBasicsCocoaDL/Sources/Geometry/TranguloidTrefoilGeometry.mm new file mode 100755 index 00000000..612808d6 --- /dev/null +++ b/GLSLBasicsCocoaDL/Sources/Geometry/TranguloidTrefoilGeometry.mm @@ -0,0 +1,492 @@ +//--------------------------------------------------------------------------------------- +// +// File: TranguloidTrefoilGeometry.m +// +// Abstract: Tranguloid Trefoil geometry class +// +// Disclaimer: IMPORTANT: This Apple software is supplied to you by +// Inc. ("Apple") in consideration of your agreement to the following terms, +// and your use, installation, modification or redistribution of this Apple +// software constitutes acceptance of these terms. If you do not agree with +// these terms, please do not use, install, modify or redistribute this +// Apple software. +// +// In consideration of your agreement to abide by the following terms, and +// subject to these terms, Apple grants you a personal, non-exclusive +// license, under Apple's copyrights in this original Apple software (the +// "Apple Software"), to use, reproduce, modify and redistribute the Apple +// Software, with or without modifications, in source and/or binary forms; +// provided that if you redistribute the Apple Software in its entirety and +// without modifications, you must retain this notice and the following +// text and disclaimers in all such redistributions of the Apple Software. +// Neither the name, trademarks, service marks or logos of Apple Inc. may +// be used to endorse or promote products derived from the Apple Software +// without specific prior written permission from Apple. Except as +// expressly stated in this notice, no other rights or licenses, express +// or implied, are granted by Apple herein, including but not limited to +// any patent rights that may be infringed by your derivative works or by +// other works in which the Apple Software may be incorporated. +// +// The Apple Software is provided by Apple on an "AS IS" basis. APPLE +// MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION +// THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND +// OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. +// +// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL +// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, +// MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED +// AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), +// STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Copyright (c) 2007-2008 Apple Inc., All rights reserved. +// +//--------------------------------------------------------------------------------------- +// +// Uses techniques described by Paul Bourke 1999 - 2002 +// Tranguloid Trefoil and other example surfaces by Roger Bagula +// see +// +//--------------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------------- + +#include +#include + +//--------------------------------------------------------------------------------------- + +#include "TranguloidTrefoilGeometry.h" + +//--------------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------------- + +static const GLdouble kTwoPi = 2.0 * M_PI; +static const GLdouble kPi = M_PI; +static const GLdouble kTwoPiThird = ( 2.0 * M_PI ) / 3.0; + +//--------------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------------- + +#pragma mark - +#pragma mark Private Data Structures + +//--------------------------------------------------------------------------------------- + +struct Position +{ + union + { + GLdouble P[3]; + + struct + { + GLdouble x; + GLdouble y; + GLdouble z; + }; // union + }; // struct +}; + +typedef Position Position; + +//--------------------------------------------------------------------------------------- + +struct TexCoords +{ + union + { + GLdouble T[2]; + + struct + { + GLdouble s; + GLdouble t; + }; // struct + }; // union +}; + +typedef TexCoords TexCoords; + +//--------------------------------------------------------------------------------------- + +struct Vertex +{ + Position positions; + Position normals; + TexCoords texCoords; +}; + +typedef Vertex Vertex; + +//--------------------------------------------------------------------------------------- + +typedef std::vector Vertices; + +//--------------------------------------------------------------------------------------- + +struct Geometry +{ + GLint rows; + GLint columns; + Vertices vertices; +}; + +typedef Geometry Geometry; + +//--------------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------------- + +#pragma mark - +#pragma mark Vector Class + +//--------------------------------------------------------------------------------------- + +class Vector +{ + public: + + Vector(); + Vector(const Position *p); + + Vector normalize(); + + Vector operator-(Vector &v); + Vector operator^(Vector &v); // Exterior cross product + + Position position(); + + public: + + GLdouble x; + GLdouble y; + GLdouble z; +}; // class Vector + +//--------------------------------------------------------------------------------------- + +Vector::Vector() +{ + x = 0; + y = 0; + z = 0; +} // Default Constructor + +//--------------------------------------------------------------------------------------- + +Vector::Vector(const Position *p) +{ + if( p != NULL ) + { + x = p->x; + y = p->y; + z = p->z; + } // if + else + { + x = 0; + y = 0; + z = 0; + } // else +}// Constructor + +//--------------------------------------------------------------------------------------- + +Vector Vector::operator-(Vector &v) +{ + Vector w; + + w.x = x - v.x; + w.y = y - v.y; + w.z = z - v.z; + + return w; +} // Vector::operator- + +//--------------------------------------------------------------------------------------- +// +// Exterior (vector) cross product +// +//--------------------------------------------------------------------------------------- + +Vector Vector::operator^(Vector &v) +{ + Vector w; + + w.x = y * v.z - z * v.y; + w.y = z * v.x - x * v.z; + w.z = x * v.y - y * v.x; + + return w; +} // Vector::operator^ + +//--------------------------------------------------------------------------------------- + +Vector Vector::normalize() +{ + GLdouble L = (GLdouble)std::sqrt(x * x + y * y + z * z); + + Vector w; + + if( L != 0.0 ) + { + L = 1.0/L; + + w.x = L * x; + w.y = L * y; + w.z = L * z; + } // if + + return w; +} // Vector::normalize + +//--------------------------------------------------------------------------------------- + +Position Vector::position() +{ + Position p; + + p.x = x; + p.y = y; + p.z = z; + + return p; +} // Vector::position + +//--------------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------------- + +#pragma mark - +#pragma mark Utility Vector Function + +//--------------------------------------------------------------------------------------- + +static Position ComputeNormals(const Position *p, + const Position *q, + const Position *r) +{ + Vector u(p); + Vector v(q); + Vector w(r); + + Vector n; + Vector dv; + Vector dw; + + Position normals; + + dv = v - u; + dv = dv.normalize(); + + dw = w - u; + dw = dw.normalize(); + + n = dv ^ dw; + n = n.normalize(); + + normals = n.position(); + + return normals; +} // ComputeNormals + +//--------------------------------------------------------------------------------------- + +#pragma mark - +#pragma mark Tranguloid Trefoil Geometry + +//--------------------------------------------------------------------------------------- +// +// Note that -Pi <= u <= Pi and -Pi <= v <= Pi +// +//--------------------------------------------------------------------------------------- + +static Position TranguloidTrefoilGeometry(const GLdouble u, + const GLdouble v) +{ + Position p; + + GLdouble t = v + kTwoPiThird; + GLdouble w = 2.0 * u; + GLdouble A = 2.0 + cos(t); + GLdouble B = 2.0 + cos(v); + + p.x = 2.0 * sin(3.0 * u) / B; + p.y = 2.0 * (sin(u) + 2.0 * sin(w)) / A; + p.z = 0.25 * (cos(u) - 2.0 * cos(w)) * A * B; + + return p; +} // TranguloidTrefoilGeometry + +//--------------------------------------------------------------------------------------- + +static void NewTranguloidTrefoilSurface(Geometry *geometry) +{ + GLint i; + GLint j; + GLint maxI = geometry->rows; + GLint maxJ = geometry->columns; + GLdouble invMaxI = 1.0 / (GLdouble)maxI; + GLdouble invMaxJ = 1.0 / (GLdouble)maxJ; + GLdouble delta = 0.0005; + GLdouble u[2]; + Vertex vertex; + Position position[2]; + + for(i = 0; i < maxI; i++) + { + for(j = 0; j < maxJ; j++) + { + u[0] = kTwoPi * (i % maxI) * invMaxI - kPi; + u[1] = kTwoPi * (j % maxJ) * invMaxJ - kPi; + + vertex.positions = TranguloidTrefoilGeometry(u[0], u[1]); + + position[0] = TranguloidTrefoilGeometry(u[0] + delta, u[1]); + position[1] = TranguloidTrefoilGeometry(u[0], u[1] + delta); + + vertex.normals = ComputeNormals(&vertex.positions, &position[0], &position[1]); + + vertex.texCoords.s = (GLdouble)i * invMaxI * 5.0; + vertex.texCoords.t = (GLdouble)j * invMaxJ; + + geometry->vertices.push_back(vertex); + } // for + } // for +} // NewTranguloidTrefoilSurface + +//--------------------------------------------------------------------------------------- + +static void BuildVertex(const GLint index, + Geometry *geometry) +{ + glNormal3dv(geometry->vertices[index].normals.P); + glTexCoord2dv(geometry->vertices[index].texCoords.T); + glVertex3dv(geometry->vertices[index].positions.P); +} // BuildVertex + +//--------------------------------------------------------------------------------------- + +static GLuint NewTranguloidTrefoilDisplayList(Geometry *geometry) +{ + GLint i; + GLint j; + GLint k; + GLint l; + GLint m; + GLint maxI = geometry->rows; + GLint maxJ = geometry->columns; + GLuint displayList; + + displayList = glGenLists(1); + + glNewList(displayList, GL_COMPILE); + + for(i = 0; i < maxI; i++) + { + glBegin(GL_TRIANGLE_STRIP); + + for(j = 0; j <= maxJ; j++) + { + m = (j % maxJ); + + k = (i % maxI) * maxJ + m; + + BuildVertex(k, geometry); + + l = ((i + 1) % maxI) * maxJ + m; + + BuildVertex(l, geometry); + } // for + + glEnd(); + } // for + + glEndList(); + + return displayList; +} // NewTranguloidTrefoilDisplayList + +//--------------------------------------------------------------------------------------- + +static GLuint GetTranguloidTrefoilDisplayList(const GLuint subdivisions, + const GLuint xyRatio) +{ + Geometry geometry; + GLuint displayList = 0; + + geometry.rows = subdivisions * xyRatio; + geometry.columns = subdivisions; + + // Build surface + + NewTranguloidTrefoilSurface(&geometry); + + // Now get the display list + + displayList = NewTranguloidTrefoilDisplayList(&geometry); + + return displayList; +} // GetTranguloidTrefoilDisplayList + +//--------------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------------- + +#pragma mark - + +//--------------------------------------------------------------------------------------- + +@implementation TranguloidTrefoil + +//--------------------------------------------------------------------------------------- + +- (id) initTranguloidTrefoilWithAttribbutes:(const GLuint)theSubdivisions + ratio:(const GLuint)theRatio +{ + self = [super init]; + + if( self ) + { + displayList = GetTranguloidTrefoilDisplayList(theSubdivisions, theRatio); + } // if + + return self; +} // init + +//--------------------------------------------------------------------------------------- + +- (GLuint) displayList +{ + return displayList; +} // displayList + +//--------------------------------------------------------------------------------------- + +- (void) dealloc +{ + // delete the last used display list + + if(displayList) + { + glDeleteLists(displayList, 1); + } // if + + [super dealloc]; +} // dealloc + +//--------------------------------------------------------------------------------------- + +@end + +//--------------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------------- diff --git a/GLSLBasicsCocoaDL/Sources/Hardware/GLSLHardwareSupport.c b/GLSLBasicsCocoaDL/Sources/Hardware/GLSLHardwareSupport.c new file mode 100755 index 00000000..28db4253 --- /dev/null +++ b/GLSLBasicsCocoaDL/Sources/Hardware/GLSLHardwareSupport.c @@ -0,0 +1,163 @@ +//--------------------------------------------------------------------------------- +// +// File: GLSLHardwareSupport.c +// +// Abstract: Check to see if fragment & vertex shader can execute in hardware. +// +// Disclaimer: IMPORTANT: This Apple software is supplied to you by +// Apple Inc. ("Apple") in consideration of your agreement to the +// following terms, and your use, installation, modification or +// redistribution of this Apple software constitutes acceptance of these +// terms. If you do not agree with these terms, please do not use, +// install, modify or redistribute this Apple software. +// +// In consideration of your agreement to abide by the following terms, and +// subject to these terms, Apple grants you a personal, non-exclusive +// license, under Apple's copyrights in this original Apple software (the +// "Apple Software"), to use, reproduce, modify and redistribute the Apple +// Software, with or without modifications, in source and/or binary forms; +// provided that if you redistribute the Apple Software in its entirety and +// without modifications, you must retain this notice and the following +// text and disclaimers in all such redistributions of the Apple Software. +// Neither the name, trademarks, service marks or logos of Apple Inc. +// may be used to endorse or promote products derived from the Apple +// Software without specific prior written permission from Apple. Except +// as expressly stated in this notice, no other rights or licenses, express +// or implied, are granted by Apple herein, including but not limited to +// any patent rights that may be infringed by your derivative works or by +// other works in which the Apple Software may be incorporated. +// +// The Apple Software is provided by Apple on an "AS IS" basis. APPLE +// MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION +// THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND +// OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. +// +// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL +// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, +// MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED +// AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), +// STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Copyright (c) 2008 Apple Inc., All rights reserved. +// +//--------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------- + +#import "GLSLHardwareSupport.h" + +//--------------------------------------------------------------------------------- + +#import + +//--------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------- + +static inline GLboolean CheckForExtension(const GLchar *extensionName, + const GLubyte *extensions) +{ + GLboolean bExtensionAvailable = gluCheckExtension((GLubyte *)extensionName, + extensions); + + return bExtensionAvailable; +} // CheckForExtension + +//--------------------------------------------------------------------------------- + +static inline void CheckForAndLogExtensionAvailable(const GLboolean extensionAvailable, + const GLchar *extensionName) +{ + if( extensionAvailable == GL_FALSE ) + { + NSLog(@">> WARNING: \"%s\" extension is not available!\n", + extensionName); + } // if +} // CheckForExtensions + +//--------------------------------------------------------------------------------- + +static void CheckForShaders(NSOpenGLPixelFormatAttribute *thePixelAttributes) +{ + const GLubyte *extensions = glGetString(GL_EXTENSIONS); + + GLboolean bShaderObjectAvailable = CheckForExtension("GL_ARB_shader_objects", extensions); + GLboolean bShaderLanguage100Available = CheckForExtension("GL_ARB_shading_language_100", extensions); + GLboolean bVertexShaderAvailable = CheckForExtension("GL_ARB_vertex_shader", extensions); + GLboolean bFragmentShaderAvailable = CheckForExtension("GL_ARB_fragment_shader", extensions); + + GLboolean bForceSoftwareRendering = (bShaderObjectAvailable == GL_FALSE) + || (bShaderLanguage100Available == GL_FALSE) + || (bVertexShaderAvailable == GL_FALSE) + || (bFragmentShaderAvailable == GL_FALSE); + + if( bForceSoftwareRendering ) + { + // Force software rendering, so fragment shaders will execute + + CheckForAndLogExtensionAvailable(bShaderObjectAvailable, "GL_ARB_shader_objects"); + CheckForAndLogExtensionAvailable(bShaderLanguage100Available, "GL_ARB_shading_language_100"); + CheckForAndLogExtensionAvailable(bVertexShaderAvailable, "GL_ARB_vertex_shader"); + CheckForAndLogExtensionAvailable(bFragmentShaderAvailable, "GL_ARB_fragment_shader"); + + thePixelAttributes [3] = NSOpenGLPFARendererID; + thePixelAttributes [4] = kCGLRendererGenericFloatID; + } // if +} // CheckForShaders + +//--------------------------------------------------------------------------------- + +static void CheckForClipVolumeHint(NSOpenGLPixelFormatAttribute *thePixelAttributes) +{ + const GLubyte *extensions = glGetString(GL_EXTENSIONS); + + // Inform OpenGL that the geometry is entirely within the + // view volume and that view-volume clipping is unnecessary. + // Normal clipping can be resumed by setting this hint to + // GL_DONT_CARE. When clipping is disabled with this hint, + // results are undefined if geometry actually falls outside + //the view volume. + + GLboolean bClipVolumeHintExtAvailable = CheckForExtension("GL_EXT_clip_volume_hint", + extensions); + + if( bClipVolumeHintExtAvailable == GL_TRUE) + { + glHint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT,GL_FASTEST); + } // if +} // CheckForClipVolumeHint + +//--------------------------------------------------------------------------------- + +void CheckForGLSLHardwareSupport(NSOpenGLPixelFormatAttribute *thePixelAttributes) +{ + // Create a pre-flight context to check for GLSL hardware support + + NSOpenGLPixelFormat *pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:thePixelAttributes]; + + if( pixelFormat != nil ) + { + NSOpenGLContext *preflight = [[NSOpenGLContext alloc] initWithFormat:pixelFormat + shareContext:nil]; + + if( preflight != nil ) + { + [preflight makeCurrentContext]; + + CheckForShaders(thePixelAttributes); + CheckForClipVolumeHint(thePixelAttributes); + + [preflight release]; + } // if + + [pixelFormat release]; + } // if +} // CheckForGLSLHardwareSupport + +//--------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------- diff --git a/GLSLBasicsCocoaDL/Sources/Hardware/GLSLHardwareSupport.h b/GLSLBasicsCocoaDL/Sources/Hardware/GLSLHardwareSupport.h new file mode 100755 index 00000000..2d10e96f --- /dev/null +++ b/GLSLBasicsCocoaDL/Sources/Hardware/GLSLHardwareSupport.h @@ -0,0 +1,65 @@ +//--------------------------------------------------------------------------------- +// +// File: GLSLHardwareSupport.c +// +// Abstract: Check to see if fragment & vertex shader can execute in hardware. +// +// Disclaimer: IMPORTANT: This Apple software is supplied to you by +// Apple Inc. ("Apple") in consideration of your agreement to the +// following terms, and your use, installation, modification or +// redistribution of this Apple software constitutes acceptance of these +// terms. If you do not agree with these terms, please do not use, +// install, modify or redistribute this Apple software. +// +// In consideration of your agreement to abide by the following terms, and +// subject to these terms, Apple grants you a personal, non-exclusive +// license, under Apple's copyrights in this original Apple software (the +// "Apple Software"), to use, reproduce, modify and redistribute the Apple +// Software, with or without modifications, in source and/or binary forms; +// provided that if you redistribute the Apple Software in its entirety and +// without modifications, you must retain this notice and the following +// text and disclaimers in all such redistributions of the Apple Software. +// Neither the name, trademarks, service marks or logos of Apple Inc. +// may be used to endorse or promote products derived from the Apple +// Software without specific prior written permission from Apple. Except +// as expressly stated in this notice, no other rights or licenses, express +// or implied, are granted by Apple herein, including but not limited to +// any patent rights that may be infringed by your derivative works or by +// other works in which the Apple Software may be incorporated. +// +// The Apple Software is provided by Apple on an "AS IS" basis. APPLE +// MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION +// THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND +// OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. +// +// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL +// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, +// MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED +// AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), +// STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Copyright (c) 2008 Apple Inc., All rights reserved. +// +//------------------------------------------------------------------------- + +#ifndef _GLSL_HARDWARE_SUPPORT_H_ +#define _GLSL_HARDWARE_SUPPORT_H_ + +#import +#import + +#ifdef __cplusplus +extern "C" { +#endif + + void CheckForGLSLHardwareSupport(NSOpenGLPixelFormatAttribute *thePixelAttributes); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/GLSLBasicsCocoaDL/Sources/Other/main.m b/GLSLBasicsCocoaDL/Sources/Other/main.m new file mode 100755 index 00000000..e33d383b --- /dev/null +++ b/GLSLBasicsCocoaDL/Sources/Other/main.m @@ -0,0 +1,54 @@ +//--------------------------------------------------------------------------- +// +// File: main.m +// +// Abstract: Appliucation Main +// +// Disclaimer: IMPORTANT: This Apple software is supplied to you by +// Inc. ("Apple") in consideration of your agreement to the following terms, +// and your use, installation, modification or redistribution of this Apple +// software constitutes acceptance of these terms. If you do not agree with +// these terms, please do not use, install, modify or redistribute this +// Apple software. +// +// In consideration of your agreement to abide by the following terms, and +// subject to these terms, Apple grants you a personal, non-exclusive +// license, under Apple's copyrights in this original Apple software (the +// "Apple Software"), to use, reproduce, modify and redistribute the Apple +// Software, with or without modifications, in source and/or binary forms; +// provided that if you redistribute the Apple Software in its entirety and +// without modifications, you must retain this notice and the following +// text and disclaimers in all such redistributions of the Apple Software. +// Neither the name, trademarks, service marks or logos of Apple Inc. may +// be used to endorse or promote products derived from the Apple Software +// without specific prior written permission from Apple. Except as +// expressly stated in this notice, no other rights or licenses, express +// or implied, are granted by Apple herein, including but not limited to +// any patent rights that may be infringed by your derivative works or by +// other works in which the Apple Software may be incorporated. +// +// The Apple Software is provided by Apple on an "AS IS" basis. APPLE +// MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION +// THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND +// OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. +// +// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL +// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, +// MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED +// AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), +// STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Copyright (c) 2007-2008 Apple Inc., All rights reserved. +// +//--------------------------------------------------------------------------- + +#import + +int main(int argc, char *argv[]) +{ + return NSApplicationMain(argc, (const char **) argv); +} diff --git a/GLSLBasicsCocoaDL/Sources/Plasma/Plasma.fs b/GLSLBasicsCocoaDL/Sources/Plasma/Plasma.fs new file mode 100755 index 00000000..df978046 --- /dev/null +++ b/GLSLBasicsCocoaDL/Sources/Plasma/Plasma.fs @@ -0,0 +1,63 @@ +//--------------------------------------------------------------------------- +// +// File: Plasma.frag +// +// Abstract: GLSL Plasma fragment shader +// +// Disclaimer: IMPORTANT: This Apple software is supplied to you by +// Inc. ("Apple") in consideration of your agreement to the following terms, +// and your use, installation, modification or redistribution of this Apple +// software constitutes acceptance of these terms. If you do not agree with +// these terms, please do not use, install, modify or redistribute this +// Apple software. +// +// In consideration of your agreement to abide by the following terms, and +// subject to these terms, Apple grants you a personal, non-exclusive +// license, under Apple's copyrights in this original Apple software (the +// "Apple Software"), to use, reproduce, modify and redistribute the Apple +// Software, with or without modifications, in source and/or binary forms; +// provided that if you redistribute the Apple Software in its entirety and +// without modifications, you must retain this notice and the following +// text and disclaimers in all such redistributions of the Apple Software. +// Neither the name, trademarks, service marks or logos of Apple Inc. may +// be used to endorse or promote products derived from the Apple Software +// without specific prior written permission from Apple. Except as +// expressly stated in this notice, no other rights or licenses, express +// or implied, are granted by Apple herein, including but not limited to +// any patent rights that may be infringed by your derivative works or by +// other works in which the Apple Software may be incorporated. +// +// The Apple Software is provided by Apple on an "AS IS" basis. APPLE +// MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION +// THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND +// OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. +// +// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL +// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, +// MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED +// AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), +// STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Copyright (c) 2004-2008 Apple Inc., All rights reserved. +// +//--------------------------------------------------------------------------- + +uniform sampler1D palette; +uniform sampler2D pattern; +uniform float offset; +varying float LightIntensity; + +void main() +{ + vec4 color; + color = texture2D(pattern, gl_TexCoord[0].st); + color = texture1D(palette, (color.r+offset)); + color.a = 1.0; + color = color * LightIntensity; + color = clamp(color, 0.0, 1.0); + gl_FragColor = color; +} diff --git a/GLSLBasicsCocoaDL/Sources/Plasma/Plasma.vs b/GLSLBasicsCocoaDL/Sources/Plasma/Plasma.vs new file mode 100755 index 00000000..121c0f2f --- /dev/null +++ b/GLSLBasicsCocoaDL/Sources/Plasma/Plasma.vs @@ -0,0 +1,62 @@ +//--------------------------------------------------------------------------- +// +// File: Plasma.vert +// +// Abstract: GLSL Plasma vertex shader +// +// Disclaimer: IMPORTANT: This Apple software is supplied to you by +// Inc. ("Apple") in consideration of your agreement to the following terms, +// and your use, installation, modification or redistribution of this Apple +// software constitutes acceptance of these terms. If you do not agree with +// these terms, please do not use, install, modify or redistribute this +// Apple software. +// +// In consideration of your agreement to abide by the following terms, and +// subject to these terms, Apple grants you a personal, non-exclusive +// license, under Apple's copyrights in this original Apple software (the +// "Apple Software"), to use, reproduce, modify and redistribute the Apple +// Software, with or without modifications, in source and/or binary forms; +// provided that if you redistribute the Apple Software in its entirety and +// without modifications, you must retain this notice and the following +// text and disclaimers in all such redistributions of the Apple Software. +// Neither the name, trademarks, service marks or logos of Apple Inc. may +// be used to endorse or promote products derived from the Apple Software +// without specific prior written permission from Apple. Except as +// expressly stated in this notice, no other rights or licenses, express +// or implied, are granted by Apple herein, including but not limited to +// any patent rights that may be infringed by your derivative works or by +// other works in which the Apple Software may be incorporated. +// +// The Apple Software is provided by Apple on an "AS IS" basis. APPLE +// MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION +// THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND +// OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. +// +// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL +// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, +// MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED +// AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), +// STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Copyright (c) 2004-2008 Apple Inc., All rights reserved. +// +//--------------------------------------------------------------------------- + +varying float LightIntensity; +uniform vec3 LightPosition; + +void main() +{ + vec4 ECposition = gl_ModelViewMatrix * gl_Vertex; + vec3 tnorm = normalize(vec3 (gl_NormalMatrix * gl_Normal)); + + LightIntensity = dot(normalize(LightPosition - vec3 (ECposition)), tnorm) * 1.5; + + gl_Position = ftransform(); + + gl_TexCoord[0] = gl_MultiTexCoord0; +} diff --git a/GLSLBasicsCocoaDL/Sources/Shader/Shader.h b/GLSLBasicsCocoaDL/Sources/Shader/Shader.h new file mode 100755 index 00000000..9e883192 --- /dev/null +++ b/GLSLBasicsCocoaDL/Sources/Shader/Shader.h @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------- +// +// File: Shader.h +// +// Abstract: Rudimentary class to instantiate a shader object +// NOTE: This class does not validate the program object +// +// Disclaimer: IMPORTANT: This Apple software is supplied to you by +// Inc. ("Apple") in consideration of your agreement to the following terms, +// and your use, installation, modification or redistribution of this Apple +// software constitutes acceptance of these terms. If you do not agree with +// these terms, please do not use, install, modify or redistribute this +// Apple software. +// +// In consideration of your agreement to abide by the following terms, and +// subject to these terms, Apple grants you a personal, non-exclusive +// license, under Apple's copyrights in this original Apple software (the +// "Apple Software"), to use, reproduce, modify and redistribute the Apple +// Software, with or without modifications, in source and/or binary forms; +// provided that if you redistribute the Apple Software in its entirety and +// without modifications, you must retain this notice and the following +// text and disclaimers in all such redistributions of the Apple Software. +// Neither the name, trademarks, service marks or logos of Apple Inc. may +// be used to endorse or promote products derived from the Apple Software +// without specific prior written permission from Apple. Except as +// expressly stated in this notice, no other rights or licenses, express +// or implied, are granted by Apple herein, including but not limited to +// any patent rights that may be infringed by your derivative works or by +// other works in which the Apple Software may be incorporated. +// +// The Apple Software is provided by Apple on an "AS IS" basis. APPLE +// MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION +// THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND +// OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. +// +// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL +// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, +// MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED +// AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), +// STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Copyright (c) 2008 Apple Inc., All rights reserved. +// +//------------------------------------------------------------------------- + +//------------------------------------------------------------------------- +// +// Required Includes +// +//------------------------------------------------------------------------- + +#import +#import + +//------------------------------------------------------------------------- +// +// GLSL Shader +// +//------------------------------------------------------------------------- + +@interface Shader : NSObject +{ + @private + const GLcharARB *fragmentShaderSource; // the GLSL source for the fragment Shader + const GLcharARB *vertexShaderSource; // the GLSL source for the vertex Shader + GLhandleARB programObject; // the program object +} // Shader + +- (id) initWithShadersInAppBundle:(NSString *)theShadersName; + +- (GLhandleARB) programObject; + +- (GLint) getUniformLocation:(const GLcharARB *)theUniformName; + +@end + +//------------------------------------------------------------------------- + diff --git a/GLSLBasicsCocoaDL/Sources/Shader/Shader.m b/GLSLBasicsCocoaDL/Sources/Shader/Shader.m new file mode 100755 index 00000000..c96214c0 --- /dev/null +++ b/GLSLBasicsCocoaDL/Sources/Shader/Shader.m @@ -0,0 +1,380 @@ +//--------------------------------------------------------------------------------- +// +// File: Shader.m +// +// Abstract: Rudimentary class to instantiate a shader object +// NOTE: This class does not validate the program object +// +// Disclaimer: IMPORTANT: This Apple software is supplied to you by +// Inc. ("Apple") in consideration of your agreement to the following terms, +// and your use, installation, modification or redistribution of this Apple +// software constitutes acceptance of these terms. If you do not agree with +// these terms, please do not use, install, modify or redistribute this +// Apple software. +// +// In consideration of your agreement to abide by the following terms, and +// subject to these terms, Apple grants you a personal, non-exclusive +// license, under Apple's copyrights in this original Apple software (the +// "Apple Software"), to use, reproduce, modify and redistribute the Apple +// Software, with or without modifications, in source and/or binary forms; +// provided that if you redistribute the Apple Software in its entirety and +// without modifications, you must retain this notice and the following +// text and disclaimers in all such redistributions of the Apple Software. +// Neither the name, trademarks, service marks or logos of Apple Inc. may +// be used to endorse or promote products derived from the Apple Software +// without specific prior written permission from Apple. Except as +// expressly stated in this notice, no other rights or licenses, express +// or implied, are granted by Apple herein, including but not limited to +// any patent rights that may be infringed by your derivative works or by +// other works in which the Apple Software may be incorporated. +// +// The Apple Software is provided by Apple on an "AS IS" basis. APPLE +// MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION +// THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND +// OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. +// +// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL +// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, +// MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED +// AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), +// STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Copyright (c) 2008 Apple Inc., All rights reserved. +// +//--------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------- + +#import "Shader.h" + +//--------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------- + +#pragma mark -- Compiling shaders & linking a program object -- + +//--------------------------------------------------------------------------------- + +static GLhandleARB LoadShader(GLenum theShaderType, + const GLcharARB **theShader, + GLint *theShaderCompiled) +{ + GLhandleARB shaderObject = NULL; + + if( theShader != NULL ) + { + GLint infoLogLength = 0; + + shaderObject = glCreateShaderObjectARB(theShaderType); + + glShaderSourceARB(shaderObject, 1, theShader, NULL); + glCompileShaderARB(shaderObject); + + glGetObjectParameterivARB(shaderObject, + GL_OBJECT_INFO_LOG_LENGTH_ARB, + &infoLogLength); + + if( infoLogLength > 0 ) + { + GLcharARB *infoLog = (GLcharARB *)malloc(infoLogLength); + + if( infoLog != NULL ) + { + glGetInfoLogARB(shaderObject, + infoLogLength, + &infoLogLength, + infoLog); + + NSLog(@">> Shader compile log:\n%s\n", infoLog); + + free(infoLog); + } // if + } // if + + glGetObjectParameterivARB(shaderObject, + GL_OBJECT_COMPILE_STATUS_ARB, + theShaderCompiled); + + if( *theShaderCompiled == 0 ) + { + NSLog(@">> Failed to compile shader %s\n", theShader); + } // if + } // if + else + { + *theShaderCompiled = 1; + } // else + + return shaderObject; +} // LoadShader + +//--------------------------------------------------------------------------------- + +static void LinkProgram(GLhandleARB programObject, + GLint *theProgramLinked) +{ + GLint infoLogLength = 0; + + glLinkProgramARB(programObject); + + glGetObjectParameterivARB(programObject, + GL_OBJECT_INFO_LOG_LENGTH_ARB, + &infoLogLength); + + if( infoLogLength > 0 ) + { + GLcharARB *infoLog = (GLcharARB *)malloc(infoLogLength); + + if( infoLog != NULL) + { + glGetInfoLogARB(programObject, + infoLogLength, + &infoLogLength, + infoLog); + + NSLog(@">> Program link log:\n%s\n", infoLog); + + free(infoLog); + } // if + } // if + + glGetObjectParameterivARB(programObject, + GL_OBJECT_LINK_STATUS_ARB, + theProgramLinked); + + if( *theProgramLinked == 0 ) + { + NSLog(@">> Failed to link program 0x%lx\n", (GLubyte *)&programObject); + } // if +} // LinkProgram + +//--------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------- + +@implementation Shader + +//--------------------------------------------------------------------------------- + +#pragma mark -- Get shaders from resource -- + +//--------------------------------------------------------------------------------- + +- (GLcharARB *) getShaderSourceFromResource:(NSString *)theShaderResourceName + extension:(NSString *)theExtension +{ + NSBundle *appBundle = [NSBundle mainBundle]; + + NSString *shaderTempSource = [appBundle pathForResource:theShaderResourceName + ofType:theExtension]; + GLcharARB *shaderSource = NULL; + + shaderTempSource = [NSString stringWithContentsOfFile:shaderTempSource]; + shaderSource = (GLcharARB *)[shaderTempSource cStringUsingEncoding:NSASCIIStringEncoding]; + + return shaderSource; +} // getShaderSourceFromResource + +//--------------------------------------------------------------------------------- + +- (void) getFragmentShaderSourceFromResource:(NSString *)theFragmentShaderResourceName +{ + fragmentShaderSource = [self getShaderSourceFromResource:theFragmentShaderResourceName + extension:@"fs" ]; +} // getFragmentShaderSourceFromResource + +//--------------------------------------------------------------------------------- + +- (void) getVertexShaderSourceFromResource:(NSString *)theVertexShaderResourceName +{ + vertexShaderSource = [self getShaderSourceFromResource:theVertexShaderResourceName + extension:@"vs" ]; +} // getVertexShaderSourceFromResource + +//--------------------------------------------------------------------------------- + +- (GLhandleARB) loadShader:(GLenum)theShaderType + shaderSource:(const GLcharARB **)theShaderSource +{ + GLint shaderCompiled = 0; + GLhandleARB shaderHandle = LoadShader(theShaderType, + theShaderSource, + &shaderCompiled); + + if( !shaderCompiled ) + { + if( shaderHandle ) + { + glDeleteObjectARB(shaderHandle); + shaderHandle = NULL; + } // if + } // if + + return shaderHandle; +} // loadShader + +//--------------------------------------------------------------------------------- + +- (BOOL) newProgramObject:(GLhandleARB)theVertexShader + fragmentShaderHandle:(GLhandleARB)theFragmentShader +{ + GLint programLinked = 0; + + // Create a program object and link both shaders + + programObject = glCreateProgramObjectARB(); + + glAttachObjectARB(programObject, theVertexShader); + glDeleteObjectARB(theVertexShader); // Release + + glAttachObjectARB(programObject, theFragmentShader); + glDeleteObjectARB(theFragmentShader); // Release + + LinkProgram(programObject, &programLinked); + + if( !programLinked ) + { + glDeleteObjectARB(programObject); + + programObject = NULL; + + return NO; + } // if + + return YES; +} // newProgramObject + +//--------------------------------------------------------------------------------- + +- (BOOL) setProgramObject +{ + BOOL programObjectSet = NO; + + // Load and compile both shaders + + GLhandleARB vertexShader = [self loadShader:GL_VERTEX_SHADER_ARB + shaderSource:&vertexShaderSource]; + + // Ensure vertex shader compiled + + if( vertexShader != NULL ) + { + GLhandleARB fragmentShader = [self loadShader:GL_FRAGMENT_SHADER_ARB + shaderSource:&fragmentShaderSource]; + + // Ensure fragment shader compiled + + if( fragmentShader != NULL ) + { + // Create a program object and link both shaders + + programObjectSet = [self newProgramObject:vertexShader + fragmentShaderHandle:fragmentShader]; + } // if + } // if + + return programObjectSet; +} // setProgramObject + +//--------------------------------------------------------------------------------- + +#pragma mark -- Designated Initializer -- + +//--------------------------------------------------------------------------------- + +- (id) initWithShadersInAppBundle:(NSString *)theShadersName +{ + self = [super init]; + + if( self) + { + BOOL loadedShaders = NO; + + // Load vertex and fragment shader + + [self getVertexShaderSourceFromResource:theShadersName]; + + if( vertexShaderSource != NULL ) + { + [self getFragmentShaderSourceFromResource:theShadersName]; + + if( fragmentShaderSource != NULL ) + { + loadedShaders = [self setProgramObject]; + + if( !loadedShaders) + { + NSLog(@">> WARNING: Failed to load GLSL \"%@\" fragment & vertex shaders!\n", + theShadersName); + } // if + } // if + } // if + } // if + + return self; +} // initWithShadersInAppBundle + +//--------------------------------------------------------------------------------- + +#pragma mark -- Deallocating Resources -- + +//--------------------------------------------------------------------------------- + +- (void) dealloc +{ + // Delete OpenGL resources + + if( programObject ) + { + glDeleteObjectARB(programObject); + + programObject = NULL; + } // if + + //Dealloc the superclass + + [super dealloc]; +} // dealloc + +//--------------------------------------------------------------------------------- + +#pragma mark -- Accessors -- + +//--------------------------------------------------------------------------------- + +- (GLhandleARB) programObject +{ + return programObject; +} // programObject + +//--------------------------------------------------------------------------------- + +#pragma mark -- Utilities -- + +//--------------------------------------------------------------------------------- + +- (GLint) getUniformLocation:(const GLcharARB *)theUniformName +{ + GLint uniformLoacation = glGetUniformLocationARB(programObject, + theUniformName); + + if( uniformLoacation == -1 ) + { + NSLog( @">> WARNING: No such uniform named \"%s\"\n", theUniformName ); + } // if + + return uniformLoacation; +} // getUniformLocation + +//--------------------------------------------------------------------------------- + +@end + +//--------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------- + diff --git a/GLSLBasicsCocoaDL/Sources/View/GLSLBasicsView.h b/GLSLBasicsCocoaDL/Sources/View/GLSLBasicsView.h new file mode 100755 index 00000000..a00ac8ef --- /dev/null +++ b/GLSLBasicsCocoaDL/Sources/View/GLSLBasicsView.h @@ -0,0 +1,95 @@ +//------------------------------------------------------------------------- +// +// File: GLSLBasicsView.h +// +// Abstract: Main rendering class +// +// Disclaimer: IMPORTANT: This Apple software is supplied to you by +// Inc. ("Apple") in consideration of your agreement to the following terms, +// and your use, installation, modification or redistribution of this Apple +// software constitutes acceptance of these terms. If you do not agree with +// these terms, please do not use, install, modify or redistribute this +// Apple software. +// +// In consideration of your agreement to abide by the following terms, and +// subject to these terms, Apple grants you a personal, non-exclusive +// license, under Apple's copyrights in this original Apple software (the +// "Apple Software"), to use, reproduce, modify and redistribute the Apple +// Software, with or without modifications, in source and/or binary forms; +// provided that if you redistribute the Apple Software in its entirety and +// without modifications, you must retain this notice and the following +// text and disclaimers in all such redistributions of the Apple Software. +// Neither the name, trademarks, service marks or logos of Apple Inc. may +// be used to endorse or promote products derived from the Apple Software +// without specific prior written permission from Apple. Except as +// expressly stated in this notice, no other rights or licenses, express +// or implied, are granted by Apple herein, including but not limited to +// any patent rights that may be infringed by your derivative works or by +// other works in which the Apple Software may be incorporated. +// +// The Apple Software is provided by Apple on an "AS IS" basis. APPLE +// MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION +// THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND +// OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. +// +// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL +// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, +// MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED +// AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), +// STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Copyright (c) 2007-2008 Apple Inc., All rights reserved. +// +//------------------------------------------------------------------------- + +//------------------------------------------------------------------------- +// +// Required Includes +// +//------------------------------------------------------------------------- + +#import +#import + +#import "GLUTString.h" +#import "Shader.h" +#import "TranguloidTrefoilGeometry.h" + +//------------------------------------------------------------------------- +// +// Custom OpenGL View +// +//------------------------------------------------------------------------- + +@interface GLSLBasicsView : NSOpenGLView +{ + @private + BOOL leftMouseIsDown; // was the left mouse button pressed? + BOOL rightMouseIsDown; // was the right mouse button pressed? + GLhandleARB programObject; // the program object + GLuint tranguloidTrefoilDL; // display list ID for the geometry + GLuint paletteID; // texture color palette + GLuint patternID; // texture color patterns + GLint locations[4]; // uniforms for the fragment & vertex shaders + GLfloat zoom; // zoom used for animation + GLfloat angle; // angle used for animation + GLfloat pitch; // pitch used for animation + GLfloat offset; // delta change for animation + NSPoint lastMousePoint; // last mouse point + NSRect bounds; // current view bounds + NSTimeInterval lastFrameReferenceTime; // used to compute change in time + NSTimer *timer; // timer to update the view content + NSString *infoString; // view bounds as string + GLUTString *info; // for displaying a string using GLUT bitmap fonts + TranguloidTrefoil *tranguloidTrefoil; // tranguloid trefoil geometry + Shader *plasma; // plasma fragemnt and vertex shaders +} // OpenGLView + +@end + +//------------------------------------------------------------------------- + diff --git a/GLSLBasicsCocoaDL/Sources/View/GLSLBasicsView.m b/GLSLBasicsCocoaDL/Sources/View/GLSLBasicsView.m new file mode 100755 index 00000000..0ce14e76 --- /dev/null +++ b/GLSLBasicsCocoaDL/Sources/View/GLSLBasicsView.m @@ -0,0 +1,1044 @@ +//--------------------------------------------------------------------------------- +// +// File: GLSLBasicsView.m +// +// Abstract: Main rendering class +// +// Disclaimer: IMPORTANT: This Apple software is supplied to you by +// Inc. ("Apple") in consideration of your agreement to the following terms, +// and your use, installation, modification or redistribution of this Apple +// software constitutes acceptance of these terms. If you do not agree with +// these terms, please do not use, install, modify or redistribute this +// Apple software. +// +// In consideration of your agreement to abide by the following terms, and +// subject to these terms, Apple grants you a personal, non-exclusive +// license, under Apple's copyrights in this original Apple software (the +// "Apple Software"), to use, reproduce, modify and redistribute the Apple +// Software, with or without modifications, in source and/or binary forms; +// provided that if you redistribute the Apple Software in its entirety and +// without modifications, you must retain this notice and the following +// text and disclaimers in all such redistributions of the Apple Software. +// Neither the name, trademarks, service marks or logos of Apple Inc. may +// be used to endorse or promote products derived from the Apple Software +// without specific prior written permission from Apple. Except as +// expressly stated in this notice, no other rights or licenses, express +// or implied, are granted by Apple herein, including but not limited to +// any patent rights that may be infringed by your derivative works or by +// other works in which the Apple Software may be incorporated. +// +// The Apple Software is provided by Apple on an "AS IS" basis. APPLE +// MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION +// THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND +// OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. +// +// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL +// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, +// MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED +// AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), +// STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Copyright (c) 2007-2008 Apple Inc., All rights reserved. +// +//--------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------- + +#import "GLSLHardwareSupport.h" +#import "GLSLBasicsView.h" + +//--------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------- + +#pragma mark - +#pragma mark Constatnts + +//--------------------------------------------------------------------------------- + +static const GLfloat kPi = 3.1415927f; // IEEE-754 single precision +static const GLint kFloatSize = sizeof(GLfloat); +static const GLfloat kOffsetDelta = 1.0f/256.0f; +static const GLdouble kViewRotationDegreesPerSecond = 20.0; +static const NSTimeInterval kScheduledTimerInSeconds = 1.0f/120.0f; + +//--------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------- + +#pragma mark - +#pragma mark Private Enumerated Types + +//--------------------------------------------------------------------------------- + +enum UniformLocations +{ + kUniformLightPosition = 0, + kUniformOffset, + kUniformPattern, + kUniformPalette +}; + +typedef enum UniformLocations UniformLocations; + +//--------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------- + +#pragma mark - + +//--------------------------------------------------------------------------------- + +@implementation GLSLBasicsView + +//--------------------------------------------------------------------------------- + +#pragma mark - +#pragma mark Initialize 1D & 2D Textures + +//--------------------------------------------------------------------------------- + +- (GLuint) initTexture1D:(const GLvoid *)thePixels + count:(const GLsizei)theCount +{ + GLuint textureID = 0; + + glActiveTexture(GL_TEXTURE1); + glGenTextures(1, &textureID); + glBindTexture(GL_TEXTURE_1D, textureID); + + glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + glTexImage1D(GL_TEXTURE_1D, + 0, + GL_RGBA, + theCount, + 0, + GL_RGB, + GL_FLOAT, + thePixels); + + return textureID; +} // initTexture1D + +//--------------------------------------------------------------------------------- + +- (GLuint) initTexture2D:(const GLvoid *)thePixels + width:(const GLsizei)theWidth + height:(const GLsizei)theHeight +{ + GLuint textureID = 0; + + glActiveTexture(GL_TEXTURE0); + glGenTextures(1, &textureID); + glBindTexture(GL_TEXTURE_2D, textureID); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + glTexImage2D(GL_TEXTURE_2D, + 0, + GL_RGBA, + theWidth, + theHeight, + 0, + GL_LUMINANCE, + GL_FLOAT, + thePixels); + + return textureID; +} // initTexture2D + +//--------------------------------------------------------------------------------- + +#pragma mark - +#pragma mark Initialize palette + +//--------------------------------------------------------------------------------- + +- (void) initPalettePixels:(GLfloat *)thePixels + count:(const GLsizei)theCount +{ + GLfloat a = (GLfloat)theCount; + GLfloat b = 0.5f * a; + GLfloat c = 1.5f * a; + GLfloat d = 2.0f / a; + GLfloat x[2]; + GLfloat n; + GLint i; + GLint j; + + a = 1.0f / a; + c = 1.0f / c; + + for( i = 0; i < theCount; i++ ) + { + n = (GLfloat)i; + + x[0] = kPi * n; + x[1] = sinf( a * x[0] ); + + j = 3 * i; + + thePixels[j] = 1.0f - x[1]; + thePixels[j+1] = b * c * ( 1.0f + sinf( d * x[0] ) ); + thePixels[j+2] = x[1]; + } // for +} // initPalettePixels + +//--------------------------------------------------------------------------------- + +- (void) initPalette +{ + GLsizei count = 256; + GLfloat *palettePixels = (GLfloat *)malloc( 3 * count * kFloatSize ); + + if( palettePixels != NULL ) + { + [self initPalettePixels:palettePixels + count:count]; + + paletteID = [self initTexture1D:palettePixels + count:count]; + + free( palettePixels ); + + palettePixels = NULL; + } // if +} // initPalette + +//--------------------------------------------------------------------------------- + +#pragma mark - +#pragma mark Initialize pattern + +//--------------------------------------------------------------------------------- + +- (void) initPatternPixels:(GLfloat *)thePixels + width:(const GLsizei)theWidth + height:(const GLsizei)theHeight +{ + GLfloat a = (GLfloat)theWidth; + GLfloat b = 0.25f * a; + GLfloat c = 0.125f * a; + GLfloat f; + GLfloat x; + GLfloat y; + GLint i; + GLint iMax = theWidth >> 1; + GLint j; + GLint jMax = theHeight >> 1; + GLint k = theWidth - 1; + GLint l; + GLint m; + GLint n; + + b = 1.0f / b; + c = 1.0f / c; + + for( i = 0; i < iMax; i++ ) + { + y = (GLfloat)i; + + for( j = 0; j < jMax; j++ ) + { + x = (GLfloat) j; + f = 0.25f*(sinf(b*x) + sinf(b*y) + sinf(b*(x+y)) + sinf(c*sqrtf(x*x+y*y))); + + l = i * theWidth; + m = k * theWidth - l; + n = k - j; + + thePixels[l+j] = f; + thePixels[l+n] = f; + thePixels[m+j] = f; + thePixels[m+n] = f; + } // for + } // for +} // initPatternPixels + +//--------------------------------------------------------------------------------- + +- (void) initPattern +{ + GLsizei width = 128; + GLsizei height = 128; + GLfloat *patternPixels = (GLfloat *)malloc(3 * width * height * kFloatSize); + + if( patternPixels != NULL ) + { + [self initPatternPixels:patternPixels + width:width + height:height]; + + patternID = [self initTexture2D:patternPixels + width:width + height:height]; + + free( patternPixels ); + + patternPixels = NULL; + } // if +} // initPattern + +//--------------------------------------------------------------------------------- + +#pragma mark - +#pragma mark Setup OpenGL & shader uniforms + +//--------------------------------------------------------------------------------- + +- (void) initShaderUniforms +{ + // Enable the program object + + glUseProgramObjectARB(programObject); + + // Store the values of the uniforms from the vertex + // and the fragment shaders + + locations[kUniformLightPosition] = [plasma getUniformLocation:"LightPosition"]; + locations[kUniformOffset] = [plasma getUniformLocation:"offset"]; + locations[kUniformPattern] = [plasma getUniformLocation:"pattern"]; + locations[kUniformPalette] = [plasma getUniformLocation:"palette"]; + + // Set the (x,y,z) coordinates of the light position + + glUniform3fARB(locations[kUniformLightPosition], 0.0, 0.0, 20.0); + + // Set the samplers + + glUniform1iARB(locations[kUniformPattern], 0); + glUniform1iARB(locations[kUniformPalette], 1); + + // Disable the program object + + glUseProgramObjectARB(NULL); +} // initShaderUniforms + +//--------------------------------------------------------------------------------- + +#pragma mark - +#pragma mark Setup OpenGL + +//--------------------------------------------------------------------------------- + +- (void) initOpenGLStates +{ + [[self openGLContext] makeCurrentContext]; + + //----------------------------------------------------------------- + // + // For some OpenGL implementations, texture coordinates generated + // during rasterization aren't perspective correct. However, you + // can usually make them perspective correct by calling the API + // glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST). Colors + // generated at the rasterization stage aren't perspective correct + // in almost every OpenGL implementation, / and can't be made so. + // For this reason, you're more likely to encounter this problem + // with colors than texture coordinates. + // + //----------------------------------------------------------------- + + glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST); + + // Set up the projection + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + glFrustum(-0.3, 0.3, 0.0, 0.6, 1.0, 8.0); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + glTranslatef(0.0, 0.0, -2.0); + + // Turn on depth test + + glEnable(GL_DEPTH_TEST); + + // front - or back - facing facets can be culled + + glEnable(GL_CULL_FACE); +} // initOpenGL + +//--------------------------------------------------------------------------------- + +- (void) initTexturesForShader +{ + // Create the palette + + [self initPalette]; + + // Create the plasma pattern + + [self initPattern]; +} // initTexturesForShader + +//--------------------------------------------------------------------------------- + +- (void) initGLSLShader +{ + // Initialize the plasma shader from the application bundle + + plasma = [[Shader alloc] initWithShadersInAppBundle:@"Plasma"]; + + if( plasma ) + { + // Get the program object for the plasma shader + + programObject = [plasma programObject]; + + // Setup the uniforms for the plasma shader + + [self initShaderUniforms]; + } // if +} // initGLSLShader + +//--------------------------------------------------------------------------------- + +- (void) initOpenGLDisplayList +{ + tranguloidTrefoil = [[TranguloidTrefoil alloc] initTranguloidTrefoilWithAttribbutes:128 + ratio:16]; + + if( tranguloidTrefoil ) + { + tranguloidTrefoilDL = [tranguloidTrefoil displayList]; + } // if +} // initOpenGLDisplayList + +//--------------------------------------------------------------------------------- + + - (void) initGLUTString:(const NSRect *)theFrame +{ + NSSize size = theFrame->size; + GLsizei width = (GLsizei)size.width; + GLsizei height = (GLsizei)size.height; + + NSPoint coordinates = NSMakePoint(10.0, 10.0); + + info = [[GLUTString alloc] initWithViewSizeAndDrawCoordinates:&size + coordinates:&coordinates]; + + infoString = [[NSString alloc] initWithFormat:@"Bounds: %ld x %ld",width,height]; +} // initGLUTString + +//--------------------------------------------------------------------------------- + +- (void) initOpenGL:(const NSRect *)theFrame +{ + [self initOpenGLStates]; + [self initTexturesForShader]; + [self initGLSLShader]; + [self initOpenGLDisplayList]; + [self initGLUTString:theFrame]; +} // initOpenGL + +//--------------------------------------------------------------------------------- + +#pragma mark - +#pragma mark Animation Timer + +//--------------------------------------------------------------------------------- + +- (void) heartbeat +{ + [self drawRect:[self bounds]]; +} // heartbeat + +//--------------------------------------------------------------------------------- + +- (void) initUpdateTimer +{ + timer = [NSTimer timerWithTimeInterval:kScheduledTimerInSeconds + target:self + selector:@selector(heartbeat) + userInfo:nil + repeats:YES]; + + [[NSRunLoop currentRunLoop] addTimer:timer + forMode:NSDefaultRunLoopMode]; + + [[NSRunLoop currentRunLoop] addTimer:timer + forMode:NSEventTrackingRunLoopMode]; +} // initUpdateTimer + +//--------------------------------------------------------------------------------- + +#pragma mark - +#pragma mark Initializations + +//--------------------------------------------------------------------------------- + +- (void) initViewAttributes +{ + + lastFrameReferenceTime = [NSDate timeIntervalSinceReferenceDate]; + + leftMouseIsDown = NO; + rightMouseIsDown = NO; + + angle = 0.0f; + pitch = 25.0f; + zoom = 1.0f; + + bounds.origin.x = 0.0f; + bounds.origin.y = 0.0f; + bounds.size.width = 0.0f; + bounds.size.height = 0.0f; +} // initViewAttributes + +//--------------------------------------------------------------------------------- +// +// Sync to VBL to avoid tearing. +// +//--------------------------------------------------------------------------------- + +- (void) initSyncToVBL +{ + GLint swapInterval = 1; + + [[self openGLContext] setValues:&swapInterval + forParameter:NSOpenGLCPSwapInterval]; +} // initSyncToVBL + +//--------------------------------------------------------------------------------- + +- (void) initOpenGLView:(const NSRect *)theFrame +{ + // Setting the view's frame size + + [self setFrameSize:theFrame->size]; + + // View attributes initilizations + + [self initViewAttributes]; + + // New timer for updating OpenGL view + + [self initUpdateTimer]; + + // Sync to VBL to avoid tearing + + [self initSyncToVBL]; + + // OpenGL initializations + + [self initOpenGL:theFrame]; + + // Did the frame change? + + [self setPostsFrameChangedNotifications:YES]; +} // initOpenGLView + +//--------------------------------------------------------------------------------- + +#pragma mark - +#pragma mark Designated initializer + +//--------------------------------------------------------------------------------- + +- (NSOpenGLPixelFormat *) initPixelFormat +{ + NSOpenGLPixelFormatAttribute pixelAttributes[] + = { + NSOpenGLPFADoubleBuffer, + NSOpenGLPFADepthSize, 24, + NSOpenGLPFAStencilSize, 8, + 0 + }; + + CheckForGLSLHardwareSupport( pixelAttributes ); + + NSOpenGLPixelFormat *pixelFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes:pixelAttributes] + autorelease]; + + return pixelFormat; +} // initPixelFormat + +//--------------------------------------------------------------------------------- + +- (id) initWithFrame:(NSRect)theFrame + pixelFormat:(NSOpenGLPixelFormat *)thePixelFormat +{ + // Create a GL Context to use - i.e. init the superclass + + if( thePixelFormat == nil ) + { + thePixelFormat = [self initPixelFormat]; + } // if + + self = [super initWithFrame:theFrame + pixelFormat:thePixelFormat]; + + if( self ) + { + [self initOpenGLView:&theFrame]; + } // if + + return self; +} // initWithFrame + +//--------------------------------------------------------------------------------- + +- (id) initWithFrame:(NSRect)theFrame +{ + return [self initWithFrame:theFrame + pixelFormat:nil]; +} // initWithFrame + +//--------------------------------------------------------------------------------- + +#pragma mark - +#pragma mark Deallocating Resources + +//--------------------------------------------------------------------------------- + +- (void) deallocTimer +{ + if( timer ) + { + [timer invalidate]; + [timer release]; + + timer = nil; + } // if +} // deallocTimer + +//--------------------------------------------------------------------------------- + +- (void) deallocOpenGLResources +{ + if( tranguloidTrefoil ) + { + [tranguloidTrefoil release]; + + tranguloidTrefoil = nil; + } // if + + if( patternID ) + { + glDeleteTextures(1, &patternID); + } // if + + if( paletteID ) + { + glDeleteTextures(1, &paletteID); + } // if + + if( plasma ) + { + [plasma release]; + + plasma = nil; + } // if + + if( info ) + { + [info release]; + + info = nil; + } // if + + if( infoString ) + { + [infoString release]; + + infoString = nil; + } // if +} //deallocOpenGLResources + +//--------------------------------------------------------------------------------- + +- (void) dealloc +{ + // Release the update timer + + [self deallocTimer]; + + // Delete OpenGL resources + + [self deallocOpenGLResources]; + + //Dealloc the superclass + + [super dealloc]; +} // dealloc + +//--------------------------------------------------------------------------------- + +#pragma mark - +#pragma mark Binding palette & pattern + +//--------------------------------------------------------------------------------- + +- (void) bindPalette +{ + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_1D, paletteID); +} // bindPalette + +//--------------------------------------------------------------------------------- + +- (void) bindPattern +{ + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, patternID); +} // bindPattern + +//--------------------------------------------------------------------------------- + +#pragma mark - +#pragma mark Updating Drawing Parameters + +//--------------------------------------------------------------------------------- + +- (void) updateOffset +{ + offset += kOffsetDelta; + + if( offset > 1.0f ) + { + offset = 0.0f; + } // if +} // updateOffset + +//--------------------------------------------------------------------------------- + +- (NSTimeInterval) updateTimeDelta +{ + NSTimeInterval timeNow = [NSDate timeIntervalSinceReferenceDate]; + NSTimeInterval timeDelta = timeNow - lastFrameReferenceTime; + + return timeDelta; +} // updateTimeDelta + +//--------------------------------------------------------------------------------- + +- (void) updatePitch +{ + if( pitch < -45.0f ) + { + pitch = -45.0f; + } // if + else if( pitch > 90.0f ) + { + pitch = 90.0f; + } // else if + + glRotatef(pitch, 1.0f, 0.0f, 0.0f); +} // updatePitch + +//--------------------------------------------------------------------------------- + +- (void) updateAngle +{ + if( !leftMouseIsDown && !rightMouseIsDown ) + { + NSTimeInterval updateTimeDelta = [self updateTimeDelta]; + + angle += kViewRotationDegreesPerSecond * updateTimeDelta; + + if( angle >= 360.0f ) + { + angle -= 360.0f; + } // if + } // if + + // update object rotation + + glRotatef( angle, 0.0f, 1.0f, 0.0f ); + + // reset time in all cases + + lastFrameReferenceTime = [NSDate timeIntervalSinceReferenceDate]; +} // updateAngle + +//--------------------------------------------------------------------------------- + +#pragma mark - +#pragma mark Updating & Resizing + +//--------------------------------------------------------------------------------- + +- (void) updatePrespectiveMatrix +{ + GLdouble width = (GLdouble)NSWidth(bounds); + GLdouble height = (GLdouble)NSHeight(bounds); + GLdouble aspect = width / height; + GLdouble right = 0.15 * aspect * zoom; + GLdouble left = -right; + GLdouble top = 0.15 * zoom; + GLdouble bottom = -top; + GLdouble zNear = 1.0; + GLdouble zFar = 8.0; + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + glFrustum(left, right, bottom, top, zNear, zFar); + + glMatrixMode(GL_MODELVIEW); +} // updatePrespectiveMatrix + +//--------------------------------------------------------------------------------- +// +// Handles resizing/updating of OpenGL needs context update and if the window +// dimensions change, window dimensions update, reseting of viewport and an update +// of the projection matrix. +// +//--------------------------------------------------------------------------------- + +- (void) resizeView +{ + NSRect viewBounds = [self bounds]; + + if( !NSEqualRects( viewBounds, bounds ) ) + { + GLsizei width = (GLsizei)NSWidth(viewBounds); + GLsizei height = (GLsizei)NSHeight(viewBounds); + + // GLUT string object needs to know the view bounds have changed as well + + if( infoString ) + { + [infoString release]; + + infoString = nil; + } // if + + infoString = [[NSString alloc] initWithFormat:@"Bounds: %ld x %ld",width,height]; + + [info setViewSize:&viewBounds.size]; + + // Update the view bounds + + bounds = viewBounds; + + // Prespective matrix & the OpenGL view needs an update as well + + [self updatePrespectiveMatrix]; + + // View port has changed as well + + glViewport(0, 0, width, height); + } // if +} // resizeView + +//--------------------------------------------------------------------------------- +// +// Window resizes, moves and display changes. +// +//--------------------------------------------------------------------------------- + +- (void) update +{ + [super update]; +} // update + +//--------------------------------------------------------------------------------- + +#pragma mark - +#pragma mark Draw Utilities + +//--------------------------------------------------------------------------------- + +- (void) drawBegin +{ + [[self openGLContext] makeCurrentContext]; + + [self resizeView]; + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + glClearColor(0.075f, 0.075f, 0.075f, 1.0f); + + glPushMatrix(); +} // drawBegin + +//--------------------------------------------------------------------------------- + +- (void) drawEnd +{ + glPopMatrix(); + + [info drawString:infoString]; + + [[self openGLContext] flushBuffer]; +} // drawEnd + +//--------------------------------------------------------------------------------- + +#pragma mark - +#pragma mark Drawing Utilities + +//--------------------------------------------------------------------------------- + +- (void) scaleModel +{ + glScalef(0.055f, 0.055f, 0.055f); + + // Use our display list + + glCallList(tranguloidTrefoilDL); +} // scaleModel + +//--------------------------------------------------------------------------------- + +- (void) applyShader +{ + // Bind the shader + + glUseProgramObjectARB(programObject); + + // Modify offset uniform + + glUniform1fvARB(locations[kUniformOffset], 1, &offset); + + // Use our display list + + [self scaleModel]; + + // Unbind the shader + + glUseProgramObjectARB(NULL); +} // applyShader + +//--------------------------------------------------------------------------------- + +- (void) drawModel +{ + [self bindPalette]; + + [self bindPattern]; + + [self applyShader]; + + [self updateOffset]; +} // drawModel + +//--------------------------------------------------------------------------------- + +-(void) updateModel +{ + // Constant rotation of the subject + + [self updatePitch]; + + [self updateAngle]; + + // Draw the model + + [self drawModel]; +} // updateModel + +//--------------------------------------------------------------------------------- + +- (void) drawRect:(NSRect)theRect +{ + [self drawBegin]; + + [self updateModel]; + + [self drawEnd]; +} // drawRect + +//--------------------------------------------------------------------------------- + +#pragma mark - +#pragma mark Handling mouse events + +//--------------------------------------------------------------------------------- + +- (void)mouseDown:(NSEvent *)theEvent +{ + lastMousePoint = [self convertPoint:[theEvent locationInWindow] + fromView:nil]; + leftMouseIsDown = YES; +} // mouseDown + +//--------------------------------------------------------------------------------- + +- (void)rightMouseDown:(NSEvent *)theEvent +{ + lastMousePoint = [self convertPoint:[theEvent locationInWindow] + fromView:nil]; + rightMouseIsDown = YES; +} // rightMouseDown + +//--------------------------------------------------------------------------------- + +- (void)mouseUp:(NSEvent *)theEvent +{ + leftMouseIsDown = NO; +} // mouseUp + +//--------------------------------------------------------------------------------- + +- (void)rightMouseUp:(NSEvent *)theEvent +{ + rightMouseIsDown = NO; +} // rightMouseUp + +//--------------------------------------------------------------------------------- + +- (void)mouseDragged:(NSEvent *)theEvent +{ + if( [theEvent modifierFlags] & NSRightMouseDown ) + { + [self rightMouseDragged:theEvent]; + } // if + else + { + NSPoint mouse = [self convertPoint:[theEvent locationInWindow] + fromView:nil]; + + pitch += lastMousePoint.y - mouse.y; + angle -= lastMousePoint.x - mouse.x; + + lastMousePoint = mouse; + + [self setNeedsDisplay:YES]; + } // else +} // mouseDragged + +//--------------------------------------------------------------------------------- + +- (void)rightMouseDragged:(NSEvent *)theEvent +{ + NSPoint mouse = [self convertPoint:[theEvent locationInWindow] + fromView:nil]; + + zoom += 0.01f * (lastMousePoint.y - mouse.y); + + if( zoom < 0.05f ) + { + zoom = 0.05f; + } // if + else if( zoom > 2.0f ) + { + zoom = 2.0f; + } // else if + + lastMousePoint = mouse; + + [self updatePrespectiveMatrix]; + + [self setNeedsDisplay:YES]; +} // rightMouseDragged + +//--------------------------------------------------------------------------------- + +@end + +//--------------------------------------------------------------------------------- + +//--------------------------------------------------------------------------------- + diff --git a/GLSLBasicsCocoaDL/app/Release/GLSLBasicsCocoaDL.app/Contents/Info.plist b/GLSLBasicsCocoaDL/app/Release/GLSLBasicsCocoaDL.app/Contents/Info.plist new file mode 100644 index 00000000..b5308ef4 --- /dev/null +++ b/GLSLBasicsCocoaDL/app/Release/GLSLBasicsCocoaDL.app/Contents/Info.plist @@ -0,0 +1,30 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + GLSLBasicsCocoaDL + CFBundleIconFile + SimpleFBOIcon + CFBundleIdentifier + com.apple.GLSLBasicsCocoaDL + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + GLSLBasicsCocoaDL + CFBundlePackageType + APPL + CFBundleSignature + ???? + CFBundleVersion + 1.2 + LSMinimumSystemVersion + 10.5 + NSMainNibFile + MainMenu + NSPrincipalClass + NSApplication + + diff --git a/GLSLBasicsCocoaDL/app/Release/GLSLBasicsCocoaDL.app/Contents/MacOS/GLSLBasicsCocoaDL b/GLSLBasicsCocoaDL/app/Release/GLSLBasicsCocoaDL.app/Contents/MacOS/GLSLBasicsCocoaDL new file mode 100755 index 00000000..d76f3ec5 Binary files /dev/null and b/GLSLBasicsCocoaDL/app/Release/GLSLBasicsCocoaDL.app/Contents/MacOS/GLSLBasicsCocoaDL differ diff --git a/GLSLBasicsCocoaDL/app/Release/GLSLBasicsCocoaDL.app/Contents/PkgInfo b/GLSLBasicsCocoaDL/app/Release/GLSLBasicsCocoaDL.app/Contents/PkgInfo new file mode 100644 index 00000000..bd04210f --- /dev/null +++ b/GLSLBasicsCocoaDL/app/Release/GLSLBasicsCocoaDL.app/Contents/PkgInfo @@ -0,0 +1 @@ +APPL???? \ No newline at end of file diff --git a/GLSLBasicsCocoaDL/app/Release/GLSLBasicsCocoaDL.app/Contents/Resources/English.lproj/InfoPlist.strings b/GLSLBasicsCocoaDL/app/Release/GLSLBasicsCocoaDL.app/Contents/Resources/English.lproj/InfoPlist.strings new file mode 100644 index 00000000..e0938285 Binary files /dev/null and b/GLSLBasicsCocoaDL/app/Release/GLSLBasicsCocoaDL.app/Contents/Resources/English.lproj/InfoPlist.strings differ diff --git a/GLSLBasicsCocoaDL/app/Release/GLSLBasicsCocoaDL.app/Contents/Resources/English.lproj/MainMenu.nib/designable.nib b/GLSLBasicsCocoaDL/app/Release/GLSLBasicsCocoaDL.app/Contents/Resources/English.lproj/MainMenu.nib/designable.nib new file mode 100644 index 00000000..d710d4a8 --- /dev/null +++ b/GLSLBasicsCocoaDL/app/Release/GLSLBasicsCocoaDL.app/Contents/Resources/English.lproj/MainMenu.nib/designable.nib @@ -0,0 +1,719 @@ + + + + 1050 + 9E17 + 670 + 949.33 + 352.00 + + YES + + + + + YES + com.apple.InterfaceBuilder.CocoaPlugin + + + YES + + + NSApplication + + + + FirstResponder + + + NSApplication + + + 13 + 2 + {{138, 511}, {512, 512}} + 1886912512 + GLSL Basics + NSWindow + + View + + {1024, 1024} + {256, 256} + + + 256 + + YES + + + 319 + {512, 512} + + GLSLBasicsView + NSOpenGLView + + + {512, 512} + + + {{0, 0}, {1680, 1028}} + {256, 278} + {1024, 1046} + + + MainMenu + + YES + + + GLSL Basics + + 1048576 + 2147483647 + + NSImage + NSMenuCheckmark + + + NSImage + NSMenuMixedState + + submenuAction: + + GLSL Basics + + YES + + + About GLSL Basics + + 2147483647 + + + + + + YES + YES + + + 1048576 + 2147483647 + + + + + + UHJlZmVyZW5jZXPigKY + , + 1048576 + 2147483647 + + + + + + YES + YES + + + 1048576 + 2147483647 + + + + + + Services + + 1048576 + 2147483647 + + + submenuAction: + + + Services + + + YES + + _NSServicesMenu + + + + + YES + YES + + + 1048576 + 2147483647 + + + + + + Hide GLSL Basics + h + 1048576 + 2147483647 + + + + + + Hide Others + h + 1572864 + 2147483647 + + + + + + Show All + + 1048576 + 2147483647 + + + + + + YES + YES + + + 1048576 + 2147483647 + + + + + + Quit GLSL Basics + q + 1048576 + 2147483647 + + + + + _NSAppleMenu + + + + + Window + + 1048576 + 2147483647 + + + submenuAction: + + + Window + + + YES + + + Minimize + m + 1048576 + 2147483647 + + + + + + Zoom + + 1048576 + 2147483647 + + + + + + YES + YES + + + 1048576 + 2147483647 + + + + + + Bring All to Front + + 1048576 + 2147483647 + + + + + _NSWindowsMenu + + + + _NSMainMenu + + + + + YES + + + performMiniaturize: + + + + 37 + + + + arrangeInFront: + + + + 39 + + + + terminate: + + + + 139 + + + + orderFrontStandardAboutPanel: + + + + 142 + + + + hideOtherApplications: + + + + 146 + + + + hide: + + + + 152 + + + + unhideAllApplications: + + + + 153 + + + + performZoom: + + + + 198 + + + + + YES + + 0 + + YES + + + + + + -2 + + + RmlsZSdzIE93bmVyA + + + -1 + + + First Responder + + + -3 + + + Application + + + 21 + + + YES + + + + Window + + + 2 + + + YES + + + + + + 206 + + + + + 29 + + + YES + + + + + MainMenu + + + 19 + + + YES + + + + + + 24 + + + YES + + + + + + + + + 5 + + + + + 23 + + + + + 92 + + + + + 197 + + + + + 56 + + + YES + + + + + + 57 + + + YES + + + + + + + + + + + + + + + + 58 + + + + + 129 + + + + + 131 + + + YES + + + + + + 130 + + + + + 134 + + + + + 136 + + + + + 143 + + + + + 144 + + + + + 145 + + + + + 149 + + + + + 150 + + + + + 196 + + + + + + + YES + + YES + -1.IBPluginDependency + -2.IBPluginDependency + -3.IBPluginDependency + -3.ImportedFromIB2 + 129.IBPluginDependency + 129.ImportedFromIB2 + 130.IBPluginDependency + 130.ImportedFromIB2 + 131.IBPluginDependency + 131.ImportedFromIB2 + 134.IBPluginDependency + 134.ImportedFromIB2 + 136.IBPluginDependency + 136.ImportedFromIB2 + 143.IBPluginDependency + 143.ImportedFromIB2 + 144.IBPluginDependency + 144.ImportedFromIB2 + 145.IBPluginDependency + 145.ImportedFromIB2 + 149.IBPluginDependency + 149.ImportedFromIB2 + 150.IBPluginDependency + 150.ImportedFromIB2 + 19.IBPluginDependency + 19.ImportedFromIB2 + 196.IBPluginDependency + 196.ImportedFromIB2 + 197.IBPluginDependency + 197.ImportedFromIB2 + 2.IBPluginDependency + 2.ImportedFromIB2 + 206.IBPluginDependency + 206.ImportedFromIB2 + 21.IBEditorWindowLastContentRect + 21.IBPluginDependency + 21.IBWindowTemplateEditedContentRect + 21.ImportedFromIB2 + 21.NSWindowTemplate.visibleAtLaunch + 21.windowTemplate.hasMaxSize + 21.windowTemplate.hasMinSize + 21.windowTemplate.maxSize + 21.windowTemplate.minSize + 23.IBPluginDependency + 23.ImportedFromIB2 + 24.IBPluginDependency + 24.ImportedFromIB2 + 29.IBEditorWindowLastContentRect + 29.IBPluginDependency + 29.ImportedFromIB2 + 5.IBPluginDependency + 5.ImportedFromIB2 + 56.IBPluginDependency + 56.ImportedFromIB2 + 57.IBPluginDependency + 57.ImportedFromIB2 + 58.IBPluginDependency + 58.ImportedFromIB2 + 92.IBPluginDependency + 92.ImportedFromIB2 + + + YES + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + {{0, 472}, {512, 512}} + com.apple.InterfaceBuilder.CocoaPlugin + {{0, 472}, {512, 512}} + + + + + {1024, 1024} + {256, 256} + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + {{0, 975}, {198, 20}} + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + + + + + YES + + YES + + + YES + + + + + YES + + YES + + + YES + + + + 208 + + + + YES + + FirstResponder + NSObject + + IBUserSource + + + + + GLSLBasicsView + NSOpenGLView + + IBProjectSource + GLSLBasicsView.h + + + + GLSLBasicsView + NSOpenGLView + + IBUserSource + + + + + + 0 + ../GLSLBasicsCocoaDL.xcodeproj + 3 + + diff --git a/GLSLBasicsCocoaDL/app/Release/GLSLBasicsCocoaDL.app/Contents/Resources/English.lproj/MainMenu.nib/keyedobjects.nib b/GLSLBasicsCocoaDL/app/Release/GLSLBasicsCocoaDL.app/Contents/Resources/English.lproj/MainMenu.nib/keyedobjects.nib new file mode 100644 index 00000000..52d228e7 Binary files /dev/null and b/GLSLBasicsCocoaDL/app/Release/GLSLBasicsCocoaDL.app/Contents/Resources/English.lproj/MainMenu.nib/keyedobjects.nib differ diff --git a/GLSLBasicsCocoaDL/app/Release/GLSLBasicsCocoaDL.app/Contents/Resources/Plasma.fs b/GLSLBasicsCocoaDL/app/Release/GLSLBasicsCocoaDL.app/Contents/Resources/Plasma.fs new file mode 100755 index 00000000..df978046 --- /dev/null +++ b/GLSLBasicsCocoaDL/app/Release/GLSLBasicsCocoaDL.app/Contents/Resources/Plasma.fs @@ -0,0 +1,63 @@ +//--------------------------------------------------------------------------- +// +// File: Plasma.frag +// +// Abstract: GLSL Plasma fragment shader +// +// Disclaimer: IMPORTANT: This Apple software is supplied to you by +// Inc. ("Apple") in consideration of your agreement to the following terms, +// and your use, installation, modification or redistribution of this Apple +// software constitutes acceptance of these terms. If you do not agree with +// these terms, please do not use, install, modify or redistribute this +// Apple software. +// +// In consideration of your agreement to abide by the following terms, and +// subject to these terms, Apple grants you a personal, non-exclusive +// license, under Apple's copyrights in this original Apple software (the +// "Apple Software"), to use, reproduce, modify and redistribute the Apple +// Software, with or without modifications, in source and/or binary forms; +// provided that if you redistribute the Apple Software in its entirety and +// without modifications, you must retain this notice and the following +// text and disclaimers in all such redistributions of the Apple Software. +// Neither the name, trademarks, service marks or logos of Apple Inc. may +// be used to endorse or promote products derived from the Apple Software +// without specific prior written permission from Apple. Except as +// expressly stated in this notice, no other rights or licenses, express +// or implied, are granted by Apple herein, including but not limited to +// any patent rights that may be infringed by your derivative works or by +// other works in which the Apple Software may be incorporated. +// +// The Apple Software is provided by Apple on an "AS IS" basis. APPLE +// MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION +// THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND +// OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. +// +// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL +// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, +// MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED +// AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), +// STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Copyright (c) 2004-2008 Apple Inc., All rights reserved. +// +//--------------------------------------------------------------------------- + +uniform sampler1D palette; +uniform sampler2D pattern; +uniform float offset; +varying float LightIntensity; + +void main() +{ + vec4 color; + color = texture2D(pattern, gl_TexCoord[0].st); + color = texture1D(palette, (color.r+offset)); + color.a = 1.0; + color = color * LightIntensity; + color = clamp(color, 0.0, 1.0); + gl_FragColor = color; +} diff --git a/GLSLBasicsCocoaDL/app/Release/GLSLBasicsCocoaDL.app/Contents/Resources/Plasma.vs b/GLSLBasicsCocoaDL/app/Release/GLSLBasicsCocoaDL.app/Contents/Resources/Plasma.vs new file mode 100755 index 00000000..121c0f2f --- /dev/null +++ b/GLSLBasicsCocoaDL/app/Release/GLSLBasicsCocoaDL.app/Contents/Resources/Plasma.vs @@ -0,0 +1,62 @@ +//--------------------------------------------------------------------------- +// +// File: Plasma.vert +// +// Abstract: GLSL Plasma vertex shader +// +// Disclaimer: IMPORTANT: This Apple software is supplied to you by +// Inc. ("Apple") in consideration of your agreement to the following terms, +// and your use, installation, modification or redistribution of this Apple +// software constitutes acceptance of these terms. If you do not agree with +// these terms, please do not use, install, modify or redistribute this +// Apple software. +// +// In consideration of your agreement to abide by the following terms, and +// subject to these terms, Apple grants you a personal, non-exclusive +// license, under Apple's copyrights in this original Apple software (the +// "Apple Software"), to use, reproduce, modify and redistribute the Apple +// Software, with or without modifications, in source and/or binary forms; +// provided that if you redistribute the Apple Software in its entirety and +// without modifications, you must retain this notice and the following +// text and disclaimers in all such redistributions of the Apple Software. +// Neither the name, trademarks, service marks or logos of Apple Inc. may +// be used to endorse or promote products derived from the Apple Software +// without specific prior written permission from Apple. Except as +// expressly stated in this notice, no other rights or licenses, express +// or implied, are granted by Apple herein, including but not limited to +// any patent rights that may be infringed by your derivative works or by +// other works in which the Apple Software may be incorporated. +// +// The Apple Software is provided by Apple on an "AS IS" basis. APPLE +// MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION +// THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS +// FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND +// OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. +// +// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL +// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, +// MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED +// AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), +// STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Copyright (c) 2004-2008 Apple Inc., All rights reserved. +// +//--------------------------------------------------------------------------- + +varying float LightIntensity; +uniform vec3 LightPosition; + +void main() +{ + vec4 ECposition = gl_ModelViewMatrix * gl_Vertex; + vec3 tnorm = normalize(vec3 (gl_NormalMatrix * gl_Normal)); + + LightIntensity = dot(normalize(LightPosition - vec3 (ECposition)), tnorm) * 1.5; + + gl_Position = ftransform(); + + gl_TexCoord[0] = gl_MultiTexCoord0; +} diff --git a/GLSLBasicsCocoaDL/info.plist b/GLSLBasicsCocoaDL/info.plist new file mode 100755 index 00000000..47c66bd2 --- /dev/null +++ b/GLSLBasicsCocoaDL/info.plist @@ -0,0 +1,30 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIconFile + SimpleFBOIcon + CFBundleIdentifier + com.apple.GLSLBasicsCocoaDL + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + APPL + CFBundleSignature + ???? + CFBundleVersion + 1.2 + NSMainNibFile + MainMenu + NSPrincipalClass + NSApplication + LSMinimumSystemVersion + 10.5 + +