From: Elias N. <eli...@us...> - 2002-12-19 16:35:39
|
Update of /cvsroot/java-game-lib/LWJGL/src/native/win32 In directory sc8-pr-cvs1:/tmp/cvs-serv17077/src/native/win32 Modified Files: org_lwjgl_Display.cpp org_lwjgl_input_Keyboard.cpp org_lwjgl_input_Mouse.cpp org_lwjgl_opengl_BaseGL.cpp Log Message: Moved BaseGL constructor parameters to Display 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.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- org_lwjgl_Display.cpp 18 Dec 2002 16:40:12 -0000 1.9 +++ org_lwjgl_Display.cpp 19 Dec 2002 16:35:35 -0000 1.10 @@ -56,6 +56,37 @@ 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( @@ -192,7 +223,8 @@ * Signature: (IIIIZ)Z */ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate - (JNIEnv * env, jclass clazz, jint width, jint height, jint bpp, jint freq, jboolean fullscreen) + (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); @@ -259,7 +291,7 @@ printf("Failed to create directinput"); switch (ret) { case DIERR_BETADIRECTINPUTVERSION : - printf(" - Beta versio0n\n"); + printf(" - Beta version\n"); break; case DIERR_INVALIDPARAM : printf(" - Invalid parameter\n"); @@ -272,13 +304,98 @@ break; default: printf("\n"); - } + } + destroyWindow(); 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, // 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); + return JNI_TRUE; } @@ -289,20 +406,7 @@ */ JNIEXPORT void JNICALL Java_org_lwjgl_Display_nDestroy (JNIEnv * env, jclass clazz) -{ - // 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); -} +{ + destroyAll(); +} + Index: org_lwjgl_input_Keyboard.cpp CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/win32/org_lwjgl_input_Keyboard.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/win32/org_lwjgl_input_Keyboard.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- org_lwjgl_input_Keyboard.cpp 27 Aug 2002 20:42:47 -0000 1.4 +++ org_lwjgl_input_Keyboard.cpp 19 Dec 2002 16:35:35 -0000 1.5 @@ -137,14 +137,6 @@ lpdiKeyboard->Release(); lpdiKeyboard = NULL; } - - // Release directinput if the mouse is not present - if (lpdi != NULL) { - // Release directinput - lpdi->Release(); - lpdi = NULL; - - } } /* Index: org_lwjgl_input_Mouse.cpp CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/win32/org_lwjgl_input_Mouse.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/win32/org_lwjgl_input_Mouse.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- org_lwjgl_input_Mouse.cpp 12 Dec 2002 20:04:56 -0000 1.4 +++ org_lwjgl_input_Mouse.cpp 19 Dec 2002 16:35:35 -0000 1.5 @@ -154,12 +154,6 @@ lpdiMouse = NULL; } - // Release directinput - if (lpdi != NULL) { - // Release directinput - lpdi->Release(); - lpdi = NULL; - } } /* Index: org_lwjgl_opengl_BaseGL.cpp CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/win32/org_lwjgl_opengl_BaseGL.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/win32/org_lwjgl_opengl_BaseGL.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- org_lwjgl_opengl_BaseGL.cpp 12 Dec 2002 22:04:05 -0000 1.8 +++ org_lwjgl_opengl_BaseGL.cpp 19 Dec 2002 16:35:35 -0000 1.9 @@ -53,86 +53,11 @@ * Signature: (IIII)Z */ JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_BaseGL_nCreate - (JNIEnv * env, jobject obj, jint colorBits, jint alphaBits, jint depthBits, jint stencilBits) + (JNIEnv * env, jobject obj) { if (!hwnd) { printf("No window handle\n"); - 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)colorBits, - 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 < colorBits) { - printf("This application requires a greater colour depth.\n"); - 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"); - return JNI_FALSE; - } - - PIXELFORMATDESCRIPTOR desc; - if (DescribePixelFormat(hdc, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &desc) == 0) { - printf("Could not describe pixel format\n"); - return JNI_FALSE; - } - - if (desc.cColorBits < colorBits) { - printf("This application requires a greater colour depth.\n"); - return JNI_FALSE; - } - - if (desc.cStencilBits < stencilBits) { - printf("This application requires a greater stencil depth.\n"); - return JNI_FALSE; - } - - if (desc.cDepthBits < depthBits) { - printf("This application requires a greater depth buffer depth.\n"); - return JNI_FALSE; - } - - if ((desc.dwFlags & flags) == 0) { - printf("Capabilities not supported.\n"); - 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"); return JNI_FALSE; } if (extgl_Open() != 0) |