Friday, March 30, 2012

Part 8: Touch Events and Movement


Now, it would be fun if our object could somehow move. That way, we would truly see the effect of adding lighting to the scene. What would also be fun is to add a touch event to start and stop the object from moving. The best part is that it's very easy to do with the UIKit's gesture recognizers. And yes, you can use them in the GLKView!

What we're going to do is that every time you double tap, it will either start or stop the cube from rotating. Here's a link to the project after adding Touch events and movement:


Thursday, March 29, 2012

Part 7: Lighting


For this post, we're going to add basic lighting to the model. This will make the edges pop out and the shape will definitely have a better 3D feel. For this, we will need to add normal data for each vertex. This will allow us to calculate light intensity at each vertex, and the rasterize stage will be able to interpolate those values across the shape. More vertex data means a new attribute, and we'll also need to modify the shaders. Everything else should be unchanged.

I've also compiled what we've done so far, and I put some of the methods in a helper class called GLHelper. Additionally, I dropped the vertex data in a header file. These changes make the Controller's implementation a bit cleaner.



Wednesday, March 28, 2012

Part 6 : Drawing!


This post is about one little thing left do to after all this code. Draw the damn cube! Everything we've done with VAOs and VBOs will make our task considerably easier.

Part 5: VBOs and VAOs and more


In this post, we'll be creating the 2 VBOs that will allow us to pass our vertex data as well as the indices describing the shape directly to the GPU's memory. VBOs will make drawing much faster since you won't need to pass that data every time you want to draw. What you still need to do is bind those buffers and "describe" the data so that OpenGL can understand how to use it as an attribute in your shader program.

We'll also be creating a VAO, which will store the set of bindings. So, instead of binding the first VBO and describing it, as well as binding the second one and describing it, we'll just bind the VAO, and everything else will be done for us inside OpenGL.

Tuesday, March 27, 2012

Part 4: The Program


In this post, I will write the code to compile and link the shaders inside the program to be able to use it for drawing.

Part 3: Vertex Data and Shader Source


In this post, I will give you the arrays I will be using for drawing my cube (not a rabbit), both vertices and indices array. I will add a little piece of code that enables some features in OpenGL and the view, and I will set up the ViewPort. Finally, I will add the 2 shader files to my project and write the code for each of them.

Part 2: Timeout or a post about posts


In this post, I will compile a list of links or books that I found extremely useful to help me understand how everything works together in OpenGL ES 2.0 and GLKit. I will try to update my post when I find something new, or if I remember other links that I forgot to put in earlier. You can probably imagine that I was inspired by many other blogs or websites all over the internet, but I'm not trying to steal anything, so just e-mail me if I forgot to mention your obscure internet blog.

Monday, March 26, 2012

Part 1: The template


This post is mostly to get you up and running (almost) from scratch. Remember that I'm using iOS 5. This means automatic reference counting and storyboards, which are both amazing features that make your life easier. After this post, you'll have a basic template to use when you want to make OpenGL applications.


Introduction

The purpose of this blog is to put together a journal of what I've learned trying to draw some 3D on my iOS device. I want to do it mostly for myself as an exercise to remember all this stuff, but I'm also hoping it might help someone in the future.

In the past few months, I've read books about openGL ES, iOS 5 programming, and I also watched the videos of Paul Hegarty's iPhone application development class on iTunes. The problem is the following: There's just not many tutorials out there that blend together openGL ES 2.0, iOS, and GLKit.

I know that this is very platform specific, but not all developers want to have a multi-platform solution written in C or C++. Plus, if you've chosen iOS, then you've probably chosen the easiest platform to get you started working with OpenGL ES 2.0. GLKit is extremely easy to use and does a lot of nasty stuff behind the scenes for you, and provides a math library, a texture loader, and many other goodies.