Hi!
I managed to do rendering to texture in a slightly different way.
First of all generate a texture with the same format and dimensions as my viewport and no filtering:
Code: Select all
glGenTextures(1, (GLuint*)&frameBufferTexture);
glBindTexture(GL_TEXTURE_2D, (GLuint)frameBufferTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, viewportWidth, viewportHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
Then I generate the frame buffer and bind the texture to it in this way:
Code: Select all
glGenFramebuffers(1, &frameBufferHandle);
glBindFramebuffer(GL_FRAMEBUFFER, frameBufferHandle);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, (GLuint)frameBufferTexture,0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
Then I draw a square mesh with screen dimensions and map the texture to it. Selecting the buffer in this way:
Code: Select all
glBindFramebuffer(GL_FRAMEBUFFER, frameBufferHandle);
//draw to the custom buffer
glBindFramebuffer(GL_FRAMEBUFFER, 0)
//draw the custom buffer as a textured mesh to the back-buffer
eglSwapBuffers(display, surface);
Hope it will be useful!