private static void run() throws InterruptedException {
        while (!finished) {
            Display.update();
            if (Display.isCloseRequested()) {
                finished = true;
            } else if (Display.isActive()) {
                Display.sync(FRAMERATE);
                render();
            } else {
                // The window is not in the foreground, so we can allow other stuff to run and
                // infrequently update
                Thread.sleep(100);
                if (Display.isVisible() || Display.isDirty()) {
                    render();
                }
            }
        }
    }