Here is a selfcontained framebuffer test that works on my laptop with a ATI radeon 9700.
import java.nio.IntBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL12.*;
import static org.lwjgl.opengl.EXTFramebufferObject.*;
public class PBOTest {
public static void main(String args[]) throws Exception {
try {
Display.setDisplayMode(new DisplayMode(640, 480));
Display.create();
glClearColor(0.0f, 0.0f, 1.0f, 0.0f);
int TEX_WIDTH = 256;
int TEX_HEIGHT = 256;
boolean fboEnabled = GLContext.getCapabilities().GL_EXT_framebuffer_object;
System.out.println("GL_EXT_framebuffer_object enabled="+fboEnabled);
IntBuffer fboId = BufferUtils.createIntBuffer(1);
glGenFramebuffersEXT(fboId);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboId.get(0));
// add depth buffer
IntBuffer depthbufferId = BufferUtils.createIntBuffer(1);
glGenRenderbuffersEXT(depthbufferId);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthbufferId.get(0));
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, TEX_WIDTH, TEX_HEIGHT);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthbufferId.get(0));
// add a texture
IntBuffer imgId = BufferUtils.createIntBuffer(1);
glGenTextures(imgId);
glBindTexture(GL_TEXTURE_2D, imgId.get(0));
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, TEX_WIDTH, TEX_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glGenerateMipmapEXT(GL_TEXTURE_2D);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, imgId.get(0), 0);
if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT) {
throw new RuntimeException("Framebuffer not complete");
}
while (!Display.isCloseRequested()) {
glViewport(0, 0, 640, 480);
glClearColor(0.0f, 0.0f, 1.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
// render to texture
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboId.get(0));
glClearColor(1.0f, 0.5f, 1.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(0, 1, 0);
drawQuad(-100, -100, 240, 280);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
// draw quad
glColor3f(1, 1, 1);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, imgId.get(0));
drawQuad(100, 100, 200, 200);
glDisable(GL_TEXTURE_2D);
Display.update();
Thread.yield();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
Display.destroy();
}
}
private static void drawQuad(int x, int y, int width, int height) {
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex3f(x, y, 0);
glTexCoord2f(1, 0);
glVertex3f(x+width, y, 0);
glTexCoord2f(1, 1);
glVertex3f(x+width, y+height, 0);
glTexCoord2f(0, 1);
glVertex3f(x, y+height, 0);
glEnd();
}
}