Search in sources :

Example 41 with GdxRuntimeException

use of com.badlogic.gdx.utils.GdxRuntimeException in project libgdx by libgdx.

the class AndroidLiveWallpaper method initialize.

public void initialize(ApplicationListener listener, AndroidApplicationConfiguration config) {
    if (this.getVersion() < MINIMUM_SDK) {
        throw new GdxRuntimeException("LibGDX requires Android API Level " + MINIMUM_SDK + " or later.");
    }
    setApplicationLogger(new AndroidApplicationLogger());
    graphics = new AndroidGraphicsLiveWallpaper(this, config, config.resolutionStrategy == null ? new FillResolutionStrategy() : config.resolutionStrategy);
    // factory in use, but note: AndroidInputFactory causes exceptions when obfuscated: java.lang.RuntimeException: Couldn't
    // construct AndroidInput, this should never happen, proguard deletes constructor used only by reflection
    input = AndroidInputFactory.newAndroidInput(this, this.getService(), graphics.view, config);
    // input = new AndroidInput(this, this.getService(), null, config);
    audio = new AndroidAudio(this.getService(), config);
    // added initialization of android local storage: /data/data/<app package>/files/
    // workaround for Android bug #10515463
    this.getService().getFilesDir();
    files = new AndroidFiles(this.getService().getAssets(), this.getService().getFilesDir().getAbsolutePath());
    net = new AndroidNet(this);
    this.listener = listener;
    clipboard = new AndroidClipboard(this.getService());
    // Unlike activity, fragment and daydream applications there's no need for a specialized audio listener.
    // See description in onPause method.
    Gdx.app = this;
    Gdx.input = input;
    Gdx.audio = audio;
    Gdx.files = files;
    Gdx.graphics = graphics;
    Gdx.net = net;
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) FillResolutionStrategy(com.badlogic.gdx.backends.android.surfaceview.FillResolutionStrategy)

Example 42 with GdxRuntimeException

use of com.badlogic.gdx.utils.GdxRuntimeException in project libgdx by libgdx.

the class Lwjgl3Cursor method setSystemCursor.

static void setSystemCursor(long windowHandle, SystemCursor systemCursor) {
    Long glfwCursor = systemCursors.get(systemCursor);
    if (glfwCursor == null) {
        long handle = 0;
        if (systemCursor == SystemCursor.Arrow) {
            handle = GLFW.glfwCreateStandardCursor(GLFW.GLFW_ARROW_CURSOR);
        } else if (systemCursor == SystemCursor.Crosshair) {
            handle = GLFW.glfwCreateStandardCursor(GLFW.GLFW_CROSSHAIR_CURSOR);
        } else if (systemCursor == SystemCursor.Hand) {
            handle = GLFW.glfwCreateStandardCursor(GLFW.GLFW_HAND_CURSOR);
        } else if (systemCursor == SystemCursor.HorizontalResize) {
            handle = GLFW.glfwCreateStandardCursor(GLFW.GLFW_HRESIZE_CURSOR);
        } else if (systemCursor == SystemCursor.VerticalResize) {
            handle = GLFW.glfwCreateStandardCursor(GLFW.GLFW_VRESIZE_CURSOR);
        } else if (systemCursor == SystemCursor.Ibeam) {
            handle = GLFW.glfwCreateStandardCursor(GLFW.GLFW_IBEAM_CURSOR);
        } else {
            throw new GdxRuntimeException("Unknown system cursor " + systemCursor);
        }
        if (handle == 0) {
            return;
        }
        glfwCursor = handle;
        systemCursors.put(systemCursor, glfwCursor);
    }
    GLFW.glfwSetCursor(windowHandle, glfwCursor);
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException)

Example 43 with GdxRuntimeException

use of com.badlogic.gdx.utils.GdxRuntimeException in project libgdx by libgdx.

the class OpenALAudioDevice method writeSamples.

public void writeSamples(byte[] data, int offset, int length) {
    if (length < 0)
        throw new IllegalArgumentException("length cannot be < 0.");
    if (sourceID == -1) {
        sourceID = audio.obtainSource(true);
        if (sourceID == -1)
            return;
        if (buffers == null) {
            buffers = BufferUtils.createIntBuffer(bufferCount);
            alGenBuffers(buffers);
            if (alGetError() != AL_NO_ERROR)
                throw new GdxRuntimeException("Unabe to allocate audio buffers.");
        }
        alSourcei(sourceID, AL_LOOPING, AL_FALSE);
        alSourcef(sourceID, AL_GAIN, volume);
        // Fill initial buffers.
        int queuedBuffers = 0;
        for (int i = 0; i < bufferCount; i++) {
            int bufferID = buffers.get(i);
            int written = Math.min(bufferSize, length);
            tempBuffer.clear();
            tempBuffer.put(data, offset, written).flip();
            alBufferData(bufferID, format, tempBuffer, sampleRate);
            alSourceQueueBuffers(sourceID, bufferID);
            length -= written;
            offset += written;
            queuedBuffers++;
        }
        // Queue rest of buffers, empty.
        tempBuffer.clear().flip();
        for (int i = queuedBuffers; i < bufferCount; i++) {
            int bufferID = buffers.get(i);
            alBufferData(bufferID, format, tempBuffer, sampleRate);
            alSourceQueueBuffers(sourceID, bufferID);
        }
        alSourcePlay(sourceID);
        isPlaying = true;
    }
    while (length > 0) {
        int written = fillBuffer(data, offset, length);
        length -= written;
        offset += written;
    }
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException)

Example 44 with GdxRuntimeException

use of com.badlogic.gdx.utils.GdxRuntimeException in project libgdx by libgdx.

the class GwtGL20 method glReadPixels.

@Override
public void glReadPixels(int x, int y, int width, int height, int format, int type, Buffer pixels) {
    // verify request
    if ((format != WebGLRenderingContext.RGBA) || (type != WebGLRenderingContext.UNSIGNED_BYTE)) {
        throw new GdxRuntimeException("Only format RGBA and type UNSIGNED_BYTE are currently supported for glReadPixels(...). Create an issue when you need other formats.");
    }
    if (!(pixels instanceof ByteBuffer)) {
        throw new GdxRuntimeException("Inputed pixels buffer needs to be of type ByteBuffer for glReadPixels(...).");
    }
    // create new ArrayBufferView (4 bytes per pixel)
    int size = 4 * width * height;
    Uint8Array buffer = TypedArrays.createUint8Array(((HasArrayBufferView) pixels).getTypedArray().buffer(), 0, size);
    // read bytes to ArrayBufferView
    gl.readPixels(x, y, width, height, format, type, buffer);
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) Uint8Array(com.google.gwt.typedarrays.shared.Uint8Array) HasArrayBufferView(java.nio.HasArrayBufferView) ByteBuffer(java.nio.ByteBuffer)

Example 45 with GdxRuntimeException

use of com.badlogic.gdx.utils.GdxRuntimeException in project libgdx by libgdx.

the class IOSAudio method newMusic.

@Override
public Music newMusic(FileHandle fileHandle) {
    String path = fileHandle.file().getPath().replace('\\', '/');
    OALAudioTrack track = OALAudioTrack.create();
    if (track != null) {
        if (track.preloadFile(path)) {
            return new IOSMusic(track);
        }
    }
    throw new GdxRuntimeException("Error opening music file at " + path);
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) OALAudioTrack(com.badlogic.gdx.backends.iosrobovm.objectal.OALAudioTrack)

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