Add a public DisplayMode constructor

This commit is contained in:
Elias Naur 2004-08-09 11:55:48 +00:00
parent 0baf3a81f2
commit b88624e608
5 changed files with 43 additions and 13 deletions

View File

@ -104,10 +104,12 @@ public final class Display {
}
/**
* Returns the entire list of display modes as an array, in no
* Returns the entire list of possible fullscreen display modes as an array, in no
* particular order. Any given mode is not guaranteed to be available and
* the only certain way to check is to call create() and make sure it works.
* Only non-palette-indexed modes are returned (ie. bpp will be 16, 24, or 32).
* Only DisplayModes from this call can be used when the Display is in fullscreen
* mode.
*
* @return an array of all display modes the system reckons it can handle.
*/
@ -161,7 +163,7 @@ public final class Display {
destroyWindow();
try {
if (fullscreen)
switchDisplayMode(mode);
switchDisplayMode();
createWindow();
} catch (LWJGLException e) {
destroyContext();
@ -200,7 +202,13 @@ public final class Display {
private static native void nDestroyWindow();
private static native void switchDisplayMode(DisplayMode mode) throws LWJGLException;
private static void switchDisplayMode() throws LWJGLException {
if (!current_mode.isFullscreen())
throw new LWJGLException("The current DisplayMode instance cannot be used for fullscreen mode");
nSwitchDisplayMode(current_mode);
}
private static native void nSwitchDisplayMode(DisplayMode mode) throws LWJGLException;
/**
* Reset the display mode to whatever it was when LWJGL was initialized.
@ -353,6 +361,8 @@ public final class Display {
* mode returned by getDisplayMode(). The native cursor position is also reset.
*
* @param fullscreen Specify the fullscreen mode of the context.
* @throws LWJGLException If fullscreen is true, and the current DisplayMode instance is not
* from getAvailableDisplayModes() or if the mode switch fails.
*/
public static void setFullscreen(boolean fullscreen) throws LWJGLException {
if (Display.fullscreen != fullscreen) {
@ -362,7 +372,7 @@ public final class Display {
destroyWindow();
try {
if (fullscreen)
switchDisplayMode(current_mode);
switchDisplayMode();
else
resetDisplayMode();
createWindow();
@ -537,7 +547,7 @@ public final class Display {
if (isCreated())
throw new IllegalStateException("Only one LWJGL context may be instantiated at any one time.");
if (fullscreen)
switchDisplayMode(current_mode);
switchDisplayMode();
try {
GLContext.loadOpenGLLibrary();
try {

View File

@ -46,17 +46,38 @@ public final class DisplayMode {
/** properties of the display mode */
private final int width, height, bpp, freq;
/** If true, this instance can be used for fullscreen modes */
private final boolean fullscreen;
/**
* Construct a display mode.
*
* Construct a display mode. DisplayModes constructed through the
* public constructor can only be used to specify the dimensions of
* the Display in windowed mode. To get the available DisplayModes for
* fullscreen modes, use Display.getAvailableDisplayModes().
*
* @param width The Display width.
* @param height The Display height.
* @see Display
*/
private DisplayMode(int width, int height, int bpp, int freq) {
public DisplayMode(int width, int height) {
this(width, height, 0, 0, false);
}
DisplayMode(int width, int height, int bpp, int freq) {
this(width, height, bpp, freq, true);
}
private DisplayMode(int width, int height, int bpp, int freq, boolean fullscreen) {
this.width = width;
this.height = height;
this.bpp = bpp;
this.freq = freq;
this.fullscreen = fullscreen;
}
/** True iff this instance can be used for fullscreen modes */
boolean isFullscreen() {
return fullscreen;
}
public int getWidth() {

View File

@ -14,7 +14,6 @@ extern "C" {
/* Inaccessible static: title */
/* Inaccessible static: fullscreen */
/* Inaccessible static: vsync */
/* Inaccessible static: vbo_tracker */
/* Inaccessible static: context */
/* Inaccessible static: timeLate */
/*
@ -43,10 +42,10 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nDestroyWindow
/*
* Class: org_lwjgl_opengl_Display
* Method: switchDisplayMode
* Method: nSwitchDisplayMode
* Signature: (Lorg/lwjgl/opengl/DisplayMode;)V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_switchDisplayMode
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nSwitchDisplayMode
(JNIEnv *, jclass, jobject);
/*

View File

@ -602,7 +602,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_opengl_Display_nGetAvailableDispla
return getAvailableDisplayModes(env);
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_switchDisplayMode(JNIEnv *env, jclass clazz, jobject mode) {
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nSwitchDisplayMode(JNIEnv *env, jclass clazz, jobject mode) {
switchDisplayMode(env, mode);
}

View File

@ -615,7 +615,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nDestroyWindow(JNIEnv *env,
closeWindow(display_hwnd, display_hdc);
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_switchDisplayMode(JNIEnv *env, jclass clazz, jobject mode) {
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nSwitchDisplayMode(JNIEnv *env, jclass clazz, jobject mode) {
switchDisplayMode(env, mode);
}