Separated BaseGL from CoreGL and GL and renamed to GLWindow

This commit is contained in:
Elias Naur 2003-07-18 19:02:49 +00:00
parent 794c802253
commit d8f64cbb15
21 changed files with 518 additions and 575 deletions

View File

@ -1,178 +0,0 @@
/*
* 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.
*/
package org.lwjgl.opengl;
import org.lwjgl.*;
import org.lwjgl.Window;
/**
* $Id$
*
* The base GL functionality (no actual GL methods).
*
* Each instance of GL is only valid in the thread that creates it.
* In addition, only one instance may be the current GL context in any one
* thread. To make a GL instance the current context, use makeCurrent().
*
* This has been provided as a base class that we can use for either the
* full GL1.4 specification or as a cut-down OpenGL embedded spec. (aka
* a mini-driver).
*
* @author cix_foo <cix_foo@users.sourceforge.net>
* @version $Revision$
*/
public class BaseGL extends Window {
static {
System.loadLibrary(Sys.getLibraryName());
}
/** The current rendering context */
//private static BaseGL currentContext;
/** Has the GL been created yet? */
private boolean created;
/** Handle to the native GL rendering context */
protected int handle;
/** Color bits */
protected final int color;
/** Alpha bits */
protected final int alpha;
/** Depth bits */
protected final int depth;
/** Stencil bits */
protected final int stencil;
private int x, y;
/** Fullscreen */
protected final boolean fullscreen;
/**
* Construct a windowed instance of GL. If the underlying OS does not
* support windowed mode, then the width and height must match the current
* display resolution, or an Exception will be thrown. Otherwise a fullscreen
* window will be created.
*
* @param title The title of the window
* @param x The position of the window on the x axis. May be ignored.
* @param y The position of the window on the y axis. May be ignored.
* @param width The width of the window's client area
* @param height The height of the window's client area
* @param bpp Require colour bits
* @param alpha Required alpha bits
* @param depth Required depth bits
* @param stencil Required stencil bits
*/
public BaseGL(String title, int x, int y, int width, int height, int bpp, int alpha, int depth, int stencil) {
super(title, x, y, width, height);
this.x = x;
this.y = y;
this.color = bpp;
this.alpha = alpha;
this.depth = depth;
this.stencil = stencil;
this.fullscreen = false;
}
/**
* Construct a fullscreen instance of GL. If the underlying OS does not
* support fullscreen mode, then a window will be created instead. If this
* fails too then an Exception will be thrown.
*
* @param title The title of the window
* @param bpp Minimum bits per pixel
* @param alpha Minimum bits per pixel in alpha buffer
* @param depth Minimum bits per pixel in depth buffer
* @param stencil Minimum bits per pixel in stencil buffer
*/
public BaseGL(String title, int bpp, int alpha, int depth, int stencil) {
super(title, 0, 0, Display.getWidth(), Display.getHeight());
this.x = 0;
this.y = 0;
this.color = bpp;
this.alpha = alpha;
this.depth = depth;
this.stencil = stencil;
this.fullscreen = true;
}
protected void doCreate() throws Exception {
nCreate(getTitle(), x, y, getWidth(), getHeight(), color, alpha, depth, stencil, fullscreen);
}
protected void doPaint() {
swapBuffers();
}
/**
* Swap the buffers.
*/
private native void swapBuffers();
/**
* Native method to create a windowed GL
*/
private native void nCreate(
String title,
int x,
int y,
int width,
int height,
int bpp,
int alpha,
int depth,
int stencil,
boolean fullscreen) throws Exception;
/* (non-Javadoc)
* @see org.lwjgl.Window#doDestroy()
*/
protected void doDestroy() {
nDestroyGL();
}
/**
* Natively destroy any GL-related stuff
*/
private native void nDestroyGL();
}

View File

@ -47,33 +47,7 @@ import java.nio.Buffer;
* @author cix_foo <cix_foo@users.sourceforge.net>
* @version $Revision$
*/
public class CoreGL extends BaseGL implements CoreGLConstants {
/**
* @param title
* @param x
* @param y
* @param width
* @param height
* @param bpp
* @param alpha
* @param depth
* @param stencil
*/
public CoreGL(String title, int x, int y, int width, int height, int bpp, int alpha, int depth, int stencil) {
super(title, x, y, width, height, bpp, alpha, depth, stencil);
}
/**
* @param title
* @param bpp
* @param alpha
* @param depth
* @param stencil
*/
public CoreGL(String title, int bpp, int alpha, int depth, int stencil) {
super(title, bpp, alpha, depth, stencil);
}
public class CoreGL implements CoreGLConstants {
public static native void glAccum(int op, float value);
public static native void glAlphaFunc(int func, float ref);
public static native void glColorTable(

View File

@ -32,11 +32,6 @@
package org.lwjgl.opengl;
import java.lang.reflect.*;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.StringTokenizer;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.nio.CharBuffer;
@ -53,42 +48,6 @@ import java.nio.Buffer;
* @version $Revision$
*/
public class GL extends CoreGL implements GLConstants {
/**
* @param title
* @param x
* @param y
* @param width
* @param height
* @param bpp
* @param alpha
* @param depth
* @param stencil
*/
public GL(String title, int x, int y, int width, int height, int bpp, int alpha, int depth, int stencil) {
super(title, x, y, width, height, bpp, alpha, depth, stencil);
}
/**
* @param title
* @param bpp
* @param alpha
* @param depth
* @param stencil
*/
public GL(String title, int bpp, int alpha, int depth, int stencil) {
super(title, bpp, alpha, depth, stencil);
}
/* (non-Javadoc)
* @see org.lwjgl.opengl.BaseGL#doCreate()
*/
protected void doCreate() throws Exception {
super.doCreate();
determineAvailableExtensions();
}
public static native void glActiveStencilFaceEXT(int face);
public static native void glActiveTextureARB(int texture);
@ -1516,231 +1475,4 @@ public class GL extends CoreGL implements GLConstants {
public static native boolean glUnmapBufferARB(int target);
public static native void glGetBufferParameterivARB(int target, int pname, IntBuffer params);
public static native ByteBuffer glGetBufferPointervARB(int target, int pname, int size);
/*
* Available extensions
*/
public boolean ARB_imaging;
public boolean ARB_depth_texture;
public boolean ARB_matrix_palette;
public boolean ARB_multisample;
public boolean ARB_multitexture;
public boolean ARB_point_parameters;
public boolean ARB_shadow;
public boolean ARB_shadow_ambient;
public boolean ARB_texture_compression;
public boolean ARB_texture_env_add;
public boolean ARB_texture_env_dot3;
public boolean ARB_texture_env_combine;
public boolean ARB_texture_env_crossbar;
public boolean ARB_texture_border_clamp;
public boolean ARB_texture_cube_map;
public boolean ARB_texture_mirrored_repeat;
public boolean ARB_transpose_matrix;
public boolean ARB_vertex_blend;
public boolean ARB_vertex_program;
public boolean ARB_vertex_buffer_object;
public boolean ARB_window_pos;
public boolean EXT_abgr;
public boolean EXT_bgra;
public boolean EXT_blend_color;
public boolean EXT_blend_function_separate;
public boolean EXT_blend_minmax;
public boolean EXT_blend_subtract;
public boolean EXT_compiled_vertex_array;
public boolean EXT_cull_vertex;
public boolean EXT_draw_range_elements;
public boolean EXT_fog_coord;
public boolean EXT_light_max_exponent;
public boolean EXT_multi_draw_arrays;
public boolean EXT_packed_pixels;
public boolean EXT_paletted_texture;
public boolean EXT_point_parameters;
public boolean EXT_rescale_normal;
public boolean EXT_secondary_color;
public boolean EXT_separate_specular_color;
public boolean EXT_shadow_funcs;
public boolean EXT_shared_texture_palette;
public boolean EXT_stencil_two_side;
public boolean EXT_stencil_wrap;
public boolean EXT_texture_compression_s3tc;
public boolean EXT_texture_env_combine;
public boolean EXT_texture_env_dot3;
public boolean EXT_texture_filter_anisotropic;
public boolean EXT_texture_lod_bias;
public boolean EXT_vertex_array;
public boolean EXT_vertex_shader;
public boolean EXT_vertex_weighting;
public boolean ATI_element_array;
public boolean ATI_envmap_bumpmap;
public boolean ATI_fragment_shader;
public boolean ATI_pn_triangles;
public boolean ATI_texture_mirror_once;
public boolean ATI_vertex_array_object;
public boolean ATI_vertex_streams;
public boolean ATIX_point_sprites;
public boolean ATIX_texture_env_route;
public boolean HP_occlusion_test;
public boolean NV_blend_square;
public boolean NV_copy_depth_to_color;
public boolean NV_depth_clamp;
public boolean NV_evaluators;
public boolean NV_fence;
public boolean NV_fog_distance;
public boolean NV_light_max_exponent;
public boolean NV_occlusion_query;
public boolean NV_packed_depth_stencil;
public boolean NV_point_sprite;
public boolean NV_register_combiners;
public boolean NV_register_combiners2;
public boolean NV_texgen_reflection;
public boolean NV_texture_env_combine4;
public boolean NV_texture_rectangle;
public boolean NV_texture_shader;
public boolean NV_texture_shader2;
public boolean NV_texture_shader3;
public boolean NV_vertex_array_range;
public boolean NV_vertex_array_range2;
public boolean NV_vertex_program;
public boolean NV_vertex_program1_1;
public boolean SGIS_generate_mipmap;
public boolean SGIX_shadow;
public boolean SGIX_depth_texture;
public boolean OpenGL10;
public boolean OpenGL11;
public boolean OpenGL12;
public boolean OpenGL13;
public boolean OpenGL14;
/**
* Determine which extensions are available
*/
public void determineAvailableExtensions() {
determineAvailableWGLExtensions();
// Grab all the public booleans out of this class
Field[] fields = GL.class.getDeclaredFields();
HashMap map = new HashMap(fields.length);
for (int i = 0; i < fields.length; i++) {
if (!Modifier.isStatic(fields[i].getModifiers())
&& fields[i].getType() == boolean.class)
map.put(fields[i].getName(), fields[i]);
}
String exts = glGetString(GL_EXTENSIONS);
StringTokenizer st = new StringTokenizer(exts);
while (st.hasMoreTokens()) {
String ext = st.nextToken();
Field f = (Field) map.get(ext);
if (f != null) {
//System.out.println("Extension : "+ext+" : present");
try {
f.setBoolean(this, true);
} catch (IllegalAccessException e) {
e.printStackTrace(System.err);
}
// } else {
// System.out.println("Extension : "+ext+" : NOT AVAILABLE");
}
}
// Let's see what openGL version we are too:
String version = glGetString(GL_VERSION);
int i = version.indexOf("1.");
if (i > -1) {
char c = version.charAt(i + 2);
// Each case intentionally falls through!
switch (c) {
case '4':
OpenGL14 = true;
case '3':
OpenGL13 = true;
case '2':
OpenGL12 = true;
case '1':
OpenGL11 = true;
case '0':
OpenGL10 = true;
break ;
default:
// Unexpected character - ignore
}
}
}
/*
* Available WGL extensions
*/
public static boolean WGL_ARB_buffer_region;
public static boolean WGL_ARB_extensions_string;
public static boolean WGL_ARB_pbuffer;
public static boolean WGL_ARB_pixel_format;
public static boolean WGL_ARB_render_texture;
public static boolean WGL_EXT_extensions_string;
public static boolean WGL_EXT_swap_control;
/**
* Checks and sets WGL_EXT_extensions_string and WGL_ARB_extensions_string
* if available.
*/
private static native void checkWGLExtensionsString();
/**
* Determine which WGL extensions are available
*/
private void determineAvailableWGLExtensions() {
// First we must determine if WGL_EXT_extensions_string is available
checkWGLExtensionsString();
if (!WGL_EXT_extensions_string && !WGL_ARB_extensions_string)
return;
// Grab all the public booleans out of this class
Field[] fields = GL.class.getDeclaredFields();
HashMap map = new HashMap(fields.length);
for (int i = 0; i < fields.length; i++) {
if (Modifier.isStatic(fields[i].getModifiers())
&& fields[i].getType() == boolean.class)
map.put(fields[i].getName(), fields[i]);
}
final String exts;
if (WGL_ARB_extensions_string)
exts = wglGetExtensionsStringARB(getHandle());
// Remember - this is an HWND not an HDC, which is what's required. The native
// code on the other side of wglGetExtensionsStringARB gets the HDC from the HWND
// behind the scenes.
else
exts = wglGetExtensionsStringEXT();
if (exts == null)
return;
if(org.lwjgl.Sys.DEBUG) {
System.out.println("Available WGL extensions:");
}
StringTokenizer st = new StringTokenizer(exts);
while (st.hasMoreTokens()) {
String ext = st.nextToken();
if(org.lwjgl.Sys.DEBUG) {
System.out.println(ext);
}
Field f = (Field) map.get(ext);
if (f != null) {
try {
f.setBoolean(GL.class, true);
} catch (IllegalAccessException e) {
e.printStackTrace(System.err);
}
}
}
}
}

View File

@ -0,0 +1,401 @@
/*
* 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.
*/
package org.lwjgl.opengl;
import org.lwjgl.*;
import org.lwjgl.Window;
import java.lang.reflect.*;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.StringTokenizer;
/**
* $Id$
*
* A visible GL context. Can either be windowed or fullscreen.
*
* Each instance of GLWindow is only valid in the thread that creates it.
* In addition, only one instance may be created at any one time.
*
* @author cix_foo <cix_foo@users.sourceforge.net>
* @version $Revision$
*/
public class GLWindow extends Window {
/** Has the GL been created yet? */
private boolean created;
/** Handle to the native GL rendering context */
protected int handle;
/** Color bits */
protected final int color;
/** Alpha bits */
protected final int alpha;
/** Depth bits */
protected final int depth;
/** Stencil bits */
protected final int stencil;
private int x, y;
/** Fullscreen */
protected final boolean fullscreen;
/*
* Available extensions
*/
public boolean ARB_imaging;
public boolean ARB_depth_texture;
public boolean ARB_matrix_palette;
public boolean ARB_multisample;
public boolean ARB_multitexture;
public boolean ARB_point_parameters;
public boolean ARB_shadow;
public boolean ARB_shadow_ambient;
public boolean ARB_texture_compression;
public boolean ARB_texture_env_add;
public boolean ARB_texture_env_dot3;
public boolean ARB_texture_env_combine;
public boolean ARB_texture_env_crossbar;
public boolean ARB_texture_border_clamp;
public boolean ARB_texture_cube_map;
public boolean ARB_texture_mirrored_repeat;
public boolean ARB_transpose_matrix;
public boolean ARB_vertex_blend;
public boolean ARB_vertex_program;
public boolean ARB_vertex_buffer_object;
public boolean ARB_window_pos;
public boolean EXT_abgr;
public boolean EXT_bgra;
public boolean EXT_blend_color;
public boolean EXT_blend_function_separate;
public boolean EXT_blend_minmax;
public boolean EXT_blend_subtract;
public boolean EXT_compiled_vertex_array;
public boolean EXT_cull_vertex;
public boolean EXT_draw_range_elements;
public boolean EXT_fog_coord;
public boolean EXT_light_max_exponent;
public boolean EXT_multi_draw_arrays;
public boolean EXT_packed_pixels;
public boolean EXT_paletted_texture;
public boolean EXT_point_parameters;
public boolean EXT_rescale_normal;
public boolean EXT_secondary_color;
public boolean EXT_separate_specular_color;
public boolean EXT_shadow_funcs;
public boolean EXT_shared_texture_palette;
public boolean EXT_stencil_two_side;
public boolean EXT_stencil_wrap;
public boolean EXT_texture_compression_s3tc;
public boolean EXT_texture_env_combine;
public boolean EXT_texture_env_dot3;
public boolean EXT_texture_filter_anisotropic;
public boolean EXT_texture_lod_bias;
public boolean EXT_vertex_array;
public boolean EXT_vertex_shader;
public boolean EXT_vertex_weighting;
public boolean ATI_element_array;
public boolean ATI_envmap_bumpmap;
public boolean ATI_fragment_shader;
public boolean ATI_pn_triangles;
public boolean ATI_texture_mirror_once;
public boolean ATI_vertex_array_object;
public boolean ATI_vertex_streams;
public boolean ATIX_point_sprites;
public boolean ATIX_texture_env_route;
public boolean HP_occlusion_test;
public boolean NV_blend_square;
public boolean NV_copy_depth_to_color;
public boolean NV_depth_clamp;
public boolean NV_evaluators;
public boolean NV_fence;
public boolean NV_fog_distance;
public boolean NV_light_max_exponent;
public boolean NV_occlusion_query;
public boolean NV_packed_depth_stencil;
public boolean NV_point_sprite;
public boolean NV_register_combiners;
public boolean NV_register_combiners2;
public boolean NV_texgen_reflection;
public boolean NV_texture_env_combine4;
public boolean NV_texture_rectangle;
public boolean NV_texture_shader;
public boolean NV_texture_shader2;
public boolean NV_texture_shader3;
public boolean NV_vertex_array_range;
public boolean NV_vertex_array_range2;
public boolean NV_vertex_program;
public boolean NV_vertex_program1_1;
public boolean SGIS_generate_mipmap;
public boolean SGIX_shadow;
public boolean SGIX_depth_texture;
public boolean OpenGL10;
public boolean OpenGL11;
public boolean OpenGL12;
public boolean OpenGL13;
public boolean OpenGL14;
/**
* Determine which extensions are available
*/
private void determineAvailableExtensions() {
if (Display.getPlatform() == Display.PLATFORM_WGL)
determineAvailableWGLExtensions();
// Grab all the public booleans out of this class
Field[] fields = GL.class.getDeclaredFields();
HashMap map = new HashMap(fields.length);
for (int i = 0; i < fields.length; i++) {
if (!Modifier.isStatic(fields[i].getModifiers())
&& fields[i].getType() == boolean.class)
map.put(fields[i].getName(), fields[i]);
}
String exts = CoreGL.glGetString(CoreGL.GL_EXTENSIONS);
StringTokenizer st = new StringTokenizer(exts);
while (st.hasMoreTokens()) {
String ext = st.nextToken();
Field f = (Field) map.get(ext);
if (f != null) {
//System.out.println("Extension : "+ext+" : present");
try {
f.setBoolean(this, true);
} catch (IllegalAccessException e) {
e.printStackTrace(System.err);
}
// } else {
// System.out.println("Extension : "+ext+" : NOT AVAILABLE");
}
}
// Let's see what openGL version we are too:
String version = CoreGL.glGetString(CoreGL.GL_VERSION);
int i = version.indexOf("1.");
if (i > -1) {
char c = version.charAt(i + 2);
// Each case intentionally falls through!
switch (c) {
case '4':
OpenGL14 = true;
case '3':
OpenGL13 = true;
case '2':
OpenGL12 = true;
case '1':
OpenGL11 = true;
case '0':
OpenGL10 = true;
break ;
default:
// Unexpected character - ignore
}
}
}
/*
* Available WGL extensions
*/
public static boolean WGL_ARB_buffer_region;
public static boolean WGL_ARB_extensions_string;
public static boolean WGL_ARB_pbuffer;
public static boolean WGL_ARB_pixel_format;
public static boolean WGL_ARB_render_texture;
public static boolean WGL_EXT_extensions_string;
public static boolean WGL_EXT_swap_control;
/**
* Checks and sets WGL_EXT_extensions_string and WGL_ARB_extensions_string
* if available.
*/
private static native void checkWGLExtensionsString();
/**
* Determine which WGL extensions are available
*/
private void determineAvailableWGLExtensions() {
// First we must determine if WGL_EXT_extensions_string is available
checkWGLExtensionsString();
if (!WGL_EXT_extensions_string && !WGL_ARB_extensions_string)
return;
// Grab all the public booleans out of this class
Field[] fields = GL.class.getDeclaredFields();
HashMap map = new HashMap(fields.length);
for (int i = 0; i < fields.length; i++) {
if (Modifier.isStatic(fields[i].getModifiers())
&& fields[i].getType() == boolean.class)
map.put(fields[i].getName(), fields[i]);
}
final String exts;
if (WGL_ARB_extensions_string)
exts = GL.wglGetExtensionsStringARB(getHandle());
// Remember - this is an HWND not an HDC, which is what's required. The native
// code on the other side of wglGetExtensionsStringARB gets the HDC from the HWND
// behind the scenes.
else
exts = GL.wglGetExtensionsStringEXT();
if (exts == null)
return;
if(org.lwjgl.Sys.DEBUG) {
System.out.println("Available WGL extensions:");
}
StringTokenizer st = new StringTokenizer(exts);
while (st.hasMoreTokens()) {
String ext = st.nextToken();
if(org.lwjgl.Sys.DEBUG) {
System.out.println(ext);
}
Field f = (Field) map.get(ext);
if (f != null) {
try {
f.setBoolean(GL.class, true);
} catch (IllegalAccessException e) {
e.printStackTrace(System.err);
}
}
}
}
static {
System.loadLibrary(Sys.getLibraryName());
}
/**
* Construct a windowed context. If the underlying OS does not
* support windowed mode, then the width and height must match the current
* display resolution, or an Exception will be thrown. Otherwise a fullscreen
* window will be created.
*
* @param title The title of the window
* @param x The position of the window on the x axis. May be ignored.
* @param y The position of the window on the y axis. May be ignored.
* @param width The width of the window's client area
* @param height The height of the window's client area
* @param bpp Require colour bits
* @param alpha Required alpha bits
* @param depth Required depth bits
* @param stencil Required stencil bits
*/
public GLWindow(String title, int x, int y, int width, int height, int bpp, int alpha, int depth, int stencil) {
super(title, x, y, width, height);
this.x = x;
this.y = y;
this.color = bpp;
this.alpha = alpha;
this.depth = depth;
this.stencil = stencil;
this.fullscreen = false;
}
/**
* Construct a fullscreen context. If the underlying OS does not
* support fullscreen mode, then a window will be created instead. If this
* fails too then an Exception will be thrown.
*
* @param title The title of the window
* @param bpp Minimum bits per pixel
* @param alpha Minimum bits per pixel in alpha buffer
* @param depth Minimum bits per pixel in depth buffer
* @param stencil Minimum bits per pixel in stencil buffer
*/
public GLWindow(String title, int bpp, int alpha, int depth, int stencil) {
super(title, 0, 0, Display.getWidth(), Display.getHeight());
this.x = 0;
this.y = 0;
this.color = bpp;
this.alpha = alpha;
this.depth = depth;
this.stencil = stencil;
this.fullscreen = true;
}
protected void doCreate() throws Exception {
nCreate(getTitle(), x, y, getWidth(), getHeight(), color, alpha, depth, stencil, fullscreen);
determineAvailableExtensions();
}
protected void doPaint() {
swapBuffers();
}
/**
* Swap the buffers.
*/
private native void swapBuffers();
/**
* Native method to create a windowed GL
*/
private native void nCreate(
String title,
int x,
int y,
int width,
int height,
int bpp,
int alpha,
int depth,
int stencil,
boolean fullscreen) throws Exception;
/* (non-Javadoc)
* @see org.lwjgl.Window#doDestroy()
*/
protected void doDestroy() {
nDestroyGL();
}
/**
* Natively destroy the context
*/
private native void nDestroyGL();
}

View File

@ -8,6 +8,7 @@ package org.lwjgl.test;
import org.lwjgl.*;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GLWindow;
/**
* @author Brian
@ -15,23 +16,18 @@ import org.lwjgl.opengl.GL;
public class WindowCreationTest {
public static void main(String[] args) {
GL gl = null;
GLWindow gl = null;
DisplayMode[] modes = Display.getAvailableDisplayModes();
System.out.println("Found " + modes.length + " display modes");
try {
gl = new GL("WindowCreationTest", 50, 50, 320, 240, 16, 0, 0, 0);
} catch (Exception e) {
e.printStackTrace();
}
try {
gl = new GLWindow("WindowCreationTest", 50, 50, 320, 240, 16, 0, 0, 0);
gl.create();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Display created");
while(!gl.isCloseRequested()) {
@ -45,4 +41,4 @@ public class WindowCreationTest {
gl.destroy();
}
}
}

View File

@ -36,6 +36,7 @@ import org.lwjgl.Display;
import org.lwjgl.DisplayMode;
import org.lwjgl.input.Controller;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GLWindow;
import org.lwjgl.opengl.GLU;
import org.lwjgl.vector.Vector2f;
@ -50,7 +51,7 @@ import org.lwjgl.vector.Vector2f;
public class ControllerCreationTest {
/** OpenGL instance */
private GL gl;
private GLWindow gl;
/** position of quad to draw */
private Vector2f position = new Vector2f(320.0f, 240.0f);
@ -77,9 +78,9 @@ public class ControllerCreationTest {
try {
if(fullscreen) {
Display.setDisplayMode(displayMode);
gl = new GL("MouseCreationTest", 16, 0, 0, 0);
gl = new GLWindow("ControllerCreationTest", 16, 0, 0, 0);
} else {
gl = new GL("MouseCreationTest", 50, 50, 640, 480, 16, 0, 0, 0);
gl = new GLWindow("ControllerCreationTest", 50, 50, 640, 480, 16, 0, 0, 0);
}
gl.create();

View File

@ -35,6 +35,7 @@ import org.lwjgl.DisplayMode;
import org.lwjgl.input.Controller;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GLWindow;
import org.lwjgl.opengl.GLU;
import org.lwjgl.vector.Vector2f;
@ -49,7 +50,7 @@ import org.lwjgl.vector.Vector2f;
public class ControllerTest {
/** OpenGL instance */
private GL gl;
private GLWindow gl;
/** GLU instance */
private GLU glu;
@ -78,7 +79,7 @@ public class ControllerTest {
private void setupDisplay(boolean fullscreen) {
try {
gl = new GL("ControllerTest", 50, 50, 640, 480, 16, 0, 0, 0);
gl = new GLWindow("ControllerTest", 50, 50, 640, 480, 16, 0, 0, 0);
gl.create();
} catch (Exception e) {
e.printStackTrace();

View File

@ -51,7 +51,7 @@ public class HWCursorTest {
private DisplayMode mode;
/** GL instance */
private GL gl;
private GLWindow gl;
/** GLU instance */
private GLU glu;
@ -83,7 +83,7 @@ public class HWCursorTest {
mode = findDisplayMode(800, 600, 16);
// start of in windowed mode
gl = new GL("Test", 50, 50, mode.width, mode.height, mode.bpp, 0, 0, 0);
gl = new GLWindow("Test", 50, 50, mode.width, mode.height, mode.bpp, 0, 0, 0);
gl.create();
glInit();
@ -233,7 +233,7 @@ public class HWCursorTest {
gl.destroy();
Display.setDisplayMode(mode);
gl = new GL("Test", mode.bpp, 0, 0, 0);
gl = new GLWindow("Test", mode.bpp, 0, 0, 0);
gl.create();
glInit();
@ -260,7 +260,7 @@ public class HWCursorTest {
gl.destroy();
Display.resetDisplayMode();
gl = new GL("Test", 50, 50, mode.width, mode.height, mode.bpp, 0, 0, 0);
gl = new GLWindow("Test", 50, 50, mode.width, mode.height, mode.bpp, 0, 0, 0);
gl.create();
glInit();
@ -332,7 +332,6 @@ public class HWCursorTest {
*/
private void glInit() {
// Go into orthographic projection mode.
gl.determineAvailableExtensions();
GL.glMatrixMode(GL.GL_PROJECTION);
GL.glLoadIdentity();
GLU.gluOrtho2D(0, mode.width, 0, mode.height);
@ -344,7 +343,7 @@ public class HWCursorTest {
GL.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
//sync frame (only works on windows)
if (GL.WGL_EXT_swap_control) {
if (gl.WGL_EXT_swap_control) {
GL.wglSwapIntervalEXT(1);
}
}

View File

@ -34,6 +34,7 @@ package org.lwjgl.test.input;
import org.lwjgl.DisplayMode;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GLWindow;
import org.lwjgl.opengl.GLU;
import org.lwjgl.vector.Vector2f;
@ -48,7 +49,7 @@ import org.lwjgl.vector.Vector2f;
public class KeyboardTest {
/** OpenGL instance */
private GL gl;
private GLWindow gl;
/** GLU instance */
private GLU glu;
@ -81,7 +82,7 @@ public class KeyboardTest {
private void setupDisplay(boolean fullscreen) {
try {
gl = new GL("KeyboardTest", 50, 50, 640, 480, 16, 0, 0, 0);
gl = new GLWindow("KeyboardTest", 50, 50, 640, 480, 16, 0, 0, 0);
gl.create();
} catch (Exception e) {

View File

@ -36,6 +36,7 @@ import org.lwjgl.Display;
import org.lwjgl.DisplayMode;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GLWindow;
import org.lwjgl.opengl.GLU;
import org.lwjgl.vector.Vector2f;
@ -50,7 +51,7 @@ import org.lwjgl.vector.Vector2f;
public class MouseCreationTest {
/** OpenGL instance */
private GL gl;
private GLWindow gl;
/** GLU instance */
private GLU glu;
@ -80,9 +81,9 @@ public class MouseCreationTest {
try {
if(fullscreen) {
Display.setDisplayMode(displayMode);
gl = new GL("MouseCreationTest", 16, 0, 0, 0);
gl = new GLWindow("MouseCreationTest", 16, 0, 0, 0);
} else {
gl = new GL("MouseCreationTest", 50, 50, 640, 480, 16, 0, 0, 0);
gl = new GLWindow("MouseCreationTest", 50, 50, 640, 480, 16, 0, 0, 0);
}
gl.create();

View File

@ -35,6 +35,7 @@ import org.lwjgl.DisplayMode;
import org.lwjgl.input.Mouse;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GLWindow;
import org.lwjgl.opengl.GLU;
import org.lwjgl.vector.Vector2f;
@ -49,7 +50,7 @@ import org.lwjgl.vector.Vector2f;
public class MouseTest {
/** OpenGL instance */
private GL gl;
private GLWindow gl;
/** GLU instance */
private GLU glu;
@ -78,7 +79,7 @@ public class MouseTest {
private void setupDisplay(boolean fullscreen) {
try {
gl = new GL("MouseTest", 50, 50, 640, 480, 16, 0, 0, 0);
gl = new GLWindow("MouseTest", 50, 50, 640, 480, 16, 0, 0, 0);
gl.create();
} catch (Exception e) {

View File

@ -35,6 +35,7 @@ import org.lwjgl.openal.AL;
import org.lwjgl.openal.eax.*;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GLWindow;
import java.nio.IntBuffer;
import java.nio.FloatBuffer;
@ -51,7 +52,7 @@ import java.nio.FloatBuffer;
public class MovingSoundTest extends BasicTest {
public static float MOVEMENT = 50.00f;
private GL gl = new GL("Moving Sound Test", 100, 100, 320, 240, 32, 0 ,0 ,0);
private GLWindow gl = new GLWindow("Moving Sound Test", 100, 100, 320, 240, 32, 0 ,0 ,0);
/**
* Creates an instance of MovingSoundTest

View File

@ -50,7 +50,7 @@ public class FullScreenWindowedTest {
private DisplayMode mode;
/** GL instance */
private GL gl;
private GLWindow gl;
/** GLU instance */
private GLU glu;
@ -96,7 +96,7 @@ public class FullScreenWindowedTest {
mode = findDisplayMode(800, 600, 16);
// start of in windowed mode
gl = new GL("Test", 50, 50, mode.width, mode.height, mode.bpp, 0, 0, 0);
gl = new GLWindow("Test", 50, 50, mode.width, mode.height, mode.bpp, 0, 0, 0);
gl.create();
glInit();
@ -205,7 +205,7 @@ public class FullScreenWindowedTest {
gl.destroy();
Display.setDisplayMode(mode);
gl = new GL("Test", mode.bpp, 0, 0, 0);
gl = new GLWindow("Test", mode.bpp, 0, 0, 0);
gl.create();
glInit();
@ -223,7 +223,7 @@ public class FullScreenWindowedTest {
gl.destroy();
Display.resetDisplayMode();
gl = new GL("Test", 50, 50, mode.width, mode.height, mode.bpp, 0, 0, 0);
gl = new GLWindow("Test", 50, 50, mode.width, mode.height, mode.bpp, 0, 0, 0);
gl.create();
glInit();
@ -310,7 +310,6 @@ public class FullScreenWindowedTest {
*/
private void glInit() {
// Go into orthographic projection mode.
gl.determineAvailableExtensions();
GL.glMatrixMode(GL.GL_PROJECTION);
GL.glLoadIdentity();
GLU.gluOrtho2D(0, mode.width, 0, mode.height);
@ -322,7 +321,7 @@ public class FullScreenWindowedTest {
GL.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
//sync frame (only works on windows)
if (GL.WGL_EXT_swap_control) {
if (gl.WGL_EXT_swap_control) {
GL.wglSwapIntervalEXT(1);
}
}
@ -338,4 +337,4 @@ public class FullScreenWindowedTest {
FullScreenWindowedTest fswTest = new FullScreenWindowedTest();
fswTest.execute();
}
}
}

View File

@ -72,7 +72,7 @@ public final class Game {
}
}
public static final GL gl = new GL("LWJGL Game Example", 16, 0, 0,0);
public static final GLWindow gl = new GLWindow("LWJGL Game Example", 16, 0, 0,0);
static {
try {
gl.create();

View File

@ -88,7 +88,7 @@ public class Grass {
}
}
public static final GL gl = new GL("LWJGL Grass", 50, 50, 640, 480, 16, 0, 0,0);
public static final GLWindow gl = new GLWindow("LWJGL Grass", 50, 50, 640, 480, 16, 0, 0,0);
static {
try {

View File

@ -52,7 +52,7 @@ public class PbufferTest {
private DisplayMode mode;
/** GL instance */
private GL gl;
private GLWindow gl;
/** GLU instance */
private GLU glu;
@ -98,8 +98,8 @@ public class PbufferTest {
mode = findDisplayMode(800, 600, 16);
// start of in windowed mode
gl = new GL("Test", 50, 50, mode.width, mode.height, mode.bpp, 0, 0, 0);
// gl = new GL("Test", 50, 50, mode.width, mode.height, mode.bpp, 0, 0, 0);
gl = new GLWindow("Test", 50, 50, mode.width, mode.height, mode.bpp, 0, 0, 0);
// gl = new GLWindow("Test", 50, 50, mode.width, mode.height, mode.bpp, 0, 0, 0);
gl.create();
if ((Pbuffer.getPbufferCaps() & Pbuffer.PBUFFER_SUPPORTED) == 0) {
System.out.println("No Pbuffer support!");
@ -262,7 +262,7 @@ public class PbufferTest {
gl.destroy();
Display.setDisplayMode(mode);
gl = new GL("Test", mode.bpp, 0, 0, 0);
gl = new GLWindow("Test", mode.bpp, 0, 0, 0);
gl.create();
glInit();
initPbuffer();
@ -283,7 +283,7 @@ public class PbufferTest {
gl.destroy();
Display.resetDisplayMode();
gl = new GL("Test", 50, 50, mode.width, mode.height, mode.bpp, 0, 0, 0);
gl = new GLWindow("Test", 50, 50, mode.width, mode.height, mode.bpp, 0, 0, 0);
gl.create();
glInit();
initPbuffer();
@ -391,10 +391,8 @@ public class PbufferTest {
* Initializes OGL
*/
private void glInit() {
// Go into orthographic projection mode.
gl.determineAvailableExtensions();
//sync frame (only works on windows)
if (GL.WGL_EXT_swap_control) {
if (gl.WGL_EXT_swap_control) {
GL.wglSwapIntervalEXT(1);
}
GL.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);

View File

@ -1,40 +0,0 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class org_lwjgl_opengl_BaseGL */
#ifndef _Included_org_lwjgl_opengl_BaseGL
#define _Included_org_lwjgl_opengl_BaseGL
#ifdef __cplusplus
extern "C" {
#endif
/* Inaccessible static: _00024assertionsDisabled */
/* Inaccessible static: currentWindow */
/* Inaccessible static: class_00024org_00024lwjgl_00024Window */
/*
* Class: org_lwjgl_opengl_BaseGL
* Method: swapBuffers
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_swapBuffers
(JNIEnv *, jobject);
/*
* Class: org_lwjgl_opengl_BaseGL
* Method: nCreate
* Signature: (Ljava/lang/String;IIIIIIIIZ)V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nCreate
(JNIEnv *, jobject, jstring, jint, jint, jint, jint, jint, jint, jint, jint, jboolean);
/*
* Class: org_lwjgl_opengl_BaseGL
* Method: nDestroyGL
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nDestroyGL
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,56 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class org_lwjgl_opengl_GLWindow */
#ifndef _Included_org_lwjgl_opengl_GLWindow
#define _Included_org_lwjgl_opengl_GLWindow
#ifdef __cplusplus
extern "C" {
#endif
/* Inaccessible static: _00024assertionsDisabled */
/* Inaccessible static: currentWindow */
/* Inaccessible static: class_00024org_00024lwjgl_00024Window */
/* Inaccessible static: WGL_ARB_buffer_region */
/* Inaccessible static: WGL_ARB_extensions_string */
/* Inaccessible static: WGL_ARB_pbuffer */
/* Inaccessible static: WGL_ARB_pixel_format */
/* Inaccessible static: WGL_ARB_render_texture */
/* Inaccessible static: WGL_EXT_extensions_string */
/* Inaccessible static: WGL_EXT_swap_control */
/* Inaccessible static: class_00024org_00024lwjgl_00024opengl_00024GL */
/*
* Class: org_lwjgl_opengl_GLWindow
* Method: checkWGLExtensionsString
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLWindow_checkWGLExtensionsString
(JNIEnv *, jclass);
/*
* Class: org_lwjgl_opengl_GLWindow
* Method: swapBuffers
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLWindow_swapBuffers
(JNIEnv *, jobject);
/*
* Class: org_lwjgl_opengl_GLWindow
* Method: nCreate
* Signature: (Ljava/lang/String;IIIIIIIIZ)V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLWindow_nCreate
(JNIEnv *, jobject, jstring, jint, jint, jint, jint, jint, jint, jint, jint, jboolean);
/*
* Class: org_lwjgl_opengl_GLWindow
* Method: nDestroyGL
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLWindow_nDestroyGL
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -10,7 +10,7 @@ NATIVE = \
org_lwjgl_input_Keyboard.cpp \
org_lwjgl_input_Mouse.cpp \
org_lwjgl_input_Cursor.cpp \
org_lwjgl_opengl_BaseGL.cpp \
org_lwjgl_opengl_GLWindow.cpp \
org_lwjgl_opengl_Pbuffer.cpp \
org_lwjgl_Window.cpp \
extxcursor.cpp

View File

@ -41,7 +41,7 @@
#include "extgl.h"
#include "Window.h"
#include "org_lwjgl_opengl_BaseGL.h"
#include "org_lwjgl_opengl_GLWindow.h"
#define USEGLX13 true
@ -204,11 +204,11 @@ static bool initWindowGLX(JNIEnv *env, Display *disp, int screen, jstring title,
}
/*
* Class: org_lwjgl_opengl_BaseGL
* Class: org_lwjgl_opengl_GLWindow
* Method: nCreate
* Signature: (IIII)Z
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nCreate
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLWindow_nCreate
(JNIEnv * env, jobject obj, jstring title, jint x, jint y, jint width, jint height, jint bpp, jint alpha, jint depth, jint stencil, jboolean fullscreen)
{
int screen;
@ -256,33 +256,33 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nCreate
}
/*
* Class: org_lwjgl_opengl_BaseGL
* Class: org_lwjgl_opengl_GLWindow
* Method: makeCurrent
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_makeCurrent
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLWindow_makeCurrent
(JNIEnv *env, jobject obj)
{
makeCurrent();
}
/*
* Class: org_lwjgl_opengl_BaseGL
* Class: org_lwjgl_opengl_GLWindow
* Method: nDestroy
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nDestroyGL
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLWindow_nDestroyGL
(JNIEnv * env, jobject obj)
{
destroy();
}
/*
* Class: org_lwjgl_opengl_BaseGL
* Class: org_lwjgl_opengl_GLWindow
* Method: swapBuffers
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_swapBuffers(JNIEnv * env, jobject obj)
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLWindow_swapBuffers(JNIEnv * env, jobject obj)
{
if (USEGLX13 && extgl_Extensions.glx.GLX13)
glXSwapBuffers(getCurrentDisplay(), glx_window);

View File

@ -40,7 +40,7 @@
*/
#include <windows.h>
#include "org_lwjgl_opengl_BaseGL.h"
#include "org_lwjgl_opengl_GLWindow.h"
#include "extgl.h"
#include "Window.h"
#include "jni.h"
@ -131,11 +131,11 @@ static int findPixelFormat(JNIEnv *env, unsigned int flags, int bpp, int alpha,
}
/*
* Class: org_lwjgl_opengl_BaseGL
* Class: org_lwjgl_opengl_GLWindow
* Method: nCreate
* Signature: (Ljava/lang/String;IIIIIIIIZ)V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nCreate
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLWindow_nCreate
(JNIEnv * env, jobject obj,
jstring title, jint x, jint y, jint width, jint height, jint bpp, jint alpha, jint depth, jint stencil, jboolean fullscreen)
{
@ -185,11 +185,11 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nCreate
}
/*
* Class: org_lwjgl_opengl_BaseGL
* Class: org_lwjgl_opengl_GLWindow
* Method: nDestroy
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nDestroyGL
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLWindow_nDestroyGL
(JNIEnv * env, jobject obj)
{
wglMakeCurrent(NULL, NULL);
@ -207,11 +207,11 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nDestroyGL
}
/*
* Class: org_lwjgl_opengl_BaseGL
* Class: org_lwjgl_opengl_GLWindow
* Method: swapBuffers
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_swapBuffers
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLWindow_swapBuffers
(JNIEnv *, jobject)
{
wglSwapLayerBuffers(hdc, WGL_SWAP_MAIN_PLANE);