Coder Social home page Coder Social logo

opengl.swift's Introduction

#OpenGL.swift

If you try to create a new OpenGL ES project in Xcode using Swift you will find that all of the code is commented out. This is primarily because Swift doesn't support union structs as they are inherently unsafe, however GLKit's math utilities heavily rely on them.

This project provides a drop in replacement for GLKit's math functions and types (it still uses them under the hood though). Instead of using GLK* types and functions you can now use TD* in Swift. As well as this the project also covers:

  • Operator overloading so that matrix math is really simple
  • Properties added via class extensions to all of GLKit's classes
  • Wrappers around common OpenGL functions for submitting vertex and uniform data using the TD* matrix and vector types

##Installation

You'll need to add Math.h, Math.m and Math-Swift.swift to your Xcode project. In order for these to compile properly you'll need to add #import "Math.h" to your bridging header.

##Example

let aspect = GLfloat(CGRectGetWidth(self.view.bounds) / CGRectGetHeight(self.view.bounds))
let projectionMatrix = TDMatrix4MakePerspective(GLKMathDegreesToRadians(65.0), aspect, 0.1, 100.0)
var modelViewMatrix = TDMatrix4MakeTranslation(0.0, 0.0, 1.5)
modelViewMatrix = TDMatrix4Rotate(modelViewMatrix, rotation, 1.0, 1.0, 1.0)

//If using GLKit
self.effect?.transform.td_projectionMatrix = projectionMatrix
self.effect?.transform.td_modelviewMatrix = modelViewMatrix

//If using raw shaders
let mvpMatrix = projectionMatrix * modelViewMatrix
glUniformMatrix4fv(mvpMatrixSlot, TDFalse, mvpMatrix)

##Contact

Either create an issue on GitHub or email [email protected].

##License

Apache v2, see LICENSE file.

opengl.swift's People

Contributors

clns avatar programmingthomas avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.