I am trying to render some balls to a texture then place it behind fengGUI. The problem is the quad just comes up white, the balls are definitely getting rendered and when I use SimpleGame and no fengGUI everything works fine. Below is my RTT initialization, update and render methods. I use GameTaskQueueManager because createTextureRenderer() needs to be in the OpenGL thread, so maybe that could be the issue. Any help or ideas would be very appreciated.
public void initJme() {
initDefaultTextureState();
rootNode = new Node( "Gui Root" );
selectionBallNode = new Node( "Selection Balls" );
int ballNumber = 0;
for( int row=-1; row<2; ++row ) {
for( int col=-1; col<2; ++col ) {
Spatial ball = new Sphere( "", 16, 16, Globals.ballSize );
Utils.color( ball, ColorRGBA.randomColor(), 0 );
ball.setLocalTranslation( col*5, row*5, 0 );
selectionBallNode.attachChild( ball );
++ballNumber;
}
}
ZBufferState zBuffer = DisplaySystem.getDisplaySystem().getRenderer().createZBufferState();
zBuffer.setEnabled( true );
zBuffer.setFunction( ZBufferState.CF_LEQUAL );
selectionBallNode.setRenderState( zBuffer );
LightState lightState = jme_Driver.getJmeBase().getDisplay().getRenderer().createLightState();
DirectionalLight light = new DirectionalLight();
light.setDirection( new Vector3f( 0, 0, 1 ) );
light.setAmbient( new ColorRGBA( 0.5f, 0.5f, 0.5f, 1.0f ) );
light.setDiffuse( new ColorRGBA( 0.75f, 0.75f, 0.75f, 1.0f ) );
light.setSpecular( new ColorRGBA( 1f, 1f, 1f, 1.0f ) );
lightState.setGlobalAmbient( new ColorRGBA( 0.5f, 0.5f, 0.5f, 1 ) );
lightState.setTwoSidedLighting( false );
light.setEnabled( true );
lightState.attach( light );
selectionBallNode.setRenderState( lightState );
selectionBallNode.updateGeometricState( 0.0f, true );
selectionBallNode.updateRenderState();
rootNode.attachChild( selectionBallNode );
GameTaskQueueManager.getManager().update(new Callable<Object>() {
public Object call() throws Exception {
final Quad textureQuad = new Quad(" Quad", 25, 25 );
textureQuad.setLocalTranslation(new Vector3f( -25,0,0 ) );
textureQuad.setModelBound(new BoundingBox());
textureQuad.updateModelBound();
textureQuad.setLightCombineMode(LightState.OFF);
rootNode.attachChild( textureQuad );
rootNode.updateRenderState();
textureRenderer = DisplaySystem.getDisplaySystem().createTextureRenderer( 512, 512, TextureRenderer.RENDER_TEXTURE_2D );
textureRenderer.setBackgroundColor( new ColorRGBA( 0f, 0f, 0f, 1f ) );
selectionBallTexture = new Texture();
textureRenderer.setupTexture( selectionBallTexture );
TextureState screen = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
screen.setTexture( selectionBallTexture );
screen.setEnabled( true );
textureRenderer.getCamera().setLocation( new Vector3f( 0, 0, 50f ) );
textureQuad.setRenderState( screen );
jmeInited = true;
return null;
}
});
}
private void initDefaultTextureState() {
Texture defTex = TextureState.getDefaultTexture().createSimpleClone();
defTex.setScale( Vector3f.UNIT_XYZ );
defaultTextureState = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
defaultTextureState.setTexture( defTex );
}
public void update( float timePerFrame ) {
selectionBallNode.updateGeometricState( timePerFrame, false );
rootNode.updateGeometricState( timePerFrame, false
}
public void render( float tpf ) {
defaultTextureState.apply();
if ( jmeInited ) {
textureRenderer.render( selectionBallNode, selectionBallTexture );
DisplaySystem.getDisplaySystem().getRenderer().draw( rootNode );
}
disp.display();
}