Starting OpenGL
quinta-feira, fevereiro 12th, 2009Last August I joined a small team of individuals who wanted to create
a game. Through some dumb luck and opinion, I somehow convinced them
to work on an iPhone game. Since I was the only developer, I was
nominated to “learn how” and so I set to it.
I have never programmed in OpenGL before, and really, never programmed
a game that wasn’t in Pascal or QBasic back in High School, so this
was certainly new territory. I am a web application programmer by
trade, so most of my time as a developer has been spent interfacing
with databases through highly abstracted frameworks designed to make
features simple to implement and change. OpenGL is certainly not one
of those frameworks.
OpenGL, while it does make life easier on the programmer, is only as
performant as you’re willing to get dirty. The more you rely on the
framework, the less you’re going to get out of your game. When
you’re on a desktop, this is something you can get by with, but when
you’re developing for a mobile device, every CPU cycle is precious,
and every byte of memory is sacred. All we wanted to do was put
sprites on the screen and move them around. Hmmm, this was going to
be harder than I thought.
I started off by taking the example “Crash Lander” app that Apple
shipped with the iPhone SDK and began tweaking. I got my own sprites
appearing, and then got them rendering on a background of my choosing.
So far so good. We ended up creating a few “parallel to the screen”
planes to draw in where we put the background texture on and then I
spent quite a bit of time figuring out how gl_translate and gl_ortho
worked. It wasn’t pretty.
Once I had abstracted things away, I was able to hack together a UI
and some animations. They weren’t properly extracted and they
weren’t optimized, but they worked. Oh, the joy of seeing your
“game” working. At least it wasn’t exploding.
So, what I learned from all of this is that you have to approach
OpenGL programming from the same standpoint as any other kind of
programming: with a willingness to make mistakes and refactor. I
ended up finding another OpenGL programmer to make more progress since
my day job was demanding more time, but I can tell you now that I
would design and create a better STRUCTURE for the animation and user
input. Learning Objective-C might be a battle, but it’s nothing
compared to the crap I did in college.
In conclusion : Keep trying. Move forward. Refactor. Retool.
Make changes. Throw it away and start over. Learn from your
mistakes.
(by Mark Simoneau)





