Search in sources :

Example 11 with GLFWErrorCallback

use of org.lwjgl.glfw.GLFWErrorCallback 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 12 with GLFWErrorCallback

use of org.lwjgl.glfw.GLFWErrorCallback 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)

Example 13 with GLFWErrorCallback

use of org.lwjgl.glfw.GLFWErrorCallback 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 14 with GLFWErrorCallback

use of org.lwjgl.glfw.GLFWErrorCallback 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

GLFWErrorCallback (org.lwjgl.glfw.GLFWErrorCallback)14 GLFWKeyCallback (org.lwjgl.glfw.GLFWKeyCallback)13 GLFWVidMode (org.lwjgl.glfw.GLFWVidMode)13 GLFWFramebufferSizeCallback (org.lwjgl.glfw.GLFWFramebufferSizeCallback)12 IntBuffer (java.nio.IntBuffer)3 GLCapabilities (org.lwjgl.opengl.GLCapabilities)2 FillLayout (org.eclipse.swt.layout.FillLayout)1 GLCanvas (org.eclipse.swt.opengl.GLCanvas)1 GLData (org.eclipse.swt.opengl.GLData)1 Display (org.eclipse.swt.widgets.Display)1 Event (org.eclipse.swt.widgets.Event)1 Listener (org.eclipse.swt.widgets.Listener)1 Shell (org.eclipse.swt.widgets.Shell)1 GLFWCursorPosCallback (org.lwjgl.glfw.GLFWCursorPosCallback)1 GLFWMouseButtonCallback (org.lwjgl.glfw.GLFWMouseButtonCallback)1 GLFWWindowFocusCallback (org.lwjgl.glfw.GLFWWindowFocusCallback)1 GLFWWindowSizeCallback (org.lwjgl.glfw.GLFWWindowSizeCallback)1 Callback (org.lwjgl.system.Callback)1