2010-12-04

Review of OpenGL SuperBible 5th Edition

This is my review of OpenGL SuperBible: Comprehensive Tutorial and Reference (5th Edition):

For years, books in the OpenGL SuperBible series were recommended for anyone looking for an excellent tutorial and thorough coverage of OpenGL features. But up to OpenGL 2.0, programming in OpenGL was done through the fixed function pipeline, and the OpenGL SuperBible books were the best place to start learning that. With GLSL introduced in OpenGL 2.0, OpenGL supported both the traditional fixed function pipeline and a new programmable pipeline where you can write your own shader programs and have much more control over the graphic card. OpenGL 2.0 tried to have the best of both worlds: if you liked the old OpenGL then you can use it, and if you wanted to experiment with modern OpenGL you can use that as well. This resulted in a huge API with conflicting design goals. This conflict can be seen in the OpenGL(R) SuperBible: Comprehensive Tutorial and Reference (4th Edition), reflecting the version of OpenGL it covered. The tutorial part focused exclusively on fixed-function OpenGL. That part was excellent and I still use it as a reference when I'm programming for old mobile devices that supported only OpenGL ES 1.0. The book also introduced shaders among other advanced topics in the second part. This introduction didn't really follow from what you learned in the tutorial part. It was a group of separate articles that were written in a different style and tone. I don't doubt you can easily pick it up and learn writing shaders from these chapters, but they didn't really go about teaching you how to write shaders, instead focusing more on showing you cool examples of stuff you can do with shaders. Given that a lot of what you do with shaders requires a mathematical background -- which the 4th edition got around by introducing only what's necessary, someone learning OpenGL without such a background would get confused when suddenly the later chapters are talking about cosines and other concepts.

Eventually, the OpenGL API evolved and the fixed function commands were all deprecated and later moved to a different profile. The new OpenGL was much leaner and only revolves about creating shaders and writing to buffers. The problem is that it's easy to teach the old OpenGL, you don't need to know the underlying details of how light is calculated or how transformations are performed to write a program in fixed function OpenGL. You can get away without teaching anything but basic mathematics, and you could still come up with strong examples. With modern OpenGL, things are different. There is no built in lighting equation, no matrix stack, no functions to rotate an object or set a camera. You have to write all of that yourself. A book teaching modern OpenGL, or the core profile of OpenGL 3.3, needs to teach you not only OpenGL, but also the fundamentals of 3D graphics. Such a book would be quite big, advanced for many users, and wouldn't be able to cover all the features of OpenGL. How can you create a simple and thorough book about modern OpenGL? If you can assume that the reader knows the fixed function pipeline, then it's easier to teach them the new features. But what if you can't assume that?

The authors of OpenGL SuperBible 5 found a way around, and it works quite well. The authors built a library that allows people to start writing impressive programs right away. They don't have to worry about setting up vertex buffer objects, writing shaders, or any of that. This way you can start teaching by giving practical examples, and you slowly teach OpenGL by introducing the concepts behind that library. Make no mistake, this book doesn't teach you to use that specific library, it teaches you OpenGL. Anything you do with the library you will learn to do yourself in OpenGL in later chapters. Shaders are introduced early and follow wonderfully from previous discussion. Many advanced features are covered in detail and you learn how to write shaders, and not just how to copy and paste example code. The result is fantastic; the tutorial part is by far the best introduction to modern OpenGL you'll find. You still don't need a mathematical background, and the 3D math chapter does a good job of introducing all the ingredients you will need to write programs.

The book is divided into 3 parts. The first part is an introduction and tutorial, the second part is about advanced topics such as buffers and dealing with geometry, and the final part is about platform specific issues including a coverage of OpenGL ES for mobile devices. The tutorial part is great and if the book constituted only of this part, it'd definitely be worth buying. The advanced topic coverage is really variable. Some topics are covered in great detail and with useful examples (I really liked the introduction to the geometry shader for example), other topics are introduced in a hurry and just throw examples at you without even explaining what the example is supposed to do or teach. I'm not sure if this is really a bad thing. You need to realize that some of these advanced topics are actually quite advanced, and the book doesn't assume much from the reader. Including them in the book is a benefit because once you've learned more from other sources or from your own experiments you can go back to these chapters and understand them better. None of these chapters is bad, they just don't follow from what you learned from the tutorial part. For example, the basic idea of multisampling is introduced early, which is good for an example where you just enable multisampling and see the result. Later chapters go into the fine details of how multisampling is implemented, based on the basic introduction. If you already understand multisampling then it'd all make sense, but if your only source is the book then it can be hard to follow. Another example is the chapter which introduces buffers, the sample program tries to 'look cool' where a simpler (and uglier) sample would have been more appropriate.

Speaking of the sample programs, the code is generally well written and properly commented. Going through the source code for the book library is a great way to learn. Most of the samples compiled fine on Linux (using the binary Nvidia driver), but some gave me black screens or wrong results. I also had to make some changes to the code to make certain samples work. A few samples don't even come with makefiles for Linux. I sent an email about it to the author and it'll hopefully get fixed eventually. The google code repository where the samples are hosted does get updated so I wouldn't worry much about that.

Summary: if you want to learn modern OpenGL (post 3.0), then get the book. Even if you already have the 4th edition and know a bit about shaders and buffers, you will still benefit from the book because it covers many more advanced topics and I'm sure there will be a thing or two you didn't know about. While I spent some time talking about perceived problems like complex advanced chapters or few samples that don't work, I assure you that it's not as bad as I make it sound. I just thought it was fair to note these minor issues in case there was a 6th edition for OpenGL 5.0! I was worried about two things when I considered getting the 5th edition: (1) I already have the 4th edition so is this an incremental update or something completely new? And (2) if the book uses a library to hide some of the advanced features then does it spend a lot of time on that as opposed to teaching real OpenGL? The answer to the first question is that it's a completely new book that is exclusively about OpenGL 3.3. The answer to the second question is, like I said earlier, that the book library is there for a purpose, which is ultimately teaching you how to do things with nothing but OpenGL. I apologize for writing so much, I never wrote a book review before. :)

No comments:

Post a Comment