I’ve just spent the last few hours java-fying this tile rendering library, and I thought I’d share it with everyone here.
I’m using it in conjunction with this fast screenshot code to generate high-res images for print.
Like so:
try
{
// allocate the buffer
RandomAccessFile out = new RandomAccessFile( imageFile, "rw" );
FileChannel ch = out.getChannel();
int fileLength = TARGA_HEADER_SIZE + imageSize.width * imageSize.height * 3;
out.setLength( fileLength );
MappedByteBuffer image = ch.map( FileChannel.MapMode.READ_WRITE, 0, fileLength );
// write the TARGA header
image.put( 0, ( byte ) 0 ).put( 1, ( byte ) 0 );
image.put( 2, ( byte ) 2 ); // uncompressed type
image.put( 12, ( byte ) ( imageSize.width & 0xFF ) ); // width
image.put( 13, ( byte ) ( imageSize.width >> 8 ) ); // width
image.put( 14, ( byte ) ( imageSize.height & 0xFF ) ); // height
image.put( 15, ( byte ) ( imageSize.height >> 8 ) ); // height
image.put( 16, ( byte ) 24 ); // pixel size
// go to image data position
image.position( TARGA_HEADER_SIZE );
// jogl needs a sliced buffer
ByteBuffer bgr = image.slice();
// setup the tile rendering
TileRender tr = new TileRender();
tr.setTileSize( tileSize.width, tileSize.height, 0 );
tr.setImageSize( imageSize.width, imageSize.height );
tr.setImageBuffer( GL.GL_BGR, GL.GL_UNSIGNED_BYTE, bgr );
tr.trPerspective( fieldOfView, aspectRatio, nearPlane, farPlane );
// do the rendering
do
{
tr.beginTile( gl );
// put your rendering here, but don't touch the projection
// matrix stack
}
while( tr.endTile( gl );
// close the file channel
ch.close();
}
catch( Exception e )
{
e.printStackTrace();
}
Have fun!