From 157e7673ccd229d2356a3d84f2d10556505dfabc Mon Sep 17 00:00:00 2001 From: Caspian Rychlik-Prince Date: Fri, 28 Mar 2003 23:16:15 +0000 Subject: [PATCH] Big changes for the new 0.6 LWJGL release --- src/java/org/lwjgl/Display.java | 2 +- src/java/org/lwjgl/Window.java | 8 ++++++- src/native/win32/org_lwjgl_Display.cpp | 14 ++++++++---- src/native/win32/org_lwjgl_Window.cpp | 24 ++++++++++++++++++-- src/native/win32/org_lwjgl_opengl_BaseGL.cpp | 3 +++ 5 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/java/org/lwjgl/Display.java b/src/java/org/lwjgl/Display.java index ddf0dc8b..9e0abcdb 100644 --- a/src/java/org/lwjgl/Display.java +++ b/src/java/org/lwjgl/Display.java @@ -139,7 +139,7 @@ public final class Display { * Reset the display mode to whatever it was when LWJGL was initialized. * Fails silently. */ - public static native void resetDisplayMode() throws Exception; + public static native void resetDisplayMode(); /** * Retrieves the width of the created display diff --git a/src/java/org/lwjgl/Window.java b/src/java/org/lwjgl/Window.java index b247e102..afd88ddb 100644 --- a/src/java/org/lwjgl/Window.java +++ b/src/java/org/lwjgl/Window.java @@ -184,7 +184,7 @@ public abstract class Window { /** * Destroy the window. */ - public final void destroy() { + public final synchronized void destroy() { if (!created) return; doDestroy(); @@ -239,4 +239,10 @@ public abstract class Window { return "Window["+title+"]"; } + /** + * @return the current window, or null, if there is no current window + */ + public static Window getCurrentWindow() { + return currentWindow; + } } diff --git a/src/native/win32/org_lwjgl_Display.cpp b/src/native/win32/org_lwjgl_Display.cpp index 4118ab66..487211f2 100644 --- a/src/native/win32/org_lwjgl_Display.cpp +++ b/src/native/win32/org_lwjgl_Display.cpp @@ -46,7 +46,7 @@ jobjectArray GetAvailableDisplayModesNT(JNIEnv * env); jobjectArray GetAvailableDisplayModes9x(JNIEnv * env); - +bool modeSet = false; // Whether we've done a display mode change /* @@ -254,6 +254,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Display_setDisplayMode env->SetStaticObjectField(clazz, fid_initialMode, newMode); env->DeleteLocalRef(newMode); + modeSet = true; } /* @@ -264,11 +265,14 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Display_setDisplayMode JNIEXPORT void JNICALL Java_org_lwjgl_Display_resetDisplayMode (JNIEnv * env, jclass clazz) { - // Under Win32, all we have to do is: - ChangeDisplaySettings(NULL, 0); + if (modeSet) { + modeSet = false; + // Under Win32, all we have to do is: + ChangeDisplaySettings(NULL, 0); - // And we'll call init() again to put the correct mode back in Display - Java_org_lwjgl_Display_init(env, clazz); + // And we'll call init() again to put the correct mode back in Display + Java_org_lwjgl_Display_init(env, clazz); + } } /* diff --git a/src/native/win32/org_lwjgl_Window.cpp b/src/native/win32/org_lwjgl_Window.cpp index b727bb66..a9948fc0 100644 --- a/src/native/win32/org_lwjgl_Window.cpp +++ b/src/native/win32/org_lwjgl_Window.cpp @@ -101,19 +101,31 @@ void closeWindow() { // Release DirectInput if (lpdi != NULL) { +#ifdef _DEBUG + printf("Destroying directinput\n"); +#endif lpdi->Release(); lpdi = NULL; } // Release device context if (hdc != NULL && hwnd != NULL) { +#ifdef _DEBUG + printf("Releasing DC\n"); +#endif ReleaseDC(hwnd, hdc); } // Close the window if (hwnd != NULL) { +#ifdef _DEBUG + printf("Destroy window\n"); +#endif // Vape the window DestroyWindow(hwnd); +#ifdef _DEBUG + printf("Destroyed window\n"); +#endif hwnd = NULL; } @@ -144,7 +156,6 @@ LRESULT CALLBACK lwjglWindowProc(HWND hWnd, LPARAM lParam) { if (environment == NULL) { - printf("No environment!\n"); return DefWindowProc(hWnd, msg, wParam, lParam); } @@ -227,7 +238,9 @@ bool registerWindow() printf("Failed to register window class\n"); return false; } +#ifdef _DEBUG printf("Window registered\n"); +#endif oneShotInitialised = true; } @@ -308,7 +321,7 @@ bool createWindow(const char * title, int x, int y, int width, int height, bool // and then to issue commands to it, you need to call gl::makeCurrent(). // 3. Hide the mouse if necessary - isFullScreen = fullscreen; + isFullScreen = fullscreen == JNI_TRUE; if (isFullScreen) { ShowCursor(FALSE); } @@ -356,7 +369,14 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Window_swapBuffers JNIEXPORT void JNICALL Java_org_lwjgl_Window_nDestroy (JNIEnv * env, jobject obj) { + // Cache env and obj + environment = env; + window = obj; + closeWindow(); + + environment = NULL; + window = NULL; } /* diff --git a/src/native/win32/org_lwjgl_opengl_BaseGL.cpp b/src/native/win32/org_lwjgl_opengl_BaseGL.cpp index eb3d82f5..48fd2db5 100644 --- a/src/native/win32/org_lwjgl_opengl_BaseGL.cpp +++ b/src/native/win32/org_lwjgl_opengl_BaseGL.cpp @@ -198,6 +198,9 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nDestroyGL // Delete the rendering context if (hglrc != NULL) { +#ifdef _DEBUG + printf("Delete GL context\n"); +#endif wglDeleteContext(hglrc); hglrc = NULL; }