use of org.lwjgl.LWJGLException in project lwjgl by LWJGL.
the class AL method create.
/**
* @param openDevice Whether to automatically open the device
* @see #create(String, int, int, boolean)
*/
public static void create(String deviceArguments, int contextFrequency, int contextRefresh, boolean contextSynchronized, boolean openDevice) throws LWJGLException {
if (created)
throw new IllegalStateException("Only one OpenAL context may be instantiated at any one time.");
String libname;
String[] library_names;
switch(LWJGLUtil.getPlatform()) {
case LWJGLUtil.PLATFORM_WINDOWS:
if (Sys.is64Bit()) {
libname = "OpenAL64";
library_names = new String[] { "OpenAL64.dll" };
} else {
libname = "OpenAL32";
library_names = new String[] { "OpenAL32.dll" };
}
break;
case LWJGLUtil.PLATFORM_LINUX:
libname = "openal";
library_names = new String[] { "libopenal64.so", "libopenal.so", "libopenal.so.0" };
break;
case LWJGLUtil.PLATFORM_MACOSX:
libname = "openal";
library_names = new String[] { "openal.dylib" };
break;
default:
throw new LWJGLException("Unknown platform: " + LWJGLUtil.getPlatform());
}
String[] oalPaths = LWJGLUtil.getLibraryPaths(libname, library_names, AL.class.getClassLoader());
LWJGLUtil.log("Found " + oalPaths.length + " OpenAL paths");
for (String oalPath : oalPaths) {
try {
nCreate(oalPath);
created = true;
init(deviceArguments, contextFrequency, contextRefresh, contextSynchronized, openDevice);
break;
} catch (LWJGLException e) {
LWJGLUtil.log("Failed to load " + oalPath + ": " + e.getMessage());
}
}
if (!created && LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_MACOSX) {
// Try to load OpenAL from the framework instead
nCreateDefault();
created = true;
init(deviceArguments, contextFrequency, contextRefresh, contextSynchronized, openDevice);
}
if (!created)
throw new LWJGLException("Could not locate OpenAL library.");
}
use of org.lwjgl.LWJGLException in project lwjgl by LWJGL.
the class DisplayTest method setDisplayModeTest.
/**
* Tests setting display modes
*/
private void setDisplayModeTest() throws LWJGLException {
DisplayMode mode = null;
DisplayMode[] modes = null;
System.out.println("==== Test setDisplayMode ====");
System.out.println("Retrieving available displaymodes");
modes = Display.getAvailableDisplayModes();
// no modes check
if (modes == null) {
System.out.println("FATAL: unable to find any modes!");
System.exit(-1);
}
// find a mode
System.out.print("Looking for 640x480...");
for (DisplayMode mode1 : modes) {
if (mode1.getWidth() == 640 && mode1.getHeight() == 480) {
mode = mode1;
System.out.println("found!");
break;
}
}
// no mode check
if (mode == null) {
System.out.println("error\nFATAL: Unable to find basic mode.");
System.exit(-1);
}
// change to mode, and wait a bit
System.out.print("Changing to mode...");
try {
Display.setDisplayMode(mode);
Display.setFullscreen(true);
Display.create();
} catch (Exception e) {
System.out.println("error\nFATAL: Error setting mode");
System.exit(-1);
}
System.out.println("done");
System.out.println("Resolution: " + Display.getDisplayMode().getWidth() + "x" + Display.getDisplayMode().getHeight() + "x" + Display.getDisplayMode().getBitsPerPixel() + "@" + Display.getDisplayMode().getFrequency() + "Hz");
pause(5000);
// reset
System.out.print("Resetting mode...");
try {
Display.setFullscreen(false);
} catch (LWJGLException e) {
e.printStackTrace();
}
System.out.println("done");
System.out.println("---- Test setDisplayMode ----");
}
use of org.lwjgl.LWJGLException in project lwjgl by LWJGL.
the class Display method setDisplayConfiguration.
/**
* 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);
}
}
use of org.lwjgl.LWJGLException in project lwjgl by LWJGL.
the class Display method createWindow.
/**
* Create the native window peer from the given mode and fullscreen flag.
* A native context must exist, and it will be attached to the window.
*/
private static void createWindow() throws LWJGLException {
if (window_created) {
return;
}
Canvas tmp_parent = isFullscreen() ? null : parent;
if (// Only a best effort check, since the parent can turn undisplayable hereafter
tmp_parent != null && !tmp_parent.isDisplayable())
throw new LWJGLException("Parent.isDisplayable() must be true");
if (tmp_parent != null) {
tmp_parent.addComponentListener(component_listener);
}
DisplayMode mode = getEffectiveMode();
display_impl.createWindow(drawable, mode, tmp_parent, getWindowX(), getWindowY());
window_created = true;
width = Display.getDisplayMode().getWidth();
height = Display.getDisplayMode().getHeight();
setTitle(title);
initControls();
// set cached window icon if exists
if (cached_icons != null) {
setIcon(cached_icons);
} else {
setIcon(new ByteBuffer[] { LWJGLUtil.LWJGLIcon32x32, LWJGLUtil.LWJGLIcon16x16 });
}
}
use of org.lwjgl.LWJGLException in project lwjgl by LWJGL.
the class LinuxCanvasImplementation method findConfiguration.
/**
* Find a proper GraphicsConfiguration from the given GraphicsDevice and PixelFormat.
*
* @return The GraphicsConfiguration corresponding to a visual that matches the pixel format.
*/
public GraphicsConfiguration findConfiguration(GraphicsDevice device, PixelFormat pixel_format) throws LWJGLException {
try {
int screen = getScreenFromDevice(device);
int visual_id_matching_format = findVisualIDFromFormat(screen, pixel_format);
GraphicsConfiguration[] configurations = device.getConfigurations();
for (GraphicsConfiguration configuration : configurations) {
int visual_id = getVisualIDFromConfiguration(configuration);
if (visual_id == visual_id_matching_format)
return configuration;
}
} catch (LWJGLException e) {
LWJGLUtil.log("Got exception while trying to determine configuration: " + e);
}
// In case we failed to locate the visual, or if we're not on a SUN JDK
return null;
}
Aggregations