views:

233

answers:

0

I am attempting to make an image stretch effect on the iphone. I make a vertex array and shift the texture data for each indice within an arbitrary radius of a background image. Then make the following calls to display:

int n = gridSize_.x * gridSize_.y;
glEnableClientState( GL_VERTEX_ARRAY);
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glVertexPointer(3, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_FLOAT, 0, texCoordinates);
glDrawElements(GL_TRIANGLES, n*6, GL_UNSIGNED_SHORT, indices);

//if(num_myindices > 0)
// glDrawElements(GL_TRIANGLES, num_myindices*6, GL_UNSIGNED_SHORT, myindices);
glDisableClientState(GL_VERTEX_ARRAY );
glDisableClientState( GL_TEXTURE_COORD_ARRAY );

My problem is the edge of area that is stretched looks very choppy with a relatively small grid size like 32x32 or even 64x64. Any larger makes it smoother but much much slower.

So I tried adding a copy of the background image, and restricted the vertex array to only the affected indices. I use a much smaller grid size but for a smaller area. The drawing code above now looks like:

//glDrawElements(GL_TRIANGLES, n*6, GL_UNSIGNED_SHORT, indices);
if(num_myindices > 0)
glDrawElements(GL_TRIANGLES, num_myindices*6, GL_UNSIGNED_SHORT,myindices);

The affected area is displayed but the background image appears to flash and disappear, my stretched area is floating on a black background. Obviously my background is rendered first and then my code above overwrites and renders only the data in my vertex array.

Does anyone have advice on how to efficiently combine the drawing of the images?

I plan to make a 2nd simple vertex array for the background and make a call to glDrawArray just prior to my if statement so all the drawing is done in a single method. Is this the right way to go about this? Is there a better way? Should all the image data be combined into 1 simple vertex array somehow?