Search in sources :

Example 36 with GdxRuntimeException

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();
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) ByteBuffer(java.nio.ByteBuffer) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 37 with GdxRuntimeException

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);
    }
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) OutputStream(java.io.OutputStream) BufferedOutputStream(java.io.BufferedOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException)

Example 38 with GdxRuntimeException

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);
    }
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) OutputStream(java.io.OutputStream) BufferedOutputStream(java.io.BufferedOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException)

Example 39 with GdxRuntimeException

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;
    }
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) GLSurfaceView20(com.badlogic.gdx.backends.android.surfaceview.GLSurfaceView20) GLSurfaceView20API18(com.badlogic.gdx.backends.android.surfaceview.GLSurfaceView20API18) EGLConfigChooser(android.opengl.GLSurfaceView.EGLConfigChooser)

Example 40 with GdxRuntimeException

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;
    }
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) GLSurfaceView20(com.badlogic.gdx.backends.android.surfaceview.GLSurfaceView20) GLSurfaceView20API18(com.badlogic.gdx.backends.android.surfaceview.GLSurfaceView20API18) EGLConfigChooser(android.opengl.GLSurfaceView.EGLConfigChooser)

Aggregations

GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)202 IOException (java.io.IOException)40 FileHandle (com.badlogic.gdx.files.FileHandle)14 Array (com.badlogic.gdx.utils.Array)13 Texture (com.badlogic.gdx.graphics.Texture)12 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)11 AtlasRegion (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion)9 InputStream (java.io.InputStream)9 Pixmap (com.badlogic.gdx.graphics.Pixmap)8 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)8 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)7 AtlasSprite (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite)7 BufferedInputStream (java.io.BufferedInputStream)7 File (java.io.File)7 OutputStream (java.io.OutputStream)7 VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)6 LifecycleListener (com.badlogic.gdx.LifecycleListener)5 ByteBuffer (java.nio.ByteBuffer)5 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)4 NinePatch (com.badlogic.gdx.graphics.g2d.NinePatch)4