render to texture

Hi,

Can i render to texture in OpenGL ES?
Its the same way we render to texture in the OpenGL?

I wanna render to texture and get the pixel of this texture.

If someone have an example or may give me any kind of help, i would appreciate that.

Thank you

There are three ways of rendering to a texture:

  1. Using glCopyTexImage2D

You just render to the framebuffer, but instead of calling eglSwapBuffers to make the rendered image visible you call glCopyTexImage2D to copy the contents of the framebuffer to a texture.

This approach works everywhere, but it might require a copy operation, and you’re limited to the size of your current framebuffer.

  1. Using an EGL pbuffer surface

You create a texture bindable pbuffer with eglCreatePbufferSurface. Then you make it the current draw surface of the context with eglMakeCurrent and render. When you’re finished you restore the previous draw surface and bind the pbuffer to a texture object using eglBindTexImage. Don’t forget to call eglReleaseTexImage when you’re finished.

Unfortunately some platforms don’t support pbuffer surfaces.

  1. Using the OES_framebuffer_object extension
GLuint renderbuffer, framebuffer;
// Create depth renderbuffer
glGenRenderbuffersOES(1, &renderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, renderbuffer);
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT_16, width, height);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, 0);

// Create framebuffer object
glGenFramebuffersOES(1, &framebuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, framebuffer);

// Attach depth renderbuffer and texture
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, renderbuffer); 
glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);

if (glCheckFramebufferStatus(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES)
{
  // error
}

// render ...

// unbind framebuffer object
glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);


// cleanup when you don't need objects any longer
glDeleteRenderbuffersOES(1, &renderbuffer);
glDeleteFramebufferOES(1, &framebuffer);

This is probably even less widely supported than pbuffer surfaces.

Hi
Thanks for your illusration Xmas.

What about using the extensions WGL_ARB_pbuffer, WGL_ARB_pixel_format and WGL_ARB_make_current_read?

I just read about them put don’t know how to use them nor even how to get any of their implementations.

So if anyone can give some explanation of these extensions I will be very thankful.

These are WGL extensions. WGL is the platform integration library for OpenGL on Windows. OpenGL ES typically uses EGL though, not WGL.

Instead of glCopyTexImage2D, you should use glCopyTexSubImage2D because the former allocates a texture and then does the copy and the later will just do a copy.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.