|
From: Caspian Rychlik-P. <ci...@us...> - 2002-12-22 19:52:47
|
Update of /cvsroot/java-game-lib/LWJGL/src/native/win32 In directory sc8-pr-cvs1:/tmp/cvs-serv9062/src/native/win32 Modified Files: org_lwjgl_Sys.cpp org_lwjgl_Display.cpp Log Message: Alert code & new displaymode code Index: org_lwjgl_Sys.cpp CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/win32/org_lwjgl_Sys.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/win32/org_lwjgl_Sys.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- org_lwjgl_Sys.cpp 15 Aug 2002 15:43:02 -0000 1.2 +++ org_lwjgl_Sys.cpp 22 Dec 2002 19:52:44 -0000 1.3 @@ -42,6 +42,9 @@ #include <windows.h> #include "org_lwjgl_Sys.h" +// Handle to the application's window +extern HWND hwnd; + __int64 hires_timer_freq; // Hires timer frequency __int64 hires_timer_start; // Hires timer start __int64 hires_timer; // Hires timer current time @@ -138,4 +141,25 @@ printf("Failed to set priority class.\n"); #endif } +} + +/* + * Class: org_lwjgl_Sys + * Method: alert + * Signature: (Ljava/lang/String;Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_lwjgl_Sys_alert + (JNIEnv * env, jclass clazz, jstring title, jstring message) +{ + jboolean copy = JNI_FALSE; + const char * eMessageText = env->GetStringUTFChars(message, ©); + const char * cTitleBarText = env->GetStringUTFChars(title, ©); + MessageBox(hwnd, eMessageText, cTitleBarText, MB_OK | MB_TOPMOST); + +#ifdef _DEBUG + printf("*** Alert ***%s\n%s\n", cTitleBarText, eMessageText); +#endif + + env->ReleaseStringUTFChars(message, eMessageText); + env->ReleaseStringUTFChars(title, cTitleBarText); } Index: org_lwjgl_Display.cpp CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/win32/org_lwjgl_Display.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/win32/org_lwjgl_Display.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- org_lwjgl_Display.cpp 19 Dec 2002 16:35:35 -0000 1.10 +++ org_lwjgl_Display.cpp 22 Dec 2002 19:52:44 -0000 1.11 @@ -50,59 +50,59 @@ #define WINDOWCLASSNAME "LWJGLWINDOW" extern HINSTANCE dll_handle; -// Initialise static variables +// Initialise static variables bool oneShotInitialised = false; HWND hwnd = NULL; // Handle to the window HDC hdc = NULL; // Device context -LPDIRECTINPUT lpdi = NULL; - -void destroyDI(void) -{ - lpdi->Release(); - lpdi = NULL; -} - -void destroyWindow(void) -{ - // Reset the display if necessary - ChangeDisplaySettings(NULL, 0); - - if (hwnd != NULL) { - // Vape the window - DestroyWindow(hwnd); - hwnd = NULL; - } - -#ifdef _DEBUG - printf("Destroyed display\n"); -#endif - - // Show the mouse - ShowCursor(TRUE); -} - -void destroyAll(void) -{ - destroyDI(); - destroyWindow(); -} - -void dumpLastError(void) { - LPVOID lpMsgBuf; - FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - GetLastError(), - 0, // Default language - (LPTSTR) &lpMsgBuf, - 0, - NULL - ); - printf("System error: %s\n", lpMsgBuf); - LocalFree(lpMsgBuf); -} +LPDIRECTINPUT lpdi = NULL; + +void destroyDI(void) +{ + lpdi->Release(); + lpdi = NULL; +} + +void destroyWindow(void) +{ + // Reset the display if necessary + ChangeDisplaySettings(NULL, 0); + + if (hwnd != NULL) { + // Vape the window + DestroyWindow(hwnd); + hwnd = NULL; + } + +#ifdef _DEBUG + printf("Destroyed display\n"); +#endif + + // Show the mouse + ShowCursor(TRUE); +} + +void destroyAll(void) +{ + destroyDI(); + destroyWindow(); +} + +void dumpLastError(void) { + LPVOID lpMsgBuf; + FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + GetLastError(), + 0, // Default language + (LPTSTR) &lpMsgBuf, + 0, + NULL + ); + printf("System error: %s\n", lpMsgBuf); + LocalFree(lpMsgBuf); +} /* * A dummy WindowProc which does nothing. Used so we can have an invisible OpenGL window @@ -198,19 +198,30 @@ // Allocate an array of DisplayModes big enough jclass displayModeClass = env->FindClass("org/lwjgl/DisplayMode"); - jobjectArray ret = env->NewObjectArray(n, displayModeClass, NULL); - jmethodID displayModeConstructor = env->GetMethodID(displayModeClass, "<init>", "(IIII)V"); + + // Note the * 32 - this is because we are manufacturing available alpha/depth/stencil combos. + jobjectArray ret = env->NewObjectArray(n * 32, displayModeClass, NULL); + jmethodID displayModeConstructor = env->GetMethodID(displayModeClass, "<init>", "(IIIIIII)V"); i = n = 0; while (EnumDisplaySettings(NULL, i ++, &mode) != 0) { // Filter out indexed modes - if (mode.dmBitsPerPel < 16) { + if (mode.dmBitsPerPel <= 8) { continue; } else { - jobject displayMode = env->NewObject(displayModeClass, displayModeConstructor, mode.dmPelsWidth, mode.dmPelsHeight, - mode.dmBitsPerPel, mode.dmDisplayFrequency); + jobject displayMode; - env->SetObjectArrayElement(ret, n ++, displayMode); + for (int depthBits = 0; depthBits <= 24; depthBits += 8) { + for (int stencilBits = 0; stencilBits <= 8; stencilBits += 8) { + for (int alphaBits = 0; alphaBits <= 8; alphaBits += 8) { + + displayMode = env->NewObject(displayModeClass, displayModeConstructor, mode.dmPelsWidth, mode.dmPelsHeight, + mode.dmBitsPerPel, mode.dmDisplayFrequency, alphaBits, depthBits, stencilBits); + + env->SetObjectArrayElement(ret, n ++, displayMode); + } + } + } } } @@ -223,19 +234,19 @@ * Signature: (IIIIZ)Z */ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate - (JNIEnv * env, jclass clazz, jint width, jint height, jint bpp, jint freq, + (JNIEnv * env, jclass clazz, jint width, jint height, jint bpp, jint freq, jint alphaBits, jint depthBits, jint stencilBits, jboolean fullscreen) { #ifdef _DEBUG printf("Creating display: size %dx%d %dhz %dbpp...\n", width, height, freq, bpp); -#endif +#endif if (fullscreen && SetDisplayMode(width, height, bpp, freq) != 1) return JNI_FALSE; /* Register a window. This window does nothing, it's just a requirement that we get a handle to it so we can do other things - */ + */ if (!oneShotInitialised) { WNDCLASS windowClass; @@ -251,23 +262,31 @@ windowClass.lpszClassName = WINDOWCLASSNAME; if (RegisterClass(&windowClass) == 0) { - dumpLastError(); + dumpLastError(); printf("Failed to register window class\n"); return JNI_FALSE; - } + } oneShotInitialised = true; } + int windowflags; + + if (fullscreen) { + windowflags = WS_POPUP; + } else { + windowflags = WS_POPUP | WS_CAPTION; + } + // Create the window now, using that class: hwnd = CreateWindow( WINDOWCLASSNAME, "LWJGL", - WS_POPUP, // | WS_MAXIMIZE, + windowflags, 0, 0, width, height, NULL, NULL, - GetModuleHandle(NULL), + dll_handle, NULL); // And we never look at windowClass again... @@ -304,98 +323,98 @@ break; default: printf("\n"); - } + } destroyWindow(); return JNI_FALSE; } - int flags = PFD_DRAW_TO_WINDOW | // support window - PFD_SUPPORT_OPENGL | // support OpenGL - PFD_GENERIC_ACCELERATED | - PFD_DOUBLEBUFFER; // double buffered - - PIXELFORMATDESCRIPTOR pfd = { - sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd - 1, // version number - flags, // RGBA type - PFD_TYPE_RGBA, - (BYTE)bpp, - 0, 0, 0, 0, 0, 0, // color bits ignored - (BYTE)alphaBits, - 0, // shift bit ignored - 0, // no accumulation buffer - 0, 0, 0, 0, // accum bits ignored - (BYTE)depthBits, - (BYTE)stencilBits, - 0, // One auxiliary buffer - PFD_MAIN_PLANE, // main layer - 0, // reserved - 0, 0, 0 // layer masks ignored - }; - - // Ensure desktop color depth is adequate - int availableBitDepth = GetDeviceCaps(hdc, BITSPIXEL); - if (availableBitDepth < bpp) { - printf("This application requires a greater colour depth.\n"); - destroyAll(); - return JNI_FALSE; - }; - - int iPixelFormat; - - // get the best available match of pixel format for the device context - iPixelFormat = ChoosePixelFormat(hdc, &pfd); - if (iPixelFormat == 0) { - printf("Failed to choose pixel format.\n"); - destroyAll(); - return JNI_FALSE; - } - - PIXELFORMATDESCRIPTOR desc; - if (DescribePixelFormat(hdc, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &desc) == 0) { - printf("Could not describe pixel format\n"); - destroyAll(); - return JNI_FALSE; - } - - if (desc.cColorBits < bpp) { - printf("This application requires a greater colour depth.\n"); - destroyAll(); - return JNI_FALSE; - } - - if (desc.cStencilBits < stencilBits) { - printf("This application requires a greater stencil depth.\n"); - destroyAll(); - return JNI_FALSE; - } - - if (desc.cDepthBits < depthBits) { - printf("This application requires a greater depth buffer depth.\n"); - destroyAll(); - return JNI_FALSE; - } - - if ((desc.dwFlags & flags) == 0) { - printf("Capabilities not supported.\n"); - destroyAll(); - return JNI_FALSE; - } - -#ifdef _DEBUG - printf("Pixel format is %d\n", iPixelFormat); -#endif - - // make that the pixel format of the device context - if (SetPixelFormat(hdc, iPixelFormat, &pfd) == FALSE) { - printf("Failed to set pixel format\n"); - destroyAll(); - return JNI_FALSE; - } - - jfieldID fid_handle = env->GetStaticFieldID(clazz, "handle", "I"); - env->SetStaticIntField(clazz, fid_handle, (jint) hwnd); - + int flags = PFD_DRAW_TO_WINDOW | // support window + PFD_SUPPORT_OPENGL | // support OpenGL + PFD_GENERIC_ACCELERATED | + PFD_DOUBLEBUFFER; // double buffered + + PIXELFORMATDESCRIPTOR pfd = { + sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd + 1, // version number + flags, // RGBA type + PFD_TYPE_RGBA, + (BYTE)bpp, + 0, 0, 0, 0, 0, 0, // color bits ignored + (BYTE)alphaBits, + 0, // shift bit ignored + 0, // no accumulation buffer + 0, 0, 0, 0, // accum bits ignored + (BYTE)depthBits, + (BYTE)stencilBits, + 0, // No auxiliary buffer + PFD_MAIN_PLANE, // main layer + 0, // reserved + 0, 0, 0 // layer masks ignored + }; + + // Ensure desktop color depth is adequate + int availableBitDepth = GetDeviceCaps(hdc, BITSPIXEL); + if (availableBitDepth < bpp) { + printf("This application requires a greater colour depth.\n"); + destroyAll(); + return JNI_FALSE; + }; + + int iPixelFormat; + + // get the best available match of pixel format for the device context + iPixelFormat = ChoosePixelFormat(hdc, &pfd); + if (iPixelFormat == 0) { + printf("Failed to choose pixel format.\n"); + destroyAll(); + return JNI_FALSE; + } + + PIXELFORMATDESCRIPTOR desc; + if (DescribePixelFormat(hdc, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &desc) == 0) { + printf("Could not describe pixel format\n"); + destroyAll(); + return JNI_FALSE; + } + + if (desc.cColorBits < bpp) { + printf("This application requires a greater colour depth.\n"); + destroyAll(); + return JNI_FALSE; + } + + if (desc.cStencilBits < stencilBits) { + printf("This application requires a greater stencil depth.\n"); + destroyAll(); + return JNI_FALSE; + } + + if (desc.cDepthBits < depthBits) { + printf("This application requires a greater depth buffer depth.\n"); + destroyAll(); + return JNI_FALSE; + } + + if ((desc.dwFlags & flags) == 0) { + printf("Capabilities not supported.\n"); + destroyAll(); + return JNI_FALSE; + } + +#ifdef _DEBUG + printf("Pixel format is %d\n", iPixelFormat); +#endif + + // make that the pixel format of the device context + if (SetPixelFormat(hdc, iPixelFormat, &pfd) == FALSE) { + printf("Failed to set pixel format\n"); + destroyAll(); + return JNI_FALSE; + } + + jfieldID fid_handle = env->GetStaticFieldID(clazz, "handle", "I"); + env->SetStaticIntField(clazz, fid_handle, (jint) hwnd); + return JNI_TRUE; } @@ -406,7 +425,7 @@ */ JNIEXPORT void JNICALL Java_org_lwjgl_Display_nDestroy (JNIEnv * env, jclass clazz) -{ - destroyAll(); -} - +{ + destroyAll(); +} + |