260 CHAPTER 8: Putting It All Together^
Now is the time to dump any image utilities over into their own routine. I’ve created
OpenGLCreateTexture for this and have moved loadTexture() from the solar-system
controller to here. This will help support the above call. The .png file can be whatever
you want that will replace the current 3D sun model. What we want this for is to draw a
flat bitmap of the sun where the spherical model would normally render as it has done in
the past. The reason is that we can finely control the look of our star to make it resemble
more closely how the eye might perceive this. The stark yellow ball, while technically
more accurate, just doesn’t look right because any optical receptor to this would add all
sorts of various distortions, reflections, and highlights (lens flares, for example). Shaders
could be employed that mathematically model the optics of the eye, for example, but
that’s a lot of work for a fuzzy ball-like-thing for the time being. You can download my
own artwork from the Apress site if you choose. Or just copy something to suit your own
tastes. Figure 8-5 is what I am using with translucent background. Interesting enough,
this image fools my own eyes enough to make my brain think that I am actually looking
at something too bright, because it causes all sorts of eyestrain when I stare at it.
This uses a technique called billboarding, which takes a flat 2D texture and keeps it
aimed toward the viewer no matter what where they are. It permits complex and fairly
random organic objects (things called trees I think) to be easily depicted while using only
simple textures. As your viewpoint changes, the billboard objects rotate to compensate.
Figure 8-5. The sun image used to give a more authentic-looking glow
Add the following to the interface definition for the solar-system controller:
LensFlare *m_LensFlare;
GLKTextureInfo *m_FlareSource;
Next, move the createTexture module created in Chapter 7 over, and add it to this
project in its own file, such as OpenGLCreateTexture.mm. This way, texture generation is
no longer confined to the planet object but accessible by anyone. When done, add the
contents of Listing 8-9 for a more flexible rendering routine. What this does is draw a
rectangular texture to the screen in orthographic mode. This means they would be
unaffected by perspective. That way, you can draw textures near the viewpoint or way in
the background behind other stuff and still count on them being the same size no matter
what. Something like this is very handy when drawing text labels, for example, to the
screen. Since OpenGL has no native text support, any labels must be drawn as any