Display texture or off-frame framebuffer

I have a problem rendering to a texture and offscreen OpenGLES from OpenGLES to iPhone.

alt text
(source: imagehost.org )
alt text
(source: imagehost.org )

The first image shows mahjong tiles rendered directly in CAEAGLLayer and that’s right. The second shows tiles rendered into off-screen glCopyTexImage2D , copied to the texture using glCopyTexImage2D and textures rendered in CAEAGLLayer . Both use a white opaque quad for the background. I also tried rendering directly to the texture, but the effect was the same as behind the frame buffer frame.

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 the tiles from the texture atlas with a single call to glDrawElements using VBO to transmit interlaced vertex data (coordinates, texture coordinates, color). I use the RGBA8888 texture format , drawing each image on two triangles (quadrangles) with glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) the glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) blend glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) . I do not use the depth buffer (in all cases).

Can someone tell me what could be the problem?

+6
iphone opengl-es framebuffer fbo render-to-texture
source share
1 answer

It seems that you have not posted enough code, but from what is published, it seems that you have merged with the role of texture and rendering in your FBO. (your title name means texture rendering) Also you forgot to define your drawing buffers.

A render buffer attached to the FBO is typically used as a depth buffer. So try the following:

 GLuint framebuffer; glGenFramebuffersOES(1, &framebuffer); glBindFramebufferOES(GL_FRAMEBUFFER_OES, framebuffer); //set up the Depth Buffer GLuint renderbuffer; glGenRenderbuffersOES(1, &renderbuffer); glBindRenderbufferOES(GL_RENDERBUFFER_OES, renderbuffer); glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT24, 512, 512); glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER_OES, renderbuffer); //set up the texture that you will be rendering to glActiveTexture(GL_TEXTURE0); GLuint textureID; glGenTextures(1, &textureID); glBindTexture(GL_TEXTURE_2D, textureID); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); //add various other texture parameters here glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8_OES, 512,512); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureID, 0); // define your draw buffers GLenum drawBuffers[1] = {GL_COLOR_ATTACHMENT0}; glDrawBuffers(1, drawBuffers); 

hope that helps

0
source share

All Articles