|
From: <eli...@us...> - 2006-11-20 08:39:28
|
Revision: 2672
http://svn.sourceforge.net/java-game-lib/?rev=2672&view=rev
Author: elias_naur
Date: 2006-11-20 00:39:22 -0800 (Mon, 20 Nov 2006)
Log Message:
-----------
Added AWTInputAdapter testing to applet/OpenGL.java
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/test/applet/OpenGL.java
Modified: trunk/LWJGL/src/java/org/lwjgl/test/applet/OpenGL.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/applet/OpenGL.java 2006-11-20 08:14:50 UTC (rev 2671)
+++ trunk/LWJGL/src/java/org/lwjgl/test/applet/OpenGL.java 2006-11-20 08:39:22 UTC (rev 2672)
@@ -36,9 +36,15 @@
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
+import org.lwjgl.opengl.AWTInputAdapter;
+import org.lwjgl.input.Keyboard;
+import org.lwjgl.input.Mouse;
+
public class OpenGL extends AWTGLCanvas implements Test {
float angle = 0;
+ float x;
+ float y;
public OpenGL() throws LWJGLException {
}
@@ -47,15 +53,22 @@
GL11.glMatrixMode(GL11.GL_PROJECTION_MATRIX);
GL11.glLoadIdentity();
GL11.glOrtho(0, 640, 0, 480, 1, -1);
+ x = 320;
+ y = 240;
GL11.glMatrixMode(GL11.GL_MODELVIEW_MATRIX);
setVSyncEnabled(true);
+ try {
+ AWTInputAdapter.create(this);
+ } catch (LWJGLException e) {
+ e.printStackTrace();
+ }
}
public void paintGL() {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
GL11.glPushMatrix();
- GL11.glTranslatef(320, 240, 0.0f);
+ GL11.glTranslatef(x, y, 0.0f);
GL11.glRotatef(angle, 0, 0, 1.0f);
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex2i(-50, -50);
@@ -67,6 +80,47 @@
angle += 1;
+ if (Mouse.isCreated()) {
+ Mouse.poll();
+ while (Mouse.next()) {
+ x += Mouse.getEventDX();
+ y += Mouse.getEventDY();
+ }
+ }
+ if (Keyboard.isCreated()) {
+ Keyboard.poll();
+ }
+ while (Keyboard.isCreated() && Keyboard.next()) {
+ if (Keyboard.getEventKey() != Keyboard.KEY_NONE) {
+ String key_name = Keyboard.getKeyName(Keyboard.getEventKey());
+ if (Keyboard.getEventKeyState()) {
+ switch (Keyboard.getEventKey()) {
+ case Keyboard.KEY_H:
+ AWTInputAdapter.destroy();
+ break;
+ case Keyboard.KEY_G:
+ Mouse.setGrabbed(!Mouse.isGrabbed());
+ break;
+ default:
+ break;
+ }
+ System.out.println("Pressed: " + key_name);
+ } else
+ System.out.println("Released: " + key_name);
+ }
+ if (Keyboard.getEventCharacter() != Keyboard.CHAR_NONE)
+ System.out.println("Typed: " + Keyboard.getEventCharacter());
+ }
+ if (Keyboard.isCreated()) {
+ if (Keyboard.isKeyDown(Keyboard.KEY_UP))
+ y += 5;
+ else if (Keyboard.isKeyDown(Keyboard.KEY_DOWN))
+ y -= 5;
+ if (Keyboard.isKeyDown(Keyboard.KEY_LEFT))
+ x -= 5;
+ else if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT))
+ x += 5;
+ }
try {
swapBuffers();
if (isVisible())
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|