FBObject

FrameBuffer Object (FBO)
package com.jogamp.opengl;

Creating FBO
final FBObject fbo = new FBObject; // Create FrameBuffer final GL2ES2 gl = GLContext.getCurrentGL.getGL2ES2; fbo.reset(gl, width, height); // int width, height - size of FBO, can be resized with the same call // With MSAA: // fbo.reset(gl, width, height, sampleNum, true); // int width, height, sampleNum - size/sampleNum of FBO, can be resized with the same call fbo.attachTexture2D(gl, 0, true); // Create GL_TEXTURE_2D texture which can be used as sampler2D at the shader code // Created texture will be bound to FBO's GL_COLOR_ATTACHMENT0 (see the second parameter 0) fbo.attachRenderbuffer(gl, Attachment.Type.DEPTH, 32); // Create depth buffer (if required) fbo.unbind(gl); // See Note-3 for use with MSAA. Unbind FrameBuffer (You will probably want to make bind - render - unbind loop later on)

Render to FBO
fbo.bind(gl); // Render scene as usual fbo.unbind(gl); // See Note-3 for use with MSAA

Render from FBO to another FBO
Imagine we have 2 FBO, source and target. Source FBO must have TextureAttachment (created with attachTexture2D, for example) FBObject source; FBObject target;

Using low-level texture binding: final TextureAttachment tex0 = (TextureAttachment) source.getColorbuffer(0); target.bind(gl); // Starting rendering to target FBO gl.glActiveTexture(GL2.GL_TEXTURE0); gl.glEnable(GL2.GL_TEXTURE_2D); // Should not call this for CORE profiles, i.e. ES2, GL3, .. gl.glBindTexture(GL2.GL_TEXTURE_2D, tex0.getName); // See Notes 1, 2. Binding source FBO's TextureAttachment as GL_TEXTURE_2D // Here you can render something using source texture as GL_TEXTURE0 // For example, you can enable shader with some filter, which makes use of sampler2D and render a fullscreen quad. target.unbind(gl); // See Note-3 for use with MSAA. Unbind FBO

Render from FBO to screen
final TextureAttachment tex0 = (TextureAttachment) source.getColorbuffer(0); gl.glActiveTexture(GL2.GL_TEXTURE0); gl.glEnable(GL2.GL_TEXTURE_2D); // Should not call this for CORE profiles, i.e. ES2, GL3, .. gl.glBindTexture(GL2.GL_TEXTURE_2D, tex0.getName); // See Notes 1, 2. Binding source FBO's TextureAttachment as GL_TEXTURE_2D // Here you can just render a fullscreen quad to show FBO content, or do something more exciting

Demos/Tests

 * [/git/?p=jogl.git;a=blob;f=src/test/com/jogamp/opengl/test/junit/jogl/acore/TestFBOMix2DemosES2NEWT.java;hb=HEAD TestFBOMix2DemosES2NEWT.java]