1
\$\begingroup\$

As first I want excuse me for opening another FBO question. I found alot of them but I still can not manage to get it working. I want to implement a framebuffer class for postprocesing in my 2D Android Applikation. Since it's 2D I do not need a renderbuffer for depth testing. My current code has the problem that nothing gets rendered so the framebuffer is maybe empty. I am doing this steps:

private final int framebuffer[] = new int[1];
private final int mTextureID;
//GLTexture is my Class for drawing textures..
//I can secure that this class works with drawing normal Textures
private final GLTexture mFrame;

//init
public GLPostProcessor()
{
    //create empty Texture
    mTextureID = GLSurf.mTexMng.createNewEmpty();

    //gen Framebuffer
    GLES20.glGenFramebuffers(1, framebuffer, 0);

    //bind
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, framebuffer[0]);

    //set Texture
    GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, mTextureID, 0);

    //unbind
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);

    //init GLTexture
    mFrame = new GLTexture(-1, false);
    mFrame.setPos(0, 0, 1920, 1080);
    mFrame.mTextureID = mTextureID;
    mFrame.setShader(GLShader.sProgram_PostProcessing);
}

public final void beginRender()
{
    //bind framebuffer
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, framebuffer[0]);

    //reset Viewport and clear
    GLES20.glViewport(0, 0, 1920, 1080);
    GLES20.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); //white
}

public final void endRender()
{
    //unbind
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
}

public final void Render()
{
    mFrame.Render();
}

My createNewEmpty() which returns 1 as new Texture ID:

public final int createNewEmpty()
{
    final int texid = getfreeGLID(); //In this case it has the value 1

    if (texid >= MAX_TEXTURES)
        return 0;

    // Bind texture to texturename
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + texid);
    //mTextureIDs is created by glGenTextures()
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureIDs[texid]);

    // Set filtering
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, 
                           GLES20.GL_NEAREST);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, 
                           GLES20.GL_NEAREST);

    // Set wrapping mode
    //is this necessary or not?
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, 
                           GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, 
                           GLES20.GL_CLAMP_TO_EDGE);

    GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 1920, 1080, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);

    return texid;
}

I already tried a POT colorbuffer (1024x1024 at glTexImage2D() and glViewport()). That did not make a difference for my problem. But i found out, that if i change my shader code to sth. like "Color = Position" my screen gets colored.. so the rendercall is working in some way but the texture seems to be empty..

I think it's obvious but this is how I use the class:

GLPostProcessor glpp = new GLPostProcessor();
//...
glpp.beginRender();
//render some things
glpp.endRender();
glpp.Render();

Thanks in advance and comment if code is missing.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.