Example usage for org.lwjgl.opengl GL createCapabilities

List of usage examples for org.lwjgl.opengl GL createCapabilities

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL createCapabilities.

Prototype

public static GLCapabilities createCapabilities() 

Source Link

Document

Creates a new GLCapabilities instance for the OpenGL context that is current in the current thread.

Usage

From source file:org.lwjgl.demo.opengl.raytracing.PhotonMappingDemo.java

License:Open Source License

private void init() throws IOException {
    glfwSetErrorCallback(errCallback = new GLFWErrorCallback() {
        private GLFWErrorCallback delegate = GLFWErrorCallback.createPrint(System.err);

        @Override/*from ww  w  .ja  v a2 s. c o m*/
        public void invoke(int error, long description) {
            if (error == GLFW_VERSION_UNAVAILABLE)
                System.err.println("This demo requires OpenGL 4.3 or higher.");
            delegate.invoke(error, description);
        }

        @Override
        public void free() {
            delegate.free();
        }
    });

    if (!glfwInit())
        throw new IllegalStateException("Unable to initialize GLFW");

    glfwDefaultWindowHints();
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
    glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);

    window = glfwCreateWindow(width, height,
            "Photon Mapping Demo - compute shader (with SSBO) + raster (with instancing)", NULL, NULL);
    if (window == NULL) {
        throw new AssertionError("Failed to create the GLFW window");
    }

    System.out.println("Press 'r' to clear the photon map.");
    System.out.println("Press arrow 'up' to increase photon map resolution.");
    System.out.println("Press arrow 'down' to decrease the photon map resolution.");
    System.out.println("Press arrow 'right' to increase number of photons per frame.");
    System.out.println("Press arrow 'left' to decrease number of photons per frame.");
    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_R) {
                PhotonMappingDemo.this.clearPhotonMapTexture = true;
            } else if (key == GLFW_KEY_UP) {
                PhotonMappingDemo.this.photonMapSize *= 2;
                PhotonMappingDemo.this.photonMapSize = Math.min(PhotonMappingDemo.this.photonMapSize,
                        maxPhotonMapSize);
                PhotonMappingDemo.this.recreatePhotonMapTexture = true;
                System.out.println("Photon map resolution: " + PhotonMappingDemo.this.photonMapSize);
            } else if (key == GLFW_KEY_DOWN) {
                PhotonMappingDemo.this.photonMapSize /= 2;
                PhotonMappingDemo.this.photonMapSize = Math.max(PhotonMappingDemo.this.photonMapSize, 4);
                PhotonMappingDemo.this.recreatePhotonMapTexture = true;
                System.out.println("Photon map resolution: " + PhotonMappingDemo.this.photonMapSize);
            } else if (key == GLFW_KEY_RIGHT) {
                PhotonMappingDemo.this.photonsPerFrame *= 2;
                PhotonMappingDemo.this.photonsPerFrame = Math.min(PhotonMappingDemo.this.photonsPerFrame,
                        maxPhotonsPerFrame);
                System.out.println("Photons per frame: " + PhotonMappingDemo.this.photonsPerFrame);
            } else if (key == GLFW_KEY_LEFT) {
                PhotonMappingDemo.this.photonsPerFrame /= 2;
                PhotonMappingDemo.this.photonsPerFrame = Math.max(PhotonMappingDemo.this.photonsPerFrame, 4);
                System.out.println("Photons per frame: " + PhotonMappingDemo.this.photonsPerFrame);
            }
        }
    });

    glfwSetFramebufferSizeCallback(window, fbCallback = new GLFWFramebufferSizeCallback() {
        @Override
        public void invoke(long window, int width, int height) {
            if (width > 0 && height > 0
                    && (PhotonMappingDemo.this.width != width || PhotonMappingDemo.this.height != height)) {
                PhotonMappingDemo.this.width = width;
                PhotonMappingDemo.this.height = height;
                PhotonMappingDemo.this.resetFramebuffer = true;
            }
        }
    });

    glfwSetCursorPosCallback(window, cpCallback = new GLFWCursorPosCallback() {
        @Override
        public void invoke(long window, double x, double y) {
            PhotonMappingDemo.this.mouseX = (float) x;
        }
    });

    glfwSetMouseButtonCallback(window, mbCallback = new GLFWMouseButtonCallback() {
        @Override
        public void invoke(long window, int button, int action, int mods) {
            if (action == GLFW_PRESS) {
                PhotonMappingDemo.this.mouseDownX = PhotonMappingDemo.this.mouseX;
                PhotonMappingDemo.this.mouseDown = true;
            } else if (action == GLFW_RELEASE) {
                PhotonMappingDemo.this.mouseDown = false;
                PhotonMappingDemo.this.rotationAboutY = PhotonMappingDemo.this.currRotationAboutY;
            }
        }
    });

    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();

    /* Create all needed GL resources */
    createPhotonMapTexture();
    createSampler();
    createPhotonTraceProgram();
    initPhotonTraceProgram();
    createRasterProgram();
    initRasterProgram();
    createSceneSSBO();
    createSceneVao();

    /* Set some state */
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);

    firstTime = System.nanoTime();
}

From source file:org.lwjgl.demo.opengl.raytracing.TransformFeedbackDemo.java

License:Open Source License

void init() throws IOException {
    glfwSetErrorCallback(errCallback = new GLFWErrorCallback() {
        GLFWErrorCallback delegate = GLFWErrorCallback.createPrint(System.err);

        @Override/* w  w  w. j  a  v  a  2 s  . c  o  m*/
        public void invoke(int error, long description) {
            if (error == GLFW_VERSION_UNAVAILABLE)
                System.err.println("This demo requires OpenGL 4.3 or higher.");
            delegate.invoke(error, description);
        }

        @Override
        public void free() {
            delegate.free();
        }
    });

    if (!glfwInit())
        throw new IllegalStateException("Unable to initialize GLFW");

    glfwDefaultWindowHints();
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
    glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);

    window = glfwCreateWindow(width, height, "Raytracing Demo (transform feedback)", 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() {
        @Override
        public void invoke(long window, int width, int height) {
            if (width > 0 && height > 0 && (TransformFeedbackDemo.this.width != width
                    || TransformFeedbackDemo.this.height != height)) {
                TransformFeedbackDemo.this.width = width;
                TransformFeedbackDemo.this.height = height;
                TransformFeedbackDemo.this.resetFramebuffer = true;
            }
        }
    });

    glfwSetCursorPosCallback(window, cpCallback = new GLFWCursorPosCallback() {
        @Override
        public void invoke(long window, double x, double y) {
            TransformFeedbackDemo.this.mouseX = (float) x;
        }
    });

    glfwSetMouseButtonCallback(window, mbCallback = new GLFWMouseButtonCallback() {
        @Override
        public void invoke(long window, int button, int action, int mods) {
            if (action == GLFW_PRESS) {
                TransformFeedbackDemo.this.mouseDownX = TransformFeedbackDemo.this.mouseX;
                TransformFeedbackDemo.this.mouseDown = true;
            } else if (action == GLFW_RELEASE) {
                TransformFeedbackDemo.this.mouseDown = false;
                TransformFeedbackDemo.this.rotationAboutY = TransformFeedbackDemo.this.currRotationAboutY;
            }
        }
    });

    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);

    /* Load OBJ model */
    WavefrontMeshLoader loader = new WavefrontMeshLoader();
    mesh = loader.loadMesh("org/lwjgl/demo/opengl/models/smoothicosphere.obj.zip");

    caps = GL.createCapabilities();
    debugProc = GLUtil.setupDebugMessageCallback();

    /* Create all needed GL resources */
    createRaytracingTexture();
    createSampler();
    createSceneSSBO();
    createSceneVao();
    createFeedbackProgram();
    createComputeProgram();
    initComputeProgram();
    if (!caps.GL_NV_draw_texture) {
        createFullScreenVao();
        createQuadProgram();
    }

    lastTime = System.nanoTime();
}

From source file:org.lwjgl.demo.opengl.shader.ImmediateModeDemo.java

License:Open Source License

void init() throws IOException {
    glfwSetErrorCallback(errCallback = new GLFWErrorCallback() {
        GLFWErrorCallback delegate = GLFWErrorCallback.createPrint(System.err);

        @Override/*w  w w.  j  a v  a  2s  . c  om*/
        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_VISIBLE, GLFW_FALSE);
    glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);

    window = glfwCreateWindow(width, height, "Immediate mode 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
                    && (ImmediateModeDemo.this.width != width || ImmediateModeDemo.this.height != height)) {
                ImmediateModeDemo.this.width = width;
                ImmediateModeDemo.this.height = height;
            }
        }
    });

    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);
            }
        }
    });

    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();
    // and set some GL state
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}

From source file:org.lwjgl.demo.opengl.shader.NoVerticesBSplineDemo.java

License:Open Source License

void init() throws IOException {
    glfwSetErrorCallback(errCallback = new GLFWErrorCallback() {
        GLFWErrorCallback delegate = GLFWErrorCallback.createPrint(System.err);

        @Override//from ww w . j  av  a2s  . c o m
        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);
}

From source file:org.lwjgl.demo.opengl.shader.NoVerticesPolygonDemo.java

License:Open Source License

void init() throws IOException {
    glfwSetErrorCallback(errCallback = new GLFWErrorCallback() {
        GLFWErrorCallback delegate = GLFWErrorCallback.createPrint(System.err);

        @Override/*from  www .  ja v a  2s.c o m*/
        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 polygon 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 && (NoVerticesPolygonDemo.this.width != width
                    || NoVerticesPolygonDemo.this.height != height)) {
                NoVerticesPolygonDemo.this.width = width;
                NoVerticesPolygonDemo.this.height = height;
            }
        }
    });

    System.out.println("Press 'arrow up' to increase the polygon vertex count");
    System.out.println("Press 'arrow down' to decrease the polygon vertex count");
    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)) {
                count++;
            } else if (key == GLFW_KEY_DOWN && (action == GLFW_RELEASE || action == GLFW_REPEAT)) {
                count = Math.max(3, count - 1);
            }
        }
    });

    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();
    // and set some GL state
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}

From source file:org.lwjgl.demo.opengl.shadow.ShadowMappingDemo.java

License:Open Source License

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);
        }//  w  w w .  j  a v a 2s.c o m

        @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();
}

From source file:org.lwjgl.demo.opengl.shadow.ShadowMappingDemo20.java

License:Open Source License

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);
        }// w ww .  j a  v  a 2 s  . c  om

        @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();
}

From source file:org.lwjgl.demo.opengl.textures.BillboardCubemapDemo.java

License:Open Source License

void init() throws IOException {
    glfwSetErrorCallback(errCallback = new GLFWErrorCallback() {
        GLFWErrorCallback delegate = GLFWErrorCallback.createPrint(System.err);

        @Override//from w  w w.  j a  va2 s .  c o m
        public void invoke(int error, long description) {
            if (error == GLFW_VERSION_UNAVAILABLE)
                System.err.println("This demo requires OpenGL 1.1 or higher.");
            delegate.invoke(error, description);
        }

        @Override
        public void free() {
            delegate.free();
        }
    });

    if (!glfwInit())
        throw new IllegalStateException("Unable to initialize GLFW");

    glfwDefaultWindowHints();
    glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
    glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);

    window = glfwCreateWindow(width, height, "Cubemap texture sampling with projected quad", 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 && (BillboardCubemapDemo.this.width != width
                    || BillboardCubemapDemo.this.height != height)) {
                BillboardCubemapDemo.this.width = width;
                BillboardCubemapDemo.this.height = height;
            }
        }
    });

    System.out.println("Press 'D' to debug the blackhole rendering.");
    System.out.println("Press 'arrow up' to increase the polygon refinement.");
    System.out.println("Press 'arrow down ' to decrease the polygon refinement.");
    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_D && action == GLFW_RELEASE) {
                debug = !debug;
            } else if (key == GLFW_KEY_UP && (action == GLFW_PRESS || action == GLFW_REPEAT)) {
                circleRefinement++;
                createBillboardPolygon();
                System.out.println("Circle refinement: " + circleRefinement);
            } else if (key == GLFW_KEY_DOWN && (action == GLFW_PRESS || action == GLFW_REPEAT)) {
                circleRefinement = Math.max(circleRefinement - 1, 3);
                createBillboardPolygon();
                System.out.println("Circle refinement: " + circleRefinement);
            }
        }
    });

    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();

    String vendor = glGetString(GL_VENDOR);
    isCrappyIntel = vendor != null && vendor.toLowerCase().contains("intel");
    if (!caps.GL_ARB_shader_objects) {
        throw new AssertionError("This demo requires the ARB_shader_objects extension.");
    }
    if (!caps.GL_ARB_vertex_shader) {
        throw new AssertionError("This demo requires the ARB_vertex_shader extension.");
    }
    if (!caps.GL_ARB_fragment_shader) {
        throw new AssertionError("This demo requires the ARB_fragment_shader extension.");
    }
    if (!caps.GL_ARB_texture_cube_map && !caps.OpenGL13) {
        throw new AssertionError("This demo requires the ARB_texture_cube_map extension or OpenGL 1.3.");
    }

    debugProc = GLUtil.setupDebugMessageCallback();

    /* Create all needed GL resources */
    createTexture();
    createFullScreenQuad();
    createBillboardPolygon();
    createBackgroundProgram();
    createBlackholeProgram();

    /* Activate vertex array */
    glEnableClientState(GL_VERTEX_ARRAY);
}

From source file:org.lwjgl.demo.opengl.textures.EnvironmentDemo.java

License:Open Source License

void init() throws IOException {
    if (!glfwInit())
        throw new IllegalStateException("Unable to initialize GLFW");

    glfwDefaultWindowHints();/*from ww w  .j a v a 2s .  c om*/
    glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
    glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
    window = glfwCreateWindow(width, height, "Spherical environment mapping demo", NULL, NULL);
    if (window == NULL)
        throw new AssertionError("Failed to create the GLFW window");

    System.out.println("Move the mouse to look around");
    System.out.println("Zoom in/out with mouse wheel");
    glfwSetFramebufferSizeCallback(window, fbCallback = new GLFWFramebufferSizeCallback() {
        @Override
        public void invoke(long window, int width, int height) {
            if (width > 0 && height > 0
                    && (EnvironmentDemo.this.width != width || EnvironmentDemo.this.height != height)) {
                EnvironmentDemo.this.width = width;
                EnvironmentDemo.this.height = height;
            }
        }
    });
    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);
            }
        }
    });
    glfwSetCursorPosCallback(window, cpCallback = new GLFWCursorPosCallback() {
        @Override
        public void invoke(long window, double x, double y) {
            float nx = (float) x / width * 2.0f - 1.0f;
            float ny = (float) y / height * 2.0f - 1.0f;
            rotX = ny * (float) Math.PI * 0.5f;
            rotY = nx * (float) Math.PI;
        }
    });
    glfwSetScrollCallback(window, sCallback = new GLFWScrollCallback() {
        @Override
        public void invoke(long window, double xoffset, double yoffset) {
            if (yoffset < 0)
                fov *= 1.05f;
            else
                fov *= 1f / 1.05f;
            if (fov < 10.0f)
                fov = 10.0f;
            else if (fov > 120.0f)
                fov = 120.0f;
        }
    });

    GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    glfwSetWindowPos(window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2);
    glfwMakeContextCurrent(window);
    glfwSwapInterval(0);
    glfwShowWindow(window);
    glfwSetCursorPos(window, width / 2, height / 2);

    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_ARB_shader_objects)
        throw new AssertionError("This demo requires the ARB_shader_objects extension.");
    if (!caps.GL_ARB_vertex_shader)
        throw new AssertionError("This demo requires the ARB_vertex_shader extension.");
    if (!caps.GL_ARB_fragment_shader)
        throw new AssertionError("This demo requires the ARB_fragment_shader extension.");
    debugProc = GLUtil.setupDebugMessageCallback();

    /* Create all needed GL resources */
    createTexture();
    createFullScreenQuad();
    createProgram();
}

From source file:org.lwjgl.demo.opengl.textures.EnvironmentTeapotDemo.java

License:Open Source License

void init() throws IOException {
    if (!glfwInit())
        throw new IllegalStateException("Unable to initialize GLFW");

    glfwDefaultWindowHints();//from  w ww  . j  a v  a 2s .  c  om
    glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
    glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
    window = glfwCreateWindow(width, height, "Spherical environment mapping with teapot demo", NULL, NULL);
    if (window == NULL)
        throw new AssertionError("Failed to create the GLFW window");

    System.out.println("Move the mouse to look around");
    System.out.println("Zoom in/out with mouse wheel");
    glfwSetFramebufferSizeCallback(window, fbCallback = new GLFWFramebufferSizeCallback() {
        @Override
        public void invoke(long window, int width, int height) {
            if (width > 0 && height > 0 && (EnvironmentTeapotDemo.this.width != width
                    || EnvironmentTeapotDemo.this.height != height)) {
                EnvironmentTeapotDemo.this.width = width;
                EnvironmentTeapotDemo.this.height = height;
            }
        }
    });
    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);
            }
        }
    });
    glfwSetCursorPosCallback(window, cpCallback = new GLFWCursorPosCallback() {
        @Override
        public void invoke(long window, double x, double y) {
            float nx = (float) x / width * 2.0f - 1.0f;
            float ny = (float) y / height * 2.0f - 1.0f;
            rotX = ny * (float) Math.PI * 0.5f;
            rotY = nx * (float) Math.PI;
        }
    });
    glfwSetScrollCallback(window, sCallback = new GLFWScrollCallback() {
        @Override
        public void invoke(long window, double xoffset, double yoffset) {
            if (yoffset < 0)
                fov *= 1.05f;
            else
                fov *= 1f / 1.05f;
            if (fov < 10.0f)
                fov = 10.0f;
            else if (fov > 120.0f)
                fov = 120.0f;
        }
    });

    GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    glfwSetWindowPos(window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2);
    glfwMakeContextCurrent(window);
    glfwSwapInterval(0);
    glfwShowWindow(window);
    glfwSetCursorPos(window, width / 2, height / 2);

    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_ARB_shader_objects)
        throw new AssertionError("This demo requires the ARB_shader_objects extension.");
    if (!caps.GL_ARB_vertex_shader)
        throw new AssertionError("This demo requires the ARB_vertex_shader extension.");
    if (!caps.GL_ARB_fragment_shader)
        throw new AssertionError("This demo requires the ARB_fragment_shader extension.");
    debugProc = GLUtil.setupDebugMessageCallback();

    /* Create all needed GL resources */
    loadMesh();
    createTexture();
    createFullScreenQuad();
    createTeapotProgram();
    createEnvironmentProgram();
}