Posts

Showing posts from July, 2015

0.1: The SwiftOpenGLView

Image
Create the View Now that you have a working Xcode project, we can set up the app for displaying some OpenGL content.  Cocoa apps are built using a number of windows and views.  A single window contains one base view--the content view.  It is the content view that holds subsequent views such as buttons, labels, text fields, etc.  Notice that every part of the user interface is at it's heart, a view. To insert a view into the app that will display our OpenGL content, we need to do two things:  1) use interface builder to insert an NSOpenGLView object into the app's window's content view, and 2) create a subclass of NSOpenGLView. Interface Builder To get to Interface Builder, click on Main.storyboard in the Project Navigator (if you can't see it press  ⌘1 to show the Navigator view or ⇧⌘Space to search the project for Main.storyboard).  The Editor view in the center of the project, will display a white background or it might show some windows.  To see everythin

0.0: Swift OpenGL Setup

Image
To follow along with these tutorials, you'll need a Mac with the latest public version of Xcode (Xcode 6.4 as of this writing).  To get Xcode, open the App Store and search for Xcode.  You'll see a bunch of applications, but Xcode should be the first one if you typed in "xcode" into the search field.  I already have the application downloaded, so the button says "Open", but if you haven't downloaded Xcode, the button will say "Get". You may be prompted to input your AppleID and password and click "Buy".  Remember, the app is free.  The app will download automatically when you "Buy" the app.  Once it has downloaded, you'll find it in your Applications folder, Launchpad, or by holding down  ⌘  and pressing the spacebar you'll get Spotlight Search where you can type in "xcode" and press return on the keyboard. The first time you open Xcode, you should see the splash screen.

Using Swift with OpenGL

Image
Programming with Mac has changed a lot since the introduction of Swift to the platform.  It's a great language that has grown so much since its conception a year ago.  The tendency is to continue to use old paradigms with new tools; however, Swift is so different from C and Obj-C.  It demands that we rethink how we program on the Mac so we aren't limiting the potential of this new language. With those ideas in mind, I have endeavored to rethink OpenGL programming in terms of using Swift.  Classically a C++ dominated topic, graphics programming in Swift offers some interesting twists this programming genre.  Though there are some great tutorials for using OpenGL in a Swift project, most of them do not utilize some of the new Swift paradigms (namely protocols, extensions, and more value types instead of reference types).  I am not an expert or even professional programmer by any means, but the tutorials that I shall write here work and are intended to be in line (as much as