I’m trying to render to texture using a FBO. I’m not sure what I’m doing wrong, but when rendering the resulting texture is all white. Below is some of my code. Please tell me if you see what I’m doing wrong. Am I missing something?
// render code
renderToTexture.activate();
GL11.glPushAttrib(GL11.GL_VIEWPORT_BIT);
GL11.glViewport(0, 0, width, height);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
renderNoise();
p1.render();
p2.render();
ball.render();
renderToTexture.deactivate();
GL11.glPopAttrib();
SlickCallable.enterSafeBlock();
int rtt = renderToTexture.getTexture();
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, rtt);
glBegin(GL_QUADS);
glNormal3d(0, 0, 1);
glTexCoord2f(0, 0);
glVertex2f(0, 0);
glTexCoord2f(1, 0);
glVertex2f(width, 0);
glTexCoord2f(1, 1);
glVertex2f(width, height);
glTexCoord2f(0, 1);
glVertex2f(0, height);
glEnd();
glDisable(GL_TEXTURE_2D);
SlickCallable.leaveSafeBlock();
// fbo helper class
public class FBORenderer {
private int fbo;
private int rbo;
private int texture;
private int height;
private int width;
private ByteBuffer byteBuffer;
public FBORenderer(int w, int h) {
fbo = ARBFramebufferObject.glGenFramebuffers();
texture = GL11.glGenTextures();
width = w;
height = h;
activate();
byteBuffer = BufferUtils.createByteBuffer(4 * 4 * width * height);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA, GL11.GL_FLOAT, byteBuffer);
ARBFramebufferObject.glFramebufferTexture2D(ARBFramebufferObject.GL_DRAW_FRAMEBUFFER,
ARBFramebufferObject.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, texture, 0);
deactivate();
}
public void activate(){
ARBFramebufferObject.glBindFramebuffer(ARBFramebufferObject.GL_DRAW_FRAMEBUFFER, fbo);
}
public void deactivate() {
ARBFramebufferObject.glBindFramebuffer(ARBFramebufferObject.GL_DRAW_FRAMEBUFFER, 0);
ARBFramebufferObject.glBindRenderbuffer(ARBFramebufferObject.GL_RENDERBUFFER, 0);
}
public int getTexture() {
return texture;
}
}