diff --git a/src/java/org/lwjgl/Display.java b/src/java/org/lwjgl/Display.java index b0e0304c..4948737a 100644 --- a/src/java/org/lwjgl/Display.java +++ b/src/java/org/lwjgl/Display.java @@ -80,14 +80,16 @@ public final class Display { * already created then no action is taken - the display must first be * destroyed. * - * @param displayMode a display mode to choose - * @param fullscreen whether to create the display fullscreen + * @param displayMode A display mode to choose + * @param fullscreen Whether to create the display fullscreen + * @param title The title for the application * @throws Exception if the display mode could not be set * @see #destroy() */ public static void create( DisplayMode displayMode, - boolean fullscreen) + boolean fullscreen, + String title) throws Exception { if (created) @@ -100,7 +102,8 @@ public final class Display { displayMode.alpha, displayMode.depth, displayMode.stencil, - fullscreen)) + fullscreen, + title)) throw new Exception("Failed to set display mode to " + displayMode); created = true; @@ -121,7 +124,8 @@ public final class Display { int alpha_bits, int depth_bits, int stencil_bits, - boolean fullscreen); + boolean fullscreen, + String title); /** * Destroy the display and return it to normal. If the display has not yet diff --git a/src/java/org/lwjgl/test/openal/ALCTest.java b/src/java/org/lwjgl/test/openal/ALCTest.java index 9efcdb30..25766a91 100644 --- a/src/java/org/lwjgl/test/openal/ALCTest.java +++ b/src/java/org/lwjgl/test/openal/ALCTest.java @@ -98,7 +98,7 @@ public class ALCTest extends BasicTest { alc.processContext(context); //suspend - alc.suspendContext(context); + // alc.suspendContext(context); //query System.out.println("DEFAULT_DEVICE_SPECIFIER: " + alc.getString(device, ALC.DEFAULT_DEVICE_SPECIFIER)); diff --git a/src/java/org/lwjgl/test/openal/MovingSoundTest.java b/src/java/org/lwjgl/test/openal/MovingSoundTest.java index ef48ab82..228a356a 100644 --- a/src/java/org/lwjgl/test/openal/MovingSoundTest.java +++ b/src/java/org/lwjgl/test/openal/MovingSoundTest.java @@ -92,7 +92,7 @@ public class MovingSoundTest extends BasicTest { break; } } - Display.create(modes[mode], false); + Display.create(modes[mode], false, "MovingSoundTest"); } catch (Exception e) { e.printStackTrace(); exit(-1); diff --git a/src/java/org/lwjgl/test/opengl/Game.java b/src/java/org/lwjgl/test/opengl/Game.java index ffdc2167..0f6c9658 100644 --- a/src/java/org/lwjgl/test/opengl/Game.java +++ b/src/java/org/lwjgl/test/opengl/Game.java @@ -45,7 +45,7 @@ import org.lwjgl.*; import org.lwjgl.opengl.*; import org.lwjgl.input.*; -import java.nio.*; +import java.nio.*; public final class Game { static { @@ -63,131 +63,131 @@ public final class Game { } //select above found displaymode - Display.create(modes[mode], false); + Display.create(modes[mode], false, "LWJGL Game Example"); System.out.println("Created display."); } catch (Exception e) { System.err.println("Failed to create display due to " + e); System.exit(1); } } - - public static final GL gl = new GL(); - public static final GLU glu = new GLU(gl); - - static { - try { - gl.create(); - System.out.println("Created OpenGL."); - } catch (Exception e) { - System.err.println("Failed to create OpenGL due to " + e); - System.exit(1); - } - } - - /** Is the game finished? */ - private static boolean finished; - - /** A rotating square! */ - private static float angle; - - /** - * No construction allowed - */ - private Game() { - } - - public static void main(String[] arguments) { - try { - init(); - while (!finished) { - Keyboard.poll(); - - mainLoop(); - - render(); - - gl.swapBuffers(); - } - } catch (Throwable t) { - t.printStackTrace(); - } finally { - cleanup(); - } - } - - /** - * All calculations are done in here - */ - private static void mainLoop() { - angle += 1f; - if (angle > 360.0f) - angle = 0.0f; - - if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) { - finished = true; - } - } - - /** - * All rendering is done in here - */ - private static void render() { - gl.clear(GL.COLOR_BUFFER_BIT); - gl.pushMatrix(); - gl.translatef(Display.getWidth() / 2, Display.getHeight() / 2, 0.0f); - gl.rotatef(angle, 0, 0, 1.0f); - gl.begin(GL.QUADS); - { - gl.vertex2i(-50, -50); - gl.vertex2i(50, -50); - gl.vertex2i(50, 50); - gl.vertex2i(-50, 50); - } - gl.end(); - gl.popMatrix(); - } - - /** - * Initialize - */ - private static void init() throws Exception { - System.out.println("Press the ESCAPE key to exit"); - - Keyboard.create(); - - //reset time - Sys.setTime(0); - - //set priority of this process - Sys.setProcessPriority(Sys.LOW_PRIORITY); - - //print timer resolution info - System.out.println("Timer resolution: " + Sys.getTimerResolution() + " ticks per second"); - - // Go into orthographic projection mode. - gl.matrixMode(GL.PROJECTION); - gl.loadIdentity(); - glu.ortho2D(0, Display.getWidth(), 0, Display.getHeight()); - gl.matrixMode(GL.MODELVIEW); - gl.loadIdentity(); - gl.viewport(0, 0, Display.getWidth(), Display.getHeight()); - - //lets print out some info - ByteBuffer num_tex_units_buf = ByteBuffer.allocateDirect(4); - num_tex_units_buf.order(ByteOrder.nativeOrder()); - int buf_addr = Sys.getDirectBufferAddress(num_tex_units_buf); - gl.getIntegerv(GL.MAX_TEXTURE_UNITS_ARB, buf_addr); - - System.out.println( - "Number of texture units: " + num_tex_units_buf.getInt()); - } - - /** - * Cleanup - */ - private static void cleanup() { - Keyboard.destroy(); - gl.destroy(); - Display.destroy(); - } -} \ No newline at end of file + + public static final GL gl = new GL(); + public static final GLU glu = new GLU(gl); + static { + try { + gl.create(); + System.out.println("Created OpenGL."); + } catch (Exception e) { + System.err.println("Failed to create OpenGL due to "+e); + System.exit(1); + } + } + + /** Is the game finished? */ + private static boolean finished; + + /** A rotating square! */ + private static float angle; + + /** + * No construction allowed + */ + private Game() { + } + + public static void main(String[] arguments) { + try { + init(); + while (!finished) { +// Keyboard.poll(); + mainLoop(); + render(); + gl.swapBuffers(); + } + } catch (Throwable t) { + t.printStackTrace(); + } finally { + cleanup(); + } + } + + /** + * All calculations are done in here + */ + private static void mainLoop() { + angle += 1f; + if (angle > 360.0f) + angle = 0.0f; + + Mouse.poll(); + if (Mouse.dx != 0 || Mouse.dy != 0 || Mouse.dz != 0) + System.out.println("Mouse moved " + Mouse.dx + " " + Mouse.dy + " " + Mouse.dz); + for (int i = 0; i < 8; i++) + if (Mouse.isButtonDown(i)) + System.out.println("Button " + i + " down"); +/* Keyboard.poll(); + if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) + finished = true;*/ + Keyboard.read(); + for (int i = 0; i < Keyboard.getNumKeyboardEvents(); i++) { + Keyboard.next(); + if (Keyboard.key == Keyboard.KEY_ESCAPE && Keyboard.state) + finished = true; + if (Keyboard.key == Keyboard.KEY_T && Keyboard.state) + System.out.println("Current time: " + Sys.getTime()); + } + } + + /** + * All rendering is done in here + */ + private static void render() { + gl.clear(GL.COLOR_BUFFER_BIT); + gl.pushMatrix(); + gl.translatef(Display.getWidth() / 2, Display.getHeight() / 2, 0.0f); + gl.rotatef(angle, 0, 0, 1.0f); + gl.begin(GL.QUADS); + gl.vertex2i(-50, -50); + gl.vertex2i(50, -50); + gl.vertex2i(50, 50); + gl.vertex2i(-50, 50); + gl.end(); + gl.popMatrix(); + } + + /** + * Initialize + */ + private static void init() throws Exception { + Keyboard.create(); + Keyboard.enableBuffer(); + Mouse.create(); + Sys.setTime(0); + Sys.setProcessPriority(Sys.HIGH_PRIORITY); + System.out.println("Timer resolution: " + Sys.getTimerResolution()); + // Go into orthographic projection mode. + gl.matrixMode(GL.PROJECTION); + gl.loadIdentity(); + glu.ortho2D(0, Display.getWidth(), 0, Display.getHeight()); + gl.matrixMode(GL.MODELVIEW); + gl.loadIdentity(); + gl.viewport(0, 0, Display.getWidth(), Display.getHeight()); + ByteBuffer num_tex_units_buf = ByteBuffer.allocateDirect(4); + num_tex_units_buf.order(ByteOrder.nativeOrder()); + int buf_addr = Sys.getDirectBufferAddress(num_tex_units_buf); + gl.getIntegerv(GL.MAX_TEXTURE_UNITS_ARB, buf_addr); + System.out.println("Number of texture units: " + num_tex_units_buf.getInt()); + // Fix the refresh rate to the display frequency. +// gl.wglSwapIntervalEXT(1); + } + + /** + * Cleanup + */ + private static void cleanup() { + Keyboard.destroy(); + Mouse.destroy(); + gl.destroy(); + Display.destroy(); + } + } diff --git a/src/java/org/lwjgl/test/opengl/Grass.java b/src/java/org/lwjgl/test/opengl/Grass.java index b2ddd349..707d5a19 100644 --- a/src/java/org/lwjgl/test/opengl/Grass.java +++ b/src/java/org/lwjgl/test/opengl/Grass.java @@ -50,42 +50,41 @@ import java.io.*; import java.nio.*; import java.util.*; -class Aslod { - float angle; - float value; - float ripple; - float count; -} - public class Grass { - private static boolean finished = false; - private static Random rand = new Random(); + static class Aslod { + float angle; + float value; + float ripple; + float count; + } + private static boolean finished = false; + private static Random rand = new Random(); static { try { - int mode = -1; - DisplayMode[] modes = Display.getAvailableDisplayModes(); - for (int i = 0; i < modes.length; i ++) { - if( modes[i].width == 640 && - modes[i].height == 480 && - modes[i].bpp >= 16) { - mode = i; - break; - } - } - - if (mode == -1) { - System.out.println("did not find suitable mode"); - } else { - System.out.println("Display mode: " + modes[mode]); - } + int mode = -1; + DisplayMode[] modes = Display.getAvailableDisplayModes(); + for (int i = 0; i < modes.length; i++) { + if (modes[i].width == 640 + && modes[i].height == 480 + && modes[i].bpp >= 16) { + mode = i; + break; + } + } + + if (mode == -1) { + System.out.println("did not find suitable mode"); + } else { + System.out.println("Display mode: " + modes[mode]); + } // For now let's just pick a mode we're certain to have - - Display.create(modes[mode], false); + + Display.create(modes[mode], false, "Grass"); System.out.println("Created display."); } catch (Exception e) { - e.printStackTrace(); + e.printStackTrace(); System.exit(1); } } @@ -96,35 +95,35 @@ public class Grass { static { try { gl.create(); - Keyboard.create(); - Keyboard.enableBuffer(); - Mouse.create(); + Keyboard.create(); + Keyboard.enableBuffer(); + Mouse.create(); System.out.println("Created OpenGL."); } catch (Exception e) { - System.err.println("Failed to create OpenGL due to "+e); + System.err.println("Failed to create OpenGL due to " + e); System.exit(1); } } - private static Aslod aslod = new Aslod(); + private static Aslod aslod = new Aslod(); - private static int mesh; - private static int program_handle; + private static int mesh; + private static int program_handle; private static byte[] loadFile(String file) { int next; java.util.Vector bytes = new java.util.Vector(); try { - ClassLoader loader = ClassLoader.getSystemClassLoader(); - URL url = loader.getResource(file); + ClassLoader loader = ClassLoader.getSystemClassLoader(); + URL url = loader.getResource(file); InputStream stream = new BufferedInputStream(url.openStream()); while ((next = (stream.read())) != -1) - bytes.add(new Byte((byte)next)); + bytes.add(new Byte((byte) next)); stream.close(); byte[] result = new byte[bytes.size()]; for (int i = 0; i < result.length; i++) - result[i] = ((Byte)bytes.get(i)).byteValue(); + result[i] = ((Byte) bytes.get(i)).byteValue(); return result; } catch (Exception e) { e.printStackTrace(); @@ -132,41 +131,50 @@ public class Grass { return null; } - - public static void main(String[] args) { + public static void main(String[] args) { ByteBuffer byte_buf = ByteBuffer.allocateDirect(4); - byte_buf.order(ByteOrder.nativeOrder()); - System.out.println("Vertex program supported: " + gl.NV_vertex_program); - gl.genProgramsNV(1, Sys.getDirectBufferAddress(byte_buf)); - IntBuffer int_buf = byte_buf.asIntBuffer(); - if (int_buf.get(0) == 0) - throw new RuntimeException("Could not allocate new vertex program id!"); + byte_buf.order(ByteOrder.nativeOrder()); + System.out.println("Vertex program supported: " + gl.NV_vertex_program); + gl.genProgramsNV(1, Sys.getDirectBufferAddress(byte_buf)); + IntBuffer int_buf = byte_buf.asIntBuffer(); + if (int_buf.get(0) == 0) + throw new RuntimeException("Could not allocate new vertex program id!"); - program_handle = int_buf.get(0); + program_handle = int_buf.get(0); byte[] program = loadFile("cg_grass2.vp"); - ByteBuffer program_buf = ByteBuffer.allocateDirect(program.length); - program_buf.order(ByteOrder.nativeOrder()); - program_buf.rewind(); - program_buf.put(program); - program_buf.rewind(); - gl.loadProgramNV(GL.VERTEX_PROGRAM_NV, program_handle, program_buf.remaining(), Sys.getDirectBufferAddress(program_buf)); + ByteBuffer program_buf = ByteBuffer.allocateDirect(program.length); + program_buf.order(ByteOrder.nativeOrder()); + program_buf.rewind(); + program_buf.put(program); + program_buf.rewind(); + gl.loadProgramNV( + GL.VERTEX_PROGRAM_NV, + program_handle, + program_buf.remaining(), + Sys.getDirectBufferAddress(program_buf)); /*gl.getIntegerv(GL.PROGRAM_ERROR_POSITION_NV, Sys.getDirectBufferAddress(int_buf)); System.out.println("error position: " + int_buf.get(0));*/ genMesh(); - float[] LightDiffuse = {1.0f, 0.0f, 0.0f, 1.0f}; - float[] LightPosition = {1.0f, 1.0f, 1.0f, 0.0f}; - ByteBuffer light_buf = ByteBuffer.allocateDirect(4*4); - light_buf.order(ByteOrder.nativeOrder()); - FloatBuffer light_buf_f = light_buf.asFloatBuffer(); - light_buf_f.rewind(); - light_buf_f.put(LightDiffuse); + float[] LightDiffuse = { 1.0f, 0.0f, 0.0f, 1.0f }; + float[] LightPosition = { 1.0f, 1.0f, 1.0f, 0.0f }; + ByteBuffer light_buf = ByteBuffer.allocateDirect(4 * 4); + light_buf.order(ByteOrder.nativeOrder()); + FloatBuffer light_buf_f = light_buf.asFloatBuffer(); + light_buf_f.rewind(); + light_buf_f.put(LightDiffuse); - gl.lightfv(GL.LIGHT0, GL.DIFFUSE, Sys.getDirectBufferAddress(light_buf_f)); - light_buf_f.rewind(); - light_buf_f.put(LightPosition); - gl.lightfv(GL.LIGHT0, GL.POSITION, Sys.getDirectBufferAddress(light_buf_f)); + gl.lightfv( + GL.LIGHT0, + GL.DIFFUSE, + Sys.getDirectBufferAddress(light_buf_f)); + light_buf_f.rewind(); + light_buf_f.put(LightPosition); + gl.lightfv( + GL.LIGHT0, + GL.POSITION, + Sys.getDirectBufferAddress(light_buf_f)); gl.enable(GL.LIGHT0); gl.enable(GL.LIGHTING); @@ -189,10 +197,10 @@ public class Grass { aslod.count = 0.0f; while (!finished) { - keyPoll(); + keyPoll(); float degree = (1.0f + (aslod.value * 20.0f)) * 0.01745329f; - degree *= (0.5 + myrand()) ; + degree *= (0.5 + myrand()); ptrAnimate(degree); gl.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT); @@ -203,18 +211,22 @@ public class Grass { gl.swapBuffers(); } - Mouse.destroy(); - Keyboard.destroy(); - gl.destroy(); - Display.destroy(); - } + Mouse.destroy(); + Keyboard.destroy(); + gl.destroy(); + Display.destroy(); + } private static float myrand() { // returns a value between 0 and 1 - return rand.nextFloat(); + return rand.nextFloat(); } - private static void genGrass( float fFaceHeight, float fFaceWidth, float fX, float fZ ) { + private static void genGrass( + float fFaceHeight, + float fFaceWidth, + float fX, + float fZ) { int cFaces; int numFaces; float cWidth; @@ -223,8 +235,16 @@ public class Grass { float fRigid; numFaces = 5; - frndHeight = fFaceHeight + ((fFaceHeight / 1.5f) * (float)java.lang.Math.cos(java.lang.Math.abs(rand.nextInt()))); - frndWidth = fFaceWidth + ((fFaceWidth / 4.0f) * (float)java.lang.Math.cos(java.lang.Math.abs(rand.nextInt()))); + frndHeight = + fFaceHeight + + ((fFaceHeight / 1.5f) + * (float) java.lang.Math.cos( + java.lang.Math.abs(rand.nextInt()))); + frndWidth = + fFaceWidth + + ((fFaceWidth / 4.0f) + * (float) java.lang.Math.cos( + java.lang.Math.abs(rand.nextInt()))); fDecWidth = frndWidth / 5.0f; fRotate = myrand() * 3.1415f; fRigid = ((fRigid = myrand()) < 0.2f) ? 0.2f : fRigid; @@ -234,13 +254,19 @@ public class Grass { else gl.begin(GL.QUAD_STRIP); - for (cFaces = 0; cFaces < numFaces; cFaces++) - { - for (cWidth = frndWidth; cWidth >=-frndWidth; cWidth-=(frndWidth * 2.0f)) - { - gl.color4f(fX, fRigid, fZ, (float)cFaces/(float)numFaces); - gl.vertex3f((float)(((cFaces-2)*0.1f)*java.lang.Math.cos(fRotate)+(cWidth)*java.lang.Math.sin(fRotate)), cFaces*frndHeight, - -(float)(((cFaces-2)*0.1f)*java.lang.Math.sin(fRotate) + (cWidth)*java.lang.Math.cos(fRotate))); + for (cFaces = 0; cFaces < numFaces; cFaces++) { + for (cWidth = frndWidth; + cWidth >= -frndWidth; + cWidth -= (frndWidth * 2.0f)) { + gl.color4f(fX, fRigid, fZ, (float) cFaces / (float) numFaces); + gl.vertex3f( + (float) (((cFaces - 2) * 0.1f) + * java.lang.Math.cos(fRotate) + + (cWidth) * java.lang.Math.sin(fRotate)), + cFaces * frndHeight, + - (float) + (((cFaces - 2) * 0.1f) * java.lang.Math.sin(fRotate) + + (cWidth) * java.lang.Math.cos(fRotate))); } frndWidth -= fDecWidth; } @@ -252,12 +278,10 @@ public class Grass { float cI, cJ, fArea; fArea = 20.0f; - mesh = gl.genLists(1); + mesh = gl.genLists(1); gl.newList(mesh, GL.COMPILE); - for (cI = -fArea/2; cI < fArea/2; cI+=0.25f) - { - for (cJ = -fArea/2; cJ < fArea/2; cJ+=0.25f) - { + for (cI = -fArea / 2; cI < fArea / 2; cI += 0.25f) { + for (cJ = -fArea / 2; cJ < fArea / 2; cJ += 0.25f) { genGrass(0.5f, 0.1f, cI, cJ); } } @@ -265,66 +289,184 @@ public class Grass { } - private static void grsDraw() - { + private static void grsDraw() { gl.enable(GL.VERTEX_PROGRAM_NV); gl.bindProgramNV(GL.VERTEX_PROGRAM_NV, program_handle); - gl.trackMatrixNV(GL.VERTEX_PROGRAM_NV, 0, GL.MODELVIEW_PROJECTION_NV, GL.IDENTITY_NV); + gl.trackMatrixNV( + GL.VERTEX_PROGRAM_NV, + 0, + GL.MODELVIEW_PROJECTION_NV, + GL.IDENTITY_NV); - gl.programParameter4fNV( GL.VERTEX_PROGRAM_NV, 4, 0.0f, 0.0f, 0.0f, 0.0f); - gl.programParameter4fNV( GL.VERTEX_PROGRAM_NV, 5, 0.0f, 0.0f, 0.0f, 0.0f); - gl.programParameter4fNV( GL.VERTEX_PROGRAM_NV, 6, 1.763609f, 0.496495f, 0.0f, 0.0f); - gl.programParameter4fNV( GL.VERTEX_PROGRAM_NV, 7, -0.943599f, 3.203737f, 0.0f, 0.0f); - gl.programParameter4fNV( GL.VERTEX_PROGRAM_NV, 8, 4.101107f, 0.943413f, 0.0f, 0.0f); - gl.programParameter4fNV( GL.VERTEX_PROGRAM_NV, 9, -1.218603f, 6.259399f, 0.0f, 0.0f); - gl.programParameter4fNV( GL.VERTEX_PROGRAM_NV, 10, 7.214299f, 1.352961f, 0.0f, 0.0f); - gl.programParameter4fNV( GL.VERTEX_PROGRAM_NV, 11, -1.540748f, 10.080958f, 0.0f, 0.0f); - gl.programParameter4fNV( GL.VERTEX_PROGRAM_NV, 12, 10.880035f, 1.759046f, 0.0f, 0.0f); - gl.programParameter4fNV( GL.VERTEX_PROGRAM_NV, 13, -1.852705f, 14.468674f, 0.0f, 0.0f); - gl.programParameter4fNV( GL.VERTEX_PROGRAM_NV, 14, 14.292879f, 1.973329f, 0.0f, 0.0f); - gl.programParameter4fNV( GL.VERTEX_PROGRAM_NV, 15, -1.973387f, 18.506531f, 0.0f, 0.0f); - gl.programParameter4fNV( GL.VERTEX_PROGRAM_NV, 16, (float)(java.lang.Math.sin(aslod.angle) * (aslod.value + aslod.ripple)), 0.0f, (float)(java.lang.Math.cos(aslod.angle) * (aslod.value + aslod.ripple)), 0.0f); + gl.programParameter4fNV( + GL.VERTEX_PROGRAM_NV, + 4, + 0.0f, + 0.0f, + 0.0f, + 0.0f); + gl.programParameter4fNV( + GL.VERTEX_PROGRAM_NV, + 5, + 0.0f, + 0.0f, + 0.0f, + 0.0f); + gl.programParameter4fNV( + GL.VERTEX_PROGRAM_NV, + 6, + 1.763609f, + 0.496495f, + 0.0f, + 0.0f); + gl.programParameter4fNV( + GL.VERTEX_PROGRAM_NV, + 7, + -0.943599f, + 3.203737f, + 0.0f, + 0.0f); + gl.programParameter4fNV( + GL.VERTEX_PROGRAM_NV, + 8, + 4.101107f, + 0.943413f, + 0.0f, + 0.0f); + gl.programParameter4fNV( + GL.VERTEX_PROGRAM_NV, + 9, + -1.218603f, + 6.259399f, + 0.0f, + 0.0f); + gl.programParameter4fNV( + GL.VERTEX_PROGRAM_NV, + 10, + 7.214299f, + 1.352961f, + 0.0f, + 0.0f); + gl.programParameter4fNV( + GL.VERTEX_PROGRAM_NV, + 11, + -1.540748f, + 10.080958f, + 0.0f, + 0.0f); + gl.programParameter4fNV( + GL.VERTEX_PROGRAM_NV, + 12, + 10.880035f, + 1.759046f, + 0.0f, + 0.0f); + gl.programParameter4fNV( + GL.VERTEX_PROGRAM_NV, + 13, + -1.852705f, + 14.468674f, + 0.0f, + 0.0f); + gl.programParameter4fNV( + GL.VERTEX_PROGRAM_NV, + 14, + 14.292879f, + 1.973329f, + 0.0f, + 0.0f); + gl.programParameter4fNV( + GL.VERTEX_PROGRAM_NV, + 15, + -1.973387f, + 18.506531f, + 0.0f, + 0.0f); + gl.programParameter4fNV( + GL.VERTEX_PROGRAM_NV, + 16, + (float) (java.lang.Math.sin(aslod.angle) + * (aslod.value + aslod.ripple)), + 0.0f, + (float) (java.lang.Math.cos(aslod.angle) + * (aslod.value + aslod.ripple)), + 0.0f); - gl.programParameter4fNV( GL.VERTEX_PROGRAM_NV, 17, 1.7f, 5f, 2f, 0f); - gl.programParameter4fNV( GL.VERTEX_PROGRAM_NV, 18, -0.0187293f, 0.074261f, 0.2121144f, 1.570729f); - gl.programParameter4fNV( GL.VERTEX_PROGRAM_NV, 20, 0f, 0.5f, 1f, 0f); - gl.programParameter4fNV( GL.VERTEX_PROGRAM_NV, 21, 0.25f, -9f, 0.75f, 0.1591549f); - gl.programParameter4fNV( GL.VERTEX_PROGRAM_NV, 22, 24.9808f, -24.9808f, -60.14581f, 60.14581f); - gl.programParameter4fNV( GL.VERTEX_PROGRAM_NV, 23, 85.45379f, -85.45379f, -64.93935f, 64.93935f); - gl.programParameter4fNV( GL.VERTEX_PROGRAM_NV, 24, 19.73921f, -19.73921f, -1f, 1f); - gl.programParameter4fNV( GL.VERTEX_PROGRAM_NV, 25, 0f, 4f, 0f, 0f); - gl.programParameter4fNV( GL.VERTEX_PROGRAM_NV, 19, 1f, 3.141593f, 0.5f, 1f); - gl.programParameter4fNV( GL.VERTEX_PROGRAM_NV, 26, 0.7f, 0.4f, 0f, 0f); + gl.programParameter4fNV(GL.VERTEX_PROGRAM_NV, 17, 1.7f, 5f, 2f, 0f); + gl.programParameter4fNV( + GL.VERTEX_PROGRAM_NV, + 18, + -0.0187293f, + 0.074261f, + 0.2121144f, + 1.570729f); + gl.programParameter4fNV(GL.VERTEX_PROGRAM_NV, 20, 0f, 0.5f, 1f, 0f); + gl.programParameter4fNV( + GL.VERTEX_PROGRAM_NV, + 21, + 0.25f, + -9f, + 0.75f, + 0.1591549f); + gl.programParameter4fNV( + GL.VERTEX_PROGRAM_NV, + 22, + 24.9808f, + -24.9808f, + -60.14581f, + 60.14581f); + gl.programParameter4fNV( + GL.VERTEX_PROGRAM_NV, + 23, + 85.45379f, + -85.45379f, + -64.93935f, + 64.93935f); + gl.programParameter4fNV( + GL.VERTEX_PROGRAM_NV, + 24, + 19.73921f, + -19.73921f, + -1f, + 1f); + gl.programParameter4fNV(GL.VERTEX_PROGRAM_NV, 25, 0f, 4f, 0f, 0f); + gl.programParameter4fNV( + GL.VERTEX_PROGRAM_NV, + 19, + 1f, + 3.141593f, + 0.5f, + 1f); + gl.programParameter4fNV(GL.VERTEX_PROGRAM_NV, 26, 0.7f, 0.4f, 0f, 0f); gl.callList(mesh); gl.disable(GL.VERTEX_PROGRAM_NV); } -/* private static void ptrDraw() - { - glRotatef((aslod.angle * 180.0f) / 3.1415f, 0, 1, 0); - glTranslatef(0, 4.5, -7.5); - glRotatef(-90, 0, 1, 0); - glRotatef(-45, 0, 0, 1); - - glMaterialfv(GL.FRONT, GL.AMBIENT, vec4f(.1f,.1f,0,1).v); - glMaterialfv(GL.FRONT, GL.DIFFUSE, vec4f(.6f,.6f,.1f,1).v); - glMaterialfv(GL.FRONT, GL.SPECULAR, vec4f(1,1,.75f,1).v); - glMaterialf(GL.FRONT, GL.SHININESS, 128.f); - - glutSolidTeapot(aslod.value*5); - - gl.rotatef(45, 0, 0, 1); - gl.totatef(90, 0, 1, 0); - gl.translatef(0, -4.5, 7.5); - gl.rotatef(-(aslod.angle * 180.0f) / 3.1415f, 0f, 1f, 0f); - - } -*/ - private static void ptrAnimate(float degree) - { + /* private static void ptrDraw() + { + glRotatef((aslod.angle * 180.0f) / 3.1415f, 0, 1, 0); + glTranslatef(0, 4.5, -7.5); + glRotatef(-90, 0, 1, 0); + glRotatef(-45, 0, 0, 1); + + glMaterialfv(GL.FRONT, GL.AMBIENT, vec4f(.1f,.1f,0,1).v); + glMaterialfv(GL.FRONT, GL.DIFFUSE, vec4f(.6f,.6f,.1f,1).v); + glMaterialfv(GL.FRONT, GL.SPECULAR, vec4f(1,1,.75f,1).v); + glMaterialf(GL.FRONT, GL.SHININESS, 128.f); + + glutSolidTeapot(aslod.value*5); + + gl.rotatef(45, 0, 0, 1); + gl.totatef(90, 0, 1, 0); + gl.translatef(0, -4.5, 7.5); + gl.rotatef(-(aslod.angle * 180.0f) / 3.1415f, 0f, 1f, 0f); + + } + */ + private static void ptrAnimate(float degree) { aslod.count += degree; - aslod.ripple = (float)(java.lang.Math.cos(aslod.count) / 80.0); + aslod.ripple = (float) (java.lang.Math.cos(aslod.count) / 80.0); } @@ -334,21 +476,20 @@ public class Grass { Keyboard.next(); if (!Keyboard.state) continue; - switch(Keyboard.key) - { - case Keyboard.KEY_A: + switch (Keyboard.key) { + case Keyboard.KEY_A : aslod.angle += 0.1; break; - case Keyboard.KEY_D: + case Keyboard.KEY_D : aslod.angle -= 0.1; break; - case Keyboard.KEY_W: + case Keyboard.KEY_W : aslod.value += (aslod.value >= 0.15) ? 0.0 : 0.0025; break; - case Keyboard.KEY_S: + case Keyboard.KEY_S : aslod.value -= (aslod.value <= 0.005) ? 0.0 : 0.0025; break; - case Keyboard.KEY_ESCAPE: + case Keyboard.KEY_ESCAPE : finished = true; break; } @@ -356,4 +497,3 @@ public class Grass { } } - diff --git a/src/native/common/org_lwjgl_Display.h b/src/native/common/org_lwjgl_Display.h index 3ecfe512..8adec589 100644 --- a/src/native/common/org_lwjgl_Display.h +++ b/src/native/common/org_lwjgl_Display.h @@ -26,7 +26,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_getAvailableDisplayModes * Signature: (IIIIZ)Z */ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate - (JNIEnv *, jclass, jint, jint, jint, jint, jint, jint, jint, jboolean); + (JNIEnv *, jclass, jint, jint, jint, jint, jint, jint, jint, jboolean, jstring); /* * Class: org_lwjgl_Display diff --git a/src/native/win32/org_lwjgl_Display.cpp b/src/native/win32/org_lwjgl_Display.cpp index ca5618c3..a3ace8c2 100644 --- a/src/native/win32/org_lwjgl_Display.cpp +++ b/src/native/win32/org_lwjgl_Display.cpp @@ -112,6 +112,7 @@ LRESULT CALLBACK WindowProc(HWND hWnd, WPARAM wParam, LPARAM lParam) { + switch (msg) { // disable screen saver and monitor power down messages which wreak havoc case WM_SYSCOMMAND: @@ -119,14 +120,12 @@ LRESULT CALLBACK WindowProc(HWND hWnd, switch (wParam) { case SC_SCREENSAVE: case SC_MONITORPOWER: - return 0; + return 0L; break; default: break; } } - case WM_PAINT: - return 0; } // default action @@ -235,7 +234,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_getAvailableDisplayModes */ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate (JNIEnv * env, jclass clazz, jint width, jint height, jint bpp, jint freq, - jint alphaBits, jint depthBits, jint stencilBits, jboolean fullscreen) + jint alphaBits, jint depthBits, jint stencilBits, jboolean fullscreen, jstring title) { #ifdef _DEBUG printf("Creating display: size %dx%d %dhz %dbpp...\n", width, height, freq, bpp); @@ -269,29 +268,37 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate oneShotInitialised = true; } - int windowflags; + int exstyle, windowflags; if (fullscreen) { - windowflags = WS_POPUP; + exstyle = WS_EX_TOPMOST; + windowflags = WS_POPUP | WS_VISIBLE; } else { - windowflags = WS_POPUP | WS_CAPTION; + exstyle = 0; + windowflags = WS_OVERLAPPED | WS_BORDER | WS_CAPTION | WS_VISIBLE; } + const char* titleString = env->GetStringUTFChars(title, NULL); + // Create the window now, using that class: - hwnd = CreateWindow( - WINDOWCLASSNAME, - "LWJGL", - windowflags, - 0, 0, - width, height, - NULL, - NULL, - dll_handle, - NULL); + hwnd = CreateWindowEx ( + exstyle, + WINDOWCLASSNAME, + titleString, + windowflags, + 0, 0, width, height, + NULL, + NULL, + dll_handle, + NULL); + env->ReleaseStringUTFChars(title, titleString); + // And we never look at windowClass again... ShowWindow(hwnd, SW_SHOW); UpdateWindow(hwnd); + SetForegroundWindow(hwnd); + SetFocus(hwnd); hdc = GetWindowDC(hwnd);