import java.awt.Canvas; //导入方法依赖的package包/类
public DisplayParentTest() throws LWJGLException {
setTitle( "LWJGL Display Parent Test" );
setSize( 640, 320 );
setLayout( new GridLayout( 1, 2 ) );
final Canvas display_parent = new Canvas();
final Canvas display_parent_2 = new Canvas();
display_parent.setFocusable( true );
display_parent.setIgnoreRepaint( true );
add( display_parent );
display_parent_2.setFocusable( true );
display_parent_2.setIgnoreRepaint( true );
add( display_parent_2 );
addWindowListener( new WindowAdapter() {
public void windowClosing( WindowEvent e ) {
killswitch = true;
}
} );
setResizable( true );
setVisible( true );
Display.setParent( display_parent );
Display.setVSyncEnabled( true );
Display.create();
float angle = 0f;
while ( isVisible() && !killswitch ) {
angle += 1.0f;
int width;
int height;
if ( !Display.isFullscreen() ) {
width = display_parent.getWidth();
height = display_parent.getHeight();
}
else {
width = Display.getDisplayMode().getWidth();
height = Display.getDisplayMode().getHeight();
}
if ( width < 1 || height < 1 ) {
continue;
}
glViewport( 0, 0, width, height );
glClearColor( 0.0f, 1.0f, 0.0f, 1.0f );
glClear( GL_COLOR_BUFFER_BIT );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluOrtho2D( 0.0f, (float) width, 0.0f, (float) height );
glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glTranslatef( width / 2.0f, height / 2.0f, 0.0f );
glRotatef( 2 * angle, 0f, 0f, -1.0f );
glRectf( -50.0f, -50.0f, 50.0f, 50.0f );
glPopMatrix();
Display.update();
while ( Keyboard.next() ) {
// closing on ESCAPE
if ( Keyboard.getEventKey() == Keyboard.KEY_ESCAPE && Keyboard.getEventKeyState() ) {
Display.destroy();
dispose();
break;
}
if ( Keyboard.getEventKey() == Keyboard.KEY_SPACE && Keyboard.getEventKeyState() ) {
Mouse.setGrabbed( !Mouse.isGrabbed() );
}
if ( Keyboard.getEventKey() == Keyboard.KEY_F && Keyboard.getEventKeyState() ) {
Display.setFullscreen( !Display.isFullscreen() );
}
if ( Keyboard.getEventKey() == Keyboard.KEY_4 && Keyboard.getEventKeyState() ) {
if ( Display.getParent() == display_parent ) {
Display.setParent( display_parent_2 );
}
else {
Display.setParent( display_parent );
}
}
}
while ( Mouse.next() ) {
System.out.println( "Mouse.getEventX() = " + Mouse.getEventX() + " | Mouse.getEventY() = " + Mouse.getEventY() );
}
}
Display.destroy();
dispose();
}