Search in sources :

Example 1 with LWJGLException

use of org.lwjgl.LWJGLException in project MinecraftForge by MinecraftForge.

the class SplashProgress method pause.

/**
     * Call before you need to explicitly modify GL context state during loading.
     * Resource loading doesn't usually require this call.
     * Call {@link #resume()} when you're done.
     * @deprecated not a stable API, will break, don't use this yet
     */
@Deprecated
public static void pause() {
    if (!enabled)
        return;
    checkThreadState();
    pause = true;
    lock.lock();
    try {
        d.releaseContext();
        Display.getDrawable().makeCurrent();
    } catch (LWJGLException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : EnhancedRuntimeException(net.minecraftforge.fml.common.EnhancedRuntimeException) LWJGLException(org.lwjgl.LWJGLException)

Example 2 with LWJGLException

use of org.lwjgl.LWJGLException in project Catacomb-Snatch by Catacomb-Snatch.

the class DesktopLauncher method main.

public static void main(String[] arg) {
    System.out.println("Starting game in DESKTOP mode!");
    LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
    // TODO Re-enable if it got fixed on all systems (currently throws a shader error)
    // config.useGL30 = true;
    config.title = "Catacomb Snatch";
    config.width = GAME_WIDTH;
    config.height = GAME_HEIGHT;
    new LwjglApplication(new CatacombSnatch(new PlatformDependent() {

        @Override
        public void create() {
            // Set game cursor
            try {
                int size = 16, center = (size / 2);
                IntBuffer buffer = BufferUtils.newIntBuffer(size * size);
                int x = 0, y = 0;
                for (int n = 0; n < buffer.limit(); n++) {
                    if ((x == center || y == center) && (x < center - 1 || y < center - 1 || x > center + 1 || y > center + 1)) {
                        buffer = buffer.put(n, 0xFFFFFFFF);
                    }
                    x++;
                    if (x == size) {
                        x = 0;
                        y++;
                    }
                }
                Mouse.setNativeCursor(new Cursor(size, size, center, center, 1, buffer, null));
            } catch (LWJGLException e) {
                System.err.print("Error setting native cursor!\n" + e);
            }
        }

        @Override
        public Object[] createPlatformObjects() {
            throw new UnsupportedOperationException("Unimplemented");
        }

        @Override
        public void dispose() {
        }
    }), config);
}
Also used : PlatformDependent(net.catacombsnatch.game.PlatformDependent) LwjglApplication(com.badlogic.gdx.backends.lwjgl.LwjglApplication) CatacombSnatch(net.catacombsnatch.game.CatacombSnatch) IntBuffer(java.nio.IntBuffer) LwjglApplicationConfiguration(com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration) Cursor(org.lwjgl.input.Cursor) LWJGLException(org.lwjgl.LWJGLException)

Example 3 with LWJGLException

use of org.lwjgl.LWJGLException in project playn by threerings.

the class JavaGraphics method setDisplayMode.

protected void setDisplayMode(int width, int height, boolean fullscreen) {
    try {
        // check if current mode is suitable
        DisplayMode mode = Display.getDisplayMode();
        if (fullscreen == Display.isFullscreen() && mode.getWidth() == width && mode.getHeight() == height)
            return;
        if (fullscreen) {
            // try and find a mode matching width and height
            DisplayMode matching = null;
            for (DisplayMode test : Display.getAvailableDisplayModes()) {
                if (test.getWidth() == width && test.getHeight() == height && test.isFullscreenCapable()) {
                    matching = test;
                }
            }
            if (matching == null) {
                platform.log().info("Could not find a matching fullscreen mode, available: " + Arrays.asList(Display.getAvailableDisplayModes()));
            } else {
                mode = matching;
            }
        } else {
            mode = new DisplayMode(width, height);
        }
        platform.log().debug("Updating display mode: " + mode + ", fullscreen: " + fullscreen);
        // TODO: fix crashes when fullscreen is toggled repeatedly
        if (fullscreen) {
            Display.setDisplayModeAndFullscreen(mode);
        // TODO: fix alt-tab, maybe add a key listener or something?
        } else {
            Display.setDisplayMode(mode);
        }
    } catch (LWJGLException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : DisplayMode(org.lwjgl.opengl.DisplayMode) LWJGLException(org.lwjgl.LWJGLException)

Example 4 with LWJGLException

use of org.lwjgl.LWJGLException in project libgdx by libgdx.

the class LwjglApplication method mainLoop.

void mainLoop() {
    SnapshotArray<LifecycleListener> lifecycleListeners = this.lifecycleListeners;
    try {
        graphics.setupDisplay();
    } catch (LWJGLException e) {
        throw new GdxRuntimeException(e);
    }
    listener.create();
    graphics.resize = true;
    int lastWidth = graphics.getWidth();
    int lastHeight = graphics.getHeight();
    graphics.lastTime = System.nanoTime();
    boolean wasActive = true;
    while (running) {
        Display.processMessages();
        if (Display.isCloseRequested())
            exit();
        boolean isActive = Display.isActive();
        if (wasActive && !isActive) {
            // if it's just recently minimized from active state
            wasActive = false;
            synchronized (lifecycleListeners) {
                LifecycleListener[] listeners = lifecycleListeners.begin();
                for (int i = 0, n = lifecycleListeners.size; i < n; ++i) listeners[i].pause();
                lifecycleListeners.end();
            }
            listener.pause();
        }
        if (!wasActive && isActive) {
            // if it's just recently focused from minimized state
            wasActive = true;
            synchronized (lifecycleListeners) {
                LifecycleListener[] listeners = lifecycleListeners.begin();
                for (int i = 0, n = lifecycleListeners.size; i < n; ++i) listeners[i].resume();
                lifecycleListeners.end();
            }
            listener.resume();
        }
        boolean shouldRender = false;
        if (graphics.canvas != null) {
            int width = graphics.canvas.getWidth();
            int height = graphics.canvas.getHeight();
            if (lastWidth != width || lastHeight != height) {
                lastWidth = width;
                lastHeight = height;
                Gdx.gl.glViewport(0, 0, lastWidth, lastHeight);
                listener.resize(lastWidth, lastHeight);
                shouldRender = true;
            }
        } else {
            graphics.config.x = Display.getX();
            graphics.config.y = Display.getY();
            if (graphics.resize || Display.wasResized() || (int) (Display.getWidth() * Display.getPixelScaleFactor()) != graphics.config.width || (int) (Display.getHeight() * Display.getPixelScaleFactor()) != graphics.config.height) {
                graphics.resize = false;
                graphics.config.width = (int) (Display.getWidth() * Display.getPixelScaleFactor());
                graphics.config.height = (int) (Display.getHeight() * Display.getPixelScaleFactor());
                Gdx.gl.glViewport(0, 0, graphics.config.width, graphics.config.height);
                if (listener != null)
                    listener.resize(graphics.config.width, graphics.config.height);
                graphics.requestRendering();
            }
        }
        if (executeRunnables())
            shouldRender = true;
        // If one of the runnables set running to false, for example after an exit().
        if (!running)
            break;
        input.update();
        shouldRender |= graphics.shouldRender();
        input.processEvents();
        if (audio != null)
            audio.update();
        if (!isActive && graphics.config.backgroundFPS == -1)
            shouldRender = false;
        int frameRate = isActive ? graphics.config.foregroundFPS : graphics.config.backgroundFPS;
        if (shouldRender) {
            graphics.updateTime();
            graphics.frameId++;
            listener.render();
            Display.update(false);
        } else {
            // Sleeps to avoid wasting CPU in an empty loop.
            if (frameRate == -1)
                frameRate = 10;
            if (frameRate == 0)
                frameRate = graphics.config.backgroundFPS;
            if (frameRate == 0)
                frameRate = 30;
        }
        if (frameRate > 0)
            Display.sync(frameRate);
    }
    synchronized (lifecycleListeners) {
        LifecycleListener[] listeners = lifecycleListeners.begin();
        for (int i = 0, n = lifecycleListeners.size; i < n; ++i) {
            listeners[i].pause();
            listeners[i].dispose();
        }
        lifecycleListeners.end();
    }
    listener.pause();
    listener.dispose();
    Display.destroy();
    if (audio != null)
        audio.dispose();
    if (graphics.config.forceExit)
        System.exit(-1);
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) LifecycleListener(com.badlogic.gdx.LifecycleListener) LWJGLException(org.lwjgl.LWJGLException)

Example 5 with LWJGLException

use of org.lwjgl.LWJGLException in project libgdx by libgdx.

the class LwjglGraphics method getDisplayModes.

@Override
public DisplayMode[] getDisplayModes() {
    try {
        org.lwjgl.opengl.DisplayMode[] availableDisplayModes = Display.getAvailableDisplayModes();
        DisplayMode[] modes = new DisplayMode[availableDisplayModes.length];
        int idx = 0;
        for (org.lwjgl.opengl.DisplayMode mode : availableDisplayModes) {
            if (mode.isFullscreenCapable()) {
                modes[idx++] = new LwjglDisplayMode(mode.getWidth(), mode.getHeight(), mode.getFrequency(), mode.getBitsPerPixel(), mode);
            }
        }
        return modes;
    } catch (LWJGLException e) {
        throw new GdxRuntimeException("Couldn't fetch available display modes", e);
    }
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) LWJGLException(org.lwjgl.LWJGLException)

Aggregations

LWJGLException (org.lwjgl.LWJGLException)51 ByteBuffer (java.nio.ByteBuffer)6 DisplayMode (org.lwjgl.opengl.DisplayMode)5 Pbuffer (org.lwjgl.opengl.Pbuffer)4 PixelFormat (org.lwjgl.opengl.PixelFormat)4 IOException (java.io.IOException)3 IntBuffer (java.nio.IntBuffer)3 ArrayList (java.util.ArrayList)3 GLCanvas (org.eclipse.swt.opengl.GLCanvas)3 GLData (org.eclipse.swt.opengl.GLData)3 Cursor (org.lwjgl.input.Cursor)3 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)2 BufferedImage (java.awt.image.BufferedImage)2 Method (java.lang.reflect.Method)2 FloatBuffer (java.nio.FloatBuffer)2 StringTokenizer (java.util.StringTokenizer)2 EnhancedRuntimeException (net.minecraftforge.fml.common.EnhancedRuntimeException)2 Sphere (org.lwjgl.util.glu.Sphere)2 LifecycleListener (com.badlogic.gdx.LifecycleListener)1 LwjglApplication (com.badlogic.gdx.backends.lwjgl.LwjglApplication)1