渲染到纹理或离屏帧缓冲区
我在 iPhone 上使用 OpenGLES
渲染纹理和离屏帧缓冲区时遇到问题。
(来源:imagehost.org)
(来源:imagehost.org)
第一张图片显示麻将直接渲染到 CAEAGLLayer 的图块,这是正确的。第二张图显示了渲染到离屏帧缓冲区的图块,使用 glCopyTexImage2D
复制到纹理,并将纹理渲染到 CAEAGLLayer
。两者都使用白色不透明四边形作为背景。我也尝试过直接渲染到纹理,但效果与屏幕外帧缓冲区相同。
我创建帧缓冲区的代码:
GLuint framebuffer;
glGenFramebuffersOES(1, &framebuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, framebuffer);
GLuint renderbuffer;
glGenRenderbuffersOES(1, &renderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, renderbuffer);
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_RGB8_OES,
512, 512);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES,
GL_RENDERBUFFER_OES, renderbuffer);
我使用 VBO 传递隔行扫描顶点数据(坐标、纹理坐标、颜色),通过调用 glDrawElements
一次从纹理图集中绘制所有图块。我使用 RGBA8888 纹理格式,使用 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) 混合函数在两个三角形(四边形)上绘制每个图像。我不使用深度缓冲区(在所有情况下)。
有人能告诉我可能是什么问题吗?
I have a problem with rendering to texture and offscreen framebuffer with OpenGLES
on iPhone.
(source: imagehost.org)
(source: imagehost.org)
First image shows mahjong tiles rendered to CAEAGLLayer
directly and this is correct. Second one shows tiles rendered to offscreen framebuffer, copied to texture using glCopyTexImage2D
and the texture rendered to CAEAGLLayer
. Both use white opaque quad for background. I also have tried rendering directly to texture but effect was the same as with offscreen framebuffer.
My code for creating framebuffer:
GLuint framebuffer;
glGenFramebuffersOES(1, &framebuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, framebuffer);
GLuint renderbuffer;
glGenRenderbuffersOES(1, &renderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, renderbuffer);
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_RGB8_OES,
512, 512);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES,
GL_RENDERBUFFER_OES, renderbuffer);
I draw all tiles from a texture atlas with one call to glDrawElements
using VBO for passing interlaced vertex data (coordinates, texture coordinate, color). I use RGBA8888 texture format, drawing each image on two triangles (quad) with glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
blending function. I do not use depth buffer (in all cases).
Can somebody tell me what could be the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来您还没有发布足够的代码,但从发布的内容来看,您似乎将 FBO 中纹理和渲染缓冲区的角色融合在一起。 (你的帖子标题说渲染到纹理)
您还忘记定义绘制缓冲区。
附加到 FBO 的渲染缓冲区通常用作深度缓冲区。
因此请尝试以下操作:
希望有帮助
It seems that you haven't posted enough of the code but from what is posted it seems that you fused together the roles of the texture and renderbuffer in your FBO. (your post title said render to texture)
Also you forgot to define your draw buffers.
The render buffer attached to an FBO is usually used as a Depth Buffer.
Therefore try the following:
hope that helps