New extensions and static import modifications

This commit is contained in:
Ioannis Tsakpinis 2004-03-29 16:55:27 +00:00
parent 17cef91b6a
commit 0e70f051bd
21 changed files with 781 additions and 566 deletions

View file

@ -0,0 +1,174 @@
/*
* Copyright (c) 2002 Lightweight Java Game Library Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* 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.
*
* * Neither the name of 'Light Weight Java Game Library' nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* 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
* 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
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* $Id$
*
* ARB_vertex_buffer_object constants.
*
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$
*/
package org.lwjgl.opengl;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.ShortBuffer;
public final class ARBBufferObject {
/*
* Accepted by the <usage> parameter of BufferDataARB:
*/
public static final int GL_STREAM_DRAW_ARB = 0x88E0;
public static final int GL_STREAM_READ_ARB = 0x88E1;
public static final int GL_STREAM_COPY_ARB = 0x88E2;
public static final int GL_STATIC_DRAW_ARB = 0x88E4;
public static final int GL_STATIC_READ_ARB = 0x88E5;
public static final int GL_STATIC_COPY_ARB = 0x88E6;
public static final int GL_DYNAMIC_DRAW_ARB = 0x88E8;
public static final int GL_DYNAMIC_READ_ARB = 0x88E9;
public static final int GL_DYNAMIC_COPY_ARB = 0x88EA;
/*
* Accepted by the <access> parameter of MapBufferARB:
*/
public static final int GL_READ_ONLY_ARB = 0x88B8;
public static final int GL_WRITE_ONLY_ARB = 0x88B9;
public static final int GL_READ_WRITE_ARB = 0x88BA;
/*
* Accepted by the <pname> parameter of GetBufferParameterivARB:
*/
public static final int GL_BUFFER_SIZE_ARB = 0x8764;
public static final int GL_BUFFER_USAGE_ARB = 0x8765;
public static final int GL_BUFFER_ACCESS_ARB = 0x88BB;
public static final int GL_BUFFER_MAPPED_ARB = 0x88BC;
public static final int GL_BUFFER_MAP_POINTER_ARB = 0x88BD;
public static void glBindBufferARB(int target, int buffer) {
switch (target) {
case ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB:
VBOTracker.getVBOElementStack().setState(buffer);
break;
case ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB:
VBOTracker.getVBOArrayStack().setState(buffer);
break;
default: throw new IllegalArgumentException("Unsupported VBO target " + target);
}
nglBindBufferARB(target, buffer);
}
private static native void nglBindBufferARB(int target, int buffer);
public static void glDeleteBuffersARB(IntBuffer buffers) {
for (int i = buffers.position(); i < buffers.limit(); i++) {
int buffer_handle = buffers.get(i);
if (VBOTracker.getVBOElementStack().getState() == buffer_handle)
VBOTracker.getVBOElementStack().setState(0);
if (VBOTracker.getVBOArrayStack().getState() == buffer_handle)
VBOTracker.getVBOArrayStack().setState(0);
}
nglDeleteBuffersARB(buffers.remaining(), buffers, buffers.position());
}
private static native void nglDeleteBuffersARB(int n, IntBuffer buffers, int buffers_offset);
public static void glGenBuffersARB(IntBuffer buffers) {
nglGenBuffersARB(buffers.remaining(), buffers, buffers.position());
}
private static native void nglGenBuffersARB(int n, IntBuffer buffers, int buffers_offset);
public static native boolean glIsBufferARB(int buffer);
public static void glBufferDataARB(int target, int size, ByteBuffer data, int usage) {
nglBufferDataARB(target, size, data, data != null ? data.position() : 0, usage);
}
public static void glBufferDataARB(int target, int size, ShortBuffer data, int usage) {
nglBufferDataARB(target, size, data, data != null ? data.position()<<1 : 0, usage);
}
public static void glBufferDataARB(int target, int size, FloatBuffer data, int usage) {
nglBufferDataARB(target, size, data, data != null ? data.position()<<2 : 0, usage);
}
public static void glBufferDataARB(int target, int size, IntBuffer data, int usage) {
nglBufferDataARB(target, size, data, data != null ? data.position()<<2 : 0, usage);
}
private static native void nglBufferDataARB(int target, int size, Buffer data, int data_offset, int usage);
public static void glBufferSubDataARB(int target, int offset, ByteBuffer data) {
nglBufferSubDataARB(target, offset, data.remaining(), data, data.position());
}
public static void glBufferSubDataARB(int target, int offset, ShortBuffer data) {
nglBufferSubDataARB(target, offset, data.remaining()<<1, data, data.position()<<1);
}
public static void glBufferSubDataARB(int target, int offset, FloatBuffer data) {
nglBufferSubDataARB(target, offset, data.remaining()<<2, data, data.position()<<2);
}
public static void glBufferSubDataARB(int target, int offset, IntBuffer data) {
nglBufferSubDataARB(target, offset, data.remaining()<<2, data, data.position()<<2);
}
private static native void nglBufferSubDataARB(int target, int offset, int size, Buffer data, int data_offset);
public static void glGetBufferSubDataARB(int target, int offset, ByteBuffer data) {
nglGetBufferSubDataARB(target, offset, data.remaining(), data, data.position());
}
public static void glGetBufferSubDataARB(int target, int offset, ShortBuffer data) {
nglGetBufferSubDataARB(target, offset, data.remaining()<<1, data, data.position()<<1);
}
public static void glGetBufferSubDataARB(int target, int offset, IntBuffer data) {
nglGetBufferSubDataARB(target, offset, data.remaining()<<2, data, data.position()<<2);
}
public static void glGetBufferSubDataARB(int target, int offset, FloatBuffer data) {
nglGetBufferSubDataARB(target, offset, data.remaining()<<2, data, data.position()<<2);
}
private static native void nglGetBufferSubDataARB(int target, int offset, int size, Buffer data, int data_offset);
/**
* glMapBufferARB maps a gl vertex buffer buffer to a ByteBuffer. The oldBuffer argument can be null, in
* which case a new ByteBuffer will be created, pointing to the returned memory. If oldBuffer is non-null,
* it will be returned if it points to the same mapped memory, otherwise a new ByteBuffer is created.
* That way, an application will normally use glMapBufferARB like this:
*
* ByteBuffer mapped_buffer;
* mapped_buffer = glMapBufferARB(..., ..., ..., null);
* ...
* // Another map on the same buffer
* mapped_buffer = glMapBufferARB(..., ..., ..., mapped_buffer);
*
* @param size The size of the buffer area.
* @param oldBuffer A ByteBuffer. If this argument points to the same address as the new mapping, it will be returned and
* no new buffer will be created. In that case, size is ignored.
* @return A ByteBuffer representing the mapped buffer memory.
*/
public static native ByteBuffer glMapBufferARB(int target, int access, int size, ByteBuffer oldBuffer);
public static native boolean glUnmapBufferARB(int target);
public static void glGetBufferParameterARB(int target, int pname, IntBuffer params) {
BufferChecks.checkBuffer(params);
nglGetBufferParameterivARB(target, pname, params, params.position());
}
private static native void nglGetBufferParameterivARB(int target, int pname, IntBuffer params, int params_offset);
public static native ByteBuffer glGetBufferPointerARB(int target, int pname, int size);
}

View file

@ -1,7 +1,7 @@
/*
* Copyright (c) 2002 Lightweight Java Game Library Project All rights
* reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice,
@ -12,7 +12,7 @@
* * Neither the name of 'Light Weight Java Game Library' nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
*
* 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 PURPOSE
@ -32,7 +32,7 @@
package org.lwjgl.opengl;
public final class ARBFragmentProgram extends ARBProgram {
public final class ARBFragmentProgram {
/*
* Accepted by the <cap> parameter of Disable, Enable, and IsEnabled, by the

View file

@ -45,7 +45,7 @@ import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
class ARBProgram {
public final class ARBProgram {
/*
* Accepted by the <format> parameter of ProgramStringARB:

View file

@ -1,31 +1,31 @@
/*
/*
* Copyright (c) 2002 Lightweight Java Game Library Project
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
*
* * Redistributions of source code must retain the above copyright
* 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.
*
* * Neither the name of 'Light Weight Java Game Library' nor the names of
* its contributors may be used to endorse or promote products derived
* * Neither the name of 'Light Weight Java Game Library' nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
*
* 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
* 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
* 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
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
@ -41,16 +41,21 @@
package org.lwjgl.opengl;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.ShortBuffer;
public final class ARBVertexBufferObject {
/*
* Accepted by the <target> parameters of BindBufferARB, BufferDataARB,
* BufferSubDataARB, MapBufferARB, UnmapBufferARB,
* GetBufferSubDataARB, GetBufferParameterivARB, and
* GetBufferPointervARB:
*/
public static final int GL_ARRAY_BUFFER_ARB = 0x8892;
public static final int GL_ELEMENT_ARRAY_BUFFER_ARB = 0x8893;
/*
* Accepted by the <pname> parameter of GetBooleanv, GetIntegerv,
* GetFloatv, and GetDoublev:
*/
public static final int GL_ARRAY_BUFFER_BINDING_ARB = 0x8894;
public static final int GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB = 0x8895;
public static final int GL_VERTEX_ARRAY_BUFFER_BINDING_ARB = 0x8896;
@ -62,116 +67,10 @@ public final class ARBVertexBufferObject {
public static final int GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB = 0x889C;
public static final int GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB = 0x889D;
public static final int GL_WEIGHT_ARRAY_BUFFER_BINDING_ARB = 0x889E;
/*
* Accepted by the <pname> parameter of GetVertexAttribivARB:
*/
public static final int GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB = 0x889F;
public static final int GL_STREAM_DRAW_ARB = 0x88E0;
public static final int GL_STREAM_READ_ARB = 0x88E1;
public static final int GL_STREAM_COPY_ARB = 0x88E2;
public static final int GL_STATIC_DRAW_ARB = 0x88E4;
public static final int GL_STATIC_READ_ARB = 0x88E5;
public static final int GL_STATIC_COPY_ARB = 0x88E6;
public static final int GL_DYNAMIC_DRAW_ARB = 0x88E8;
public static final int GL_DYNAMIC_READ_ARB = 0x88E9;
public static final int GL_DYNAMIC_COPY_ARB = 0x88EA;
public static final int GL_READ_ONLY_ARB = 0x88B8;
public static final int GL_WRITE_ONLY_ARB = 0x88B9;
public static final int GL_READ_WRITE_ARB = 0x88BA;
public static final int GL_BUFFER_SIZE_ARB = 0x8764;
public static final int GL_BUFFER_USAGE_ARB = 0x8765;
public static final int GL_BUFFER_ACCESS_ARB = 0x88BB;
public static final int GL_BUFFER_MAPPED_ARB = 0x88BC;
public static final int GL_BUFFER_MAP_POINTER_ARB = 0x88BD;
public static void glBindBufferARB(int target, int buffer) {
switch (target) {
case GL_ELEMENT_ARRAY_BUFFER_ARB:
VBOTracker.getVBOElementStack().setState(buffer);
break;
case GL_ARRAY_BUFFER_ARB:
VBOTracker.getVBOArrayStack().setState(buffer);
break;
default: throw new IllegalArgumentException("Unsupported VBO target " + target);
}
nglBindBufferARB(target, buffer);
}
private static native void nglBindBufferARB(int target, int buffer);
public static void glDeleteBuffersARB(IntBuffer buffers) {
for (int i = buffers.position(); i < buffers.limit(); i++) {
int buffer_handle = buffers.get(i);
if (VBOTracker.getVBOElementStack().getState() == buffer_handle)
VBOTracker.getVBOElementStack().setState(0);
if (VBOTracker.getVBOArrayStack().getState() == buffer_handle)
VBOTracker.getVBOArrayStack().setState(0);
}
nglDeleteBuffersARB(buffers.remaining(), buffers, buffers.position());
}
private static native void nglDeleteBuffersARB(int n, IntBuffer buffers, int buffers_offset);
public static void glGenBuffersARB(IntBuffer buffers) {
nglGenBuffersARB(buffers.remaining(), buffers, buffers.position());
}
private static native void nglGenBuffersARB(int n, IntBuffer buffers, int buffers_offset);
public static native boolean glIsBufferARB(int buffer);
public static void glBufferDataARB(int target, int size, ByteBuffer data, int usage) {
nglBufferDataARB(target, size, data, data != null ? data.position() : 0, usage);
}
public static void glBufferDataARB(int target, int size, ShortBuffer data, int usage) {
nglBufferDataARB(target, size, data, data != null ? data.position()<<1 : 0, usage);
}
public static void glBufferDataARB(int target, int size, FloatBuffer data, int usage) {
nglBufferDataARB(target, size, data, data != null ? data.position()<<2 : 0, usage);
}
public static void glBufferDataARB(int target, int size, IntBuffer data, int usage) {
nglBufferDataARB(target, size, data, data != null ? data.position()<<2 : 0, usage);
}
private static native void nglBufferDataARB(int target, int size, Buffer data, int data_offset, int usage);
public static void glBufferSubDataARB(int target, int offset, ByteBuffer data) {
nglBufferSubDataARB(target, offset, data.remaining(), data, data.position());
}
public static void glBufferSubDataARB(int target, int offset, ShortBuffer data) {
nglBufferSubDataARB(target, offset, data.remaining()<<1, data, data.position()<<1);
}
public static void glBufferSubDataARB(int target, int offset, FloatBuffer data) {
nglBufferSubDataARB(target, offset, data.remaining()<<2, data, data.position()<<2);
}
public static void glBufferSubDataARB(int target, int offset, IntBuffer data) {
nglBufferSubDataARB(target, offset, data.remaining()<<2, data, data.position()<<2);
}
private static native void nglBufferSubDataARB(int target, int offset, int size, Buffer data, int data_offset);
public static void glGetBufferSubDataARB(int target, int offset, ByteBuffer data) {
nglGetBufferSubDataARB(target, offset, data.remaining(), data, data.position());
}
public static void glGetBufferSubDataARB(int target, int offset, ShortBuffer data) {
nglGetBufferSubDataARB(target, offset, data.remaining()<<1, data, data.position()<<1);
}
public static void glGetBufferSubDataARB(int target, int offset, IntBuffer data) {
nglGetBufferSubDataARB(target, offset, data.remaining()<<2, data, data.position()<<2);
}
public static void glGetBufferSubDataARB(int target, int offset, FloatBuffer data) {
nglGetBufferSubDataARB(target, offset, data.remaining()<<2, data, data.position()<<2);
}
private static native void nglGetBufferSubDataARB(int target, int offset, int size, Buffer data, int data_offset);
/**
* glMapBufferARB maps a gl vertex buffer buffer to a ByteBuffer. The oldBuffer argument can be null, in
* which case a new ByteBuffer will be created, pointing to the returned memory. If oldBuffer is non-null,
* it will be returned if it points to the same mapped memory, otherwise a new ByteBuffer is created.
* That way, an application will normally use glMapBufferARB like this:
*
* ByteBuffer mapped_buffer;
* mapped_buffer = glMapBufferARB(..., ..., ..., null);
* ...
* // Another map on the same buffer
* mapped_buffer = glMapBufferARB(..., ..., ..., mapped_buffer);
*
* @param size The size of the buffer area.
* @param oldBuffer A ByteBuffer. If this argument points to the same address as the new mapping, it will be returned and
* no new buffer will be created. In that case, size is ignored.
* @return A ByteBuffer representing the mapped buffer memory.
*/
public static native ByteBuffer glMapBufferARB(int target, int access, int size, ByteBuffer oldBuffer);
public static native boolean glUnmapBufferARB(int target);
public static void glGetBufferParameterARB(int target, int pname, IntBuffer params) {
BufferChecks.checkBuffer(params);
nglGetBufferParameterivARB(target, pname, params, params.position());
}
private static native void nglGetBufferParameterivARB(int target, int pname, IntBuffer params, int params_offset);
public static native ByteBuffer glGetBufferPointerARB(int target, int pname, int size);
}

View file

@ -44,7 +44,7 @@ import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.ShortBuffer;
public final class ARBVertexProgram extends ARBProgram {
public final class ARBVertexProgram {
/*
* Accepted by the <cap> parameter of Disable, Enable, and IsEnabled, by the
@ -87,7 +87,7 @@ public final class ARBVertexProgram extends ARBProgram {
public static final int GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB = 0x88B1;
public static final int GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB = 0x88B2;
public static final int GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB = 0x88B3;
/*
* Accepted by the <pname> parameter of GetBooleanv, GetIntegerv,
* GetFloatv, and GetDoublev:

View file

@ -0,0 +1,57 @@
/*
* Copyright (c) 2002 Lightweight Java Game Library Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* 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.
*
* * Neither the name of 'Light Weight Java Game Library' nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* 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
* 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
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Created by LWJGL.
* User: spasi
* Date: 28-03-2004
* Time: 10:01:34 pm
*/
package org.lwjgl.opengl;
public final class EXTDepthBoundsTest {
/*
Accepted by the <cap> parameter of Enable, Disable, and IsEnabled,
and by the <pname> parameter of GetBooleanv, GetIntegerv,
GetFloatv, and GetDoublev:
*/
public static final int DEPTH_BOUNDS_TEST_EXT = 0x8890;
/*
Accepted by the <pname> parameter of GetBooleanv, GetIntegerv,
GetFloatv, and GetDoublev:
*/
public static final int DEPTH_BOUNDS_EXT = 0x8891;
public static native void glDepthBoundsEXT(float zmin, float zmax);
}

View file

@ -0,0 +1,46 @@
/*
* Copyright (c) 2002 Lightweight Java Game Library Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* 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.
*
* * Neither the name of 'Light Weight Java Game Library' nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* 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
* 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
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Created by LWJGL.
* User: spasi
* Date: 28 Ìáñ 2004
* Time: 10:12:12 ìì
*/
package org.lwjgl.opengl;
public final class EXTPixelBufferObject {
public static final int GL_PIXEL_PACK_BUFFER_EXT = 0x88EB;
public static final int GL_PIXEL_UNPACK_BUFFER_EXT = 0x88EC;
}

View file

@ -93,11 +93,14 @@ public final class GLContext {
public static boolean GL_EXT_bgra;
public static boolean GL_EXT_blend_func_separate;
public static boolean GL_EXT_blend_subtract;
public static boolean GL_EXT_Cg_shader;
public static boolean GL_EXT_compiled_vertex_array;
public static boolean GL_EXT_depth_bounds_test;
public static boolean GL_EXT_draw_range_elements;
public static boolean GL_EXT_fog_coord;
public static boolean GL_EXT_multi_draw_arrays;
public static boolean GL_EXT_packed_pixels;
public static boolean GL_EXT_pixel_buffer_object;
public static boolean GL_EXT_point_parameters;
public static boolean GL_EXT_rescale_normal;
public static boolean GL_EXT_secondary_color;
@ -136,6 +139,7 @@ public final class GLContext {
public static boolean GL_NV_float_buffer;
public static boolean GL_NV_fog_distance;
public static boolean GL_NV_fragment_program;
public static boolean GL_NV_fragment_program_option;
public static boolean GL_NV_half_float;
public static boolean GL_NV_light_max_exponent;
public static boolean GL_NV_multisample_filter_hint;
@ -159,6 +163,7 @@ public final class GLContext {
public static boolean GL_NV_vertex_program;
public static boolean GL_NV_vertex_program1_1;
public static boolean GL_NV_vertex_program2;
public static boolean GL_NV_vertex_program2_option;
public static boolean OpenGL11;
public static boolean OpenGL12;

View file

@ -42,7 +42,7 @@ package org.lwjgl.opengl;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
public final class NVFragmentProgram extends NVProgram {
public final class NVFragmentProgram {
/*
Accepted by the <cap> parameter of Disable, Enable, and IsEnabled, by the
@ -98,20 +98,5 @@ public final class NVFragmentProgram extends NVProgram {
// ---------------------------
public static native void glProgramLocalParameter4fARB(int target, int index, float x, float y, float z, float w);
// ---------------------------
public static void glGetProgramLocalParameterARB(int target, int index, FloatBuffer params) {
BufferChecks.checkBuffer(params);
nglGetProgramLocalParameterfvARB(target, index, params, params.position());
}
private static native void nglGetProgramLocalParameterfvARB(
int target,
int index,
FloatBuffer params,
int params_offset);
// ---------------------------
}

View file

@ -43,7 +43,7 @@ import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
class NVProgram {
public final class NVProgram {
/*
Accepted by the <pname> parameter of GetProgramivNV:
@ -109,33 +109,27 @@ class NVProgram {
nglGetProgramStringNV(programID, parameterName, paramString, paramString.position());
}
private static native void nglGetProgramStringNV(
int programID,
int parameterName,
Buffer paramString,
int paramStringOffset);
private static native void nglGetProgramStringNV(int programID, int parameterName, Buffer paramString, int paramStringOffset);
// ---------------------------
public static native boolean glIsProgramNV(int programID);
// ---------------------------
public static boolean glAreProgramsResidentNV(IntBuffer programIDs, ByteBuffer programResidences) {
if (programIDs.remaining() != programResidences.remaining())
if ( programIDs.remaining() != programResidences.remaining() )
throw new IllegalArgumentException("programIDs.remaining() != programResidences.remaining()");
return nglAreProgramsResidentNV(
programIDs.remaining(),
programIDs,
programIDs.position(),
programResidences,
programResidences.position());
return nglAreProgramsResidentNV(programIDs.remaining(),
programIDs,
programIDs.position(),
programResidences,
programResidences.position());
}
private static native boolean nglAreProgramsResidentNV(
int n,
IntBuffer programIDs,
int programIDsOffset,
ByteBuffer programResidences,
int programResidencesOffset);
private static native boolean nglAreProgramsResidentNV(int n,
IntBuffer programIDs,
int programIDsOffset,
ByteBuffer programResidences,
int programResidencesOffset);
// ---------------------------
// ---------------------------

View file

@ -46,9 +46,7 @@ import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.ShortBuffer;
public final class NVVertexProgram extends NVProgram {
public final class NVVertexProgram {
/*
Accepted by the <cap> parameter of Disable, Enable, and IsEnabled,

View file

@ -54,10 +54,7 @@ import org.lwjgl.Display;
import org.lwjgl.DisplayMode;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GLContext;
import org.lwjgl.opengl.NVVertexProgram;
import org.lwjgl.opengl.Window;
import org.lwjgl.opengl.*;
import org.lwjgl.opengl.glu.GLU;
public class Grass {
@ -82,7 +79,7 @@ public class Grass {
mode = i;
break;
}
}
}
if (mode == -1) {
System.out.println("did not find suitable mode");
@ -140,7 +137,7 @@ public class Grass {
public static void main(String[] args) {
System.out.println("Vertex program supported: " + GLContext.GL_NV_vertex_program);
IntBuffer int_buf = BufferUtils.createIntBuffer(1);
NVVertexProgram.glGenProgramsNV(int_buf);
NVProgram.glGenProgramsNV(int_buf);
if (int_buf.get(0) == 0)
throw new RuntimeException("Could not allocate new vertex program id!");
@ -150,7 +147,7 @@ public class Grass {
program_buf.order(ByteOrder.nativeOrder());
program_buf.put(program);
program_buf.flip();
NVVertexProgram.glLoadProgramNV(
NVProgram.glLoadProgramNV(
NVVertexProgram.GL_VERTEX_PROGRAM_NV,
program_handle,
program_buf);
@ -286,7 +283,7 @@ public class Grass {
private static void grsDraw() {
GL11.glEnable(NVVertexProgram.GL_VERTEX_PROGRAM_NV);
NVVertexProgram.glBindProgramNV(NVVertexProgram.GL_VERTEX_PROGRAM_NV, program_handle);
NVProgram.glBindProgramNV(NVVertexProgram.GL_VERTEX_PROGRAM_NV, program_handle);
NVVertexProgram.glTrackMatrixNV(
NVVertexProgram.GL_VERTEX_PROGRAM_NV,
0,

View file

@ -41,39 +41,37 @@
package org.lwjgl.test.opengl;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import org.lwjgl.Display;
import org.lwjgl.DisplayMode;
import org.lwjgl.Sys;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.ARBVertexBufferObject;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GLContext;
import org.lwjgl.opengl.Window;
import org.lwjgl.opengl.*;
import org.lwjgl.opengl.glu.GLU;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
public final class VBOIndexTest {
static {
try {
//find first display mode that allows us 640*480*16
//find first display mode that allows us 640*480*16
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) {
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) {
if ( mode != -1 ) {
//select above found displaymode
System.out.println("Setting display mode to "+modes[mode]);
System.out.println("Setting display mode to " + modes[mode]);
Display.setDisplayMode(modes[mode]);
System.out.println("Created display.");
}
@ -81,22 +79,26 @@ public final class VBOIndexTest {
System.err.println("Failed to create display due to " + e);
}
}
static {
try {
Window.create("LWJGL Game Example", 16, 0, 0,0, 0);
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;
static {
try {
Window.create("LWJGL Game Example", 16, 0, 0, 0, 0);
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;
private static int buffer_id;
private static int indices_buffer_id;
private static FloatBuffer vertices;
@ -105,134 +107,146 @@ public final class VBOIndexTest {
private static IntBuffer indices;
private static ByteBuffer mapped_indices_buffer = null;
private static IntBuffer mapped_indices_int_buffer = null;
public static void main(String[] arguments) {
try {
init();
while (!finished) {
Window.update();
if (Window.isMinimized())
Thread.sleep(200);
else if (Window.isCloseRequested())
System.exit(0);
mainLoop();
render();
}
} 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 (Mouse.getDX() != 0 || Mouse.getDY() != 0 || Mouse.getDWheel() != 0)
System.out.println("Mouse moved " + Mouse.getDX() + " " + Mouse.getDY() + " " + Mouse.getDWheel());
for (int i = 0; i < Mouse.getButtonCount(); i++)
if (Mouse.isButtonDown(i))
System.out.println("Button " + i + " down");
if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))
finished = true;
for (int i = 0; i < Keyboard.getNumKeyboardEvents(); i++) {
Keyboard.next();
if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE && Keyboard.getEventKeyState())
finished = true;
if (Keyboard.getEventKey() == Keyboard.KEY_T && Keyboard.getEventKeyState())
System.out.println("Current time: " + Sys.getTime());
}
}
/**
* All rendering is done in here
*/
private static void render() {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
GL11.glPushMatrix();
GL11.glTranslatef(Display.getWidth() / 2, Display.getHeight() / 2, 0.0f);
GL11.glRotatef(angle, 0, 0, 1.0f);
public static void main(String[] arguments) {
try {
init();
while ( !finished ) {
Window.update();
ByteBuffer new_mapped_buffer = ARBVertexBufferObject.glMapBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, ARBVertexBufferObject.GL_WRITE_ONLY_ARB, 2*4*4, mapped_buffer);
if (new_mapped_buffer != mapped_buffer)
mapped_float_buffer = new_mapped_buffer.order(ByteOrder.nativeOrder()).asFloatBuffer();
mapped_buffer = new_mapped_buffer;
if ( Window.isMinimized() )
Thread.sleep(200);
else if ( Window.isCloseRequested() )
System.exit(0);
new_mapped_buffer = ARBVertexBufferObject.glMapBufferARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, ARBVertexBufferObject.GL_WRITE_ONLY_ARB, 4*4, mapped_indices_buffer);
if (new_mapped_buffer != mapped_indices_buffer)
mapped_indices_int_buffer = new_mapped_buffer.order(ByteOrder.nativeOrder()).asIntBuffer();
mapped_float_buffer.rewind();
vertices.rewind();
mapped_float_buffer.put(vertices);
mapped_indices_int_buffer.rewind();
indices.rewind();
mapped_indices_int_buffer.put(indices);
if (ARBVertexBufferObject.glUnmapBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB) &&
ARBVertexBufferObject.glUnmapBufferARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB)) {
GL11.glDrawElements(GL11.GL_QUADS, 4, GL11.GL_UNSIGNED_INT, 0);
}
GL11.glPopMatrix();
}
/**
* Initialize
*/
private static void init() throws Exception {
Sys.setTime(0);
Sys.setProcessPriority(Sys.HIGH_PRIORITY);
System.out.println("Timer resolution: " + Sys.getTimerResolution());
// Go into orthographic projection mode.
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());
if (!GLContext.GL_ARB_vertex_buffer_object) {
System.out.println("ARB VBO not supported!");
System.exit(1);
mainLoop();
render();
}
} catch (Throwable t) {
t.printStackTrace();
} finally {
cleanup();
}
}
IntBuffer int_buffer = ByteBuffer.allocateDirect(8).order(ByteOrder.nativeOrder()).asIntBuffer();
ARBVertexBufferObject.glGenBuffersARB(int_buffer);
buffer_id = int_buffer.get(0);
indices_buffer_id = int_buffer.get(1);
ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, buffer_id);
ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, indices_buffer_id);
vertices = ByteBuffer.allocateDirect(2*4*4).order(ByteOrder.nativeOrder()).asFloatBuffer();
vertices.put(-50).put(-50).put(50).put(-50).put(50).put(50).put(-50).put(50);
vertices.rewind();
indices = ByteBuffer.allocateDirect(4*4).order(ByteOrder.nativeOrder()).asIntBuffer();
indices.put(0).put(1).put(2).put(3);
indices.rewind();
ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, 2*4*4, (ByteBuffer)null, ARBVertexBufferObject.GL_STREAM_DRAW_ARB);
ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, 4*4, (ByteBuffer)null, ARBVertexBufferObject.GL_STREAM_DRAW_ARB);
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
GL11.glVertexPointer(2, GL11.GL_FLOAT, 0, 0);
}
/**
* Cleanup
*/
private static void cleanup() {
IntBuffer int_buffer = ByteBuffer.allocateDirect(8).order(ByteOrder.nativeOrder()).asIntBuffer();
int_buffer.put(0, buffer_id);
int_buffer.put(1, indices_buffer_id);
ARBVertexBufferObject.glDeleteBuffersARB(int_buffer);
Window.destroy();
try {
Display.resetDisplayMode();
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* All calculations are done in here
*/
private static void mainLoop() {
angle += 1f;
if ( angle > 360.0f )
angle = 0.0f;
if ( Mouse.getDX() != 0 || Mouse.getDY() != 0 || Mouse.getDWheel() != 0 )
System.out.println("Mouse moved " + Mouse.getDX() + " " + Mouse.getDY() + " " + Mouse.getDWheel());
for ( int i = 0; i < Mouse.getButtonCount(); i++ )
if ( Mouse.isButtonDown(i) )
System.out.println("Button " + i + " down");
if ( Keyboard.isKeyDown(Keyboard.KEY_ESCAPE) )
finished = true;
for ( int i = 0; i < Keyboard.getNumKeyboardEvents(); i++ ) {
Keyboard.next();
if ( Keyboard.getEventKey() == Keyboard.KEY_ESCAPE && Keyboard.getEventKeyState() )
finished = true;
if ( Keyboard.getEventKey() == Keyboard.KEY_T && Keyboard.getEventKeyState() )
System.out.println("Current time: " + Sys.getTime());
}
}
/**
* All rendering is done in here
*/
private static void render() {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
GL11.glPushMatrix();
GL11.glTranslatef(Display.getWidth() / 2, Display.getHeight() / 2, 0.0f);
GL11.glRotatef(angle, 0, 0, 1.0f);
ByteBuffer new_mapped_buffer = ARBBufferObject.glMapBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB,
ARBBufferObject.GL_WRITE_ONLY_ARB,
2 * 4 * 4,
mapped_buffer);
if ( new_mapped_buffer != mapped_buffer )
mapped_float_buffer = new_mapped_buffer.order(ByteOrder.nativeOrder()).asFloatBuffer();
mapped_buffer = new_mapped_buffer;
new_mapped_buffer = ARBBufferObject.glMapBufferARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB,
ARBBufferObject.GL_WRITE_ONLY_ARB,
4 * 4,
mapped_indices_buffer);
if ( new_mapped_buffer != mapped_indices_buffer )
mapped_indices_int_buffer = new_mapped_buffer.order(ByteOrder.nativeOrder()).asIntBuffer();
mapped_float_buffer.rewind();
vertices.rewind();
mapped_float_buffer.put(vertices);
mapped_indices_int_buffer.rewind();
indices.rewind();
mapped_indices_int_buffer.put(indices);
if ( ARBBufferObject.glUnmapBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB) &&
ARBBufferObject.glUnmapBufferARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB) ) {
GL11.glDrawElements(GL11.GL_QUADS, 4, GL11.GL_UNSIGNED_INT, 0);
}
GL11.glPopMatrix();
}
/**
* Initialize
*/
private static void init() throws Exception {
Sys.setTime(0);
Sys.setProcessPriority(Sys.HIGH_PRIORITY);
System.out.println("Timer resolution: " + Sys.getTimerResolution());
// Go into orthographic projection mode.
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());
if ( !GLContext.GL_ARB_vertex_buffer_object ) {
System.out.println("ARB VBO not supported!");
System.exit(1);
}
IntBuffer int_buffer = ByteBuffer.allocateDirect(8).order(ByteOrder.nativeOrder()).asIntBuffer();
ARBBufferObject.glGenBuffersARB(int_buffer);
buffer_id = int_buffer.get(0);
indices_buffer_id = int_buffer.get(1);
ARBBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, buffer_id);
ARBBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, indices_buffer_id);
vertices = ByteBuffer.allocateDirect(2 * 4 * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
vertices.put(-50).put(-50).put(50).put(-50).put(50).put(50).put(-50).put(50);
vertices.rewind();
indices = ByteBuffer.allocateDirect(4 * 4).order(ByteOrder.nativeOrder()).asIntBuffer();
indices.put(0).put(1).put(2).put(3);
indices.rewind();
ARBBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB,
2 * 4 * 4,
(ByteBuffer)null,
ARBBufferObject.GL_STREAM_DRAW_ARB);
ARBBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB,
4 * 4,
(ByteBuffer)null,
ARBBufferObject.GL_STREAM_DRAW_ARB);
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
GL11.glVertexPointer(2, GL11.GL_FLOAT, 0, 0);
}
/**
* Cleanup
*/
private static void cleanup() {
IntBuffer int_buffer = ByteBuffer.allocateDirect(8).order(ByteOrder.nativeOrder()).asIntBuffer();
int_buffer.put(0, buffer_id);
int_buffer.put(1, indices_buffer_id);
ARBBufferObject.glDeleteBuffersARB(int_buffer);
Window.destroy();
try {
Display.resetDisplayMode();
} catch (Exception e) {
e.printStackTrace();
}
}
}

View file

@ -41,39 +41,37 @@
package org.lwjgl.test.opengl;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import org.lwjgl.Display;
import org.lwjgl.DisplayMode;
import org.lwjgl.Sys;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.ARBVertexBufferObject;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GLContext;
import org.lwjgl.opengl.Window;
import org.lwjgl.opengl.*;
import org.lwjgl.opengl.glu.GLU;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
public final class VBOTest {
static {
try {
//find first display mode that allows us 640*480*16
//find first display mode that allows us 640*480*16
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) {
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) {
if ( mode != -1 ) {
//select above found displaymode
System.out.println("Setting display mode to "+modes[mode]);
System.out.println("Setting display mode to " + modes[mode]);
Display.setDisplayMode(modes[mode]);
System.out.println("Created display.");
}
@ -81,133 +79,143 @@ public final class VBOTest {
System.err.println("Failed to create display due to " + e);
}
}
static {
try {
Window.create("LWJGL Game Example", 16, 0, 0,0, 0);
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;
static {
try {
Window.create("LWJGL Game Example", 16, 0, 0, 0, 0);
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;
private static int buffer_id;
private static FloatBuffer vertices;
private static ByteBuffer mapped_buffer = null;
private static FloatBuffer mapped_float_buffer = null;
public static void main(String[] arguments) {
try {
init();
while (!finished) {
Window.update();
if (Window.isMinimized())
Thread.sleep(200);
else if (Window.isCloseRequested())
System.exit(0);
mainLoop();
render();
}
} 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 (Mouse.getDX() != 0 || Mouse.getDY() != 0 || Mouse.getDWheel() != 0)
System.out.println("Mouse moved " + Mouse.getDX() + " " + Mouse.getDY() + " " + Mouse.getDWheel());
for (int i = 0; i < Mouse.getButtonCount(); i++)
if (Mouse.isButtonDown(i))
System.out.println("Button " + i + " down");
if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))
finished = true;
for (int i = 0; i < Keyboard.getNumKeyboardEvents(); i++) {
Keyboard.next();
if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE && Keyboard.getEventKeyState())
finished = true;
if (Keyboard.getEventKey() == Keyboard.KEY_T && Keyboard.getEventKeyState())
System.out.println("Current time: " + Sys.getTime());
}
}
/**
* All rendering is done in here
*/
private static void render() {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
GL11.glPushMatrix();
GL11.glTranslatef(Display.getWidth() / 2, Display.getHeight() / 2, 0.0f);
GL11.glRotatef(angle, 0, 0, 1.0f);
ByteBuffer new_mapped_buffer = ARBVertexBufferObject.glMapBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, ARBVertexBufferObject.GL_WRITE_ONLY_ARB, 2*4*4, mapped_buffer);
if (new_mapped_buffer != mapped_buffer)
mapped_float_buffer = new_mapped_buffer.order(ByteOrder.nativeOrder()).asFloatBuffer();
mapped_buffer = new_mapped_buffer;
mapped_float_buffer.rewind();
vertices.rewind();
mapped_float_buffer.put(vertices);
if (ARBVertexBufferObject.glUnmapBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB))
GL11.glDrawArrays(GL11.GL_QUADS, 0, 4);
GL11.glPopMatrix();
}
/**
* Initialize
*/
private static void init() throws Exception {
Sys.setTime(0);
Sys.setProcessPriority(Sys.HIGH_PRIORITY);
System.out.println("Timer resolution: " + Sys.getTimerResolution());
// Go into orthographic projection mode.
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());
if (!GLContext.GL_ARB_vertex_buffer_object) {
System.out.println("ARB VBO not supported!");
System.exit(1);
public static void main(String[] arguments) {
try {
init();
while ( !finished ) {
Window.update();
if ( Window.isMinimized() )
Thread.sleep(200);
else if ( Window.isCloseRequested() )
System.exit(0);
mainLoop();
render();
}
} catch (Throwable t) {
t.printStackTrace();
} finally {
cleanup();
}
}
IntBuffer int_buffer = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
ARBVertexBufferObject.glGenBuffersARB(int_buffer);
buffer_id = int_buffer.get(0);
ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, buffer_id);
vertices = ByteBuffer.allocateDirect(2*4*4).order(ByteOrder.nativeOrder()).asFloatBuffer();
vertices.put(-50).put(-50).put(50).put(-50).put(50).put(50).put(-50).put(50);
ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, 2*4*4, (ByteBuffer)null, ARBVertexBufferObject.GL_STREAM_DRAW_ARB);
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
GL11.glVertexPointer(2, GL11.GL_FLOAT, 0, 0);
}
/**
* Cleanup
*/
private static void cleanup() {
IntBuffer int_buffer = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
int_buffer.put(0, buffer_id);
ARBVertexBufferObject.glDeleteBuffersARB(int_buffer);
Window.destroy();
try {
Display.resetDisplayMode();
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* All calculations are done in here
*/
private static void mainLoop() {
angle += 1f;
if ( angle > 360.0f )
angle = 0.0f;
if ( Mouse.getDX() != 0 || Mouse.getDY() != 0 || Mouse.getDWheel() != 0 )
System.out.println("Mouse moved " + Mouse.getDX() + " " + Mouse.getDY() + " " + Mouse.getDWheel());
for ( int i = 0; i < Mouse.getButtonCount(); i++ )
if ( Mouse.isButtonDown(i) )
System.out.println("Button " + i + " down");
if ( Keyboard.isKeyDown(Keyboard.KEY_ESCAPE) )
finished = true;
for ( int i = 0; i < Keyboard.getNumKeyboardEvents(); i++ ) {
Keyboard.next();
if ( Keyboard.getEventKey() == Keyboard.KEY_ESCAPE && Keyboard.getEventKeyState() )
finished = true;
if ( Keyboard.getEventKey() == Keyboard.KEY_T && Keyboard.getEventKeyState() )
System.out.println("Current time: " + Sys.getTime());
}
}
/**
* All rendering is done in here
*/
private static void render() {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
GL11.glPushMatrix();
GL11.glTranslatef(Display.getWidth() / 2, Display.getHeight() / 2, 0.0f);
GL11.glRotatef(angle, 0, 0, 1.0f);
ByteBuffer new_mapped_buffer = ARBBufferObject.glMapBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB,
ARBBufferObject.GL_WRITE_ONLY_ARB,
2 * 4 * 4,
mapped_buffer);
if ( new_mapped_buffer != mapped_buffer )
mapped_float_buffer = new_mapped_buffer.order(ByteOrder.nativeOrder()).asFloatBuffer();
mapped_buffer = new_mapped_buffer;
mapped_float_buffer.rewind();
vertices.rewind();
mapped_float_buffer.put(vertices);
if ( ARBBufferObject.glUnmapBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB) )
GL11.glDrawArrays(GL11.GL_QUADS, 0, 4);
GL11.glPopMatrix();
}
/**
* Initialize
*/
private static void init() throws Exception {
Sys.setTime(0);
Sys.setProcessPriority(Sys.HIGH_PRIORITY);
System.out.println("Timer resolution: " + Sys.getTimerResolution());
// Go into orthographic projection mode.
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());
if ( !GLContext.GL_ARB_vertex_buffer_object ) {
System.out.println("ARB VBO not supported!");
System.exit(1);
}
IntBuffer int_buffer = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
ARBBufferObject.glGenBuffersARB(int_buffer);
buffer_id = int_buffer.get(0);
ARBBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, buffer_id);
vertices = ByteBuffer.allocateDirect(2 * 4 * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
vertices.put(-50).put(-50).put(50).put(-50).put(50).put(50).put(-50).put(50);
ARBBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB,
2 * 4 * 4,
(ByteBuffer)null,
ARBBufferObject.GL_STREAM_DRAW_ARB);
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
GL11.glVertexPointer(2, GL11.GL_FLOAT, 0, 0);
}
/**
* Cleanup
*/
private static void cleanup() {
IntBuffer int_buffer = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
int_buffer.put(0, buffer_id);
ARBBufferObject.glDeleteBuffersARB(int_buffer);
Window.destroy();
try {
Display.resetDisplayMode();
} catch (Exception e) {
e.printStackTrace();
}
}
}