0

When creating an OpenGL-es application in swift, you have to convert all the parameters to their gl equivalenets. For example...

func createCamera(screenWidth:Int, screenHeight:Int){
    glViewport(GLint(0), GLint(0), GLsizei(screenWidth), GLsizei(screenHeight));

}

As you can see I have to convert every glViewPort() parameter to the data type that OpenGL likes, such as Glint. Is there a more efficient way of doing this? I feel like with swift all I've been doing is wrapping everything.

1 Answer 1

1

This is the way it is. (For now, at least? As always, file a bug if you'd like to see Apple change things.) Neither Swift nor OpenGL are really designed around being friendly to each other — OpenGL is a C API, and Swift's API bridging seems to be more centered around ObjC APIs and their conventions.

You could probably make a few type extensions and function overloads to make working with GL from Swift a bit smoother. For example, if you implement extension GLint : IntegerLiteralConvertible sensibly, you'll be able to pass integer literals to GL APIs without wrapping each in a GLint() conversion. Making GL functions take Swift types would be a taller order, but only due to the sheer number of them, not their complexity. For example:

func glViewport(x: Int, y: Int, width: Int, height: Int) {
    GL.glViewport(GLint(x), GLint(y), GLsizei(width), GLsizei(height)
}

I wouldn't be surprised if someone were already doing something like this and publishing a library, but I haven't heard of any such efforts yet.

1
  • Ok thanks. I guess in the grand scheme of things it isn't so bad.
    – NJGUY
    Oct 29, 2014 at 18:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.