Search in sources :

Example 1 with Lwjgl3Window

use of com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window in project libgdx by libgdx.

the class Lwjgl3DebugStarter method main.

public static void main(String[] argv) throws NoSuchFieldException, SecurityException, ClassNotFoundException {
    GdxTest test = new GdxTest() {

        float r = 0;

        SpriteBatch batch;

        BitmapFont font;

        FPSLogger fps = new FPSLogger();

        Texture texture;

        @Override
        public void create() {
            BufferedImage image = new BufferedImage(10, 10, BufferedImage.TYPE_4BYTE_ABGR);
            texture = new Texture("data/badlogic.jpg");
            batch = new SpriteBatch();
            font = new BitmapFont();
            Gdx.input.setInputProcessor(new InputAdapter() {

                @Override
                public boolean keyDown(int keycode) {
                    System.out.println("Key down: " + Keys.toString(keycode));
                    return false;
                }

                @Override
                public boolean keyUp(int keycode) {
                    System.out.println("Key up: " + Keys.toString(keycode));
                    return false;
                }

                @Override
                public boolean keyTyped(char character) {
                    System.out.println("Key typed: '" + character + "', " + (int) character);
                    if (character == 'f') {
                        Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
                    //							DisplayMode[] modes = Gdx.graphics.getDisplayModes();
                    //							for(DisplayMode mode: modes) {
                    //								if(mode.width == 1920 && mode.height == 1080) {
                    //									Gdx.graphics.setFullscreenMode(mode);
                    //									break;
                    //								}
                    //							}
                    }
                    if (character == 'w') {
                        Gdx.graphics.setWindowedMode(MathUtils.random(400, 800), MathUtils.random(400, 800));
                    }
                    if (character == 'e') {
                        throw new GdxRuntimeException("derp");
                    }
                    if (character == 'c') {
                        Gdx.input.setCursorCatched(!Gdx.input.isCursorCatched());
                    }
                    Lwjgl3Window window = ((Lwjgl3Graphics) Gdx.graphics).getWindow();
                    if (character == 'v') {
                        window.setVisible(false);
                    }
                    if (character == 's') {
                        window.setVisible(true);
                    }
                    if (character == 'q') {
                        window.closeWindow();
                    }
                    if (character == 'i') {
                        window.iconifyWindow();
                    }
                    if (character == 'm') {
                        window.maximizeWindow();
                    }
                    if (character == 'r') {
                        window.restoreWindow();
                    }
                    if (character == 'u') {
                        Gdx.net.openURI("https://google.com");
                    }
                    return false;
                }
            });
        }

        long start = System.nanoTime();

        @Override
        public void render() {
            Gdx.gl.glClearColor(1, 0, 0, 1);
            Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
            HdpiUtils.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
            batch.getProjectionMatrix().setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
            batch.begin();
            font.draw(batch, Gdx.graphics.getWidth() + "x" + Gdx.graphics.getHeight() + ", " + Gdx.graphics.getBackBufferWidth() + "x" + Gdx.graphics.getBackBufferHeight() + ", " + Gdx.input.getX() + ", " + Gdx.input.getY() + ", " + Gdx.input.getDeltaX() + ", " + Gdx.input.getDeltaY(), 0, 20);
            batch.draw(texture, Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY());
            batch.end();
            fps.log();
        }

        @Override
        public void resize(int width, int height) {
            Gdx.app.log("Test", "Resized " + width + "x" + height);
        }

        @Override
        public void resume() {
            Gdx.app.log("Test", "resuming");
        }

        @Override
        public void pause() {
            Gdx.app.log("Test", "pausing");
        }

        @Override
        public void dispose() {
            Gdx.app.log("Test", "disposing");
        }
    };
    Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
    config.setWindowedMode(640, 480);
    config.setWindowListener(new Lwjgl3WindowListener() {

        @Override
        public void iconified(boolean isIconified) {
            Gdx.app.log("Window", "iconified: " + (isIconified ? "true" : "false"));
        }

        @Override
        public void maximized(boolean isMaximized) {
            Gdx.app.log("Window", "maximized: " + (isMaximized ? "true" : "false"));
        }

        @Override
        public void focusLost() {
            Gdx.app.log("Window", "focus lost");
        }

        @Override
        public void focusGained() {
            Gdx.app.log("Window", "focus gained");
        }

        @Override
        public boolean closeRequested() {
            Gdx.app.log("Window", "closing");
            return false;
        }

        @Override
        public void filesDropped(String[] files) {
            for (String file : files) {
                Gdx.app.log("Window", "File dropped: " + file);
            }
        }

        @Override
        public void refreshRequested() {
            Gdx.app.log("Window", "refreshRequested");
        }
    });
    for (DisplayMode mode : Lwjgl3ApplicationConfiguration.getDisplayModes()) {
        System.out.println(mode.width + "x" + mode.height);
    }
    System.setProperty("java.awt.headless", "true");
    new Lwjgl3Application(test, config);
}
Also used : InputAdapter(com.badlogic.gdx.InputAdapter) Lwjgl3Application(com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application) GdxTest(com.badlogic.gdx.tests.utils.GdxTest) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture) BufferedImage(java.awt.image.BufferedImage) Lwjgl3ApplicationConfiguration(com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration) FPSLogger(com.badlogic.gdx.graphics.FPSLogger) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) DisplayMode(com.badlogic.gdx.Graphics.DisplayMode) Lwjgl3Window(com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window) Lwjgl3WindowListener(com.badlogic.gdx.backends.lwjgl3.Lwjgl3WindowListener) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 2 with Lwjgl3Window

use of com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window in project libgdx by libgdx.

the class Lwjgl3Application method loop.

private void loop() {
    Array<Lwjgl3Window> closedWindows = new Array<Lwjgl3Window>();
    while (running && windows.size > 0) {
        // FIXME put it on a separate thread
        if (audio instanceof OpenALAudio) {
            ((OpenALAudio) audio).update();
        }
        boolean haveWindowsRendered = false;
        closedWindows.clear();
        for (Lwjgl3Window window : windows) {
            window.makeCurrent();
            currentWindow = window;
            synchronized (lifecycleListeners) {
                haveWindowsRendered |= window.update();
            }
            if (window.shouldClose()) {
                closedWindows.add(window);
            }
        }
        GLFW.glfwPollEvents();
        boolean shouldRequestRendering;
        synchronized (runnables) {
            shouldRequestRendering = runnables.size > 0;
            executedRunnables.clear();
            executedRunnables.addAll(runnables);
            runnables.clear();
        }
        for (Runnable runnable : executedRunnables) {
            runnable.run();
        }
        if (shouldRequestRendering) {
            // in the following render.
            for (Lwjgl3Window window : windows) {
                if (!window.getGraphics().isContinuousRendering())
                    window.requestRendering();
            }
        }
        for (Lwjgl3Window closedWindow : closedWindows) {
            if (windows.size == 1) {
                // when there is only 1 window left, which is in the process of being disposed.
                for (int i = lifecycleListeners.size - 1; i >= 0; i--) {
                    LifecycleListener l = lifecycleListeners.get(i);
                    l.pause();
                    l.dispose();
                }
                lifecycleListeners.clear();
            }
            closedWindow.dispose();
            windows.removeValue(closedWindow, false);
        }
        if (!haveWindowsRendered) {
            // with continuous rendering disabled.
            try {
                Thread.sleep(1000 / config.idleFPS);
            } catch (InterruptedException e) {
            // ignore
            }
        }
    }
}
Also used : Array(com.badlogic.gdx.utils.Array) OpenALAudio(com.badlogic.gdx.backends.lwjgl3.audio.OpenALAudio) LifecycleListener(com.badlogic.gdx.LifecycleListener)

Aggregations

DisplayMode (com.badlogic.gdx.Graphics.DisplayMode)1 InputAdapter (com.badlogic.gdx.InputAdapter)1 LifecycleListener (com.badlogic.gdx.LifecycleListener)1 Lwjgl3Application (com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application)1 Lwjgl3ApplicationConfiguration (com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration)1 Lwjgl3Window (com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window)1 Lwjgl3WindowListener (com.badlogic.gdx.backends.lwjgl3.Lwjgl3WindowListener)1 OpenALAudio (com.badlogic.gdx.backends.lwjgl3.audio.OpenALAudio)1 FPSLogger (com.badlogic.gdx.graphics.FPSLogger)1 Texture (com.badlogic.gdx.graphics.Texture)1 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)1 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)1 GdxTest (com.badlogic.gdx.tests.utils.GdxTest)1 Array (com.badlogic.gdx.utils.Array)1 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)1 BufferedImage (java.awt.image.BufferedImage)1