Java Code Examples for javax.media.opengl.GL#glTexImage2D()

The following examples show how to use javax.media.opengl.GL#glTexImage2D() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BloomOpenGL.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static void createFrameBufferObject(GL gl, int[] frameBuffer,
                                            int[] colorBuffer, int width,
                                            int height) {
    gl.glGenFramebuffersEXT(1, frameBuffer, 0);
    gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, frameBuffer[0]);

    gl.glGenTextures(1, colorBuffer, 0);
    gl.glBindTexture(GL.GL_TEXTURE_2D, colorBuffer[0]);
    gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA,
                    width, height,
                    0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE,
                    BufferUtil.newByteBuffer(width * height * 4));
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
    gl.glFramebufferTexture2DEXT(GL.GL_FRAMEBUFFER_EXT,
                                 GL.GL_COLOR_ATTACHMENT0_EXT,
                                 GL.GL_TEXTURE_2D, colorBuffer[0], 0);
    gl.glBindTexture(GL.GL_TEXTURE_2D, 0);

    int status = gl.glCheckFramebufferStatusEXT(GL.GL_FRAMEBUFFER_EXT);
    if (status == GL.GL_FRAMEBUFFER_COMPLETE_EXT) {
        gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);
    } else {
        throw new IllegalStateException("Frame Buffer Oject not created.");
    }
}