It’s great that iPhone supports OpenGL, but there are a few things that are wanting (at least for things we wanted to do).
In this case, it was drawing vector art on the iPhone. We wanted to draw lines of varying widths, but iPhone does not support glPushAttrib and glPopAttrib.
Normally, if you want to change the state of a lot of different enviroment varibles, such as GL_LIGHTING, glpolygonmode, gllinewidth, things like that, you would use following code:
glPushAttrib(GL_ENABLE_BIT);
glPushAttrib(GL_LINE_BIT);
glPushAttrib(GL_POLYGON_BIT);
…
glPopAttrib();
glPopAttrib();
glPopAttrib();
Below is from http://www.bradleymacomber.com/coderef/OpenGLES/ on some of differences on iPhone OpenGL
OpenGL ES Limitations (on iPhone)
The subset of OpenGL for mobile devices is missing a lot of the typical functions. The exact details may come as a surprise. The Khronos site lacks any documentation explaining this. (Presumably this is an excuse for them to sell me a book.) So I am writing down the limitations as I find ’em. Most often the convention seems to be to eliminate functionality that is a convenient re-presentation of more fundamental low-level functionality.
- No GLU library.
- Some handy functions such as
gluPerspective()
andgluLookAt()
will have to be replaced with manual calculations.- No immediate-mode rendering.
- This means there are no
glBegin()
andglEnd()
functions. Instead you must use vertex arrays or vertex buffers. This is no surprise since games shouldn’t be using immediate mode anyway.- Simplified vertex arrays.
- The
glInterleavedArrays()
function is unavailable; each array must be specified separately, although stride can still be used. There are noglDrawRangeElements()
norglMultiDrawElements()
norglMultiDrawArrays()
functions. Instead useDrawArrays()
orDrawElements()
. There is also noArrayElement()
function, which makes sense since it requiresglBegin()
andglEnd()
.- No quads.
- All the usual geometric primitives are supported except for
GL_QUADS
,GL_QUAD_STRIP
, andGL_POLYGON
. Of course, these are provided for convenience and are almost always easily replaced by triangles.- Smaller datatypes.
- Many functions accept only smaller datatypes such as
GL_SHORT
instead ofGL_INT
, orGL_FLOAT
instead ofGL_DOUBLE
. Presumably this is to save space on a device with limited memory and a screen small enough that a lack of fine detail can go unnoticed.- GLfixed.
- This new low-level datatype is introduced to replace a variety of datatypes normally presented. For example, there is no
glColor4ub()
function. Presumably this helps support devices which do not have a FPU.- No glPushAttrib nor glPopAttrib (nor glPushClientAttrib).
- Well, this is annoying. I guess an iPhone application is supposed to be simple enough that we can keep track of all states manually, eh?
- No GL_LINE_SMOOTH.
- Enabling it has no effect.
- No display lists.
- Instead use vertex arrays or vertex buffers.
- No bitmap functions.
- Functions such as
glBitmap()
andglRasterPos*()
do not exist. This means you cannot render simple bitmap fonts. Instead, textured quads must be rendered. Of course, you could always render vector fonts. Don’t let me stop you.- Texture borders not supported.
- Probably not a big deal.
Guess that means I have to manually track some of these changes and revert them back when needed. This is not always easy to do when other parts of your program can access OpenGL without your knowledge.