problem with Frame Buffer Objects

Hi, I have a problem with frame buffer objects. I want to render to a texture once, then not have to render to it again. I want to draw this texture repeatedly each frame. It never changes. But with FBO, I have to render it each frame, otherwise the image goes black! >:(
is there a way to fix this?
Thanks,
roland

Edit: sorry this is supposed to be in the LWJGL section

It doesn’t automatically clear your textures. You’re doing something wrong.

Thanks for the reply theagentd.

I bind the texture once, draw on it, then unbind it. I can’t see why it would get affected after that.

Could you have a look at my offscreen image class?
http://pastebin.com/QqeRXc9D

//init
m_offscreenTexture = new OffscreenTexture(64,64);

//in draw 
if (!m_offscreenTexture.Drawn())
{
                //will only be called once
    		m_offscreenTexture.Bind();
    		m_offscreenTexture.TestDraw(); 
    		m_offscreenTexture.UnBind();
}

GL11.glBindTexture(GL11.GL_TEXTURE_2D, m_offscreenTexture.GetTextureID());	
Graphics.DrawTexturedSquare(0, 0, 40, 40);


I fixed it. Just got rid of the slick util Texture and uncommented the lines

m_iTextureID = GL11.glGenTextures();
    		// initialize color texture
    		GL11.glBindTexture(GL11.GL_TEXTURE_2D, m_iTextureID);									// Bind the colorbuffer texture
    		GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);				// make it linear filterd
    		GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, m_iWidth, m_iHeight, 0,GL11.GL_RGBA, GL11.GL_INT, (java.nio.ByteBuffer) null);	// Create the texture data
		

Thanks ;D

Sorry to bring this back from the dead, but I’ve been trying to get a frame buffer object up and running in my world, but cannot manage it!

I have taken rolands OffscreenTexture class and kept it exactly the same except for the testDraw method. I changed that to this:

public void TestDraw() {
		GL11.glLoadIdentity();
		GL11.glColor4b((byte)255, (byte)100, (byte)100, (byte)255);
		
		GL11.glBegin(GL11.GL_QUADS);
			GL11.glVertex3f(0, 0, 0);
			GL11.glVertex3f(200, 0, 0);
			GL11.glVertex3f(200, 200, 0);
			GL11.glVertex3f(0, 200, 0);
		GL11.glEnd();
	}

Now, in the main game, an OffscreenTexture is created:

OffscreenTexture buffer = new OffscreenTexture(900, 500);

and this code is called once:

buffer.Bind();
buffer.TestDraw();
buffer.UnBind();

and later, every frame this code is executed:

private void renderGame() {
		
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
		
		GL11.glEnable(GL11.GL_TEXTURE_2D);
		GL11.glBindTexture(GL11.GL_TEXTURE_2D, buffer.getTextureID());
		
		GL11.glBegin(GL11.GL_QUADS);
		GL11.glTexCoord2f(0, 0);
		GL11.glVertex2i(0, 0);
	
		GL11.glTexCoord2f(1, 0);
		GL11.glVertex2i(900, 0);
	
		GL11.glTexCoord2f(1, 1);;
		GL11.glVertex2i(900, 500);
	
		GL11.glTexCoord2f(0, 1);
		GL11.glVertex2i(0, 500);
		GL11.glEnd();
	}

Is there a problem with the way I have used the opengl to draw everything rather than graphics, or is the problem somewhere else?

Assuming the OffscreenTexture class does all the necessary setup (glViewport() comes to mind ::)), your problem is most likely just that you’re setting the texture settings before binding the texture. Just move your glTexParameteri()s to after you’ve bound the texture. Most likely it’s not working because the texture is set to using mipmaps —> the texture is considered incomplete since you don’t have mipmaps.

That doesn’t seem to have helped.

I’m wondering if I need to add some code in the renderGame() method, after glEnd(), to tell OpenGL to render the buffer to the Display. Or does it do this automatically?

Maybe OffscreenTexture already does this, but try to add a glViewport() call each time you switch render target (= bind or unbind an FBO) to the correct size. Can you also post the code for OffscreenTexture?

I’ve actually got the viewport the same throughout the whole program.
Here is the OffScreenTexture class (I renamed a few things just to confuse you :))
http://pastebin.java-gaming.org/befe25d6728

As usual, this is called once:

	FrameBuffer buffer = new FrameBuffer(900, 500);
		buffer.bind();
		buffer.render();
		buffer.unBind();

and then this is called every frame:

private void renderGame() {
		
		GL11.glEnable(GL11.GL_TEXTURE_2D);
		GL11.glBindTexture(GL11.GL_TEXTURE_2D, buffer.getTextureID());
		
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
		
		GL11.glBegin(GL11.GL_QUADS);
			GL11.glTexCoord2f(0, 0);
			GL11.glVertex2i(0, 0);
		
			GL11.glTexCoord2f(1, 0);
			GL11.glVertex2i(900, 0);
		
			GL11.glTexCoord2f(1, 1);;
			GL11.glVertex2i(900, 500);
			
			
			GL11.glTexCoord2f(0, 1);
			GL11.glVertex2i(0, 500);
		GL11.glEnd();
}

Thankyou for your help.