Here is a complete and minimal code example that produces this problem:
public static void main(String[] args)
{
try
{
Display.setDisplayMode(new DisplayMode(800, 600));
Display.create();
Display.setVSyncEnabled(true);
}
catch(LWJGLException e)
{
e.printStackTrace();
System.exit(0);
}
// Requirements
if(!GLContext.getCapabilities().GL_EXT_framebuffer_object)
throw new Error("FBOs not supported! Get a better computer!");
// Defaults
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glDisable(GL11.GL_DEPTH_BUFFER_BIT);
// Set up orthographic projection for 2D
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, 800, 0, 600, -100, 100);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
// Create a FBO
// Generate the fbo
int fbo = EXTFramebufferObject.glGenFramebuffersEXT();
// Attach a texture to render to
int texture = GL11.glGenTextures();
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
// The null at the end must be cast to tell javac which overload to use,
// even though the last parameter (for the different overloads) isn't even used
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, 800, 600, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer)null);
// Unbind texture
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
// Bind the fbo for use
EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, fbo);
EXTFramebufferObject.glFramebufferTexture2DEXT(
EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT,
GL11.GL_TEXTURE_2D, texture, 0); // The 0 is for mip map levels, we aren't using any
// Check
if(EXTFramebufferObject.glCheckFramebufferStatusEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT) != EXTFramebufferObject.GL_FRAMEBUFFER_COMPLETE_EXT)
throw new Error("Could not create FBO!");
// An fbo has its own viewport, so lets set it
GL11.glViewport(0, 0, 800, 600);
// Unbind
EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, 0);
EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0);
// Game loop
while(!Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))
{
GL11.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
// --------------------- Render to the FBO ----------------------
// Unbind textures
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, fbo);
// Save view port information
GL11.glPushAttrib(GL11.GL_VIEWPORT_BIT);
// Clear the FBO to a color
GL11.glClearColor(0.5f, 0.3f, 0.3f, 1.0f);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
// Finish all operations so can use texture
GL11.glFlush();
// Restore saved information for main rendering context
GL11.glPopAttrib();
// Unbind the FBO
EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0);
// ------------------ Render FBO to the screen -----------------------
// Draw a quad with the FBO on it
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0.0f, 0.0f); GL11.glVertex2f(200.0f, 200.0f);
GL11.glTexCoord2f(1.0f, 0.0f); GL11.glVertex2f(600.0f, 200.0f);
GL11.glTexCoord2f(1.0f, 1.0f); GL11.glVertex2f(600.0f, 600.0f);
GL11.glTexCoord2f(0.0f, 1.0f); GL11.glVertex2f(200.0f, 600.0f);
GL11.glEnd();
Display.update();
}
}
The FBO does not change from a plain white texture, so I assume it is never really rendering to it.