In the previous article, we saw how to create a sphere, which we’ll now use in this project as basis for a simple benchmark:

AnXcode project for the iPhone is provided with full src code, which you can use in your own project. The core code is written in plain C, so the project should be very easy to port over to GLUT or any other framework.
There were several driving factors that motivated me to create this project. I wanted to learn:
1 how many primitive (unlit, untextured) triangles can my iPhone render?
2 how to implement FPS (Frames Per Second) counter?
3 how to implement a simple HUD (Heads Up Display)?
4 how to use textures?
5 how to render text using OpenGL only?
6 how to handle changes to screen orientations?
Answer 1: On my 3G iPhone the answer appears to be around 30k triangles per second (the number of triangles per frame is printed out to stderr, so check your log). The project as it is currently setup, renders 4936 triangles per frame at 60 fps. Also notice that the grid rendered on top of the spheres has a different triangle count that the sphere itself. See pen.c for more details.
Answer 2: To be useful, the FPS counter updates its value on the screen once per second (more often updates make the reading difficult), with a value that is an average of all sampled frames in the past 1 second. In addition to the FPS value, I personally found it useful to display a second line underneath showing the utilization, which quickly tells me if the GPU is maxed out or not, and how much more stuff I could push. See fps.c for more details.
Answer 3: The HUD is a simple transparent rectangle, rendered using glOrthof projection, which uses alpha blending to allow the scene underneath it to show through. See fps.c for more details.
Answer 4: All the GPU cares about are raw pixel values, so we can load a texture in any way we want to, or generate one procedurally. Just before uploading the pixels, however, we need to make sure that they are right side up. Also, and this is very important or otherwise your texture will not show up, we must define GL_TEXTURE_MIN_FILTER, GL_TEXTURE_MAG_FILTER, GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T. Lastly, if the texture uses alpha pixels and is transparent, the blend function to use is glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA). See fps.c for more details.
Answer 5: To render text using only OpenGL, we need two things: font texture and the glyph positions. To generate font texture I used PC utility called bmfont which also generates glyph positions in several different formats. I picked xml, but then instead of hooking in xml parser I just manually created a table for the 16 glyphs I use in this project. For real apps we would obviously need to use the actual xml. See EAGLView.m for more details.
Answer 6: The screen orientation is easily handled with glRotatef (GLfloat angle, GLfloat x, GLfloat y, GLfloat z) with the only caveat being that for the orthogonal projection we also need to apply translations. See tilt.c for more details.