The OpenGL SuperBible
OpenGL 3.+ on OS X
So here's the thing. When we first started this book we thought it inconceivable that Apple would not have an OpenGL 3.x implementation available for OS X by the time the book shipped. The latest version of OpenGL is 4.2, and as of this date, OS X 10.6.5 (Snow Leopard), Apples most advanced and sophisticated operating system still only supports OpenGL 2.1.
Yes, Apple, you should be embarrassed. I love my Mac, and will never go back to Windows... but honestly, really? There is no excuse for being so far behind the ball on this, other than some poor engineer was continually ignored by a middle manager somewhere who should probably be managing some other aspect of the company.
Okay, so here's the thing... again. Apple actually hasn't done "too bad" a job of keeping up with OpenGL over the last few years. The big hang up appears to be the new shading language. Well, it's NOT THAT NEW ANYMORE NOW IS IT... sorry, I need to get a hold of myself don't I? You would think though that a company the size of Apple with as much money as they have in the bank might could afford to hire at least one or two more engineers who could write a language parser.
</rant really I mean it this time>
Word is, it will be OS X Lion before we see proper OpenGL 3.x (or greater) support. Fortunately, that's not like years and years away. In the mean time there is some middle ground to be had. As I said, the hold up appears to be the support for the new GLSL. I know this because if you look at the extensions supported on the Mac, pretty much the rest of the feature set is generally available. All they need is GLSL 1.3 support, and volia - OpenGL 3.0!
So, theoretically, if you took most of the shaders from the book and worked them back to GLSL 1.2 or earlier equivalents, would the examples in the book work? Well, MOSTLY yes. There are some client features covered in the book that just aren't in the Apple OpenGL implementation. There are also lots of language features in GLSL 1.3 or later that just don't have any equivalents in the older shading language. Many simple 1.3 or greater shaders can be made to work on an OpenGL 2.1 (GLSL 1.2) implementation that has the needed OpenGL 3.x or later extensions exposed.
A quickie set of porting rules are thus:
1. #version must be 120 or less
2. In the vertex program, in becomes attribute.
3. In the vertex program, out becomes varying.
4. There aren't any of the smooth, flat, or perspective keywords.
5. In the fragment program, in becomes varying.
6. In the fragment program, gl_FragColor is the output color value.
7. In the fragment program, texture() becomes texture2D() or texture1D() as appropriate.
For example, see the following two vertex programs:
Or the following two fragment shaders:
All of the stock shaders in GLTools actually use GLSL 1.1 style shader code. This is not covered in the book, as the point of the GLShader manager is to show you how to USE shaders, not write them. This keeps GLTools useful for older OpenGL projects (such as the many that I still maintain and support). It would be a great class project for you (the student/reader) to convert those shaders to GLSL 1.3 or later. Still, remember this is of limited use. The book covers OpenGL 3.3, not OpenGL 2.1. These are simple changes to syntax, but do not account for the many additional features and capabilities that have been added to GLSL over the last few years. I'll be looking forward to the first developer preview of OS X Lion to see if it contains an OpenGL 3.x driver. Apple would probably frown on me telling you if it's there or not, but at least I could get a start on porting ALL of the books samples to OS X.
The XCode projects for the first seven chapters can be downloaded here. Yes, I'm working on more when I can get to them. Unzip them in the main SB5 folder though. Only the shader files are actually different from those in the /src folders.