This program makes its first appearance on p. 161 of the OpenGL SuperBible. It aquires a camera on p. 171, textures on p. 226, and a logo on p. 291. It is ported to Windows on p. 559, to OS X on p. 580, and to iPhone on pp. 639–652.
SphereWorld.cpp
creates the torus, spheres, and floor.main.mm
GLAppDelegate
GLViewController
EAGLView
UIApplicationMain
in the
main
function remain
nil
.
Do not remove
MainWindow.xib
from the application or from the
Info.plist
file.
Add → New Group
.
Name the new group
GLTools
.
It isn’t a folder, but it looks like one.
SB5.zip
and
Xcode.zip
from the
OpenGL SuperBible
home page
into the
Downloads
folder on your Mac.
In
SB5.zip
go to the folder
Src/GLTools/src
and copy all the files except
glew.c
into the root folder of your project.
(There should be five files.)
Then go to the folder
Src/GLTools/include
and copy all the
.h
files into the root directory of your project.
(There should be 11 files.)
In the Groups & Files pane of Xcode,
select the
GLTools
group you created and add these 16 files to the project.
SB5.zip
,
go to the folder
Src/Chapter05/SphereWorld
.
Copy the three texture files into the root directory of your project.
In the Groups & Files pane of Xcode,
select the
Resources
group and add these three files to the project.
SB5.zip
,
go to the folder
Src/Chapter05/SphereWorld
.
Copy the file
SphereWorld.cpp
into the root directory of your project.
In the Groups & Files pane of Xcode,
select the
Other Sources
group and add this file to the project.
Project →
Edit Active Target "GL" →
Build →
Search Paths
SB5.zip
,
go to the folder
GLTools/GLTools
.
Copy the file
libGLTools.a
into the root directory of your project.
Project →
Edit Active Target "GL" →
General →
Linked Libraries
OpenGLES.framework
to the project.
Press the plus sign again and
Add Other…
to add to the project the
libGLTools.a
you copied into the root folder of your project.
.m
files that call functions written in C++ have to be renamed to
.mm
:
main.mm
,
GLViewController.mm
,
and
EAGLView.mm
.
In the Groups & Files pane of Xcode,
right-click on the filename and select Rename.
Update the filename at the top of each file.
main.mm
includes
GLTools.h
and
the
main
function calls
gltSetWorkingDirectory
.RenderScene
is declared at the top of
GLViewController.mm
and called in
drawFrame
.
Almost all of
drawFrame
is commented out.SetupRC
,
ChangeSize
,
and
ShutdownRC
are declared at the top of
EAGLView.mm
.
SetupRC
and
ChangeSize
are called in
createFramebuffer
;
ShutdownRC
is called in
deleteFrameffer
.SphereWorld.cpp
does not use the GLUT library.
Comment out the two lines that include
glut.h
.
Comment out the calls to the functions
glewInit
,
glutSwapBuffers
,
and
glutPostRedisplay
.
Comment out the entire functions
SpecialKeys
and
main
.
LoadTGATexture
function in
SphereWorld.cpp
,
change the macro
GL_COMPRESSED_RGB
to
nComponents
.
EAGLView
already contains a
renderbuffer.
Let’s also give it a depth buffer.
Add the following instance variable to class
EAGLView
in
EAGLView.h
.
GLuint depthRenderbuffer;Insert the following code into the
createFramebuffer
method in
EAGLView.mm
.
//Create the depth buffer. glGenRenderbuffers(1, &depthRenderbuffer); glBindRenderbuffer(GL_RENDERBUFFER, depthRenderbuffer); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, framebufferWidth, framebufferHeight); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRenderbuffer);Insert the following code into the
deleteFramebuffer
method in
EAGLView.mm
.
(I’ll get around to doing this.)
if (depthRenderbuffer) { glDeleteRenderbuffers(1, &depthRenderbuffer); depthRenderbuffer = 0; }
touchesMoved:withEvent:
method to class
EAGLView
in
EAGLView.mm
.ChangeSize
function in
SphereWorld.cpp
,
and add the 90°
rotation.
Swipe left and right, up and down—slowly.