Okay, so I'm working on an OpenGL ES application for the iPhone, and I ran into an interesting issue.
I have a function that computes the vertices, normals, and texture coordinates of a sphere dependent upon a detail level and a range of spherical coordinates.
Originally, storing a vertex in an array looked something like this:
//After I figure out the size of the vertices:
GLfloat* vertices = (GLfloat *) (malloc(sizeof(GLfloat) * arraySize)));
//Later on when I'm computing vertices...
GLfloat* vertPosition = vertices;
vertPosition[0] = px;
vertPosition[1] = py;
vertPosition[2] = pz;
vertPosition += 3;
This turned out to be a disaster. I ended up with something like the AT&T logo. :-) A bit more work I discovered adding a counter and using that to index the array fixed everything:
vertPosition[(vertexCount * 3) + 0] = px;
vertPosition[(vertexCount * 3) + 1] = py;
vertPosition[(vertexCount * 3) + 2] = pz;
vertexCount++;
My questions are: What happened with using a temporary pointer and moving it ahead? Is what I've got now just as efficient, or would the pointer arithmetic be better?