Simplification work
This commit is contained in:
parent
fca57cefd5
commit
3df3d2d401
|
@ -32,6 +32,7 @@
|
||||||
|
|
||||||
package org.lwjgl;
|
package org.lwjgl;
|
||||||
|
|
||||||
|
import java.nio.*;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.nio.FloatBuffer;
|
import java.nio.FloatBuffer;
|
||||||
|
@ -88,4 +89,20 @@ public final class BufferUtils {
|
||||||
return createByteBuffer(size << 2).asFloatBuffer();
|
return createByteBuffer(size << 2).asFloatBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A helper function which is used to get the byte offset in an arbitrary buffer
|
||||||
|
* based on its position
|
||||||
|
* @return the position of the buffer, in BYTES
|
||||||
|
*/
|
||||||
|
public static int getOffset(Buffer buffer) {
|
||||||
|
if (buffer instanceof FloatBuffer || buffer instanceof IntBuffer)
|
||||||
|
return buffer.position() << 2;
|
||||||
|
else if (buffer instanceof ShortBuffer || buffer instanceof CharBuffer)
|
||||||
|
return buffer.position() << 1;
|
||||||
|
else if (buffer instanceof DoubleBuffer || buffer instanceof LongBuffer)
|
||||||
|
return buffer.position() << 3;
|
||||||
|
else
|
||||||
|
return buffer.position();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -476,8 +476,6 @@ public class Keyboard {
|
||||||
*/
|
*/
|
||||||
public static int getNumKeyboardEvents() {
|
public static int getNumKeyboardEvents() {
|
||||||
assert created : "The keyboard has not been created.";
|
assert created : "The keyboard has not been created.";
|
||||||
assert readBuffer != null : "Keyboard buffering has not been enabled.";
|
|
||||||
|
|
||||||
return numEvents;
|
return numEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,8 @@ import java.nio.FloatBuffer;
|
||||||
import java.nio.IntBuffer;
|
import java.nio.IntBuffer;
|
||||||
import java.nio.ShortBuffer;
|
import java.nio.ShortBuffer;
|
||||||
|
|
||||||
|
import org.lwjgl.BufferUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $Id$
|
* $Id$
|
||||||
*
|
*
|
||||||
|
@ -321,12 +323,12 @@ public final class ARBImaging {
|
||||||
private static native void nglGetConvolutionParameteriv(int target, int pname, IntBuffer params, int params_offset);
|
private static native void nglGetConvolutionParameteriv(int target, int pname, IntBuffer params, int params_offset);
|
||||||
public static void glSeparableFilter2D(int target, int internalformat, int width, int height, int format, int type, Buffer row, Buffer column) {
|
public static void glSeparableFilter2D(int target, int internalformat, int width, int height, int format, int type, Buffer row, Buffer column) {
|
||||||
// TODO: check buffer size valid
|
// TODO: check buffer size valid
|
||||||
nglSeparableFilter2D(target, internalformat, width, height, format, type, row, Util.getOffset(row), column, Util.getOffset(column));
|
nglSeparableFilter2D(target, internalformat, width, height, format, type, row, BufferUtils.getOffset(row), column, BufferUtils.getOffset(column));
|
||||||
}
|
}
|
||||||
private static native void nglSeparableFilter2D(int target, int internalformat, int width, int height, int format, int type, Buffer row, int row_offset, Buffer column, int column_offset);
|
private static native void nglSeparableFilter2D(int target, int internalformat, int width, int height, int format, int type, Buffer row, int row_offset, Buffer column, int column_offset);
|
||||||
public static void glGetSeparableFilter(int target, int format, int type, Buffer row, Buffer column, Buffer span) {
|
public static void glGetSeparableFilter(int target, int format, int type, Buffer row, Buffer column, Buffer span) {
|
||||||
// TODO: check buffer size valid
|
// TODO: check buffer size valid
|
||||||
nglGetSeparableFilter(target, format, type, row, Util.getOffset(row), column, Util.getOffset(column), span, Util.getOffset(span));
|
nglGetSeparableFilter(target, format, type, row, BufferUtils.getOffset(row), column, BufferUtils.getOffset(column), span, BufferUtils.getOffset(span));
|
||||||
}
|
}
|
||||||
private static native void nglGetSeparableFilter(int target, int format, int type, Buffer row, int row_offset, Buffer column, int column_offset, Buffer span, int span_offset);
|
private static native void nglGetSeparableFilter(int target, int format, int type, Buffer row, int row_offset, Buffer column, int column_offset, Buffer span, int span_offset);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,8 @@ package org.lwjgl.opengl;
|
||||||
|
|
||||||
import java.nio.*;
|
import java.nio.*;
|
||||||
|
|
||||||
|
import org.lwjgl.BufferUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple utility class.
|
* Simple utility class.
|
||||||
*
|
*
|
||||||
|
@ -40,34 +42,28 @@ import java.nio.*;
|
||||||
* @version $Revision$
|
* @version $Revision$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
abstract class Util {
|
public final class Util {
|
||||||
|
|
||||||
static final IntBuffer int_buffer = ByteBuffer.allocateDirect(64).order(ByteOrder.nativeOrder()).asIntBuffer();
|
private static final IntBuffer int_buffer = BufferUtils.createIntBuffer(16);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A helper function which is used to get the byte offset in an arbitrary buffer
|
* No c'tor
|
||||||
* based on its position
|
|
||||||
* @return the position of the buffer, in BYTES
|
|
||||||
*/
|
*/
|
||||||
static int getOffset(Buffer buffer) {
|
private Util() {}
|
||||||
if (buffer instanceof FloatBuffer || buffer instanceof IntBuffer)
|
|
||||||
return buffer.position() << 2;
|
|
||||||
else if (buffer instanceof ShortBuffer || buffer instanceof CharBuffer)
|
|
||||||
return buffer.position() << 1;
|
|
||||||
else if (buffer instanceof DoubleBuffer || buffer instanceof LongBuffer)
|
|
||||||
return buffer.position() << 3;
|
|
||||||
else
|
|
||||||
return buffer.position();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void checkGLError() {
|
public static void checkGLError() {
|
||||||
int err = GL11.glGetError();
|
int err = GL11.glGetError();
|
||||||
if (err != GL11.GL_NO_ERROR) {
|
if (err != GL11.GL_NO_ERROR) {
|
||||||
throw new OpenGLException(err);
|
throw new OpenGLException(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getGLInteger(int gl_enum) {
|
/**
|
||||||
|
* Obtain a GL integer value from the driver
|
||||||
|
* @param gl_enum The GL value you want
|
||||||
|
* @return the integer value
|
||||||
|
*/
|
||||||
|
public static int glGetInteger(int gl_enum) {
|
||||||
GL11.glGetInteger(gl_enum, int_buffer);
|
GL11.glGetInteger(gl_enum, int_buffer);
|
||||||
return int_buffer.get(0);
|
return int_buffer.get(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ class VBOTracker {
|
||||||
private final StateStack attrib_stack;
|
private final StateStack attrib_stack;
|
||||||
|
|
||||||
private VBOTracker() {
|
private VBOTracker() {
|
||||||
int stack_size = Util.getGLInteger(GL11.GL_MAX_CLIENT_ATTRIB_STACK_DEPTH);
|
int stack_size = Util.glGetInteger(GL11.GL_MAX_CLIENT_ATTRIB_STACK_DEPTH);
|
||||||
vbo_array_stack = new StateStack(stack_size, 0);
|
vbo_array_stack = new StateStack(stack_size, 0);
|
||||||
vbo_element_stack = new StateStack(stack_size, 0);
|
vbo_element_stack = new StateStack(stack_size, 0);
|
||||||
attrib_stack = new StateStack(stack_size, 0);
|
attrib_stack = new StateStack(stack_size, 0);
|
||||||
|
|
|
@ -242,7 +242,6 @@ public class PositionTest extends BasicTest {
|
||||||
// render and paint if !minimized and not dirty
|
// render and paint if !minimized and not dirty
|
||||||
if(Window.isFocused() || Window.isDirty()) {
|
if(Window.isFocused() || Window.isDirty()) {
|
||||||
render();
|
render();
|
||||||
Window.paint();
|
|
||||||
} else {
|
} else {
|
||||||
// sleeeeeep
|
// sleeeeeep
|
||||||
pause(100);
|
pause(100);
|
||||||
|
|
|
@ -29,7 +29,6 @@
|
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $Id$
|
* $Id$
|
||||||
*
|
*
|
||||||
|
@ -38,12 +37,8 @@
|
||||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||||
* @version $Revision$
|
* @version $Revision$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.lwjgl.test.opengl;
|
package org.lwjgl.test.opengl;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.nio.ByteOrder;
|
|
||||||
|
|
||||||
import org.lwjgl.Display;
|
import org.lwjgl.Display;
|
||||||
import org.lwjgl.DisplayMode;
|
import org.lwjgl.DisplayMode;
|
||||||
import org.lwjgl.Sys;
|
import org.lwjgl.Sys;
|
||||||
|
@ -51,8 +46,8 @@ import org.lwjgl.input.Keyboard;
|
||||||
import org.lwjgl.input.Mouse;
|
import org.lwjgl.input.Mouse;
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
import org.lwjgl.opengl.GL13;
|
import org.lwjgl.opengl.GL13;
|
||||||
|
import org.lwjgl.opengl.Util;
|
||||||
import org.lwjgl.opengl.Window;
|
import org.lwjgl.opengl.Window;
|
||||||
import org.lwjgl.opengl.glu.GLU;
|
|
||||||
|
|
||||||
public final class Game {
|
public final class Game {
|
||||||
static {
|
static {
|
||||||
|
@ -61,9 +56,7 @@ public final class Game {
|
||||||
int mode = -1;
|
int mode = -1;
|
||||||
DisplayMode[] modes = Display.getAvailableDisplayModes();
|
DisplayMode[] modes = Display.getAvailableDisplayModes();
|
||||||
for (int i = 0; i < modes.length; i++) {
|
for (int i = 0; i < modes.length; i++) {
|
||||||
if (modes[i].width == 640
|
if (modes[i].width == 640 && modes[i].height == 480 && modes[i].bpp >= 16) {
|
||||||
&& modes[i].height == 480
|
|
||||||
&& modes[i].bpp >= 16) {
|
|
||||||
mode = i;
|
mode = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -78,20 +71,17 @@ public final class Game {
|
||||||
System.err.println("Failed to create display due to " + e);
|
System.err.println("Failed to create display due to " + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
Window.create("LWJGL Game Example", 16, 0, 0,0, 0);
|
Window.create("LWJGL Game Example");
|
||||||
System.out.println("Created OpenGL.");
|
System.out.println("Created OpenGL.");
|
||||||
} catch (Exception e) {
|
} 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);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Is the game finished? */
|
/** Is the game finished? */
|
||||||
private static boolean finished;
|
private static boolean finished;
|
||||||
|
|
||||||
/** A rotating square! */
|
/** A rotating square! */
|
||||||
private static float angle;
|
private static float angle;
|
||||||
|
|
||||||
|
@ -100,22 +90,19 @@ public final class Game {
|
||||||
*/
|
*/
|
||||||
private Game() {
|
private Game() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] arguments) {
|
public static void main(String[] arguments) {
|
||||||
try {
|
try {
|
||||||
init();
|
init();
|
||||||
while (!finished) {
|
while (!finished) {
|
||||||
Window.update();
|
if (Window.isMinimized()) {
|
||||||
|
|
||||||
if (Window.isMinimized())
|
|
||||||
Thread.sleep(200);
|
Thread.sleep(200);
|
||||||
else if (Window.isCloseRequested())
|
} else if (Window.isCloseRequested()) {
|
||||||
System.exit(0);
|
finished = true;
|
||||||
|
} else {
|
||||||
Keyboard.poll();
|
|
||||||
mainLoop();
|
mainLoop();
|
||||||
render();
|
render();
|
||||||
Window.paint();
|
}
|
||||||
|
Window.update();
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
|
@ -123,34 +110,23 @@ public final class Game {
|
||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All calculations are done in here
|
* All calculations are done in here
|
||||||
*/
|
*/
|
||||||
private static void mainLoop() {
|
private static void mainLoop() {
|
||||||
angle += 1f;
|
angle += 1f;
|
||||||
if (angle > 360.0f)
|
if (angle > 360.0f) angle = 0.0f;
|
||||||
angle = 0.0f;
|
|
||||||
|
|
||||||
Mouse.poll();
|
|
||||||
if (Mouse.getDX() != 0 || Mouse.getDY() != 0 || Mouse.getDWheel() != 0)
|
if (Mouse.getDX() != 0 || Mouse.getDY() != 0 || Mouse.getDWheel() != 0)
|
||||||
System.out.println("Mouse moved " + Mouse.getDX() + " " + Mouse.getDY() + " " + Mouse.getDWheel());
|
System.out.println("Mouse moved " + Mouse.getDX() + " " + Mouse.getDY() + " " + Mouse.getDWheel());
|
||||||
for (int i = 0; i < Mouse.getButtonCount(); i++)
|
for (int i = 0; i < Mouse.getButtonCount(); i++)
|
||||||
if (Mouse.isButtonDown(i))
|
if (Mouse.isButtonDown(i)) System.out.println("Button " + i + " down");
|
||||||
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++) {
|
for (int i = 0; i < Keyboard.getNumKeyboardEvents(); i++) {
|
||||||
Keyboard.next();
|
Keyboard.next();
|
||||||
if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE && Keyboard.getEventKeyState())
|
if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE && Keyboard.getEventKeyState()) finished = true;
|
||||||
finished = true;
|
|
||||||
if (Keyboard.getEventKey() == Keyboard.KEY_T && Keyboard.getEventKeyState())
|
if (Keyboard.getEventKey() == Keyboard.KEY_T && Keyboard.getEventKeyState())
|
||||||
System.out.println("Current time: " + Sys.getTime());
|
System.out.println("Current time: " + Sys.getTime());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All rendering is done in here
|
* All rendering is done in here
|
||||||
*/
|
*/
|
||||||
|
@ -167,43 +143,21 @@ public final class Game {
|
||||||
GL11.glEnd();
|
GL11.glEnd();
|
||||||
GL11.glPopMatrix();
|
GL11.glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize
|
* Initialize
|
||||||
*/
|
*/
|
||||||
private static void init() throws Exception {
|
private static void init()
|
||||||
Keyboard.create();
|
throws Exception {
|
||||||
Keyboard.enableBuffer();
|
|
||||||
Mouse.create();
|
|
||||||
Sys.setTime(0);
|
Sys.setTime(0);
|
||||||
Sys.setProcessPriority(Sys.HIGH_PRIORITY);
|
Sys.setProcessPriority(Sys.HIGH_PRIORITY);
|
||||||
System.out.println("Timer resolution: " + Sys.getTimerResolution());
|
System.out.println("Timer resolution: " + Sys.getTimerResolution());
|
||||||
// Go into orthographic projection mode.
|
System.out.println("Number of texture units: " + Util.glGetInteger(GL13.GL_MAX_TEXTURE_UNITS));
|
||||||
GL11.glMatrixMode(GL11.GL_PROJECTION);
|
|
||||||
GL11.glLoadIdentity();
|
|
||||||
GLU.gluOrtho2D(0, Display.getWidth(), 0, Display.getHeight());
|
|
||||||
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
|
||||||
GL11.glLoadIdentity();
|
|
||||||
GL11.glViewport(0, 0, Display.getWidth(), Display.getHeight());
|
|
||||||
ByteBuffer num_tex_units_buf = ByteBuffer.allocateDirect(64);
|
|
||||||
num_tex_units_buf.order(ByteOrder.nativeOrder());
|
|
||||||
GL11.glGetInteger(GL13.GL_MAX_TEXTURE_UNITS, num_tex_units_buf.asIntBuffer());
|
|
||||||
System.out.println("Number of texture units: " + num_tex_units_buf.getInt());
|
|
||||||
// Fix the refresh rate to the display frequency.
|
|
||||||
// GL11.wglSwapIntervalEXT(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cleanup
|
* Cleanup
|
||||||
*/
|
*/
|
||||||
private static void cleanup() {
|
private static void cleanup() {
|
||||||
Keyboard.destroy();
|
|
||||||
Mouse.destroy();
|
|
||||||
Window.destroy();
|
Window.destroy();
|
||||||
try {
|
|
||||||
Display.resetDisplayMode();
|
Display.resetDisplayMode();
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,7 @@ import java.nio.FloatBuffer;
|
||||||
import java.nio.IntBuffer;
|
import java.nio.IntBuffer;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import org.lwjgl.BufferUtils;
|
||||||
import org.lwjgl.Display;
|
import org.lwjgl.Display;
|
||||||
import org.lwjgl.DisplayMode;
|
import org.lwjgl.DisplayMode;
|
||||||
import org.lwjgl.input.Keyboard;
|
import org.lwjgl.input.Keyboard;
|
||||||
|
@ -137,21 +138,18 @@ public class Grass {
|
||||||
}
|
}
|
||||||
|
|
||||||
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: " + GLContext.GL_NV_vertex_program);
|
System.out.println("Vertex program supported: " + GLContext.GL_NV_vertex_program);
|
||||||
NVVertexProgram.glGenProgramsNV(byte_buf.asIntBuffer());
|
IntBuffer int_buf = BufferUtils.createIntBuffer(1);
|
||||||
IntBuffer int_buf = byte_buf.asIntBuffer();
|
NVVertexProgram.glGenProgramsNV(int_buf);
|
||||||
if (int_buf.get(0) == 0)
|
if (int_buf.get(0) == 0)
|
||||||
throw new RuntimeException("Could not allocate new vertex program id!");
|
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");
|
byte[] program = loadFile("cg_grass2.vp");
|
||||||
ByteBuffer program_buf = ByteBuffer.allocateDirect(program.length);
|
ByteBuffer program_buf = BufferUtils.createByteBuffer(program.length);
|
||||||
program_buf.order(ByteOrder.nativeOrder());
|
program_buf.order(ByteOrder.nativeOrder());
|
||||||
program_buf.rewind();
|
|
||||||
program_buf.put(program);
|
program_buf.put(program);
|
||||||
program_buf.rewind();
|
program_buf.flip();
|
||||||
NVVertexProgram.glLoadProgramNV(
|
NVVertexProgram.glLoadProgramNV(
|
||||||
NVVertexProgram.GL_VERTEX_PROGRAM_NV,
|
NVVertexProgram.GL_VERTEX_PROGRAM_NV,
|
||||||
program_handle,
|
program_handle,
|
||||||
|
@ -163,18 +161,17 @@ public class Grass {
|
||||||
|
|
||||||
float[] LightDiffuse = { 1.0f, 0.0f, 0.0f, 1.0f };
|
float[] LightDiffuse = { 1.0f, 0.0f, 0.0f, 1.0f };
|
||||||
float[] LightPosition = { 1.0f, 1.0f, 1.0f, 0.0f };
|
float[] LightPosition = { 1.0f, 1.0f, 1.0f, 0.0f };
|
||||||
ByteBuffer light_buf = ByteBuffer.allocateDirect(4 * 4);
|
FloatBuffer light_buf_f = BufferUtils.createFloatBuffer(4);
|
||||||
light_buf.order(ByteOrder.nativeOrder());
|
|
||||||
FloatBuffer light_buf_f = light_buf.asFloatBuffer();
|
|
||||||
light_buf_f.rewind();
|
|
||||||
light_buf_f.put(LightDiffuse);
|
light_buf_f.put(LightDiffuse);
|
||||||
|
light_buf_f.flip();
|
||||||
|
|
||||||
GL11.glLightfv(
|
GL11.glLightfv(
|
||||||
GL11.GL_LIGHT0,
|
GL11.GL_LIGHT0,
|
||||||
GL11.GL_DIFFUSE,
|
GL11.GL_DIFFUSE,
|
||||||
light_buf_f);
|
light_buf_f);
|
||||||
light_buf_f.rewind();
|
light_buf_f.clear();
|
||||||
light_buf_f.put(LightPosition);
|
light_buf_f.put(LightPosition);
|
||||||
|
light_buf_f.flip();
|
||||||
GL11.glLightfv(
|
GL11.glLightfv(
|
||||||
GL11.GL_LIGHT0,
|
GL11.GL_LIGHT0,
|
||||||
GL11.GL_POSITION,
|
GL11.GL_POSITION,
|
||||||
|
@ -196,7 +193,9 @@ public class Grass {
|
||||||
aslod.count = 0.0f;
|
aslod.count = 0.0f;
|
||||||
|
|
||||||
while (!finished) {
|
while (!finished) {
|
||||||
Window.update();
|
if (Window.isCloseRequested()) {
|
||||||
|
finished = true;
|
||||||
|
} else if (!Window.isMinimized()) {
|
||||||
keyPoll();
|
keyPoll();
|
||||||
float degree = (1.0f + (aslod.value * 20.0f)) * 0.01745329f;
|
float degree = (1.0f + (aslod.value * 20.0f)) * 0.01745329f;
|
||||||
|
|
||||||
|
@ -208,11 +207,9 @@ public class Grass {
|
||||||
//ptrDraw();
|
//ptrDraw();
|
||||||
|
|
||||||
grsDraw();
|
grsDraw();
|
||||||
|
|
||||||
Window.paint();
|
|
||||||
}
|
}
|
||||||
Mouse.destroy();
|
Window.update();
|
||||||
Keyboard.destroy();
|
}
|
||||||
Window.destroy();
|
Window.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,7 +445,6 @@ public class Grass {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void keyPoll() {
|
private static void keyPoll() {
|
||||||
Keyboard.read();
|
|
||||||
for (int i = 0; i < Keyboard.getNumKeyboardEvents(); i++) {
|
for (int i = 0; i < Keyboard.getNumKeyboardEvents(); i++) {
|
||||||
Keyboard.next();
|
Keyboard.next();
|
||||||
if (!Keyboard.getEventKeyState())
|
if (!Keyboard.getEventKeyState())
|
||||||
|
|
|
@ -122,35 +122,27 @@ public class PbufferTest {
|
||||||
* Runs the main loop of the "test"
|
* Runs the main loop of the "test"
|
||||||
*/
|
*/
|
||||||
private void mainLoop() {
|
private void mainLoop() {
|
||||||
while (!Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)
|
while (!Keyboard.isKeyDown(Keyboard.KEY_ESCAPE) && !Window.isCloseRequested()) {
|
||||||
&& !Window.isCloseRequested()) {
|
|
||||||
// allow subsystem to get a chance to run too
|
|
||||||
Window.update();
|
|
||||||
|
|
||||||
if (!Window.isMinimized()) {
|
if (!Window.isMinimized()) {
|
||||||
// check keyboard input
|
// check keyboard input
|
||||||
processKeyboard();
|
processKeyboard();
|
||||||
|
|
||||||
// do "game" logic, and render it
|
// do "game" logic, and render it
|
||||||
logic();
|
logic();
|
||||||
render();
|
render();
|
||||||
|
|
||||||
// paint window
|
|
||||||
Window.paint();
|
|
||||||
} else {
|
} else {
|
||||||
|
// no need to render/paint if nothing has changed (ie. window
|
||||||
// no need to render/paint if nothing has changed (ie. window dragged over)
|
// dragged over)
|
||||||
if (Window.isDirty()) {
|
if (Window.isDirty()) {
|
||||||
render();
|
render();
|
||||||
Window.paint();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't waste cpu time, sleep more
|
// don't waste cpu time, sleep more
|
||||||
try {
|
try {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
} catch (InterruptedException inte) {
|
} catch (InterruptedException inte) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Update window
|
||||||
|
Window.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue