i’m trying to get a full screen “trail” effect similar to the one here: http://elenzil.com/progs/js1k
the traditional way to do this is to not clear the image at the beginning of rendering,
but instead blend on a big polygon that’s the color of the background and has low alpha.
drawing the polygon is pretty straight-forward in openGL ES:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
GLfloat clearRectPts[] = {
-0.5f, -0.5f,
-0.5f, 0.5f,
0.5f, -0.5f,
0.5f, 0.5f,
};
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(0.0f, 0.0f, 0.0f, 30.0f / 255.0f);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT , 0, clearRectPts);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY);
glDisable(GL_BLEND);
but there’s a Gotcha,
which is that current gl operations happen to the backbuffer,
which is stale in comparison to the front buffer.
so you end up with “stuttering” images.
before i go down the road of rendering to an offscreen texture and such,
is there a known way of doing this ?
the obvious solutions i’d love to find are any of these:
- copy the front buffer to the back buffer at the start of rendering.
- instead of swapping buffers, copy the backbuffer to the front.
- run single-buffered.
figured it. kEAGLDrawablePropertyRetainedBacking needs to be TRUE, as in the following: