Esempio n. 1
0
void extcl_LoadLibrary(JNIEnv *env, jstring path) {
	char *path_str = GetStringNativeChars(env, path);
	printfDebugJava(env, "Testing '%s'", path_str);
	handleOCL = dlopen(path_str, RTLD_LAZY);
	if (handleOCL != NULL) {
		printfDebugJava(env, "Found OpenCL at '%s'", path_str);
	} else {
		throwException(env, "Could not load OpenCL library");
	}
	free(path_str);
}
Esempio n. 2
0
void extal_LoadLibrary(JNIEnv *env, jstring path) {
	char *path_str = GetStringNativeChars(env, path);
	printfDebugJava(env, "Testing '%s'", path_str);
	handleOAL = LoadLibrary(path_str);
	if (handleOAL != NULL) {
		printfDebugJava(env, "Found OpenAL at '%s'", path_str);
	} else {
		throwFormattedException(env, "Could not load OpenAL library (%d)", GetLastError());
	}
	free(path_str);
}
JNIEXPORT void JNICALL Java_org_lwjgl_WindowsSysImplementation_nAlert(JNIEnv * env, jclass unused, jlong hwnd_ptr, jstring title, jstring message) {
	HWND hwnd = (HWND)(INT_PTR)hwnd_ptr;
	char * eMessageText = GetStringNativeChars(env, message);
	char * cTitleBarText = GetStringNativeChars(env, title);
	MessageBox(hwnd, eMessageText, cTitleBarText, MB_OK | MB_TOPMOST);

	printfDebugJava(env, "*** Alert ***%s\n%s\n", cTitleBarText, eMessageText);
	
	free(eMessageText);
	free(cTitleBarText);
}
Esempio n. 4
0
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXMouseEventQueue_getMouseDeltas(JNIEnv *env, jclass unused, jobject delta_buffer) {
    CGMouseDelta dx, dy;
    CGGetLastMouseDelta(&dx, &dy);
    int buffer_length = (*env)->GetDirectBufferCapacity(env, delta_buffer);
    if (buffer_length != 2) {
        printfDebugJava(env, "Delta buffer not large enough!");
        return;
    }
    jint *buffer = (*env)->GetDirectBufferAddress(env, delta_buffer);
    buffer[0] = dx;
    buffer[1] = dy;
}
Esempio n. 5
0
/**
 * Choose displaymodes using extended codepath (multiple displaydevices)
 */
jobjectArray getAvailableDisplayModes(JNIEnv * env) {

	int i = 0, j = 0, n = 0;

//	DISPLAY_DEVICE DisplayDevice;
	DEVMODE DevMode;
	jobject *display_mode_objects = NULL;
	int list_size = 0;

	jclass displayModeClass;
	jobjectArray ret;
	displayModeClass = (*env)->FindClass(env, "org/lwjgl/opengl/DisplayMode");

	ZeroMemory(&DevMode, sizeof(DEVMODE));
//	ZeroMemory(&DisplayDevice, sizeof(DISPLAY_DEVICE));

	DevMode.dmSize = sizeof(DEVMODE);
//	DisplayDevice.cb = sizeof(DISPLAY_DEVICE);

	/* Multi-monitor stuff commented out since we're only really interested in the primary monitor */
/*	while(EnumDisplayDevices(NULL, i++, &DisplayDevice, 0) != 0) {
		// continue if mirroring device
		if((DisplayDevice.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER) != 0) {
			continue;
		}

		j = 0;
		while(EnumDisplaySettings((const char *) DisplayDevice.DeviceName, j++, &DevMode) != 0) {*/
		while(EnumDisplaySettings(NULL, j++, &DevMode) != 0) {
			// Filter out indexed modes
			if (DevMode.dmBitsPerPel > 8 && ChangeDisplaySettings(&DevMode, CDS_FULLSCREEN | CDS_TEST) == DISP_CHANGE_SUCCESSFUL) {
				jobject displayMode;
				if (list_size <= n) {
					list_size += 1;
					display_mode_objects = (jobject *)realloc(display_mode_objects, sizeof(jobject)*list_size);
					if (display_mode_objects == NULL)
						return NULL;
				}
				displayMode = createDisplayMode(env, &DevMode);
				display_mode_objects[n++] = displayMode;
			}
		}
//	}
	printfDebugJava(env, "Found %d displaymodes", n);

	ret = (*env)->NewObjectArray(env, n, displayModeClass, NULL);
	for (i = 0; i < n; i++) {
		(*env)->SetObjectArrayElement(env, ret, i, display_mode_objects[i]);
	}
	free(display_mode_objects);   
	return ret;
}
static bool getExtensions(JNIEnv *env, WGLExtensions *extensions, jobject pixel_format, jobject pixelFormatCaps) {
	int origin_x = 0; int origin_y = 0;
	HWND dummy_hwnd;
	HDC dummy_hdc;
	HGLRC dummy_context;
	HDC saved_hdc;
	HGLRC saved_context;
	int pixel_format_id;

	dummy_hwnd = createDummyWindow(origin_x, origin_y);
	if (dummy_hwnd == NULL) {
		throwException(env, "Could not create dummy window");
		return false;
	}
	dummy_hdc = GetDC(dummy_hwnd);
	pixel_format_id = findPixelFormatOnDC(env, dummy_hdc, origin_x, origin_y, pixel_format, pixelFormatCaps, false, true, false, false);
	if (pixel_format_id == -1) {
		closeWindow(&dummy_hwnd, &dummy_hdc);
		return false;
	}
	if (!applyPixelFormat(env, dummy_hdc, pixel_format_id)) {
		closeWindow(&dummy_hwnd, &dummy_hdc);
		return false;
	}
	dummy_context = wglCreateContext(dummy_hdc);
	if (dummy_context == NULL) {
		closeWindow(&dummy_hwnd, &dummy_hdc);
		throwException(env, "Could not create dummy context");
		return false;
	}
	saved_hdc = wglGetCurrentDC();
	saved_context = wglGetCurrentContext();
	if (!wglMakeCurrent(dummy_hdc, dummy_context)) {
		wglMakeCurrent(saved_hdc, saved_context);
		closeWindow(&dummy_hwnd, &dummy_hdc);
		wglDeleteContext(dummy_context);
		throwException(env, "Could not make dummy context current");
		return false;
	}
	extgl_InitWGL(extensions);
	if (!wglMakeCurrent(saved_hdc, saved_context))
		printfDebugJava(env, "ERROR: Could not restore current context");
	closeWindow(&dummy_hwnd, &dummy_hdc);
	wglDeleteContext(dummy_context);
	return true;
}
Esempio n. 7
0
static int findPixelFormatDefault(JNIEnv *env, HDC hdc, jobject pixel_format, bool use_hdc_bpp, bool double_buffer) {
	int bpp;
	int iPixelFormat;
	int fallback_bpp = 16;
	jclass cls_pixel_format = (*env)->GetObjectClass(env, pixel_format);
	if (use_hdc_bpp) {
		bpp = GetDeviceCaps(hdc, BITSPIXEL);
		iPixelFormat = findPixelFormatFromBPP(env, hdc, pixel_format, bpp, double_buffer);
		if ((*env)->ExceptionOccurred(env)) {
			(*env)->ExceptionClear(env);
			printfDebugJava(env, "Failed to find pixel format with HDC depth %d, falling back to %d\n", bpp, fallback_bpp);
			bpp = fallback_bpp;
		} else
			return iPixelFormat;
	} else
		bpp = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "bpp", "I"));
	return findPixelFormatFromBPP(env, hdc, pixel_format, bpp, double_buffer);
}
Esempio n. 8
0
jobject getCurrentGammaRamp(JNIEnv *env) {
	jobject gamma_buffer;
	WORD *gamma;
	HDC screenDC;

	gamma_buffer = createNativeGammaBuffer(env);
	if (gamma_buffer == NULL)
		return NULL;
	gamma = (WORD *)(*env)->GetDirectBufferAddress(env, gamma_buffer);

	// Get the screen
	screenDC = GetDC(NULL);
	if (screenDC == NULL) {
		throwException(env, "Couldn't get screen DC!");
		return NULL;
	}
	// Get the default gamma ramp
	if (GetDeviceGammaRamp(screenDC, gamma) == FALSE) {
		printfDebugJava(env, "Failed to get initial device gamma");
	}
	ReleaseDC(NULL, screenDC);
	return gamma_buffer;
}