use of com.badlogic.gdx.utils.GdxRuntimeException in project libgdx by libgdx.
the class LwjglGraphics method setupDisplay.
void setupDisplay() throws LWJGLException {
if (config.useHDPI) {
System.setProperty("org.lwjgl.opengl.Display.enableHighDPI", "true");
}
if (canvas != null) {
Display.setParent(canvas);
} else {
boolean displayCreated = false;
if (!config.fullscreen) {
displayCreated = setWindowedMode(config.width, config.height);
} else {
DisplayMode bestMode = null;
for (DisplayMode mode : getDisplayModes()) {
if (mode.width == config.width && mode.height == config.height) {
if (bestMode == null || bestMode.refreshRate < this.getDisplayMode().refreshRate) {
bestMode = mode;
}
}
}
if (bestMode == null) {
bestMode = this.getDisplayMode();
}
displayCreated = setFullscreenMode(bestMode);
}
if (!displayCreated) {
if (config.setDisplayModeCallback != null) {
config = config.setDisplayModeCallback.onFailure(config);
if (config != null) {
displayCreated = setWindowedMode(config.width, config.height);
}
}
if (!displayCreated) {
throw new GdxRuntimeException("Couldn't set display mode " + config.width + "x" + config.height + ", fullscreen: " + config.fullscreen);
}
}
if (config.iconPaths.size > 0) {
ByteBuffer[] icons = new ByteBuffer[config.iconPaths.size];
for (int i = 0, n = config.iconPaths.size; i < n; i++) {
Pixmap pixmap = new Pixmap(Gdx.files.getFileHandle(config.iconPaths.get(i), config.iconFileTypes.get(i)));
if (pixmap.getFormat() != Format.RGBA8888) {
Pixmap rgba = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), Format.RGBA8888);
rgba.drawPixmap(pixmap, 0, 0);
pixmap.dispose();
pixmap = rgba;
}
icons[i] = ByteBuffer.allocateDirect(pixmap.getPixels().limit());
icons[i].put(pixmap.getPixels()).flip();
pixmap.dispose();
}
Display.setIcon(icons);
}
}
Display.setTitle(config.title);
Display.setResizable(config.resizable);
Display.setInitialBackground(config.initialBackgroundColor.r, config.initialBackgroundColor.g, config.initialBackgroundColor.b);
Display.setLocation(config.x, config.y);
createDisplayPixelFormat(config.useGL30, config.gles30ContextMajorVersion, config.gles30ContextMinorVersion);
initiateGL();
}
use of com.badlogic.gdx.utils.GdxRuntimeException in project libgdx by libgdx.
the class HeadlessPreferences method flush.
@Override
public void flush() {
OutputStream out = null;
try {
out = new BufferedOutputStream(file.write(false));
properties.storeToXML(out, null);
} catch (Exception ex) {
throw new GdxRuntimeException("Error writing preferences: " + file, ex);
} finally {
StreamUtils.closeQuietly(out);
}
}
use of com.badlogic.gdx.utils.GdxRuntimeException in project libgdx by libgdx.
the class JglfwPreferences method flush.
public void flush() {
OutputStream out = null;
try {
out = new BufferedOutputStream(file.write(false));
properties.store(out, null);
} catch (Exception ex) {
throw new GdxRuntimeException("Error writing preferences: " + file, ex);
} finally {
StreamUtils.closeQuietly(out);
}
}
use of com.badlogic.gdx.utils.GdxRuntimeException in project libgdx by libgdx.
the class AndroidGraphics method createGLSurfaceView.
protected View createGLSurfaceView(AndroidApplicationBase application, final ResolutionStrategy resolutionStrategy) {
if (!checkGL20())
throw new GdxRuntimeException("Libgdx requires OpenGL ES 2.0");
EGLConfigChooser configChooser = getEglConfigChooser();
int sdkVersion = android.os.Build.VERSION.SDK_INT;
if (sdkVersion <= 10 && config.useGLSurfaceView20API18) {
GLSurfaceView20API18 view = new GLSurfaceView20API18(application.getContext(), resolutionStrategy);
if (configChooser != null)
view.setEGLConfigChooser(configChooser);
else
view.setEGLConfigChooser(config.r, config.g, config.b, config.a, config.depth, config.stencil);
view.setRenderer(this);
return view;
} else {
GLSurfaceView20 view = new GLSurfaceView20(application.getContext(), resolutionStrategy, config.useGL30 ? 3 : 2);
if (configChooser != null)
view.setEGLConfigChooser(configChooser);
else
view.setEGLConfigChooser(config.r, config.g, config.b, config.a, config.depth, config.stencil);
view.setRenderer(this);
return view;
}
}
use of com.badlogic.gdx.utils.GdxRuntimeException in project libgdx by libgdx.
the class AndroidGraphicsLiveWallpaper method createGLSurfaceView.
// <- specific for live wallpapers
// Grabbed from AndroidGraphics superclass and modified to override
// getHolder in created GLSurfaceView and GLSurfaceViewAPI18 instances
@Override
protected View createGLSurfaceView(AndroidApplicationBase application, final ResolutionStrategy resolutionStrategy) {
if (!checkGL20())
throw new GdxRuntimeException("Libgdx requires OpenGL ES 2.0");
EGLConfigChooser configChooser = getEglConfigChooser();
int sdkVersion = android.os.Build.VERSION.SDK_INT;
if (sdkVersion <= 10 && config.useGLSurfaceView20API18) {
GLSurfaceView20API18 view = new GLSurfaceView20API18(application.getContext(), resolutionStrategy) {
@Override
public SurfaceHolder getHolder() {
return getSurfaceHolder();
}
// This method is invoked via reflection by AndroidLiveWallpaper.onDestroy()
public void onDestroy() {
// calls GLSurfaceView.mGLThread.requestExitAndWait();
onDetachedFromWindow();
}
};
if (configChooser != null)
view.setEGLConfigChooser(configChooser);
else
view.setEGLConfigChooser(config.r, config.g, config.b, config.a, config.depth, config.stencil);
view.setRenderer(this);
return view;
} else {
GLSurfaceView20 view = new GLSurfaceView20(application.getContext(), resolutionStrategy) {
@Override
public SurfaceHolder getHolder() {
return getSurfaceHolder();
}
// This method is invoked via reflection by AndroidLiveWallpaper.onDestroy()
public void onDestroy() {
// calls GLSurfaceView.mGLThread.requestExitAndWait();
onDetachedFromWindow();
}
};
if (configChooser != null)
view.setEGLConfigChooser(configChooser);
else
view.setEGLConfigChooser(config.r, config.g, config.b, config.a, config.depth, config.stencil);
view.setRenderer(this);
return view;
}
}
Aggregations