Quote:
I don't know how to use your code to create an image in the enter() method of a basicGameState, and then re-use it throughout the render method.
Maybe something like this: (pseudo code)
Code:
enter {
if (fbo != null) {
fbo = new FrameBuffer(Format.RGB565, 256, 256, false);
updateOffscreen();
}
}
For context changes, you would have to take that into account. I'm fairly certain LibGDX will re-create the FrameBuffer and its texture on context switching, so all you need to do is update the offscreen image on context loss. You would do something like this:
Code:
MyClass implements RenderListener {
@Override
surfaceCreated(Application app) {
if (fbo != null) { //don't bother updating it if we haven't entered the state
updateOffscreen();
}
}
}
Where updateOffscreen looks pretty much like this:
Code:
updateOffscreen {
fbo.begin();
...render slick graphics here...
fbo.end();
}
Then in your render() method you would render the FBO texture to the screen using the code I posted earlier (starting at the line TextureImpl.unbind).
FrameBuffer works like so:
- When you create a new frame buffer, LibGDX tells OpenGL to allocate a texture of the given size. In slick terms, this is the same as using InternalTextureLoader to create an OpenGL texture (although LibGDX supports non-power-of-two size). Preferably you aren't doing this more than once.
- Calling begin() on FrameBuffer means that anything you render (even if you render it with Slick) will now be rendered to your off-screen texture instead of being rendered to the screen.
- Calling end() on FrameBuffer returns things to normal, so that rendering goes to the screen
- Once you're done modifying your texture, you need to render it to the screen in order for it to be visible.