/** * Tries to locate named library from the current ClassLoader This method exists because native * libraries are loaded from native code, and as such is exempt from ClassLoader library loading * rutines. It therefore always fails. We therefore invoke the protected method of the ClassLoader * to see if it can locate it. * * @param libname Name of library to search for * @param classloader Classloader to use * @return Absolute path to library if found, otherwise null */ private static String getPathFromClassLoader( final String libname, final ClassLoader classloader) { try { log("getPathFromClassLoader: searching for: " + libname); Class<?> c = classloader.getClass(); while (c != null) { final Class<?> clazz = c; try { return AccessController.doPrivileged( new PrivilegedExceptionAction<String>() { public String run() throws Exception { Method findLibrary = clazz.getDeclaredMethod("findLibrary", String.class); findLibrary.setAccessible(true); String path = (String) findLibrary.invoke(classloader, libname); return path; } }); } catch (PrivilegedActionException e) { log("Failed to locate findLibrary method: " + e.getCause()); c = c.getSuperclass(); } } } catch (Exception e) { log("Failure locating " + e + " using classloader:" + e); } return null; }
private static void initControls() { // Automatically create mouse, keyboard and controller if (!getPrivilegedBoolean("org.lwjgl.opengl.Display.noinput")) { if (!Mouse.isCreated() && !getPrivilegedBoolean("org.lwjgl.opengl.Display.nomouse")) { try { Mouse.create(); } catch (LWJGLException e) { if (LWJGLUtil.DEBUG) { e.printStackTrace(System.err); } else { LWJGLUtil.log("Failed to create Mouse: " + e); } } } if (!Keyboard.isCreated() && !getPrivilegedBoolean("org.lwjgl.opengl.Display.nokeyboard")) { try { Keyboard.create(); } catch (LWJGLException e) { if (LWJGLUtil.DEBUG) { e.printStackTrace(System.err); } else { LWJGLUtil.log("Failed to create Keyboard: " + e); } } } } }
private void restoreDisplayMode() { try { doSetGammaRamp(current_gamma); } catch (LWJGLException e) { LWJGLUtil.log("Failed to restore gamma: " + e.getMessage()); } if (!mode_set) { mode_set = true; try { nSwitchDisplayMode(current_mode); } catch (LWJGLException e) { LWJGLUtil.log("Failed to restore display mode: " + e.getMessage()); } } }
/** * Locates the paths required by a library. * * @param libname Local Library Name to search the classloader with ("openal"). * @param platform_lib_names The list of possible library names ("libopenal.so") * @param classloader The classloader to ask for library paths * @return Paths to located libraries, if any */ public static String[] getLibraryPaths( String libname, String[] platform_lib_names, ClassLoader classloader) { // need to pass path of possible locations of library to native side List<String> possible_paths = new ArrayList<String>(); String classloader_path = getPathFromClassLoader(libname, classloader); if (classloader_path != null) { log("getPathFromClassLoader: Path found: " + classloader_path); possible_paths.add(classloader_path); } for (String platform_lib_name : platform_lib_names) { String lwjgl_classloader_path = getPathFromClassLoader("lwjgl", classloader); if (lwjgl_classloader_path != null) { log("getPathFromClassLoader: Path found: " + lwjgl_classloader_path); possible_paths.add( lwjgl_classloader_path.substring(0, lwjgl_classloader_path.lastIndexOf(File.separator)) + File.separator + platform_lib_name); } // add Installer path String alternative_path = getPrivilegedProperty("org.lwjgl.librarypath"); if (alternative_path != null) { possible_paths.add(alternative_path + File.separator + platform_lib_name); } // Add all possible paths from java.library.path String java_library_path = getPrivilegedProperty("java.library.path"); StringTokenizer st = new StringTokenizer(java_library_path, File.pathSeparator); while (st.hasMoreTokens()) { String path = st.nextToken(); possible_paths.add(path + File.separator + platform_lib_name); } // add current path String current_dir = getPrivilegedProperty("user.dir"); possible_paths.add(current_dir + File.separator + platform_lib_name); // add pure library (no path, let OS search) possible_paths.add(platform_lib_name); } // create needed string array return possible_paths.toArray(new String[possible_paths.size()]); }
private void updateCursor() { try { if (mouse != null && shouldGrab()) nSetNativeCursor(getHwnd(), mouse.getBlankCursor()); else nSetNativeCursor(getHwnd(), current_cursor); } catch (LWJGLException e) { LWJGLUtil.log("Failed to update cursor: " + e); } }
private static void makeCurrentAndSetSwapInterval() throws LWJGLException { makeCurrent(); try { drawable.checkGLError(); } catch (OpenGLException e) { LWJGLUtil.log("OpenGL error during context creation: " + e.getMessage()); } setSwapInterval(swap_interval); }
public boolean openURL(String url) { try { FileManager.openURL(url); return true; } catch (Exception e) { LWJGLUtil.log("Exception occurred while trying to invoke browser: " + e); return false; } }
public int getPbufferCapabilities() { try { // Return the capabilities of a minimum pixel format return nGetPbufferCapabilities(new PixelFormat(0, 0, 0, 0, 0, 0, 0, 0, false)); } catch (LWJGLException e) { LWJGLUtil.log("Exception occurred while determining pbuffer capabilities: " + e); return 0; } }
static void resetCursorClipping() { if (cursor_clipped) { try { clipCursor(null); } catch (LWJGLException e) { LWJGLUtil.log("Failed to reset cursor clipping: " + e); } cursor_clipped = false; } }
static { Sys.initialize(); display_impl = createDisplayImplementation(); try { current_mode = initial_mode = display_impl.init(); LWJGLUtil.log("Initial mode: " + initial_mode); } catch (LWJGLException e) { throw new RuntimeException(e); } ; }
private static void releaseDrawable() { try { Context context = drawable.getContext(); if (context != null && context.isCurrent()) { context.releaseCurrent(); context.releaseDrawable(); } } catch (LWJGLException e) { LWJGLUtil.log("Exception occurred while trying to release context: " + e); } }
public void resetDisplayMode() { try { doSetGammaRamp(saved_gamma); } catch (LWJGLException e) { LWJGLUtil.log("Failed to reset gamma ramp: " + e.getMessage()); } current_gamma = saved_gamma; if (mode_set) { mode_set = false; nResetDisplayMode(); } resetCursorClipping(); }
private void updateClipping() { if ((Display.isFullscreen() || (mouse != null && mouse.isGrabbed())) && !isMinimized && isFocused && (getForegroundWindow() == getHwnd() || hasParent)) { try { setupCursorClipping(getHwnd()); } catch (LWJGLException e) { LWJGLUtil.log("setupCursorClipping failed: " + e.getMessage()); } } else { resetCursorClipping(); } }
/** * Method to determine if the current system is running a version of Mac OS X better than the * given version. This is only useful for Mac OS X specific code and will not work for any other * platform. */ public static boolean isMacOSXEqualsOrBetterThan(int major_required, int minor_required) { String os_version = getPrivilegedProperty("os.version"); StringTokenizer version_tokenizer = new StringTokenizer(os_version, "."); int major; int minor; try { String major_str = version_tokenizer.nextToken(); String minor_str = version_tokenizer.nextToken(); major = Integer.parseInt(major_str); minor = Integer.parseInt(minor_str); } catch (Exception e) { LWJGLUtil.log("Exception occurred while trying to determine OS version: " + e); // Best guess, no return false; } return major > major_required || (major == major_required && minor >= minor_required); }
public void update() { nUpdate(); if (!isFocused && parent != null && parent_focused.compareAndSet(true, false)) { setFocus(getHwnd()); } if (redoMakeContextCurrent) { redoMakeContextCurrent = false; /** * WORKAROUND: Making the context current (redundantly) when the window is maximized helps * some gfx cards recover from fullscreen */ try { Context context = ((DrawableLWJGL) Display.getDrawable()).getContext(); if (context != null && context.isCurrent()) context.makeCurrent(); } catch (LWJGLException e) { LWJGLUtil.log("Exception occurred while trying to make context current: " + e); } } }
/** * Returns the entire list of possible fullscreen display modes as an array, in no particular * order. Although best attempts to filter out invalid modes are done, any given mode is not * guaranteed to be available nor is it guaranteed to be within the current monitor specs (this is * especially a problem with the frequency parameter). Furthermore, it is not guaranteed that * create() will detect an illegal display mode. * * <p>The only certain way to check is to call create() and make sure it works. Only * non-palette-indexed modes are returned (ie. bpp will be 16, 24, or 32). Only DisplayModes from * this call can be used when the Display is in fullscreen mode. * * @return an array of all display modes the system reckons it can handle. */ public static DisplayMode[] getAvailableDisplayModes() throws LWJGLException { synchronized (GlobalLock.lock) { DisplayMode[] unfilteredModes = display_impl.getAvailableDisplayModes(); if (unfilteredModes == null) { return new DisplayMode[0]; } // We'll use a HashSet to filter out the duplicated modes HashSet<DisplayMode> modes = new HashSet<DisplayMode>(unfilteredModes.length); modes.addAll(Arrays.asList(unfilteredModes)); DisplayMode[] filteredModes = new DisplayMode[modes.size()]; modes.toArray(filteredModes); LWJGLUtil.log( "Removed " + (unfilteredModes.length - filteredModes.length) + " duplicate displaymodes"); return filteredModes; } }
/** * Set the display configuration to the specified gamma, brightness and contrast. The * configuration changes will be reset when destroy() is called. * * @param gamma The gamma value * @param brightness The brightness value between -1.0 and 1.0, inclusive * @param contrast The contrast, larger than 0.0. */ public static void setDisplayConfiguration(float gamma, float brightness, float contrast) throws LWJGLException { synchronized (GlobalLock.lock) { if (!isCreated()) { throw new LWJGLException("Display not yet created."); } if (brightness < -1.0f || brightness > 1.0f) throw new IllegalArgumentException("Invalid brightness value"); if (contrast < 0.0f) throw new IllegalArgumentException("Invalid contrast value"); int rampSize = display_impl.getGammaRampLength(); if (rampSize == 0) { throw new LWJGLException("Display configuration not supported"); } FloatBuffer gammaRamp = BufferUtils.createFloatBuffer(rampSize); for (int i = 0; i < rampSize; i++) { float intensity = (float) i / (rampSize - 1); // apply gamma float rampEntry = (float) java.lang.Math.pow(intensity, gamma); // apply brightness rampEntry += brightness; // apply contrast rampEntry = (rampEntry - 0.5f) * contrast + 0.5f; // Clamp entry to [0, 1] if (rampEntry > 1.0f) rampEntry = 1.0f; else if (rampEntry < 0.0f) rampEntry = 0.0f; gammaRamp.put(i, rampEntry); } display_impl.setGammaRamp(gammaRamp); LWJGLUtil.log( "Gamma set, gamma = " + gamma + ", brightness = " + brightness + ", contrast = " + contrast); } }
public String getAdapter() { try { String maxObjNo = WindowsRegistry.queryRegistrationKey( WindowsRegistry.HKEY_LOCAL_MACHINE, "HARDWARE\\DeviceMap\\Video", "MaxObjectNumber"); int maxObjectNumber = maxObjNo.charAt(0); String vga_driver_value = ""; for (int i = 0; i < maxObjectNumber; i++) { String adapter_string = WindowsRegistry.queryRegistrationKey( WindowsRegistry.HKEY_LOCAL_MACHINE, "HARDWARE\\DeviceMap\\Video", "\\Device\\Video" + i); String root_key = "\\registry\\machine\\"; if (adapter_string.toLowerCase().startsWith(root_key)) { String driver_value = WindowsRegistry.queryRegistrationKey( WindowsRegistry.HKEY_LOCAL_MACHINE, adapter_string.substring(root_key.length()), "InstalledDisplayDrivers"); if (driver_value.toUpperCase().startsWith("VGA")) { vga_driver_value = driver_value; } else if (!driver_value.toUpperCase().startsWith("RDP") && !driver_value.toUpperCase().startsWith("NMNDD")) { return driver_value; } } } if (!vga_driver_value.equals("")) { return vga_driver_value; } } catch (LWJGLException e) { LWJGLUtil.log("Exception occurred while querying registry: " + e); } return null; }
private long doHandleMessage(long hwnd, int msg, long wParam, long lParam, long millis) { /*switch ( msg ) { case 0x0: case 0x0020: case 0x0084: case WM_MOUSEMOVE: break; default: WindowsEventDebug.printMessage(msg, wParam, lParam); }*/ if (parent != null && !isFocused) { switch (msg) { case WM_LBUTTONDOWN: case WM_RBUTTONDOWN: case WM_MBUTTONDOWN: case WM_XBUTTONDOWN: sendMessage(parent_hwnd, msg, wParam, lParam); } } switch (msg) { // disable screen saver and monitor power down messages which wreak havoc case WM_ACTIVATE: /*switch ((int)wParam) { case WA_ACTIVE: case WA_CLICKACTIVE: appActivate(true); break; case WA_INACTIVE: appActivate(false); break; }*/ return 0L; case WM_SIZE: switch ((int) wParam) { case SIZE_RESTORED: case SIZE_MAXIMIZED: maximized = ((int) wParam) == SIZE_MAXIMIZED; resized = true; updateWidthAndHeight(); setMinimized(false); break; case SIZE_MINIMIZED: setMinimized(true); break; } break; case WM_SIZING: resized = true; updateWidthAndHeight(); break; case WM_SETCURSOR: if ((lParam & 0xFFFF) == HTCLIENT) { // if the cursor is inside the client area, reset it // to the current LWJGL-cursor updateCursor(); return -1; // TRUE } else { // let Windows handle cursors outside the client area for resizing, etc. return defWindowProc(hwnd, msg, wParam, lParam); } case WM_KILLFOCUS: appActivate(false); return 0L; case WM_SETFOCUS: appActivate(true); return 0L; case WM_MOUSEACTIVATE: if (parent != null) { if (!isFocused) grabFocus(); return 3L; // MA_NOACTIVATE } break; case WM_MOUSEMOVE: int xPos = (int) (short) (lParam & 0xFFFF); int yPos = transformY(getHwnd(), (int) (short) ((lParam >> 16) & 0xFFFF)); handleMouseMoved(xPos, yPos, millis); checkCursorState(); mouseInside = true; if (!trackingMouse) { trackingMouse = nTrackMouseEvent(hwnd); } return 0L; case WM_MOUSEWHEEL: int dwheel = (int) (short) ((wParam >> 16) & 0xFFFF); handleMouseScrolled(dwheel, millis); return 0L; case WM_LBUTTONDOWN: handleMouseButton(0, 1, millis); return 0L; case WM_LBUTTONUP: handleMouseButton(0, 0, millis); return 0L; case WM_RBUTTONDOWN: handleMouseButton(1, 1, millis); return 0L; case WM_RBUTTONUP: handleMouseButton(1, 0, millis); return 0L; case WM_MBUTTONDOWN: handleMouseButton(2, 1, millis); return 0L; case WM_MBUTTONUP: handleMouseButton(2, 0, millis); return 0L; case WM_XBUTTONUP: if ((wParam >> 16) == XBUTTON1) { handleMouseButton(3, 0, millis); } else { handleMouseButton(4, 0, millis); } return 1; case WM_XBUTTONDOWN: if ((wParam & 0xFF) == MK_XBUTTON1) { handleMouseButton(3, 1, millis); } else { handleMouseButton(4, 1, millis); } return 1; case WM_SYSCHAR: case WM_CHAR: handleChar(wParam, lParam, millis); return 0L; case WM_SYSKEYUP: /* Fall through */ case WM_KEYUP: // SysRq apparently only generates WM_KEYUP, so we'll fake a WM_KEYDOWN if (wParam == WindowsKeycodes.VK_SNAPSHOT && keyboard != null && !keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_SYSRQ)) { // Set key state to pressed long fake_lparam = lParam & ~(1 << 31); // Set key previous state to released fake_lparam &= ~(1 << 30); handleKeyButton(wParam, fake_lparam, millis); } /* Fall through */ case WM_SYSKEYDOWN: /* Fall through */ case WM_KEYDOWN: handleKeyButton(wParam, lParam, millis); break; case WM_QUIT: close_requested = true; return 0L; case WM_SYSCOMMAND: switch ((int) (wParam & 0xfff0)) { case SC_KEYMENU: case SC_MOUSEMENU: case SC_SCREENSAVE: case SC_MONITORPOWER: return 0L; case SC_CLOSE: close_requested = true; return 0L; default: break; } break; case WM_PAINT: is_dirty = true; break; case WM_MOUSELEAVE: mouseInside = false; trackingMouse = false; break; case WM_CANCELMODE: nReleaseCapture(); /* fall through */ case WM_CAPTURECHANGED: if (captureMouse != -1) { handleMouseButton(captureMouse, 0, millis); captureMouse = -1; } return 0L; case WM_WINDOWPOSCHANGED: if (getWindowRect(hwnd, rect_buffer)) { rect.copyFromBuffer(rect_buffer); x = rect.top; y = rect.bottom; } else { LWJGLUtil.log("WM_WINDOWPOSCHANGED: Unable to get window rect"); } break; case WM_GETICON: iconsLoaded = true; break; } return defWindowProc(hwnd, msg, wParam, lParam); }