Skip to content

Using MetalKit part 17

I am writing this article for three reasons: first, to tell you that I am working on updating all the Metalcode to Swift 3 and then moving the tutorials to a new home with a nicer design and a proper domain name; second, I wanted to show you a different way to work with MetalKit other than subclassing MTKView, that is, using the MTKViewDelegate; and third, I wanted to answer one of our readers’ question about how to draw wireframes.

Let’s start by using the code from Part 4 which is an Xcode project but we will turn it into a playground this time. This is going to be a shockingly short tutorial but all you have to do is add the following line right before encoding the draw command:


That’s it! Run the playground and enjoy the wireframed triangle. If you don’t want it to have an interpolated color, in the fragment shader also replace the return line with a constant color like green, for example:

return half4(0.0, 1.0, 0.0, 1.0);

The output image should look like this:

alt text

For a 3D rendering there is one more thing we need to do, disable the backface culling. If you’re working in the playground from Part 9 just comment out this line:


The output image should look like this:

alt text

The source code is posted on Github as usual.

Until next time!

Leave a Reply

Your email address will not be published. Required fields are marked *