OpenGL将纹理传递给下一个渲染

时间:2013-03-15 15:35:19

标签: android opengl-es-2.0

我是OpenGL的新手,我正在尝试创建一个2遍着色器。基本上,它有两个帧缓冲区和两个着色器程序。它像往常一样运行第一遍,然后我需要获取生成的纹理并将其作为输入传递给第二个着色器。这是怎么做到的?我似乎无法看到如何获取结果纹理并将其用作下一个纹理的输入?

这是一些代码:这段代码假设我已经设置了第二个过滤程序,并且程序中的一些属性和制服正确

@Override
public void onDraw(final int textureId, final FloatBuffer cubeBuffer,final FloatBuffer textureBuffer){
    //this draws the first pass (this is tested and working)
    super.onDraw(textureId, cubeBuffer, textureBuffer);


    //change the program
    GLES20.glUseProgram(secondFilterProgram);

    //clear the old colors
    GLES20.glClearColor(0, 0, 0, 1);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);



    GLES20.glActiveTexture(GLES20.GL_TEXTURE3); //change the texture
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, secondFilterOutputTexture[0]);
    GLES20.glUniform1i(secondFilterInputTextureUniform, 3);


    cubeBuffer.position(0);
    GLES20.glVertexAttribPointer(secondFilterPositionAttribute, 2, GLES20.GL_FLOAT, false, 0, cubeBuffer);
    GLES20.glEnableVertexAttribArray(secondFilterPositionAttribute);

    textureBuffer.position(0);
    GLES20.glVertexAttribPointer(secondFilterTextureCoordinateAttribute, 2, GLES20.GL_FLOAT, false, 0, textureBuffer);
    GLES20.glEnableVertexAttribArray(secondFilterTextureCoordinateAttribute); //same as line from init

    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
    GLES20.glDisableVertexAttribArray(secondFilterPositionAttribute);
    GLES20.glDisableVertexAttribArray(secondFilterTextureCoordinateAttribute);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);

    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);

}

我觉得我在这里错过了一块拼图。再说一次,我对OpenGL很陌生,所以任何帮助,甚至在概念上都是值得赞赏的

1 个答案:

答案 0 :(得分:0)

您想要实现的目标称为渲染到纹理

这里有一个关于如何用android做这个的小教程: http://blog.shayanjaved.com/2011/05/13/android-opengl-es-2-0-render-to-texture/

相关问题