lwjgl2-arm64/src/java/org/lwjgl/test/input/MouseCreationTest.java

200 lines
5.6 KiB
Java
Raw Normal View History

2004-06-12 22:28:34 +02:00
/*
* Copyright (c) 2002-2004 LWJGL Project
2003-08-17 18:58:19 +02:00
* All rights reserved.
2004-06-12 22:28:34 +02:00
*
2003-08-17 18:58:19 +02: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
2003-08-17 18:58:19 +02:00
* met:
2004-06-12 22:28:34 +02:00
*
* * Redistributions of source code must retain the above copyright
2003-08-17 18:58:19 +02: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
2003-08-17 18:58:19 +02:00
* from this software without specific prior written permission.
2004-06-12 22:28:34 +02:00
*
2003-08-17 18:58:19 +02: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
2003-08-17 18:58:19 +02: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
2003-08-17 18:58:19 +02:00
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lwjgl.test.input;
2004-07-03 15:48:52 +02:00
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
2004-02-08 21:41:00 +01:00
import org.lwjgl.Sys;
2003-08-17 18:58:19 +02:00
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
2004-07-03 15:48:52 +02:00
import org.lwjgl.opengl.Display;
2004-04-18 22:01:28 +02:00
import org.lwjgl.util.vector.Vector2f;
2003-08-17 18:58:19 +02:00
/**
* $Id$
* <br>
* Mouse test
*
* @author Brian Matzon <brian@matzon.dk>
* @version $Revision$
*/
public class MouseCreationTest {
/** position of quad to draw */
2003-08-17 18:58:19 +02:00
private Vector2f position = new Vector2f(320.0f, 240.0f);
/** Display mode selected */
private DisplayMode displayMode;
/** Creates a new instance of MouseTest */
public MouseCreationTest() {
}
private void initialize(boolean fullscreen) {
// find first display mode that allows us 640*480*16
DisplayMode[] modes = Display.getAvailableDisplayModes();
for (int i = 0; i < modes.length; i++) {
2004-07-03 15:48:52 +02:00
if (modes[i].getWidth() == 640
&& modes[i].getHeight() == 480
&& modes[i].getBitsPerPixel() >= 16) {
2003-08-17 18:58:19 +02:00
displayMode = modes[i];
break;
}
}
try {
Display.setDisplayMode(displayMode);
2004-07-03 15:48:52 +02:00
Display.setFullscreen(fullscreen);
Display.create();
2003-08-17 18:58:19 +02:00
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
initializeOpenGL();
}
private void initializeOpenGL() {
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
2003-08-17 18:58:19 +02:00
}
public void executeTest() {
initialize(false);
System.out.println("Test ready:\n");
// windowed mode
System.out.println("=========== WINDOWED MODE ==============");
for(int i=0; i<2; i++) {
System.out.println("Test " + (i+1) + ":");
wiggleMouse();
System.out.println("");
}
// recreate display in fullscreen mode
System.out.print("Destroying display...");
System.out.println("success");
System.out.print("Entering fullscreen mode...");
try {
2004-07-03 15:48:52 +02:00
Display.destroy();
2003-08-17 18:58:19 +02:00
initialize(true);
Display.setDisplayMode(displayMode);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("success");
// fullscreen mode
System.out.println("=========== FULLSCREEN MODE ==============");
for(int i=0; i<2; i++) {
System.out.println("Test " + (i+3) + ":");
wiggleMouse();
System.out.println("");
}
System.out.println("Test completed successfully!");
System.out.print("Shutting down...");
2004-07-03 15:48:52 +02:00
Display.destroy();
2003-08-17 18:58:19 +02:00
System.out.println("shutdown complete");
}
private void wiggleMouse() {
System.out.print("Please move the mouse around");
long statustime = Sys.getTime();
long endtime = Sys.getTime() + Sys.getTimerResolution() * 5;
while (Sys.getTime() < endtime) {
2004-07-03 15:48:52 +02:00
Display.update();
2003-08-17 18:58:19 +02:00
2004-02-04 21:44:07 +01:00
position.x += Mouse.getDX();
position.y += Mouse.getDY();
2003-08-17 18:58:19 +02:00
if(position.x<0) {
position.x = 0;
} else if (position.x>640-60) {
position.x = 640-60;
}
if(position.y < 0) {
position.y = 0;
} else if (position.y>480-30) {
position.y = 480-30;
}
render();
if (Sys.getTime() - statustime > Sys.getTimerResolution()) {
System.out.print(".");
statustime = Sys.getTime();
}
}
System.out.println("thank you");
}
private void render() {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
2003-08-17 18:58:19 +02:00
GL11.glBegin(GL11.GL_POLYGON);
2003-08-17 18:58:19 +02:00
{
float color = 1.0f;
int buttonDown = 0;
2004-02-04 21:44:07 +01:00
for(int i=0;i<Mouse.getButtonCount(); i++) {
2003-08-17 18:58:19 +02:00
if(Mouse.isButtonDown(i)) {
2004-02-04 21:44:07 +01:00
color = (1.0f / Mouse.getButtonCount()) * (i+1);
2003-08-17 18:58:19 +02:00
break;
}
}
GL11.glColor3f(color, color, color);
2003-08-17 18:58:19 +02:00
GL11.glVertex2f(position.x + 0.0f, position.y + 0.0f);
GL11.glVertex2f(position.x + 0.0f, position.y + 30.0f);
GL11.glVertex2f(position.x + 40.0f, position.y + 30.0f);
GL11.glVertex2f(position.x + 60.0f, position.y + 15.f);
GL11.glVertex2f(position.x + 40.0f, position.y + 0.0f);
2003-08-17 18:58:19 +02:00
}
GL11.glEnd();
2003-08-17 18:58:19 +02:00
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
MouseCreationTest mt = new MouseCreationTest();
mt.executeTest();
}
}