I've been making really good progress on the OpenGL ES 2.0 book for Prags, and I'm really happy with what I've done so far. The book isn't quite as hand-holding as Beginning iPhone 3 Development was, but it's probably more hand-holding than any graphics programming book I've ever read. If you've got prior experience with graphics programming, you may get frustrated with the pace of the book. I'm working on Chapter 8 now, and I haven't even gotten to lighting yet.
Those of you who have never worked with a programmable pipeline engine like OpenGL ES 2.0 or have tried and been frustrated by the books and resources available, will (I hope) appreciate the approach I'm taking. I'm trying to be very, very thorough. I'm trying not to leave any questions hanging in the air. I've found, over the years, graphics programming books to be frustrating in that they assume a certain level of prior knowledge that's not easy to obtain outside of college math classes. It's my goal to explain not only how to do things, but why, and give at least some high-level information about the underlying concepts and math. My goal is to make graphics programming approachable for people who don't necessarily have math knowledge beyond basic high school geometry and trig. I can't do that with everything. For example, with projection matrices, I simply didn't think it was worth trying to cover homogeneous coordinates, so I focused on how projection vectors worked and mostly skipped the why. But that's an exception. In most cases, I'm really focusing on why we do what we do.
Writing books like this is fun, to be honest. I'm learning OpenGL ES 2.0 at a much deeper level than I previously knew and I feel good about the progress of the book. From the discussions I've had, I think there's a lot of people out there who want to program in OpenGL ES 2.0 so they can do cool stuff on the iPhone and iPad, but who just don't really know where to start. It's like all the cool stuff is sitting on a shelf just out of reach. And that's frustrating.
I don't know yet when the book will be available. I'm hoping that it will get accepted into the beta books program when it's far enough along. If that happens, I'll make sure to post about it here, because then the book will be available for reading online before the official release.
Now, no part of the book is ready for public consumption yet, but I'm going to post some of my code from the book today. I know there's a shortage of good, clean, straightforward iOS OpenGL ES 2.0 code out there, so I though I'd post one of the projects from the chapter I'm working on now for anybody who wanted to try and figure out how it all fits together.
Although it's a a simple app, there's a fair amount going on. I take care of setting up a perspective projection and a model view matrix that both moves and rotates the object and also do texture mapping. There's a simple vertex shader and a fragment shader that take care of transforming the scene and doing the texture mapping. Now, in OpenGL ES 2.0, there are no built-in functions to handle any of these tasks, so it's all got to be done manually, primarily in the shaders. There are also some useful classes and functions you may be able to leverage in your own code. Much of what's in here is based on code I've posted in the past, but it's all been updated and tweaked for use in the OpenGL ES 2.0 programmable pipeline.
Yes, it's our old friend, the icosahedron, but all dressed up to look like a twenty-side die. Because, you know, what's more geeky than a twenty-sided die?
Now, this project hasn't been code reviewed. Heck, the chapter it's for hasn't even been written yet, so I'm sure there are mistakes and CBBs (could be betters). This is also not particularly efficient code. I'm putting off until later in the book a number of optimizations, including vectorizing the matrix and vector functions, interleaving per-vertex attributes, and using VBOs and VAOs. At this point, I'm much more focused on clarity and concepts than on performance, so just be aware of that before you decide to incorporate any of this code into a production project.
As always, there are no requirements placed on your use of this code. You don't have to give attribution, and you don't have to contribute back changes, though if you do fix or improve something, I'd be glad to hear about it.
You can find the Xcode project right here.
I've also made the original Blender and Pixelmator files I used to create the vertices and texture coordinates of the icosahedron as well as the texture. You can download those here.
I am sorry, but have to say that I won't be able to answer questions about the code. Between the book and client work right, most days I'm at my desk from 8:00 in the morning until 1:00 or 2:00 the next morning, seven days a week, so if you need explanations, you're going to have to wait for the book.
Tuesday, July 13, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment