This iPhone app draws the triangle that we drew on the Mac here.
Triangle.cpp
main.m
TriangleAppDelegate
TriangleViewController
EAGLView
include
GLTools
File → New Project…
Choose a template for your new project:
iOS Application
OpenGL ES Application
Choose…
Save As: Triangle
Where: Desktop
Save
MainWindow.xib
file from the project.
Do not delete the
“Main nib file base name”
line from the
Info.plist
file.
If you run the app,
you should see the bouncing square.
.h
file.
File → New File…
Choose a template for your new file:
C and C++ (under Mac OS X)
C++ file
Next
File Name: Triangle.cpp
Do not create Triangle.h
Finish
Triangle.cpp
file should contain
this.
It is the same as the
Triangle.cpp
in the
project we ran on the Mac,
with two deletions:
main
function from
Triangle.cpp
.
Our app will use the app’s
main
function in
main.m
.glut.h
in
Triangle.cpp
and do not call
glutSwapBuffers
.
TriangleViewController
and
EAGLView
will call the three C++ functions defined in
Triangle.cpp
.
To make it possible to call C++ functions,
rename
TriangleViewController.m
to
TriangleViewController.mm
,
and rename
EAGLView.m
.
to
EAGLView.mm
.
Right-click on
TriangleViewController.m
in the Classes folder in Groups & Files
Rename.
Also update the filename comment at the top of
TriangleViewController.mm
.
Do the same for
EAGLView.m
.
TriangleViewController.mm
before the
@interface
.
//C++ function defined in Triangle.cpp void display();In the
drawFrame
method of the view controller,
comment out everything except the calls to
setFrameBuffer
at the top
and
presentFramebuffer
at the bottom.
Then call
display();immediately before the
presentFramebuffer
.
EAGLView.mm
before the
@interface
.
//C++ functions defined in Triangle.cpp void reshape(int w, int h); void SetupRC();Insert
SetupRC();after the call to
glFramebufferRenderbuffer
in the
createFrameBuffer
method of class
EAGLView
.
In the
setFramebuffer
method of class
EAGLView
,
replace the call to
glViewPort
with the following.
//glViewport(0, 0, framebufferWidth, framebufferHeight); reshape(framebufferWidth, framebufferHeight);
SB5.zip
and
XCode.zip
into the
Downloads
folder on your Mac.
They should unzip into two folders named
SB5
and
Xcode
in your
Downloads
folder.Xcode/GLTools/libGLTools.a
that you just downloaded into the root directory
of your project.
Then add it to your project.
Highlight the Frameworks folder in Groups & Files.
Project →
Edit Active Target "Triangle" →
General →
Linked Libraries "Triangle"
Add Other…
libGLTools.a
.
SB5/Src/GLTools/src/GLBatch.cpp
,
GLShaderManager.cpp
,
GLTools.cpp
,
GLTriangleManager.cpp
,
and
math3.cpp
that you just downloaded into the root directory of your project.
Let’s create a “Group”
to hold them.
In the left pane of Xcode,
right-click on the name of the project (Triangle
)
and select
Add → New Group
.
Name the new group
GLTools
.
Although it is not a folder,
the group will appear as folder similar to
the existing things that look like folders:
Other Sources, Resources, etc.
Highlight the new group and add the five C++ files to the project.
include
in the root folder of your project.
Project →
Edit Active Target "Triangle" →
Build →
Search Paths
include
.
Then copy the 11 header files
SB5/Src/GLTools/include/GLBatch.h
,
GLBatchBase.h
,
GLFrame.h
,
GLFrustum.h
,
GLGeometryTransform.h
,
GLMatrixStack.h
,
GLShaderManager.h
,
GLTools.h
,
GLTriangleBatch.h
,
math3d.h
,
DLStopWatch.3dh
that you downloaded into the
include
folder you created.
Add the
include
folder to your project.
Then add the 11 files in it to your project too.