Java Examples for org.lwjgl.glfw.GLFW.glfwCreateWindow

The following java examples will help you to understand the usage of org.lwjgl.glfw.GLFW.glfwCreateWindow. These source code samples are taken from different open source projects.

Example 1
Project: javamarc-master  File: MainWindow.java View source code
private void initialize() {
    // Setup an error callback. The default implementation
    // will print the error message in System.err.
    GLFWErrorCallback.createPrint(System.err).set();
    // Initialize GLFW. Most GLFW functions will not work before doing this.
    if (!glfwInit())
        throw new IllegalStateException("Unable to initialize GLFW");
    // Configure our window
    glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MINOR, 2);
    glfwWindowHint(GLFW.GLFW_OPENGL_PROFILE, GLFW.GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW.GLFW_OPENGL_FORWARD_COMPAT, GLFW.GLFW_TRUE);
    // Create the window
    window = glfwCreateWindow(WIDTH, HEIGHT, "Java Marcher", NULL, NULL);
    WINDOW = window;
    if (window == NULL)
        throw new RuntimeException("Failed to create the GLFW window");
    // Get the resolution of the primary monitor
    GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    // Center our window
    glfwSetWindowPos(window, (vidmode.width() - WIDTH) / 2, (vidmode.height() - HEIGHT) / 2);
    // Make the OpenGL context current
    glfwMakeContextCurrent(window);
    // Enable v-sync
    glfwSwapInterval(1);
    // Make the window visible
    glfwShowWindow(window);
}
Example 2
Project: Abstract-Java-Game-Library-master  File: Window.java View source code
@Override
public boolean windowSetup() {
    // Initialize GLFW
    if (GLFW.glfwInit() != 1) {
        errorCallback.release();
        return false;
    }
    // Setup window properties
    preWindowCreation();
    // Create the window
    window = glfwCreateWindow(width, height, title, monitor, share);
    if (window == 0) {
        errorCallback.release();
        return false;
    }
    // Callback setup
    callbackSetup();
    // Setup window position
    postWindowCreation();
    return true;
}
Example 3
Project: jmonkeyengine-master  File: LwjglWindow.java View source code
/**
     * Apply the settings, changing resolution, etc.
     *
     * @param settings the settings to apply when creating the context.
     */
protected void createContext(final AppSettings settings) {
    glfwSetErrorCallback(errorCallback = new GLFWErrorCallback() {

        @Override
        public void invoke(int error, long description) {
            final String message = GLFWErrorCallback.getDescription(description);
            listener.handleError(message, new Exception(message));
        }

        @Override
        public void close() {
            super.close();
        }

        @Override
        public void callback(long args) {
            super.callback(args);
        }
    });
    if (!glfwInit()) {
        throw new IllegalStateException("Unable to initialize GLFW");
    }
    glfwDefaultWindowHints();
    if (settings.getRenderer().equals(AppSettings.LWJGL_OPENGL3)) {
        glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
        glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
        glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
        glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
    } else {
        glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
        glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
    }
    if (settings.getBoolean("RendererDebug")) {
        glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE);
    }
    if (settings.isGammaCorrection()) {
        glfwWindowHint(GLFW_SRGB_CAPABLE, GLFW_TRUE);
    }
    glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
    glfwWindowHint(GLFW_RESIZABLE, settings.isResizable() ? GLFW_TRUE : GLFW_FALSE);
    glfwWindowHint(GLFW_DEPTH_BITS, settings.getDepthBits());
    glfwWindowHint(GLFW_STENCIL_BITS, settings.getStencilBits());
    glfwWindowHint(GLFW_SAMPLES, settings.getSamples());
    glfwWindowHint(GLFW_STEREO, settings.useStereo3D() ? GLFW_TRUE : GLFW_FALSE);
    glfwWindowHint(GLFW_REFRESH_RATE, settings.getFrequency());
    if (settings.getBitsPerPixel() == 24) {
        glfwWindowHint(GLFW_RED_BITS, 8);
        glfwWindowHint(GLFW_GREEN_BITS, 8);
        glfwWindowHint(GLFW_BLUE_BITS, 8);
    } else if (settings.getBitsPerPixel() == 16) {
        glfwWindowHint(GLFW_RED_BITS, 5);
        glfwWindowHint(GLFW_GREEN_BITS, 6);
        glfwWindowHint(GLFW_BLUE_BITS, 5);
    }
    glfwWindowHint(GLFW_ALPHA_BITS, settings.getAlphaBits());
    // TODO: Add support for monitor selection
    long monitor = NULL;
    if (settings.isFullscreen()) {
        monitor = glfwGetPrimaryMonitor();
    }
    final GLFWVidMode videoMode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    if (settings.getWidth() <= 0 || settings.getHeight() <= 0) {
        settings.setResolution(videoMode.width(), videoMode.height());
    }
    window = glfwCreateWindow(settings.getWidth(), settings.getHeight(), settings.getTitle(), monitor, NULL);
    if (window == NULL) {
        throw new RuntimeException("Failed to create the GLFW window");
    }
    // Add a resize callback which delegates to the listener
    glfwSetWindowSizeCallback(window, windowSizeCallback = new GLFWWindowSizeCallback() {

        @Override
        public void invoke(final long window, final int width, final int height) {
            settings.setResolution(width, height);
            listener.reshape(width, height);
        }

        @Override
        public void close() {
            super.close();
        }

        @Override
        public void callback(long args) {
            super.callback(args);
        }
    });
    glfwSetWindowFocusCallback(window, windowFocusCallback = new GLFWWindowFocusCallback() {

        @Override
        public void invoke(final long window, final boolean focus) {
            if (wasActive != focus) {
                if (!wasActive) {
                    listener.gainFocus();
                    timer.reset();
                } else {
                    listener.loseFocus();
                }
                wasActive = !wasActive;
            }
        }

        @Override
        public void close() {
            super.close();
        }

        @Override
        public void callback(long args) {
            super.callback(args);
        }
    });
    // Center the window
    if (!settings.isFullscreen()) {
        glfwSetWindowPos(window, (videoMode.width() - settings.getWidth()) / 2, (videoMode.height() - settings.getHeight()) / 2);
    }
    // Make the OpenGL context current
    glfwMakeContextCurrent(window);
    // Enable vsync
    if (settings.isVSync()) {
        glfwSwapInterval(1);
    } else {
        glfwSwapInterval(0);
    }
    setWindowIcon(settings);
    showWindow();
    allowSwapBuffers = settings.isSwapBuffers();
}