Getting started in OpenGL ES

Lately I’ve been really diving into OpenGL ES and it actually has been much easier than I was expecting. OpenGL is always referred to with the feeling that it’s some kind of complicated voodoo. Now, it might just be because of all the great resources I’ve found from people who are much more pioneering than me but so far it’s been quite reasonable. Now I’m sure some of you are reading this saying “But a few weeks ago you were raving about how CoreAnimation is plenty powerful enough to make a 2D game” and the answer is “It is”. However quickly into prototyping my mole game I was realizing that I am probably going to want more power for cool effects to make it really look awesome. CoreAnimation is still a very reasonable approach, and it was great for prototyping the game up fairly quickly. If you’re the kind of person that thinks they would drown in a highly technical subject like OpenGL then CoreAnimation is a very valid option. I, on the other hand, am the kind of person to keep clawing my way up if there are better techniques out there. (And even here “better” isn’t necessarily the right word, it’s “more powerful” in this context.)

The Plan

The plan over the next couple weeks of blog posts is to talk about using OpenGL ES for creating a 2D game. There are a lot of OpenGL resources out there, but most of them are about OpenGL and cover topics that OpenGL ES doesn’t support. Of the remaining ones that do talk about OpenGL ES they tend to be about 3D. So I hope to address some of the topics more relevant to making a 2D game in OpenGL ES on the iPhone.

Resources

So, as I was saying over this past weekend I went through a multitude of OpenGL ES tutorials, guides, and videos. When learning something as complicated as OpenGL I really feel like reading through multiple sources is beneficial. It’s such a complex subject it’s unlikely that one source will talk hit every topic, or explain everything in a way that clicks for you. When you read several descriptions of something each one can fill in the blanks for the other.

Without further ado I present my recommended sources for someone trying to learn OpenGL ES for the iPhone:

71 Squared’s iOS Tutorials
These tutorials from 71 squared’s Mike Daley are excellent. There’s 14 videos of Mike basically starting from scratch with OpenGL so it’s absolutely packed with information! A couple notes though: They are a little dated so there are better ways of doing some things (CADisplayLink for one). Also he is learning as he goes, so you really need to watch the whole process because he address as lot of potential problems later in the series.

Learning iOS Game Programming
Also by Mike is a book he wrote after the video series. This book addresses both of the problems I listed up above. It goes through the process of making a game with OpenGL as a whole. I really can’t say enough good things about this book, if there’s one resource you should get it’s this! I hear a second one is in the works with follow up concepts, can’t wait!

Jeff Lamarche’s OpenGL Book Chapters
Jeff Lamarche was in the process of writing an OpenGL book when it got canceled. He generously posted the first four chapters he had already written on his blog. Though they mostly deal with OpenGL ES 2.0 I would say it’s one of the best resources for explaining shaders and the features from ES 2.0. It’s actually a shame this book never got finished.

All About OpenGL ES 2.x
Another OpenGL ES 2.0 tutorial, this time by Diney Bomfim. I actually didn’t find this one as helpful as the others, but I expect everyone learns differently so your mileage my vary. It’s definitely worth looking at.

Apple’s WWDC videos from 2010.
You need to log into the developer portal to access them but if you haven’t seen these yet let me tell you: They are a goldmine. There’s so much information here about all things iPhone. I hope you have many free hours to watch videos because you won’t want to stop.

Apple’s OpenGL ES Programming Guildline
This is definitely worth looking through as it has a lot to do with the specifics of the platform. Especially helpful are the tips about optimizing.

Ray Wenderlich’s Blog (New!)
Ray’s site is full of great tutorials so if you haven’t seen it yet be sure to check it out. This one is actually hot off the presses, posted just this week. Again it’s dealing with mostly ES 2.0 and 3D but covers many topics you’ll need to learn.

Phew, if those can keep you busy for a while then you have way too much time on your hands!

OpenGL ES 1.1 vs 2.0

One topic that’s going to come up a lot is the difference between OpenGL ES 1.1 and 2.0. First off the actual difference between the two is that 2.0 has a programable pipeline while 1.1 is a fixed pipeline. If you’ve read anything about OpenGL already you’ve probably heard these terms before. The short answer is that in 2.0 you have to write your own shaders while 1.1 uses pre-programmed shaders. Shaders are functions written in GLSL (GL Shader Language, similar to C) and basically control how things are rendered. If you want a better explanation about what shaders are read Jeff Lamarche’s blog linked above.

OpenGL 2.0 isn’t available on the iPhone 3G, only the 3GS and 4. This is a relevant factor though it’s becoming less relevant every day. I’m going to be starting out dealing only with ES 1.1. For 2D games the fixed pipeline will be all you need for 90% of what you do (warning: made up statistic).

Here’s a few examples of the kinds of 2D effects you could do with custom shaders in 2.0:
Depth of field – Blurring objects in the background
Bloom – When an intense light source bleeds around edges
Distortion effects – Ripples, bending
Motion Blur – Blur from high speed movement
Filters – Crosshatching, other visual styles
Various lighting and shadow effects

There are definitely some cool things you could do with 2.0 and I suspect I’ll be upgrading to 2.0 at some point, but again I want to start small and iterate upwards.

Shades of Gray

For this project I’m going to be working on a top down spaceship shooter game. It will be like a bullet hell except the fights will be mostly, if not completely, duels between you and an enemy. The concept of the game is that you live in a colorful world where things that are gray simply disappear. By shooting colored paint at your enemy you can change it’s color, you need to balance shooting RGB colors to make them Gray and thus disappear! I’ll be playing around with the actual gameplay during the process.

Hopefully next blog entry I’ll talk about getting some basic sprites set up and drawn with OpenGL ES 1.1!

Comments are closed.