Example usage for org.lwjgl.opengl GL30 glBindFramebuffer

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

Introduction

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

Prototype

public static void glBindFramebuffer(@NativeType("GLenum") int target, @NativeType("GLuint") int framebuffer) 

Source Link

Document

Binds a framebuffer to a framebuffer target.

Usage

From source file:cuchaz.jfxgl.prism.JFXGLContext.java

License:Open Source License

@Override
public void blitFBO(int srcFboId, int dstFboId, int srcX0, int srcY0, int srcX1, int srcY1, int dstX0,
        int dstY0, int dstX1, int dstY1) {
    GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, srcFboId);
    GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, dstFboId);
    GL30.glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, GL11.GL_COLOR_BUFFER_BIT,
            GL11.GL_NEAREST);/*from   w  ww  .java2  s.c o  m*/
}

From source file:cuchaz.jfxgl.prism.OffscreenBuffer.java

License:Open Source License

public boolean resize(int width, int height) {

    if (this.width == width && this.height == height) {
        return false;
    }//from  www . ja va  2s  .co  m

    this.width = width;
    this.height = height;

    // resize the texture
    if (texId != 0) {
        context.deleteTexture(texId);
    }
    texId = context.createTexture(width, height);

    // update the framebuf
    if (fboId == 0) {
        fboId = GL30.glGenFramebuffers();
    }
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, fboId);
    GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, texId, 0);

    // remove the old quad
    quadDirty = true;

    return true;
}

From source file:de.ikosa.mars.viewer.glviewer.engine.GLRenderer2Stage.java

License:Open Source License

public GLRenderer2Stage(GLScene scene, GLResources resourceManager, GLCamera camera, int width, int height) {
    this.scene = scene;
    this.camera = camera;
    this.width = width;
    this.height = height;

    // setup opengl
    GL11.glViewport(0, 0, width, height);

    // setup framebuffer
    fbAId = GL30.glGenFramebuffers();/*w  ww .  j ava 2 s  . c o m*/
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, fbAId);

    // color buffer
    fbATexId = GLTextureBuilder.createEmptyTexture("FB", width, height, (byte) 0, (byte) 0, (byte) 0, (byte) 0)
            .getTextureId();
    GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, fbATexId,
            0);

    // create depth buffer
    dbATexId = GLTextureBuilder.createEmptyTexture("DB", width, height, 0.0f).getTextureId();
    GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL11.GL_TEXTURE_2D, dbATexId, 0);

    int status = GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER);

    if (status != GL30.GL_FRAMEBUFFER_COMPLETE) {
        ML.f(String.format("Cannot set up framebuffer: %x", status));
    }

    // setup framebuffer B
    fbBId = GL30.glGenFramebuffers();
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, fbBId);

    // color buffer
    fbBTexId = GLTextureBuilder.createEmptyTexture("FB", width, height, (byte) 0, (byte) 0, (byte) 0, (byte) 0)
            .getTextureId();
    GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, fbBTexId,
            0);

    status = GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER);

    if (status != GL30.GL_FRAMEBUFFER_COMPLETE) {
        ML.f(String.format("Cannot set up framebuffer: %x", status));
    }

    ssqScene = new GLSSQScene(resourceManager, resourceManager.getShader("post"), new GLTexture("FB", fbATexId),
            new GLTexture("DB", dbATexId), resourceManager.getShader("post2"), new GLTexture("FB2", fbBTexId));
}

From source file:de.ikosa.mars.viewer.glviewer.engine.GLRenderer2Stage.java

License:Open Source License

public void Draw() {
    // forward pass
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, fbAId);
    GL20.glDrawBuffers(GL30.GL_COLOR_ATTACHMENT0);
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

    scene.Pass(GLScene.PassType.Forward, camera);

    // post pass//www .  j a  v  a  2s.  c  om
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, fbBId);
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    ssqScene.Pass(GLScene.PassType.PostProcess);

    // post B pass
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    ssqScene.Pass(GLScene.PassType.PostProcess2);

}

From source file:eu.over9000.veya.rendering.Shadow.java

License:Open Source License

public void init() {
    depthMap = GL11.glGenTextures();/*from   ww  w  . java  2 s  .co  m*/
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, depthMap);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_DEPTH_COMPONENT, SHADOW_WIDTH, SHADOW_HEIGHT, 0,
            GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, (ByteBuffer) null);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL13.GL_CLAMP_TO_BORDER);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL13.GL_CLAMP_TO_BORDER);

    shadowFBO = GL30.glGenFramebuffers();
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, shadowFBO);
    GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL11.GL_TEXTURE_2D, depthMap, 0);
    GL11.glDrawBuffer(GL11.GL_NONE);
    GL11.glReadBuffer(GL11.GL_NONE);
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
}

From source file:eu.over9000.veya.rendering.Shadow.java

License:Open Source License

public void preRender() {
    Veya.program_shadow.use(true);//from  ww w.  j  av  a  2  s .c o m
    updateMatrixLightSpaceMatrixLocation();
    GL11.glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, shadowFBO);
    GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
    GL11.glCullFace(GL11.GL_FRONT);

}

From source file:eu.over9000.veya.rendering.Shadow.java

License:Open Source License

public void postRender() {
    GL11.glCullFace(GL11.GL_BACK); // don't forget to reset original culling face
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
    Veya.program_normal.use(true);/*w  w w.  jav  a2  s .c o  m*/
    GL11.glViewport(0, 0, Display.getWidth(), Display.getHeight());

    GL13.glActiveTexture(GL13.GL_TEXTURE1);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, depthMap);
}

From source file:fr.ign.cogit.geoxygene.appli.render.LwjglLayerRenderer.java

License:Open Source License

/**
 * Draw the Rendered FBO into the Ping Pong FBO
 * /*  ww  w . java  2 s .c  o  m*/
 * @throws GLException
 */
private void drawInPingPongFBO() throws GLException {
    if (this.current_symbolizer == null) {
        logger.error("The current symbolizer is NULL");
        return;
    }
    // Get the blending mode of this symbolizer and the filter of the
    // current Layer.
    BlendingMode bmode = this.current_symbolizer.getBlendingMode();
    if (bmode == null) {
        bmode = GeoxygeneConstants.GL_VarName_DefaultBlendingMode;
    }

    LayerFilter layerfilter = ((AbstractLayer) this.getLayer()).getFilter();
    if (layerfilter == null)
        layerfilter = new LayerFilterIdentity();
    String program_name = "GLProgram-"
            + (bmode.toString() + "-" + layerfilter.getClass().getSimpleName()).toLowerCase();
    GLProgram p = GLContext.getActiveGlContext().getProgram(program_name);
    if (p == null) {
        GLProgramBuilder builder = new GLProgramBuilder();
        builder.addDelegateBuilder(new BlendingModeGLProgramBuilder(bmode, layerfilter));
        p = builder.build(program_name, null);
        if (p == null) {
            logger.warn("Failed to create the blending program " + bmode);
            logger.warn("Fallback to the default blending program "
                    + GeoxygeneConstants.GL_VarName_DefaultBlendingMode);
            bmode = GeoxygeneConstants.GL_VarName_DefaultBlendingMode;
            p = builder.build("GLProgram-"
                    + (bmode.toString() + "-" + LayerFilterIdentity.class.getSimpleName()).toLowerCase(), null);
        }
        if (p == null) {
            logger.fatal("Failed to create the blending program " + bmode + ". Exiting the rendering.");
            return;
        }
        GLContext.getActiveGlContext().addProgram(p);
    }
    GLContext.getActiveGlContext().setCurrentProgram(p);
    this.getLayerViewPanel().getGLCanvas().drawInPingPong(p);

    GL30.glBindVertexArray(LayerViewGLPanel.getScreenQuad().getVaoId());

    p.setUniform(GeoxygeneConstants.GL_VarName_ObjectOpacityVarName, 1f);
    p.setUniform(GeoxygeneConstants.GL_VarName_GlobalOpacityVarName, 1f);
    GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);

    GLTools.glCheckError("before FBO drawing textured quad");
    LwjglLayerRenderer.drawComplex(LayerViewGLPanel.getScreenQuad());
    GLTools.glCheckError("FBO drawing textured quad");
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
    GL30.glBindVertexArray(0); // unbind VAO
    GLTools.glCheckError("exiting FBO rendering");
    glBindTexture(GL_TEXTURE_2D, 0); // unbind texture
}

From source file:fr.ign.cogit.geoxygene.appli.render.LwjglLayerRenderer.java

License:Open Source License

/**
 * Initialize layer FBO to receive GL primitives from a set of identical
 * symbolizers//from w ww. j  a  v  a2s .  co  m
 * 
 * @param primitive
 * @param opacity
 * @param currentSymbolizer
 * @throws GLException
 */
private void clearFBOLayer() throws GLException {
    GLTools.glCheckError("preparing next FBO Layer");
    GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, this.getLayerViewPanel().getGLCanvas().getFboId());
    GL11.glDrawBuffer(GL30.GL_COLOR_ATTACHMENT0);

    GLTools.glCheckError("bind frame buffer");

    // Blending mode in FBO drawing.
    GLTools.glCheckError("finalizing FBO initialization");
    GL11.glClearColor(0f, 0f, 0f, 0f);
    GLTools.glCheckError("finalizing FBO initialization");
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);

    GLTools.glCheckError("finalizing FBO initialization");
    glEnable(GL11.GL_BLEND);
    GLTools.glCheckError("finalizing FBO initialization");
    GL20.glBlendEquationSeparate(GL14.GL_FUNC_ADD, GL14.GL_MAX);
    GLTools.glCheckError("finalizing FBO initialization");
    GL14.glBlendFuncSeparate(GL11.GL_ONE, GL11.GL_ZERO, GL11.GL_ZERO, GL11.GL_ZERO);
    GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, 0);
    GLTools.glCheckError("finalizing FBO initialization");
}

From source file:ion2d.INGrabber.java

License:Open Source License

/**
 * Grabs an image of the display and attachs it to the specified texture
 * @param INTexture2D texture/*from   w  w  w .  j  a v  a  2  s .c o  m*/
 * @throws Exception
 */
public void grab(INTexture2D texture) throws Exception {
    GL11.glGetInteger(GL30.GL_FRAMEBUFFER_BINDING, this.oldBufferObject);

    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, this.bufferObject.get(0));

    GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D,
            texture.getId(), 0);

    int status = GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER);

    if (status != GL30.GL_FRAMEBUFFER_COMPLETE) {
        throw new Exception("Frame Grabber could not attach texture to framebuffer");
    }

    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, this.oldBufferObject.get(0));
}