I assume your GUI could be written onto a BufferedImage. If you are having trouble getting started, here is one possible ITextureEffect implementation for copying the contents of an AWT.Image onto a texture:
private class AWTImageTextureEffect implements ITextureEffect
{
/**
* Ignored by AWTImageTextureEffect.
* @param tex The texture.
*/
@Override
public void init( Texture tex)
{}
/**
* Changes the contents of the texture.
* @param dest Pixels to change.
* @param dest Current pixels.
*/
@Override
public void apply(int[] dest, int[] source)
{
PixelGrabber pg = new PixelGrabber( guiImage, 0, 0,
imageWidth,
imageHeight,
dest, 0, textureWidth );
try
{
pg.grabPixels();
}
catch( InterruptedException e )
{
System.err.println( "interrupted waiting for pixels!" );
return;
}
if( ( pg.getStatus() & ImageObserver.ABORT ) != 0 )
{
System.err.println( "image fetch aborted or errored" );
return;
}
}
}
And here is a simple example for how to set the effect up for a Quad:
guiImage = new BufferedImage( imageWidth, imageHeight,
BufferedImage.TYPE_4BYTE_ABGR );
//only needed if image dimensions are not powers of 2:
textureWidth = nextPowerOf2( imageWidth);
textureHeight = nextPowerOf2( imageHeight );
//these can both be 1.0f if image dimensions are powers of 2:
float uw = (float) imageWidth / (float) textureWidth;
float uh = (float) imageHeight / (float) textureHeight;
guiTexture = new Texture( textureWidth, textureHeight, Color.BLACK );
TextureManager.getInstance().addTexture( "GUI Texture", guiTexture );
guiTexture.setEffect( new AWTImageTextureEffect() );
SimpleVector br = new SimpleVector( 0, 0, 0 );
SimpleVector bl = new SimpleVector( imageWidth, 0, 0 );
SimpleVector tr = new SimpleVector( 0, imageHeight, 0 );
SimpleVector tl = new SimpleVector( imageWidth, imageHeight, 0 );
guiQuad = new Object3D( 2 );
guiQuad.addTriangle( tl, 0, 0, bl, 0, uh, br, uw, uh,
TextureManager.getInstance().getTextureID( "GUI Texture" ) );
guiQuad.addTriangle( br, uw, uh, tr, uw, 0, tl, 0, 0,
TextureManager.getInstance().getTextureID( "GUI Texture" ) );
guiQuad.build();
world.addObject( guiQuad );
guiQuad.setVisibility( true );
TODO: Do something with the GUI quad (use it as an overlay, for example)
...
private static int nextPowerOf2( int x )
{
--x;
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
return ++x;
}
With this, you could draw your GUI onto the guiImage (with getGraphics(), for example). Then, any time something changes, you would simply call:
synchronized( frameBuffer.getLock() )
{
guiTexture.applyEffect();
}
One more note - there are a couple of ways you could add transparency to the above guiTexture. One way would be to use the Alpha channel, and the other way would be to use black (0,0,0) as the transparent color.