Example usage for org.lwjgl.opengl GL30 GL_FRAMEBUFFER

List of usage examples for org.lwjgl.opengl GL30 GL_FRAMEBUFFER

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL30 GL_FRAMEBUFFER.

Prototype

int GL_FRAMEBUFFER

To view the source code for org.lwjgl.opengl GL30 GL_FRAMEBUFFER.

Click Source Link

Document

Accepted by the target parameter of BindFramebuffer, CheckFramebufferStatus, FramebufferTexture{1D|2D|3D}, FramebufferRenderbuffer, and GetFramebufferAttachmentParameteriv.

Usage

From source file:com.mtbs3d.minecrift.render.FBOParams.java

License:LGPL

public FBOParams(String fboName, int textureType, int internalFormat, int baseFormat, int bufferType,
        int fboWidth, int fboHeight) throws Exception {
    Minecraft mc = Minecraft.getMinecraft();
    _textureType = textureType;/*  w ww  . j a va  2  s  .  c  om*/

    if (fboSupport == FBO_SUPPORT.USE_EXT_UNKNOWN) {
        // The framebuffer, which regroups 0, 1, or more textures, and 0 or 1 depth buffer.
        try {
            _frameBufferId = GL30.glGenFramebuffers();
            fboSupport = FBO_SUPPORT.USE_GL30;
        } catch (IllegalStateException ex) {
            System.out.println(
                    "[Minecrift] FBO creation: GL30.glGenFramebuffers not supported. Attempting to use EXTFramebufferObject.glGenFramebuffersEXT");
            fboSupport = FBO_SUPPORT.USE_EXT;

            try {
                _frameBufferId = EXTFramebufferObject.glGenFramebuffersEXT();
            } catch (IllegalStateException ex1) {
                System.out.println(
                        "[Minecrift] FBO creation: EXTFramebufferObject.glGenFramebuffersEXT not supported, FBO creation failed.");
                throw ex1;
            }
        }
    } else if (fboSupport == FBO_SUPPORT.USE_GL30) {
        _frameBufferId = GL30.glGenFramebuffers();
    } else {
        _frameBufferId = EXTFramebufferObject.glGenFramebuffersEXT();
    }

    if (fboSupport == FBO_SUPPORT.USE_GL30) {
        _colorTextureId = GL11.glGenTextures();
        _depthRenderBufferId = GL30.glGenRenderbuffers();

        GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, _frameBufferId);
        mc.checkGLError("FBO bind framebuffer");

        GL11.glBindTexture(textureType, _colorTextureId);
        mc.checkGLError("FBO bind texture");

        GL11.glEnable(textureType);
        GL11.glTexParameterf(textureType, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
        GL11.glTexParameterf(textureType, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
        GL11.glTexImage2D(textureType, 0, internalFormat, fboWidth, fboHeight, 0, baseFormat, bufferType,
                (java.nio.ByteBuffer) null);

        //System.out.println("[Minecrift] FBO '" + fboName + "': w: " + fboWidth + ", h: " + fboHeight);

        GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, textureType,
                _colorTextureId, 0);

        mc.checkGLError("FBO bind texture framebuffer");

        GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, _depthRenderBufferId); // bind the depth renderbuffer
        GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL14.GL_DEPTH_COMPONENT24, fboWidth, fboHeight); // get the data space for it
        GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER,
                _depthRenderBufferId);
        mc.checkGLError("FBO bind depth framebuffer");
    } else {
        _colorTextureId = GL11.glGenTextures();
        _depthRenderBufferId = EXTFramebufferObject.glGenRenderbuffersEXT();

        EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, _frameBufferId);
        mc.checkGLError("FBO bind framebuffer");

        GL11.glBindTexture(textureType, _colorTextureId);
        mc.checkGLError("FBO bind texture");

        GL11.glEnable(textureType);
        GL11.glTexParameterf(textureType, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
        GL11.glTexParameterf(textureType, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
        GL11.glTexImage2D(textureType, 0, internalFormat, fboWidth, fboHeight, 0, baseFormat, bufferType,
                (java.nio.ByteBuffer) null);
        //System.out.println("[Minecrift] FBO '" + fboName + "': w: " + fboWidth + ", h: " + fboHeight);

        EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
                EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, textureType, _colorTextureId, 0);

        mc.checkGLError("FBO bind texture framebuffer");

        EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT,
                _depthRenderBufferId); // bind the depth renderbuffer
        EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT,
                GL14.GL_DEPTH_COMPONENT24, fboWidth, fboHeight); // get the data space for it
        EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
                EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT,
                _depthRenderBufferId);
        mc.checkGLError("FBO bind depth framebuffer");
    }

    if (!checkFramebufferStatus()) {
        // OK, if we have an error here - then throw an exception
        System.out.println("[Minecrift] FAILED to create framebuffer!!");
        throw new Exception("Failed to create framebuffer");
    }
}

From source file:com.mtbs3d.minecrift.VRRenderer.java

License:LGPL

private void unbindFBORenderTarget() {
    try {//from w  ww  .j  av  a2  s .c o m
        GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
    } catch (IllegalStateException ex) {
        EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0);
    }
}

From source file:com.opengrave.og.light.Depth2DFramebuffer.java

License:Open Source License

public Depth2DFramebuffer(int size) {
    framebufferSize = size;//  w  w  w . ja  va 2  s. c  o  m
    framebuffer = GL30.glGenFramebuffers();
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, framebuffer);
    shadowMap = new Texture2DShadowMap(framebufferSize);

    shadowMap.bindToFrameBuffer();

    // GL11.glDrawBuffer(GL30.GL_COLOR_ATTACHMENT0);
    GL11.glDrawBuffer(GL11.GL_NONE);
    Util.checkErr();
    GL11.glReadBuffer(GL11.GL_NONE);
    int i = GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER);
    if (i != GL30.GL_FRAMEBUFFER_COMPLETE) {
        throw new RuntimeException("Framebuffer creation failed with code: " + i);
    }
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);

    // TESTING STUFF
    count = 2;
    FloatBuffer pos = BufferUtils.createFloatBuffer(3 * 3 * count);
    FloatBuffer tex = BufferUtils.createFloatBuffer(2 * 3 * count);
    pos.put(0.75f).put(0.75f).put(0f);
    pos.put(0.75f).put(0.25f).put(0f);
    pos.put(0.25f).put(0.75f).put(0f);
    pos.put(0.25f).put(0.25f).put(0f);

    pos.put(0.75f).put(0.25f).put(0f);
    pos.put(0.25f).put(0.75f).put(0f);
    pos.flip();
    tex.put(1f).put(1f);
    tex.put(1f).put(0f);
    tex.put(0f).put(1f);
    tex.put(0f).put(0f);
    tex.put(1f).put(0f);

    tex.put(0f).put(1f);
    tex.flip();
    vao_ID = GL30.glGenVertexArrays();
    GL30.glBindVertexArray(vao_ID);
    int vbo_pos_ID = GL15.glGenBuffers();
    int vbo_tex_ID = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo_pos_ID);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, pos, GL15.GL_STATIC_DRAW);
    GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 0, 0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo_tex_ID);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, tex, GL15.GL_STATIC_DRAW);
    GL20.glVertexAttribPointer(1, 2, GL11.GL_FLOAT, false, 0, 0);
}

From source file:com.opengrave.og.light.Depth2DFramebuffer.java

License:Open Source License

@Override
public void bindDraw() {
    Util.checkErr();//ww  w  . j  a  v a 2s.  c  o m

    for (int i = GL13.GL_TEXTURE0; i < GL13.GL_TEXTURE31; i++) {
        GL13.glActiveTexture(i);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
        GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, 0);
        GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, 0);
    }
    Util.checkErr();
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, framebuffer);
    Util.checkErr();
    GL11.glDisable(GL11.GL_BLEND);
    Util.checkErr();
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDepthFunc(GL11.GL_LESS);
    GL11.glDepthMask(true);
    Util.checkErr();
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    Util.checkErr();
    GL11.glViewport(0, 0, framebufferSize, framebufferSize);

}

From source file:com.opengrave.og.light.Depth2DFramebuffer.java

License:Open Source License

@Override
public void unbindDraw() {
    GL11.glFlush();
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
}

From source file:com.opengrave.og.light.DepthCubeFramebuffer.java

License:Open Source License

public DepthCubeFramebuffer(int size) {
    framebufferSize = size;/*from ww  w  . j av  a 2 s .  c  om*/
    framebuffer = GL30.glGenFramebuffers();
    // System.out.println("Creating Pointlight Framebuffer : " +
    // framebuffer);
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, framebuffer);
    shadowMap = new TextureCubeShadowMap(framebufferSize);

    // shadowMap.bindToFrameBuffer();
    shadowMap.bindToFrameBuffer(0);
    // GL11.glDrawBuffer(GL30.GL_COLOR_ATTACHMENT0);
    GL11.glDrawBuffer(GL11.GL_NONE);
    Util.checkErr();
    GL11.glReadBuffer(GL11.GL_NONE);
    int i = GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER);
    if (i != GL30.GL_FRAMEBUFFER_COMPLETE) {
        throw new RuntimeException("Framebuffer creation failed with code: " + i);
    }
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
    Util.checkErr();
}

From source file:com.opengrave.og.light.DepthCubeFramebuffer.java

License:Open Source License

public void bindDraw(int direction) {
    Util.checkErr();/*from  w w  w  .ja va 2 s .c o m*/
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, framebuffer);
    shadowMap.bindToFrameBuffer(direction);
    Util.checkErr();

    Util.checkErr();
    GL11.glDisable(GL11.GL_BLEND);
    Util.checkErr();
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDepthFunc(GL11.GL_LESS);
    GL11.glDepthMask(true);
    Util.checkErr();
    GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
    Util.checkErr();
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    GL11.glViewport(0, 0, framebufferSize, framebufferSize);

}

From source file:com.opengrave.og.light.DepthCubeFramebuffer.java

License:Open Source License

public void unbindDraw() {
    GL11.glFlush();
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
}

From source file:com.opengrave.og.light.Texture2DShadowMap.java

License:Open Source License

public void bindToFrameBuffer() {
    GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL11.GL_TEXTURE_2D, texture, 0);
    Util.checkErr();//from  w w w. ja v a  2 s  . c o  m
    // GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER,
    // GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, texture2, 0);
    // Util.checkErr();

}

From source file:com.opengrave.og.light.TextureCubeShadowMap.java

License:Open Source License

public void bindToFrameBuffer(int direction) {
    GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT,
            GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X + direction, texture, 0);
    Util.checkErr();/*from ww  w . j a  v  a2  s.  co  m*/
    // GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER,
    // GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, texture2, 0);
    // Util.checkErr();

}