PDA

View Full Version : render to texture, then apply a texture. does not work, help



Argonaft
06-27-2014, 04:48 AM
GLES20. Android.

Prompt, please, as to render to a texture, and then render this texture mesh. Not working for me:





private int wi=displayW;
private int he=displayH;


//---------------in onSurfaceCreated




GLES20.glGenFramebuffers(1, this.frameBuffer, 0);


GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBuffer[0]);



GLES20.glGenRenderbuffers(1, renderBuffer, 0);


GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, renderBuffer[0]);



GLES20.glGenTextures(1, this.textureBuffer, 0);
GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, this.textureBuffer[0]);



GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, wi, he, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);


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.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);



//-----------------------onDrawFrame

GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBuffer[0]);

GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFE R, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, this.textureBuffer[0], 0);

GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, renderBuffer[0]);

GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFE R,
GLES20.GL_DEPTH_COMPONENT16 , wi,he);


GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBU FFER,
GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER,
renderBuffer[0]);


........render

GLES20.glFlush();


GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, 0);


.......render mesh with texture