Search in sources :

Example 16 with GLFWFramebufferSizeCallback

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

the class DepthEdgeShaderDemo20 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 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, "Silhouette rendering with edge detection shader", NULL, NULL);
    if (window == NULL) {
        throw new AssertionError("Failed to create the GLFW window");
    }
    System.out.println("Press spacebar to show/hide edges.");
    glfwSetFramebufferSizeCallback(window, fbCallback = new GLFWFramebufferSizeCallback() {

        @Override
        public void invoke(long window, int width, int height) {
            if (width > 0 && height > 0 && (DepthEdgeShaderDemo20.this.width != width || DepthEdgeShaderDemo20.this.height != height)) {
                DepthEdgeShaderDemo20.this.width = width;
                DepthEdgeShaderDemo20.this.height = height;
                DepthEdgeShaderDemo20.this.resize = true;
            }
        }
    });
    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);
            } else if (key == GLFW_KEY_SPACE) {
                showEdge = !showEdge;
            }
        }
    });
    GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    glfwSetWindowPos(window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2);
    glfwMakeContextCurrent(window);
    glfwSwapInterval(0);
    glfwShowWindow(window);
    caps = GL.createCapabilities();
    if (!caps.GL_EXT_framebuffer_object) {
        throw new AssertionError("This demo requires the EXT_framebuffer_object extension");
    }
    if (!caps.GL_ARB_texture_float) {
        throw new AssertionError("This demo requires the ARB_texture_float extension");
    }
    debugProc = GLUtil.setupDebugMessageCallback();
    glClearColor(0.0f, 0.0f, 1.0f, 0.0f);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    /* Create all needed GL resources */
    createCube();
    createQuad();
    createNormalProgram();
    createEdgeProgram();
    createTex();
    createFbo();
}
Also used : GLFWKeyCallback(org.lwjgl.glfw.GLFWKeyCallback) GLFWErrorCallback(org.lwjgl.glfw.GLFWErrorCallback) GLFWFramebufferSizeCallback(org.lwjgl.glfw.GLFWFramebufferSizeCallback) GLFWVidMode(org.lwjgl.glfw.GLFWVidMode)

Example 17 with GLFWFramebufferSizeCallback

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

the class EdgeShaderMultisampleDemo20 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 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, "Multisampled silhouette rendering with Sobel edge detection shader", NULL, NULL);
    if (window == NULL) {
        throw new AssertionError("Failed to create the GLFW window");
    }
    System.out.println("Press letter 'O' to toggle between outline/edges.");
    System.out.println("Press spacebar to show/hide edges.");
    glfwSetFramebufferSizeCallback(window, fbCallback = new GLFWFramebufferSizeCallback() {

        @Override
        public void invoke(long window, int width, int height) {
            if (width > 0 && height > 0 && (EdgeShaderMultisampleDemo20.this.width != width || EdgeShaderMultisampleDemo20.this.height != height)) {
                EdgeShaderMultisampleDemo20.this.width = width;
                EdgeShaderMultisampleDemo20.this.height = height;
                EdgeShaderMultisampleDemo20.this.resize = true;
            }
        }
    });
    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);
            } else if (key == GLFW_KEY_O) {
                outlineOnly = !outlineOnly;
            } else if (key == GLFW_KEY_SPACE) {
                showEdge = !showEdge;
            }
        }
    });
    GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    glfwSetWindowPos(window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2);
    glfwMakeContextCurrent(window);
    glfwSwapInterval(0);
    glfwShowWindow(window);
    caps = GL.createCapabilities();
    if (!caps.GL_EXT_framebuffer_object) {
        throw new AssertionError("This demo requires the EXT_framebuffer_object extension");
    }
    if (!caps.GL_EXT_framebuffer_multisample) {
        throw new AssertionError("This demo requires the EXT_framebuffer_multisample extension");
    }
    if (!caps.GL_EXT_framebuffer_blit) {
        throw new AssertionError("This demo requires the EXT_framebuffer_blit extension");
    }
    debugProc = GLUtil.setupDebugMessageCallback();
    // using alpha = 0.0 is important here for the outline to work!
    glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    samples = Math.min(4, glGetInteger(GL_MAX_SAMPLES_EXT));
    /* Create all needed GL resources */
    createCube();
    createQuad();
    createNormalProgram();
    createEdgeProgram();
    createOutlineProgram();
    createTex();
    createFbos();
}
Also used : GLFWKeyCallback(org.lwjgl.glfw.GLFWKeyCallback) GLFWErrorCallback(org.lwjgl.glfw.GLFWErrorCallback) GLFWFramebufferSizeCallback(org.lwjgl.glfw.GLFWFramebufferSizeCallback) 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