I use a frameBuffer and a viewPort to display a rear mirror.
It goes fine when I start a race and gives no problems when the cleaning code is executed, but when I then start a new race I get an exception.
This is the cleaning code:
public void clean() {
screen.removeElement(rearView);
game.getRenderManager().removePreView(reflectionView);
offBuffer.dispose();
}
This is the exception:
java.lang.IllegalStateException: Framebuffer has erronous attachment.
at com.jme3.renderer.opengl.GLRenderer.checkFrameBufferError(GLRenderer.java:1343)
at com.jme3.renderer.opengl.GLRenderer.updateFrameBuffer(GLRenderer.java:1488)
at com.jme3.renderer.opengl.GLRenderer.setFrameBuffer(GLRenderer.java:1577)
at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:1005)
at com.jme3.renderer.RenderManager.render(RenderManager.java:1070)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:260)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:152)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:192)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:233)
at java.lang.Thread.run(Thread.java:745)
AL lib: (EE) alc_cleanup: 1 device not closed
It used to work on 3.0 (maybe by luck :D)… any idea what I’m doing wrong?
Ah, ok, here is the creation of the rear view mirror:
@Override
public void initialize() {
screen = game.getGameManager().getScreen();
flyCamAppState = game.getStateManager().getState(FlyCamAppState.class);
offCamera = new Camera(WIDTH, HEIGHT);
reflectionView = game.getRenderManager().createPreView("Offscreen RearView", offCamera);
reflectionView.setClearFlags(true, true, true);
reflectionView.setBackgroundColor(ColorRGBA.DarkGray);
//setup framebuffer's cam
offCamera.setFrustumPerspective(30, 2f, 1f, 500f);
// create offscreen framebuffer
offBuffer = new FrameBuffer(WIDTH, HEIGHT, 1);
//setup framebuffer's texture
offTex = new Texture2D(WIDTH, HEIGHT, Format.RGBA8);
// offTex.setMinFilter(Texture.MinFilter.Trilinear);
// offTex.setMagFilter(Texture.MagFilter.Bilinear);
//setup framebuffer to use texture
offBuffer.setDepthBuffer(Format.Depth);
offBuffer.setColorTexture(offTex);
//set viewport to render to offscreen framebuffer
reflectionView.setOutputFrameBuffer(offBuffer);
reflectionView.attachScene(game.getRootNode());
displayRearMirror();
}
private void displayRearMirror(){
rearView = new Element(screen, "rearView",
new Vector2f((screen.getWidth() - 5f), 40f),
new Vector2f(WIDTH, HEIGHT),
Vector4f.ZERO.clone(), "Interface/Textures/empty.png");
rearView.getMaterial().setTexture("ColorMap", offTex);
rearView.getMaterial().getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Front);
rearView.rotate(0, FastMath.PI, 0);
screen.addElement(rearView);
}
nb: a baseAppState take cares of calling the constructing/initializing and cleaning. At the end of a race, I detach all appStates… so my idea was that the cleaning method was the culprit.
So you are using 3.1 and it works fine in the 3.0 ?
Besides it maybe some bug on the 3.1 what is must possible ( I could not use 3.1 yet for any of my games, too many bugs ), I would try to clean the camera as well and see what happens…
I had problems with cameras when using this type of custom rendering, the camera is part of the rendering, so you need to take care of it: [SOLVED] Cant move the camera when rendering to texture - #12 by wagfeliz
I have no idea if it’s a good way but I don’t get an exception anymore and haven’t found new glitches. So unless told otherwise, I’m probably going to stick with it.
Thanks for your answers.
NB: haven’t set it as resolved yet because I’d be interested in being told if my solution is fine or if I’m opening myself to a world of troubles.