2002-08-15 11:46:18 -04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2002 Light Weight 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.
|
2002-08-11 07:49:32 -04:00
|
|
|
*
|
2002-08-15 11:46:18 -04:00
|
|
|
* * 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.
|
2002-08-11 07:49:32 -04:00
|
|
|
*
|
2002-08-15 11:46:18 -04:00
|
|
|
* * 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$
|
2002-08-11 07:49:32 -04:00
|
|
|
*
|
2002-08-15 11:46:18 -04:00
|
|
|
* Win32 specific library for display handdling.
|
2002-08-11 07:49:32 -04:00
|
|
|
*
|
2002-08-15 11:46:18 -04:00
|
|
|
* @author cix_foo <cix_foo@users.sourceforge.net>
|
|
|
|
* @version $Revision$
|
2002-08-11 07:49:32 -04:00
|
|
|
*/
|
|
|
|
|
2003-03-27 20:28:04 -05:00
|
|
|
#include "Window.h"
|
2002-08-11 07:49:32 -04:00
|
|
|
#include "org_lwjgl_Display.h"
|
2002-08-15 10:53:18 -04:00
|
|
|
|
2002-08-17 10:13:12 -04:00
|
|
|
#define WINDOWCLASSNAME "LWJGLWINDOW"
|
2002-08-11 07:49:32 -04:00
|
|
|
|
2003-03-03 16:49:46 -05:00
|
|
|
jobjectArray GetAvailableDisplayModesNT(JNIEnv * env);
|
|
|
|
jobjectArray GetAvailableDisplayModes9x(JNIEnv * env);
|
2003-03-28 18:16:15 -05:00
|
|
|
bool modeSet = false; // Whether we've done a display mode change
|
2003-03-29 16:52:14 -05:00
|
|
|
WORD* originalGamma = new WORD[256 * 3]; // Original gamma settings
|
2003-06-07 15:28:53 -04:00
|
|
|
WORD* currentGamma = new WORD[256 * 3]; // Current gamma settings
|
|
|
|
DEVMODE devmode; // Now we'll remember this value for the future
|
2003-02-07 16:54:31 -05:00
|
|
|
|
|
|
|
|
2002-08-11 07:49:32 -04:00
|
|
|
/*
|
|
|
|
* Class: org_lwjgl_Display
|
2003-03-03 16:51:13 -05:00
|
|
|
* Method: nGetAvailableDisplayModes
|
2002-08-11 07:49:32 -04:00
|
|
|
* Signature: ()[Lorg/lwjgl/DisplayMode;
|
|
|
|
*/
|
2003-03-03 16:49:46 -05:00
|
|
|
JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_nGetAvailableDisplayModes
|
2002-08-11 07:49:32 -04:00
|
|
|
(JNIEnv * env, jclass clazz)
|
|
|
|
{
|
2003-03-03 16:49:46 -05:00
|
|
|
// Determine whether to use a display name or NULL, which depends on the operating
|
|
|
|
// system
|
|
|
|
OSVERSIONINFO osvi;
|
2002-08-24 17:19:06 -04:00
|
|
|
|
2003-03-03 16:49:46 -05:00
|
|
|
osvi.dwOSVersionInfoSize = sizeof(osvi);
|
|
|
|
GetVersionEx(&osvi);
|
2002-12-23 08:23:29 -05:00
|
|
|
|
2003-03-03 16:49:46 -05:00
|
|
|
if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) {
|
|
|
|
#ifdef _DEBUG
|
2003-04-14 14:17:29 -04:00
|
|
|
printf("Selecting NT display mode check\n");
|
2003-03-03 16:49:46 -05:00
|
|
|
#endif
|
|
|
|
return GetAvailableDisplayModesNT(env);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
printf("Selecting 9x display mode check");
|
|
|
|
#endif
|
|
|
|
return GetAvailableDisplayModes9x(env);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Choose displaymodes using NT codepath (multiple displaydevices)
|
|
|
|
*/
|
|
|
|
jobjectArray GetAvailableDisplayModesNT(JNIEnv * env) {
|
2003-03-19 07:41:28 -05:00
|
|
|
int i = 0, j = 0, n = 0;
|
|
|
|
int AvailableModes = 0;
|
2003-03-03 16:49:46 -05:00
|
|
|
|
2003-03-19 07:41:28 -05:00
|
|
|
DISPLAY_DEVICE DisplayDevice;
|
|
|
|
DEVMODE DevMode;
|
2003-03-03 16:49:46 -05:00
|
|
|
|
2003-03-19 07:41:28 -05:00
|
|
|
DevMode.dmSize = sizeof(DEVMODE);
|
|
|
|
DisplayDevice.cb = sizeof(DISPLAY_DEVICE);
|
2003-03-03 16:49:46 -05:00
|
|
|
|
|
|
|
//enumerate all displays, and all of their displaymodes
|
2003-03-19 07:41:28 -05:00
|
|
|
while(EnumDisplayDevices(NULL, i++, &DisplayDevice, 0) != 0) {
|
2003-04-14 14:17:29 -04:00
|
|
|
#ifdef _DEBUG
|
|
|
|
printf("Querying %s device\n", DisplayDevice.DeviceString);
|
|
|
|
#endif
|
|
|
|
while(EnumDisplaySettingsEx(DisplayDevice.DeviceName, j++, &DevMode, 0) != 0) {
|
2003-03-19 07:41:28 -05:00
|
|
|
if (DevMode.dmBitsPerPel > 8) {
|
|
|
|
AvailableModes++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-04-14 14:17:29 -04:00
|
|
|
|
2003-03-03 16:49:46 -05:00
|
|
|
#ifdef _DEBUG
|
2003-03-19 07:41:28 -05:00
|
|
|
printf("Found %d displaymodes\n", AvailableModes);
|
2003-03-03 16:49:46 -05:00
|
|
|
#endif
|
|
|
|
|
2003-03-19 07:41:28 -05:00
|
|
|
// now that we have the count create the classes, and add 'em all - we'll remove dups in Java
|
|
|
|
// Allocate an array of DisplayModes big enough
|
2002-08-24 17:19:06 -04:00
|
|
|
jclass displayModeClass = env->FindClass("org/lwjgl/DisplayMode");
|
2002-12-22 14:52:44 -05:00
|
|
|
|
2003-03-19 07:41:28 -05:00
|
|
|
jobjectArray ret = env->NewObjectArray(AvailableModes, displayModeClass, NULL);
|
|
|
|
jmethodID displayModeConstructor = env->GetMethodID(displayModeClass, "<init>", "(IIII)V");
|
2003-03-03 16:49:46 -05:00
|
|
|
|
2003-03-19 07:41:28 -05:00
|
|
|
i = 0, j = 0, n = 0;
|
|
|
|
while(EnumDisplayDevices(NULL, i++, &DisplayDevice, 0) != 0) {
|
2003-04-14 14:17:29 -04:00
|
|
|
while(EnumDisplaySettingsEx(DisplayDevice.DeviceName, j++, &DevMode, 0) != 0) {
|
2003-03-19 07:41:28 -05:00
|
|
|
// Filter out indexed modes
|
|
|
|
if (DevMode.dmBitsPerPel > 8) {
|
|
|
|
jobject displayMode;
|
|
|
|
displayMode = env->NewObject(displayModeClass, displayModeConstructor,
|
|
|
|
DevMode.dmPelsWidth, DevMode.dmPelsHeight,
|
|
|
|
DevMode.dmBitsPerPel, DevMode.dmDisplayFrequency);
|
|
|
|
|
|
|
|
env->SetObjectArrayElement(ret, n++, displayMode);
|
2003-03-03 16:49:46 -05:00
|
|
|
}
|
2003-03-19 07:41:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
2003-03-03 16:49:46 -05:00
|
|
|
}
|
2002-12-22 14:52:44 -05:00
|
|
|
|
2003-03-03 16:49:46 -05:00
|
|
|
/**
|
|
|
|
* Choose displaymodes using 9x codepath (single displaydevice)
|
|
|
|
*/
|
|
|
|
jobjectArray GetAvailableDisplayModes9x(JNIEnv * env) {
|
2003-03-19 07:41:28 -05:00
|
|
|
int i = 0, j = 0, n = 0;
|
|
|
|
int AvailableModes = 0;
|
2003-03-03 16:49:46 -05:00
|
|
|
|
2003-03-19 07:41:28 -05:00
|
|
|
DEVMODE DevMode;
|
2003-03-03 16:49:46 -05:00
|
|
|
|
2003-03-19 07:41:28 -05:00
|
|
|
DevMode.dmSize = sizeof(DEVMODE);
|
2003-03-03 16:49:46 -05:00
|
|
|
|
2003-03-19 07:41:28 -05:00
|
|
|
//enumerate all displaymodes
|
2003-04-14 14:17:29 -04:00
|
|
|
while(EnumDisplaySettingsEx(NULL, j++, &DevMode, 0) != 0) {
|
2003-03-19 07:41:28 -05:00
|
|
|
if (DevMode.dmBitsPerPel > 8) {
|
|
|
|
AvailableModes++;
|
|
|
|
}
|
|
|
|
}
|
2003-03-03 16:49:46 -05:00
|
|
|
|
|
|
|
#ifdef _DEBUG
|
2003-03-19 07:41:28 -05:00
|
|
|
printf("Found %d displaymodes\n", AvailableModes);
|
2003-03-03 16:49:46 -05:00
|
|
|
#endif
|
|
|
|
|
2003-03-19 07:41:28 -05:00
|
|
|
// now that we have the count create the classes, and add 'em all - we'll remove dups in Java
|
|
|
|
// Allocate an array of DisplayModes big enough
|
2003-03-03 16:49:46 -05:00
|
|
|
jclass displayModeClass = env->FindClass("org/lwjgl/DisplayMode");
|
2002-12-22 14:52:44 -05:00
|
|
|
|
2003-03-22 16:39:52 -05:00
|
|
|
jobjectArray ret = env->NewObjectArray(AvailableModes, displayModeClass, NULL);
|
2003-03-19 07:41:28 -05:00
|
|
|
jmethodID displayModeConstructor = env->GetMethodID(displayModeClass, "<init>", "(IIII)V");
|
2003-03-03 16:49:46 -05:00
|
|
|
|
2003-03-19 07:41:28 -05:00
|
|
|
i = 0, j = 0, n = 0;
|
2003-04-14 14:17:29 -04:00
|
|
|
while(EnumDisplaySettingsEx(NULL, j++, &DevMode, 0) != 0) {
|
2003-03-19 07:41:28 -05:00
|
|
|
// Filter out indexed modes
|
|
|
|
if (DevMode.dmBitsPerPel > 8) {
|
|
|
|
jobject displayMode;
|
|
|
|
displayMode = env->NewObject(displayModeClass, displayModeConstructor,
|
|
|
|
DevMode.dmPelsWidth, DevMode.dmPelsHeight,
|
|
|
|
DevMode.dmBitsPerPel, DevMode.dmDisplayFrequency);
|
|
|
|
env->SetObjectArrayElement(ret, n++, displayMode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
2002-08-11 07:49:32 -04:00
|
|
|
}
|
|
|
|
|
2003-03-27 20:28:04 -05:00
|
|
|
|
2002-08-11 07:49:32 -04:00
|
|
|
/*
|
|
|
|
* Class: org_lwjgl_Display
|
2003-03-27 20:28:04 -05:00
|
|
|
* Method: getPlatform
|
|
|
|
* Signature: ()I
|
2002-08-11 07:49:32 -04:00
|
|
|
*/
|
2003-03-27 20:28:04 -05:00
|
|
|
JNIEXPORT jint JNICALL Java_org_lwjgl_Display_getPlatform
|
|
|
|
(JNIEnv * env, jclass clazz)
|
2002-08-11 07:49:32 -04:00
|
|
|
{
|
2003-03-27 20:28:04 -05:00
|
|
|
return org_lwjgl_Display_PLATFORM_WGL;
|
|
|
|
}
|
2002-12-19 11:35:35 -05:00
|
|
|
|
2003-03-27 20:28:04 -05:00
|
|
|
/*
|
|
|
|
* Class: org_lwjgl_Display
|
|
|
|
* Method: setDisplayMode
|
|
|
|
* Signature: (Lorg/lwjgl/DisplayMode;)V
|
|
|
|
*/
|
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_Display_setDisplayMode
|
|
|
|
(JNIEnv * env, jclass clazz, jobject mode)
|
|
|
|
{
|
2002-12-19 11:35:35 -05:00
|
|
|
|
2003-03-28 14:02:24 -05:00
|
|
|
jclass cls_displayMode = env->FindClass("org/lwjgl/DisplayMode");
|
|
|
|
jfieldID fid_width = env->GetFieldID(cls_displayMode, "width", "I");
|
|
|
|
jfieldID fid_height = env->GetFieldID(cls_displayMode, "height", "I");
|
|
|
|
jfieldID fid_bpp = env->GetFieldID(cls_displayMode, "bpp", "I");
|
|
|
|
jfieldID fid_freq = env->GetFieldID(cls_displayMode, "freq", "I");
|
2003-01-31 14:04:45 -05:00
|
|
|
|
2003-03-27 20:28:04 -05:00
|
|
|
int width = env->GetIntField(mode, fid_width);
|
|
|
|
int height = env->GetIntField(mode, fid_height);
|
|
|
|
int bpp = env->GetIntField(mode, fid_bpp);
|
|
|
|
int freq = env->GetIntField(mode, fid_freq);
|
2002-12-19 11:35:35 -05:00
|
|
|
|
2003-03-27 20:28:04 -05:00
|
|
|
devmode.dmSize = sizeof(DEVMODE);
|
|
|
|
devmode.dmBitsPerPel = bpp;
|
|
|
|
devmode.dmPelsWidth = width;
|
|
|
|
devmode.dmPelsHeight = height;
|
|
|
|
devmode.dmDisplayFlags = 0;
|
|
|
|
devmode.dmDisplayFrequency = freq;
|
|
|
|
devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFLAGS;
|
|
|
|
if (freq != 0)
|
|
|
|
devmode.dmFields |= DM_DISPLAYFREQUENCY;
|
2002-12-19 11:35:35 -05:00
|
|
|
|
2003-02-12 04:33:11 -05:00
|
|
|
|
2003-03-27 20:28:04 -05:00
|
|
|
LONG cdsret = ChangeDisplaySettings(&devmode, CDS_FULLSCREEN);
|
2002-12-19 11:35:35 -05:00
|
|
|
|
2003-03-27 20:28:04 -05:00
|
|
|
if (cdsret != DISP_CHANGE_SUCCESSFUL) {
|
|
|
|
// Failed: so let's check to see if it's a wierd dual screen display
|
2002-12-19 11:35:35 -05:00
|
|
|
#ifdef _DEBUG
|
2003-03-27 20:28:04 -05:00
|
|
|
printf("Failed to set display mode... assuming dual monitors\n");
|
2002-12-19 11:35:35 -05:00
|
|
|
#endif
|
2003-03-27 20:28:04 -05:00
|
|
|
devmode.dmPelsWidth = width * 2;
|
|
|
|
cdsret = ChangeDisplaySettings(&devmode, CDS_FULLSCREEN);
|
2002-12-19 11:35:35 -05:00
|
|
|
|
2003-03-27 20:28:04 -05:00
|
|
|
if (cdsret != DISP_CHANGE_SUCCESSFUL) {
|
|
|
|
#ifdef _DEBUG
|
|
|
|
printf("Failed to set display mode using dual monitors\n");
|
|
|
|
#endif
|
|
|
|
throwException(env, "Failed to set display mode.");
|
2003-03-28 14:02:24 -05:00
|
|
|
return;
|
2003-03-27 20:28:04 -05:00
|
|
|
}
|
2002-08-11 07:49:32 -04:00
|
|
|
}
|
|
|
|
|
2003-03-27 20:28:04 -05:00
|
|
|
// The change was successful but might not be the exact change we were expecting.
|
|
|
|
// Now we'll construct a new DisplayMode instance and stash it back in the Display
|
|
|
|
// class's mode instance variable.
|
|
|
|
|
|
|
|
// Get the screen
|
2003-03-29 16:52:14 -05:00
|
|
|
HDC screenDC = GetDC(NULL);
|
2003-03-27 20:28:04 -05:00
|
|
|
// Get the device caps
|
|
|
|
width = GetDeviceCaps(screenDC, HORZRES);
|
|
|
|
height = GetDeviceCaps(screenDC, VERTRES);
|
|
|
|
bpp = GetDeviceCaps(screenDC, COLORRES);
|
|
|
|
freq = GetDeviceCaps(screenDC, VREFRESH);
|
|
|
|
if (freq <= 1)
|
|
|
|
freq = 0; // Unknown
|
2003-03-29 16:52:14 -05:00
|
|
|
ReleaseDC(NULL, screenDC);
|
2003-03-27 20:28:04 -05:00
|
|
|
|
2003-03-28 14:02:24 -05:00
|
|
|
jmethodID ctor = env->GetMethodID(cls_displayMode, "<init>", "(IIII)V");
|
|
|
|
jobject newMode = env->NewObject(cls_displayMode, ctor, width, height, bpp, freq);
|
|
|
|
jfieldID fid_initialMode = env->GetStaticFieldID(clazz, "mode", "Lorg/lwjgl/DisplayMode;");
|
|
|
|
env->SetStaticObjectField(clazz, fid_initialMode, newMode);
|
2003-03-27 20:28:04 -05:00
|
|
|
env->DeleteLocalRef(newMode);
|
2002-08-17 10:13:12 -04:00
|
|
|
|
2003-03-28 18:16:15 -05:00
|
|
|
modeSet = true;
|
2002-08-11 07:49:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_lwjgl_Display
|
2003-03-27 20:28:04 -05:00
|
|
|
* Method: resetDisplayMode
|
2002-08-11 07:49:32 -04:00
|
|
|
* Signature: ()V
|
|
|
|
*/
|
2003-03-27 20:28:04 -05:00
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_Display_resetDisplayMode
|
2002-08-11 07:49:32 -04:00
|
|
|
(JNIEnv * env, jclass clazz)
|
|
|
|
{
|
2003-03-29 16:52:14 -05:00
|
|
|
|
|
|
|
// Return device gamma to normal
|
|
|
|
HDC screenDC = GetDC(NULL);
|
2003-05-27 10:12:10 -04:00
|
|
|
if (!SetDeviceGammaRamp(screenDC, originalGamma)) {
|
|
|
|
#ifdef _DEBUG
|
|
|
|
printf("Could not reset device gamma\n");
|
|
|
|
#endif
|
|
|
|
}
|
2003-03-29 16:52:14 -05:00
|
|
|
ReleaseDC(NULL, screenDC);
|
|
|
|
|
2003-03-28 18:16:15 -05:00
|
|
|
if (modeSet) {
|
|
|
|
modeSet = false;
|
|
|
|
// Under Win32, all we have to do is:
|
|
|
|
ChangeDisplaySettings(NULL, 0);
|
2003-03-27 20:28:04 -05:00
|
|
|
|
2003-03-28 18:16:15 -05:00
|
|
|
// And we'll call init() again to put the correct mode back in Display
|
|
|
|
Java_org_lwjgl_Display_init(env, clazz);
|
|
|
|
}
|
2002-08-11 07:49:32 -04:00
|
|
|
}
|
2002-12-19 11:35:35 -05:00
|
|
|
|
2003-06-07 15:28:53 -04:00
|
|
|
/*
|
|
|
|
* Temporarily reset display settings. This is called when the window is minimized.
|
|
|
|
*/
|
|
|
|
void tempResetDisplayMode() {
|
|
|
|
// Return device gamma to normal
|
|
|
|
HDC screenDC = GetDC(NULL);
|
|
|
|
if (!SetDeviceGammaRamp(screenDC, originalGamma)) {
|
|
|
|
#ifdef _DEBUG
|
|
|
|
printf("Could not reset device gamma\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
ReleaseDC(NULL, screenDC);
|
|
|
|
|
|
|
|
if (modeSet) {
|
|
|
|
#ifdef _DEBUG
|
|
|
|
printf("Attempting to temporarily reset the display mode\n");
|
|
|
|
#endif
|
|
|
|
modeSet = false;
|
|
|
|
// Under Win32, all we have to do is:
|
|
|
|
ChangeDisplaySettings(NULL, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Put display settings back to what they were when the window is maximized.
|
|
|
|
*/
|
|
|
|
void tempRestoreDisplayMode() {
|
|
|
|
// Restore gamma
|
|
|
|
HDC screenDC = GetDC(NULL);
|
|
|
|
if (!SetDeviceGammaRamp(screenDC, currentGamma)) {
|
|
|
|
#ifdef _DEBUG
|
|
|
|
printf("Could not restore device gamma\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
ReleaseDC(NULL, screenDC);
|
|
|
|
|
|
|
|
if (!modeSet) {
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
printf("Attempting to restore the display mode\n");
|
|
|
|
#endif
|
|
|
|
modeSet = true;
|
|
|
|
LONG cdsret = ChangeDisplaySettings(&devmode, CDS_FULLSCREEN);
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
if (cdsret != DISP_CHANGE_SUCCESSFUL) {
|
|
|
|
printf("Failed to restore display mode\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-07 16:54:31 -05:00
|
|
|
/*
|
|
|
|
* Class: org_lwjgl_Display
|
2003-05-27 10:12:10 -04:00
|
|
|
* Method: getGammaRampLength
|
|
|
|
* Signature: ()I
|
2003-02-07 16:54:31 -05:00
|
|
|
*/
|
2003-05-27 10:12:10 -04:00
|
|
|
JNIEXPORT jint JNICALL Java_org_lwjgl_Display_getGammaRampLength
|
|
|
|
(JNIEnv *env, jclass clazz)
|
2003-02-07 16:54:31 -05:00
|
|
|
{
|
2003-05-27 10:12:10 -04:00
|
|
|
return 256;
|
2003-03-27 20:28:04 -05:00
|
|
|
}
|
2003-02-07 16:54:31 -05:00
|
|
|
|
2003-03-27 20:28:04 -05:00
|
|
|
/*
|
|
|
|
* Class: org_lwjgl_Display
|
|
|
|
* Method: setGammaRamp
|
2003-05-27 10:12:10 -04:00
|
|
|
* Signature: (I)Z
|
2003-03-27 20:28:04 -05:00
|
|
|
*/
|
2003-03-29 16:52:14 -05:00
|
|
|
JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_setGammaRamp
|
2003-05-27 10:12:10 -04:00
|
|
|
(JNIEnv * env, jclass clazz, jint gammaRampAddress)
|
2003-03-27 20:28:04 -05:00
|
|
|
{
|
2003-05-27 10:12:10 -04:00
|
|
|
float *gammaRamp = (float *)gammaRampAddress;
|
|
|
|
// Turn array of floats into array of RGB WORDs
|
2003-06-07 15:28:53 -04:00
|
|
|
|
2003-03-29 16:52:14 -05:00
|
|
|
for (int i = 0; i < 256; i ++) {
|
2003-05-27 10:12:10 -04:00
|
|
|
float scaledRampEntry = gammaRamp[i]*0xffff;
|
|
|
|
WORD rampEntry = (WORD)scaledRampEntry;
|
2003-06-07 15:28:53 -04:00
|
|
|
currentGamma[i] = rampEntry;
|
|
|
|
currentGamma[i + 256] = rampEntry;
|
|
|
|
currentGamma[i + 512] = rampEntry;
|
2003-03-29 16:52:14 -05:00
|
|
|
}
|
|
|
|
jboolean ret;
|
|
|
|
HDC screenDC = GetDC(NULL);
|
2003-06-07 15:28:53 -04:00
|
|
|
if (SetDeviceGammaRamp(screenDC, currentGamma) == FALSE) {
|
2003-03-29 16:52:14 -05:00
|
|
|
#ifdef _DEBUG
|
|
|
|
printf("Failed to set device gamma\n");
|
|
|
|
#endif
|
|
|
|
ret = JNI_FALSE;
|
|
|
|
} else {
|
|
|
|
ret = JNI_TRUE;
|
|
|
|
}
|
|
|
|
ReleaseDC(NULL, screenDC);
|
|
|
|
|
|
|
|
return ret;
|
2003-02-07 16:54:31 -05:00
|
|
|
}
|
2003-03-21 12:08:26 -05:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_lwjgl_Display
|
2003-03-27 20:28:04 -05:00
|
|
|
* Method: init
|
|
|
|
* Signature: ()V
|
2003-03-21 12:08:26 -05:00
|
|
|
*/
|
2003-03-27 20:28:04 -05:00
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_Display_init
|
2003-03-21 12:08:26 -05:00
|
|
|
(JNIEnv * env, jclass clazz)
|
|
|
|
{
|
2003-03-27 20:28:04 -05:00
|
|
|
// Determine the current screen resolution
|
|
|
|
// Get the screen
|
2003-03-29 16:52:14 -05:00
|
|
|
HDC screenDC = GetDC(NULL);
|
2003-03-28 14:02:24 -05:00
|
|
|
if (!screenDC) {
|
|
|
|
printf("Couldn't get screen DC!\n");
|
|
|
|
return;
|
|
|
|
}
|
2003-03-27 20:28:04 -05:00
|
|
|
// Get the device caps
|
|
|
|
int width = GetDeviceCaps(screenDC, HORZRES);
|
|
|
|
int height = GetDeviceCaps(screenDC, VERTRES);
|
|
|
|
int bpp = GetDeviceCaps(screenDC, COLORRES);
|
|
|
|
int freq = GetDeviceCaps(screenDC, VREFRESH);
|
|
|
|
if (freq <= 1)
|
|
|
|
freq = 0; // Unknown
|
|
|
|
|
|
|
|
jclass jclass_DisplayMode = env->FindClass("org/lwjgl/DisplayMode");
|
|
|
|
jmethodID ctor = env->GetMethodID(jclass_DisplayMode, "<init>", "(IIII)V");
|
|
|
|
jobject newMode = env->NewObject(jclass_DisplayMode, ctor, width, height, bpp, freq);
|
2003-03-28 14:02:24 -05:00
|
|
|
jfieldID fid_initialMode = env->GetStaticFieldID(clazz, "mode", "Lorg/lwjgl/DisplayMode;");
|
2003-03-27 20:28:04 -05:00
|
|
|
env->SetStaticObjectField(clazz, fid_initialMode, newMode);
|
|
|
|
env->DeleteLocalRef(newMode);
|
2003-03-29 16:52:14 -05:00
|
|
|
|
|
|
|
// Get the default gamma ramp
|
|
|
|
if (GetDeviceGammaRamp(screenDC, originalGamma) == FALSE) {
|
|
|
|
#ifdef _DEBUG
|
|
|
|
printf("Failed to get initial device gamma\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
ReleaseDC(NULL, screenDC);
|
2003-03-21 12:08:26 -05:00
|
|
|
}
|
|
|
|
|
2003-03-27 20:28:04 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|