opengl es - 试图获得全屏“轨迹” - 单缓冲区模式还是复制前缓冲区?
我正在尝试获得类似于此处的全屏“轨迹”效果: http://elenzil.com/ progs/js1k
传统的方法是在渲染开始时不清除图像, 而是混合在一个大多边形上,该多边形是背景颜色并且具有较低的 Alpha。
在 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);
但有一个问题, 即当前的 gl 操作发生在后备缓冲区上, 与前端缓冲区相比,它是陈旧的。 所以你最终会得到“结巴”的图像。
在我走上渲染屏幕外纹理之类的道路之前, 有没有已知的方法可以做到这一点?
我希望找到的明显解决方案是以下任何一个:
- 在渲染开始时将前缓冲区复制到后缓冲区。
- 不是交换缓冲区,而是将后缓冲区复制到前缓冲区。
- 单缓冲运行。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
想通了。 kEAGLDrawablePropertyRetainedBacking 需要为 TRUE,如下所示:
figured it. kEAGLDrawablePropertyRetainedBacking needs to be TRUE, as in the following: