[swift-users] SwiftGL fundamentals are now complete!

David Turnbull dturnbull at gmail.com
Sat Jan 16 13:52:07 CST 2016


Behold, the power of Swift:

public func +<T:GLmathScalarType>(x1: T, x2: T) -> T {
    return T(x1, x2, +)
}

This is how the addition operator is implemented in SwiftGL. There's no
gyb, no macros, and no shenanigans. In less than 80 characters we created
an addition operator for 36 types.

SwiftGL fundamentals are now complete. Everything in the OpenGL 4.5 spec is
available in the loader. All the types, operators, and functions in the
GLSL 4.5 spec are available in the math library. This is a strong
foundation for 3D programming with the open source Swift. Nobody is going
to pull the rug out from under you since everything is implemented to a
spec that's been developed for over 20 years.

Funny thing is, even though everything is written to a C spec, it's all
very Swifty. All the types are MutableCollectionType, Hashable, and
Equatable. Almost everything is generic with deep prototypes. Even most of
the functions were already in Swift with exactly the same name. About the
only disconnect is that GLSL types aren't capitalized.

To prove the math library I wrote a new demo. This one has basic lighting
and camera movement with WASD. It will work on Mac and Linux. Give it a try.

Even if you're not interested in 3D programming, if the above example has
you curious there's more where that came from. SwiftGL has over 36000 lines
of code across 49 files. It was all written by one person after Swift
became open source and no, that's not an extra zero.

https://github.com/AE9RB/SwiftGL

There's still plenty to do. Documentation, tutorials, more unit tests,
libraries for resource loading, graph management, and functions that's
aren't in the spec. I'm optimistic that others will see Swift as a great
tool for creative coding and we'll soon have awesome tools.

-David "Expression too complex" Turnbull
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160116/6455dbed/attachment.html>


More information about the swift-users mailing list