Thanks for your comments.
Well, I tried once more with a real simple test application and a basic scene. Then it worked!
When I looked again at my rather complicated application with a camera, I got it working adding
GLU glu = new GLU();
gl.glMatrixMode(GL.GL_PROJECTION );
gl.glLoadIdentity();
double aspectRatio = (double)drawable.getWidth() / (double)drawable.getHeight();
glu.gluPerspective(60.0, aspectRatio, 1.0, 800.0);
into the init method which was only placed in the reshape method before.
Now testing to export a quad with a texture, it works for the simple test application but with the complicated application I get the quad drawn filled with the currently set color.
I've attached my init and display method.
public void init ( GLAutoDrawable drawable )
{
GL gl = drawable.getGL();
gl.glShadeModel( GL.GL_SMOOTH ); // Enable Smooth Shading
gl.glClearColor( 0.0f, 0.0f, 0.0f, 0.5f ); // Background color
gl.glClearDepth( 1.0f ); // Depth Buffer Setup
gl.glEnable( GL.GL_DEPTH_TEST ); // Enables Depth Testing
gl.glDepthFunc( GL.GL_LEQUAL ); // The Type Of Depth Testing To Do
gl.glHint( GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST );
GLU glu = new GLU();
gl.glMatrixMode(GL.GL_PROJECTION );
gl.glLoadIdentity();
double aspectRatio = (double)drawable.getWidth() / (double)drawable.getHeight();
glu.gluPerspective(60.0, aspectRatio, 1.0, 800.0);
}
public void display ( GLAutoDrawable drawable )
{
final GL gl = drawable.getGL();
gl.glEnable( GL.GL_DEPTH_TEST );
gl.glClear( GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT );
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
GLU glu = new GLU();
glu.gluLookAt( eyePoint.x, eyePoint.y, eyePoint.z, targetViewPoint.x,
targetViewPoint.y, targetViewPoint.z, upVector.x, upVector.y,
upVector.z );
if ( newTexture )
{
System.out.println( "loading new texture" );
newTexture = false;
if ( texture != null )
{
texture.dispose();
texture = null;
}
try
{
file = new File("image.jpg" );
texture = TextureIO.newTexture( file, true );
}
catch ( IOException e )
{
e.printStackTrace();
return;
}
}
if ( texture != null )
{
texture.enable();
texture.bind();
gl.glTexEnvi( GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE,
GL.GL_REPLACE );
TextureCoords coords = texture.getImageTexCoords();
gl.glBegin( GL.GL_QUADS );
gl.glTexCoord2f( coords.left(), coords.bottom() );
gl.glVertex3f( 0, 0, 5 );
gl.glTexCoord2f( coords.right(), coords.bottom() );
gl.glVertex3f( 50, 0, 5 );
gl.glTexCoord2f( coords.right(), coords.top() );
gl.glVertex3f( 50, 50, 5 );
gl.glTexCoord2f( coords.left(), coords.top() );
gl.glVertex3f( 0, 50, 5 );
gl.glEnd();
texture.disable();
}
if ( exportImage )
{
File outputFile = new File( "c:\\temp\\output\\export.jpg" );
System.out.println( "exporting screenshot to: " + outputFile.getName() );
System.out.println("using: " + drawable.toString());
try
{
Screenshot.writeToFile( outputFile, drawable.getWidth(), drawable.getHeight() );
}
catch ( GLException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch ( IOException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
exportImage = false;
}
}