lwjgl2-arm64/src/java/org/lwjgl/test/WindowCreationTest.java

156 lines
4.7 KiB
Java
Raw Normal View History

2004-06-12 22:28:34 +02:00
/*
* Copyright (c) 2002-2004 LWJGL Project
2004-02-04 22:50:00 +01:00
* All rights reserved.
2004-06-12 22:28:34 +02:00
*
2004-02-04 22:50:00 +01:00
* Redistribution and use in source and binary forms, with or without
2004-06-12 22:28:34 +02:00
* modification, are permitted provided that the following conditions are
2004-02-04 22:50:00 +01:00
* met:
2004-06-12 22:28:34 +02:00
*
* * Redistributions of source code must retain the above copyright
2004-02-04 22:50:00 +01:00
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
2004-06-12 22:28:34 +02:00
* * Neither the name of 'LWJGL' nor the names of
* its contributors may be used to endorse or promote products derived
2004-02-04 22:50:00 +01:00
* from this software without specific prior written permission.
2004-06-12 22:28:34 +02:00
*
2004-02-04 22:50:00 +01:00
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2004-06-12 22:28:34 +02:00
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
2004-02-04 22:50:00 +01:00
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
2004-06-12 22:28:34 +02:00
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
2004-02-04 22:50:00 +01:00
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2003-08-17 18:58:19 +02:00
*/
package org.lwjgl.test;
2004-09-15 19:07:06 +02:00
import org.lwjgl.LWJGLException;
2004-07-03 15:48:52 +02:00
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
2004-09-15 19:07:06 +02:00
import org.lwjgl.opengl.GL11;
import org.lwjgl.input.Keyboard;
2003-08-17 18:58:19 +02:00
/**
2004-02-04 22:50:00 +01:00
* Small class for testing that the Window is creatable
* If this class can't run, LWJGL wont work!
*
* @author Brian Matzon <brian@matzon.dk>
2003-08-17 18:58:19 +02:00
*/
public class WindowCreationTest {
2004-02-04 22:50:00 +01:00
/**
* Main entry point
*
* @param args ignored params to app
*/
2003-08-17 18:58:19 +02:00
public static void main(String[] args) {
2004-02-04 22:50:00 +01:00
// get avaialble modes, and print out
2003-08-17 18:58:19 +02:00
DisplayMode[] modes = Display.getAvailableDisplayModes();
System.out.println("Found " + modes.length + " display modes");
2004-09-15 19:07:06 +02:00
int x = 100, y = 100;
boolean fullscreen = false;
System.out.println("Moving to 100, 100");
Display.setLocation(x, y);
2003-08-17 18:58:19 +02:00
2004-02-04 22:50:00 +01:00
// Create the actual window
2003-08-17 18:58:19 +02:00
try {
2004-07-22 17:10:55 +02:00
setDisplayMode();
2004-07-03 15:48:52 +02:00
Display.create();
2003-08-17 18:58:19 +02:00
} catch (Exception e) {
e.printStackTrace();
2004-02-04 22:50:00 +01:00
System.out.println("Unable to create window!, exiting...");
System.exit(-1);
2003-08-17 18:58:19 +02:00
}
2004-02-04 22:50:00 +01:00
System.out.println("Window created");
2004-07-03 15:48:52 +02:00
System.out.println(Display.getDisplayMode().getHeight() + ", " + Display.getDisplayMode().getWidth() + ", " + Display.getTitle());
2004-09-15 19:07:06 +02:00
2004-11-11 17:03:19 +01:00
Display.setVSyncEnabled(true);
Display.setTitle("WindowCreationTest");
float color = 0f;
int direction = 1;
2004-02-04 22:50:00 +01:00
// wait for user to close window
2004-09-15 19:07:06 +02:00
while(!Display.isCloseRequested()) {
2004-11-11 17:03:19 +01:00
GL11.glClearColor(color, color, color, 1f);
2004-09-15 19:07:06 +02:00
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
2004-11-11 17:03:19 +01:00
color += direction*.05f;
if (color > 1f) {
color = 1f;
direction = -1*direction;
} else if (color < 0f) {
direction = -1*direction;
color = 0f;
}
2004-07-03 15:48:52 +02:00
Display.update();
2003-08-17 18:58:19 +02:00
try {
Thread.sleep(100);
} catch (Exception e) {
e.printStackTrace();
}
if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
break;
}
2004-09-15 19:07:06 +02:00
if(Keyboard.isKeyDown(Keyboard.KEY_LEFT)) {
Display.setLocation(x -= 10, y);
}
if(Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) {
Display.setLocation(x += 10, y);
}
if(Keyboard.isKeyDown(Keyboard.KEY_UP)) {
Display.setLocation(x, y -= 10);
}
if(Keyboard.isKeyDown(Keyboard.KEY_DOWN)) {
Display.setLocation(x, y += 10);
}
if(Keyboard.isKeyDown(Keyboard.KEY_F)) {
try {
Display.setFullscreen(fullscreen = !fullscreen);
} catch (LWJGLException lwjgle) {
lwjgle.printStackTrace();
}
}
2003-08-17 18:58:19 +02:00
}
2004-02-04 22:50:00 +01:00
// nuke window and get out
2004-07-03 15:48:52 +02:00
Display.destroy();
2003-08-17 18:58:19 +02:00
}
2004-07-22 17:10:55 +02:00
/**
* Sets the display mode for fullscreen mode
*/
protected static boolean setDisplayMode() {
// get modes
DisplayMode[] dm = org.lwjgl.util.Display.getAvailableDisplayModes(640, 480, -1, -1, -1, -1, 60, 60);
try {
org.lwjgl.util.Display.setDisplayMode(dm, new String[] {
"width=" + 640,
"height=" + 480,
"freq=" + 60,
"bpp=" + org.lwjgl.opengl.Display.getDisplayMode().getBitsPerPixel()
});
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
2003-08-17 18:58:19 +02:00
}