Search in sources :

Example 11 with GLFWFramebufferSizeCallback

use of org.lwjgl.glfw.GLFWFramebufferSizeCallback in project lwjgl3-demos by LWJGL.

the class GrassDemo method run.

void run() throws IOException {
    glfwSetErrorCallback(errCallback = GLFWErrorCallback.createPrint(System.err));
    if (!glfwInit())
        throw new IllegalStateException("Unable to initialize GLFW");
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
    glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
    glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
    window = glfwCreateWindow(width, height, "Hello instanced grass", NULL, NULL);
    if (window == NULL)
        throw new AssertionError("Failed to create the GLFW window");
    glfwSetFramebufferSizeCallback(window, fbCallback = new GLFWFramebufferSizeCallback() {

        public void invoke(long window, int width, int height) {
            GrassDemo.this.width = width;
            GrassDemo.this.height = height;
        }
    });
    glfwSetKeyCallback(window, keyCallback = new GLFWKeyCallback() {

        public void invoke(long window, int key, int scancode, int action, int mods) {
            if (action != GLFW_RELEASE)
                return;
            if (key == GLFW_KEY_ESCAPE)
                glfwSetWindowShouldClose(window, true);
        }
    });
    glfwMakeContextCurrent(window);
    glfwSwapInterval(0);
    glfwShowWindow(window);
    IntBuffer framebufferSize = BufferUtils.createIntBuffer(2);
    nglfwGetFramebufferSize(window, memAddress(framebufferSize), memAddress(framebufferSize) + 4);
    width = framebufferSize.get(0);
    height = framebufferSize.get(1);
    GLCapabilities caps = createCapabilities();
    if (!caps.GL_ARB_vertex_array_object)
        throw new UnsupportedOperationException("ARB_vertex_array_object is not available");
    if (!caps.GL_ARB_draw_instanced)
        throw new UnsupportedOperationException("ARB_draw_instanced is not available");
    if (!caps.GL_ARB_instanced_arrays)
        throw new UnsupportedOperationException("ARB_instanced_arrays is not available");
    debugProc = GLUtil.setupDebugMessageCallback();
    glClearColor(0.5f, 0.7f, 0.9f, 1.0f);
    glEnable(GL_DEPTH_TEST);
    createGrassTextures();
    createGrassProgram();
    generateGrassPatchVao();
    createGroundProgram();
    generateGroundVao();
    while (!glfwWindowShouldClose(window)) {
        glfwPollEvents();
        glViewport(0, 0, width, height);
        update();
        render();
        glfwSwapBuffers(window);
    }
    glfwDestroyWindow(window);
    glfwTerminate();
    errCallback.free();
    if (debugProc != null)
        debugProc.free();
    fbCallback.free();
    keyCallback.free();
}
Also used : GLFWKeyCallback(org.lwjgl.glfw.GLFWKeyCallback) GLCapabilities(org.lwjgl.opengl.GLCapabilities) GLFWFramebufferSizeCallback(org.lwjgl.glfw.GLFWFramebufferSizeCallback) IntBuffer(java.nio.IntBuffer)

Example 12 with GLFWFramebufferSizeCallback

use of org.lwjgl.glfw.GLFWFramebufferSizeCallback in project lwjgl3-demos by LWJGL.

the class NoVerticesBSplineDemo method init.

void init() throws IOException {
    glfwSetErrorCallback(errCallback = new GLFWErrorCallback() {

        GLFWErrorCallback delegate = GLFWErrorCallback.createPrint(System.err);

        @Override
        public void invoke(int error, long description) {
            if (error == GLFW_VERSION_UNAVAILABLE)
                System.err.println("This demo requires OpenGL 3.0 or higher.");
            delegate.invoke(error, description);
        }

        @Override
        public void free() {
            delegate.free();
        }
    });
    if (!glfwInit())
        throw new IllegalStateException("Unable to initialize GLFW");
    glfwDefaultWindowHints();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
    glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
    glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
    window = glfwCreateWindow(width, height, "No vertices cubic B-splines shader demo", NULL, NULL);
    if (window == NULL) {
        throw new AssertionError("Failed to create the GLFW window");
    }
    glfwSetFramebufferSizeCallback(window, fbCallback = new GLFWFramebufferSizeCallback() {

        @Override
        public void invoke(long window, int width, int height) {
            if (width > 0 && height > 0 && (NoVerticesBSplineDemo.this.width != width || NoVerticesBSplineDemo.this.height != height)) {
                NoVerticesBSplineDemo.this.width = width;
                NoVerticesBSplineDemo.this.height = height;
            }
        }
    });
    System.out.println("Press 'arrow up' to increase the lod");
    System.out.println("Press 'arrow down' to decrease the lod");
    glfwSetKeyCallback(window, keyCallback = new GLFWKeyCallback() {

        @Override
        public void invoke(long window, int key, int scancode, int action, int mods) {
            if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) {
                glfwSetWindowShouldClose(window, true);
            } else if (key == GLFW_KEY_UP && (action == GLFW_RELEASE || action == GLFW_REPEAT)) {
                lod++;
                System.out.println("Increased LOD to " + lod);
            } else if (key == GLFW_KEY_DOWN && (action == GLFW_RELEASE || action == GLFW_REPEAT)) {
                lod = Math.max(1, lod - 1);
                System.out.println("Decreased LOD to " + lod);
            }
        }
    });
    GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    glfwSetWindowPos(window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2);
    glfwMakeContextCurrent(window);
    glfwSwapInterval(1);
    glfwShowWindow(window);
    caps = GL.createCapabilities();
    debugProc = GLUtil.setupDebugMessageCallback();
    glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    // Create all needed GL resources
    createProgram();
    createUbo();
    // and set some GL state
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
Also used : GLFWKeyCallback(org.lwjgl.glfw.GLFWKeyCallback) GLFWErrorCallback(org.lwjgl.glfw.GLFWErrorCallback) GLFWFramebufferSizeCallback(org.lwjgl.glfw.GLFWFramebufferSizeCallback) GLFWVidMode(org.lwjgl.glfw.GLFWVidMode)

Example 13 with GLFWFramebufferSizeCallback

use of org.lwjgl.glfw.GLFWFramebufferSizeCallback in project lwjgl3-demos by LWJGL.

the class NoVerticesProjectedGridDemo method init.

void init() throws IOException {
    glfwSetErrorCallback(errCallback = new GLFWErrorCallback() {

        GLFWErrorCallback delegate = GLFWErrorCallback.createPrint(System.err);

        @Override
        public void invoke(int error, long description) {
            if (error == GLFW_VERSION_UNAVAILABLE)
                System.err.println("This demo requires OpenGL 3.0 or higher.");
            delegate.invoke(error, description);
        }

        @Override
        public void free() {
            delegate.free();
        }
    });
    if (!glfwInit())
        throw new IllegalStateException("Unable to initialize GLFW");
    glfwDefaultWindowHints();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
    glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
    glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
    window = glfwCreateWindow(width, height, "No vertices projected grid shader demo", NULL, NULL);
    if (window == NULL) {
        throw new AssertionError("Failed to create the GLFW window");
    }
    glfwSetFramebufferSizeCallback(window, fbCallback = new GLFWFramebufferSizeCallback() {

        @Override
        public void invoke(long window, int width, int height) {
            if (width > 0 && height > 0 && (NoVerticesProjectedGridDemo.this.width != width || NoVerticesProjectedGridDemo.this.height != height)) {
                NoVerticesProjectedGridDemo.this.width = width;
                NoVerticesProjectedGridDemo.this.height = height;
            }
        }
    });
    System.out.println("Press 'arrow right' to increase the grid size in X");
    System.out.println("Press 'arrow left' to decrease the grid size in X");
    System.out.println("Press 'arrow up' to increase the grid size in Y");
    System.out.println("Press 'arrow down' to decrease the grid size in Y");
    glfwSetKeyCallback(window, keyCallback = new GLFWKeyCallback() {

        @Override
        public void invoke(long window, int key, int scancode, int action, int mods) {
            if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) {
                glfwSetWindowShouldClose(window, true);
            }
            if (key == GLFW_KEY_LEFT && (action == GLFW_RELEASE || action == GLFW_REPEAT)) {
                sizeX = Math.max(1, sizeX - 1);
            } else if (key == GLFW_KEY_RIGHT && (action == GLFW_RELEASE || action == GLFW_REPEAT)) {
                sizeX++;
            } else if (key == GLFW_KEY_DOWN && (action == GLFW_RELEASE || action == GLFW_REPEAT)) {
                sizeY = Math.max(1, sizeY - 1);
            } else if (key == GLFW_KEY_UP && (action == GLFW_RELEASE || action == GLFW_REPEAT)) {
                sizeY++;
            }
        }
    });
    GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    glfwSetWindowPos(window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2);
    glfwMakeContextCurrent(window);
    glfwSwapInterval(0);
    glfwShowWindow(window);
    caps = createCapabilities();
    debugProc = GLUtil.setupDebugMessageCallback();
    glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    // Create all needed GL resources
    createProgram();
    // and set some GL state
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
Also used : GLFWKeyCallback(org.lwjgl.glfw.GLFWKeyCallback) GLFWErrorCallback(org.lwjgl.glfw.GLFWErrorCallback) GLFWFramebufferSizeCallback(org.lwjgl.glfw.GLFWFramebufferSizeCallback) GLFWVidMode(org.lwjgl.glfw.GLFWVidMode)

Example 14 with GLFWFramebufferSizeCallback

use of org.lwjgl.glfw.GLFWFramebufferSizeCallback in project lwjgl3-demos by LWJGL.

the class ShadowMappingDemo method init.

void init() throws IOException {
    glfwSetErrorCallback(errCallback = new GLFWErrorCallback() {

        GLFWErrorCallback delegate = GLFWErrorCallback.createPrint(System.err);

        public void invoke(int error, long description) {
            if (error == GLFW_VERSION_UNAVAILABLE)
                System.err.println("This demo requires OpenGL 3.0 or higher.");
            delegate.invoke(error, description);
        }

        @Override
        public void free() {
            delegate.free();
        }
    });
    if (!glfwInit())
        throw new IllegalStateException("Unable to initialize GLFW");
    glfwDefaultWindowHints();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
    glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
    glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
    window = glfwCreateWindow(width, height, "Shadow Mapping Demo", NULL, NULL);
    if (window == NULL) {
        throw new AssertionError("Failed to create the GLFW window");
    }
    glfwSetKeyCallback(window, keyCallback = new GLFWKeyCallback() {

        @Override
        public void invoke(long window, int key, int scancode, int action, int mods) {
            if (action != GLFW_RELEASE)
                return;
            if (key == GLFW_KEY_ESCAPE) {
                glfwSetWindowShouldClose(window, true);
            }
        }
    });
    glfwSetFramebufferSizeCallback(window, fbCallback = new GLFWFramebufferSizeCallback() {

        public void invoke(long window, int width, int height) {
            if (width > 0 && height > 0 && (ShadowMappingDemo.this.width != width || ShadowMappingDemo.this.height != height)) {
                ShadowMappingDemo.this.width = width;
                ShadowMappingDemo.this.height = height;
            }
        }
    });
    GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    glfwSetWindowPos(window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2);
    glfwMakeContextCurrent(window);
    glfwSwapInterval(0);
    glfwShowWindow(window);
    IntBuffer framebufferSize = BufferUtils.createIntBuffer(2);
    nglfwGetFramebufferSize(window, memAddress(framebufferSize), memAddress(framebufferSize) + 4);
    width = framebufferSize.get(0);
    height = framebufferSize.get(1);
    caps = GL.createCapabilities();
    debugProc = GLUtil.setupDebugMessageCallback();
    /* Set some GL states */
    glEnable(GL_CULL_FACE);
    glEnable(GL_DEPTH_TEST);
    glClearColor(0.2f, 0.3f, 0.4f, 1.0f);
    /* Create all needed GL resources */
    createVao();
    createShadowProgram();
    initShadowProgram();
    createNormalProgram();
    initNormalProgram();
    createDepthTexture();
    createFbo();
}
Also used : GLFWKeyCallback(org.lwjgl.glfw.GLFWKeyCallback) GLFWErrorCallback(org.lwjgl.glfw.GLFWErrorCallback) GLFWFramebufferSizeCallback(org.lwjgl.glfw.GLFWFramebufferSizeCallback) IntBuffer(java.nio.IntBuffer) GLFWVidMode(org.lwjgl.glfw.GLFWVidMode)

Example 15 with GLFWFramebufferSizeCallback

use of org.lwjgl.glfw.GLFWFramebufferSizeCallback in project lwjgl3-demos by LWJGL.

the class ShadowMappingDemo20 method init.

void init() throws IOException {
    glfwSetErrorCallback(errCallback = new GLFWErrorCallback() {

        GLFWErrorCallback delegate = GLFWErrorCallback.createPrint(System.err);

        public void invoke(int error, long description) {
            if (error == GLFW_VERSION_UNAVAILABLE)
                System.err.println("This demo requires OpenGL 2.0 or higher.");
            delegate.invoke(error, description);
        }

        @Override
        public void free() {
            delegate.free();
        }
    });
    if (!glfwInit())
        throw new IllegalStateException("Unable to initialize GLFW");
    glfwDefaultWindowHints();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
    glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
    glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
    window = glfwCreateWindow(width, height, "Shadow Mapping Demo", NULL, NULL);
    if (window == NULL) {
        throw new AssertionError("Failed to create the GLFW window");
    }
    glfwSetKeyCallback(window, keyCallback = new GLFWKeyCallback() {

        @Override
        public void invoke(long window, int key, int scancode, int action, int mods) {
            if (action != GLFW_RELEASE)
                return;
            if (key == GLFW_KEY_ESCAPE) {
                glfwSetWindowShouldClose(window, true);
            }
        }
    });
    glfwSetFramebufferSizeCallback(window, fbCallback = new GLFWFramebufferSizeCallback() {

        public void invoke(long window, int width, int height) {
            if (width > 0 && height > 0 && (ShadowMappingDemo20.this.width != width || ShadowMappingDemo20.this.height != height)) {
                ShadowMappingDemo20.this.width = width;
                ShadowMappingDemo20.this.height = height;
            }
        }
    });
    GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    glfwSetWindowPos(window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2);
    glfwMakeContextCurrent(window);
    glfwSwapInterval(0);
    glfwShowWindow(window);
    IntBuffer framebufferSize = BufferUtils.createIntBuffer(2);
    nglfwGetFramebufferSize(window, memAddress(framebufferSize), memAddress(framebufferSize) + 4);
    width = framebufferSize.get(0);
    height = framebufferSize.get(1);
    caps = GL.createCapabilities();
    if (!caps.GL_EXT_framebuffer_object) {
        throw new AssertionError("This demo requires the EXT_framebuffer_object extension");
    }
    debugProc = GLUtil.setupDebugMessageCallback();
    /* Set some GL states */
    glEnable(GL_CULL_FACE);
    glEnable(GL_DEPTH_TEST);
    glClearColor(0.2f, 0.3f, 0.4f, 1.0f);
    /* Create all needed GL resources */
    createVbo();
    createShadowProgram();
    initShadowProgram();
    createNormalProgram();
    initNormalProgram();
    createDepthTexture();
    createFbo();
}
Also used : GLFWKeyCallback(org.lwjgl.glfw.GLFWKeyCallback) GLFWErrorCallback(org.lwjgl.glfw.GLFWErrorCallback) GLFWFramebufferSizeCallback(org.lwjgl.glfw.GLFWFramebufferSizeCallback) IntBuffer(java.nio.IntBuffer) GLFWVidMode(org.lwjgl.glfw.GLFWVidMode)

Aggregations

GLFWFramebufferSizeCallback (org.lwjgl.glfw.GLFWFramebufferSizeCallback)17 GLFWKeyCallback (org.lwjgl.glfw.GLFWKeyCallback)16 GLFWErrorCallback (org.lwjgl.glfw.GLFWErrorCallback)12 GLFWVidMode (org.lwjgl.glfw.GLFWVidMode)12 IntBuffer (java.nio.IntBuffer)7 LongBuffer (java.nio.LongBuffer)3 PointerBuffer (org.lwjgl.PointerBuffer)3 VkCommandBuffer (org.lwjgl.vulkan.VkCommandBuffer)3 VkCommandBufferBeginInfo (org.lwjgl.vulkan.VkCommandBufferBeginInfo)3 VkDebugReportCallbackEXT (org.lwjgl.vulkan.VkDebugReportCallbackEXT)3 VkDevice (org.lwjgl.vulkan.VkDevice)3 VkInstance (org.lwjgl.vulkan.VkInstance)3 VkPhysicalDevice (org.lwjgl.vulkan.VkPhysicalDevice)3 VkPhysicalDeviceMemoryProperties (org.lwjgl.vulkan.VkPhysicalDeviceMemoryProperties)3 VkPresentInfoKHR (org.lwjgl.vulkan.VkPresentInfoKHR)3 VkQueue (org.lwjgl.vulkan.VkQueue)3 VkSemaphoreCreateInfo (org.lwjgl.vulkan.VkSemaphoreCreateInfo)3 VkSubmitInfo (org.lwjgl.vulkan.VkSubmitInfo)3 GLCapabilities (org.lwjgl.opengl.GLCapabilities)2 Layer (io.xol.chunkstories.api.gui.Layer)1