【问题标题】:OpenGL Pass texture to next renderingOpenGL 将纹理传递到下一次渲染
【发布时间】:2013-03-16 00:14:50
【问题描述】:

我对 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 很陌生,所以任何帮助,即使是概念上的帮助,都值得赞赏

【问题讨论】:

    标签: android opengl-es-2.0


    【解决方案1】:

    你想要实现的叫做Render to Texture

    可以在此处找到如何使用 android 执行此操作的小教程: http://blog.shayanjaved.com/2011/05/13/android-opengl-es-2-0-render-to-texture/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 2012-06-03
      • 2014-07-22
      • 2013-10-05
      • 1970-01-01
      • 2013-12-27
      • 1970-01-01
      相关资源
      最近更新 更多