diff --git a/src/native/win32/display.cpp b/src/native/win32/display.cpp index 2e3b058b..4ac4574f 100644 --- a/src/native/win32/display.cpp +++ b/src/native/win32/display.cpp @@ -46,16 +46,18 @@ #define WINDOWCLASSNAME "LWJGLWINDOW" +#define GAMMA_SIZE (3*256) + static jobjectArray GetAvailableDisplayModesEx(JNIEnv * env); static jobjectArray GetAvailableDisplayModes(JNIEnv * env); static char * getDriver(); -bool modeSet = false; // Whether we've done a display mode change -WORD* originalGamma = new WORD[256 * 3]; // Original gamma settings -WORD* currentGamma = new WORD[256 * 3]; // Current gamma settings -DEVMODE devmode; // Now we'll remember this value for the future -extern HWND display_hwnd = NULL; // Handle to the window +static bool modeSet = false; // Whether we've done a display mode change +static WORD originalGamma[256 * 3]; // Original gamma settings +static WORD currentGamma[256 * 3]; // Current gamma settings +static DEVMODE devmode; // Now we'll remember this value for the future +extern HWND display_hwnd; // Handle to the window extern RECT clientSize; -char * driver = getDriver(); +static char * driver = getDriver(); jobjectArray getAvailableDisplayModes(JNIEnv *env) { @@ -282,6 +284,7 @@ jobject initDisplay(JNIEnv * env) if (GetDeviceGammaRamp(screenDC, originalGamma) == FALSE) { printfDebug("Failed to get initial device gamma\n"); } + memcpy(currentGamma, originalGamma, sizeof(WORD)*GAMMA_SIZE); ReleaseDC(NULL, screenDC); return newMode; } diff --git a/src/native/win32/org_lwjgl_opengl_Display.cpp b/src/native/win32/org_lwjgl_opengl_Display.cpp index 7d1b4344..992e3969 100644 --- a/src/native/win32/org_lwjgl_opengl_Display.cpp +++ b/src/native/win32/org_lwjgl_opengl_Display.cpp @@ -550,6 +550,14 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_update JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_swapBuffers (JNIEnv * env, jobject self) { + display_hdc = GetDC(display_hwnd); + if (!applyPixelFormat(display_hdc, pixel_format_index)) { + closeWindow(display_hwnd, display_hdc); + throwException(env, "Could not apply pixel format to window"); + return; + } + + BOOL result = wglMakeCurrent(display_hdc, display_hglrc); isDirty = false; SwapBuffers(display_hdc); }