Original Post
Hi there,
Sorry I have to ask cause I
ByteBuffer tbb = ByteBuffer.allocateDirect(8);
tbb.order(ByteOrder.nativeOrder());
IntBuffer tb = tbb.asIntBuffer();
gl2.glGenTextures(2, tb);
HUtil.checkError(gl2);
int[] textures = new int[2];
tb.position(0);
tb.get(textures);
gl2.glBindTexture(GL20.GL_TEXTURE_2D, textures[0]);
HUtil.checkError(gl2);
gl2.glTexImage2D(GL20.GL_TEXTURE_2D, 0, GL20.GL_RGBA, FBO_WIDTH, FBO_HEIGHT, 0,
GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, null);
HUtil.checkError(gl2);
gl2.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MIN_FILTER,
GL20.GL_NEAREST);
gl2.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MAG_FILTER,
GL20.GL_NEAREST);
gl2.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_WRAP_S,
GL20.GL_CLAMP_TO_EDGE);
gl2.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_WRAP_T,
GL20.GL_CLAMP_TO_EDGE);
HUtil.checkError(gl2);
gl2.glBindTexture(GL20.GL_TEXTURE_2D, 0);
mFBOTexHandle = textures[0];
gl2.glBindTexture(GL20.GL_TEXTURE_2D, textures[1]);
gl2.glTexImage2D(GL20.GL_TEXTURE_2D, 0, GL20.GL_DEPTH_COMPONENT,
FBO_WIDTH, FBO_HEIGHT, 0,
GL20.GL_DEPTH_COMPONENT, GL20.GL_UNSIGNED_SHORT, null);
gl2.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MIN_FILTER,
GL20.GL_NEAREST);
gl2.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MAG_FILTER,
GL20.GL_NEAREST);
gl2.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_WRAP_S,
GL20.GL_CLAMP_TO_EDGE);
gl2.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_WRAP_T,
GL20.GL_CLAMP_TO_EDGE);
gl2.glBindTexture(GL20.GL_TEXTURE_2D, 0);
HUtil.checkError(gl2);
ByteBuffer fbb = ByteBuffer.allocateDirect(4);
fbb.order(ByteOrder.nativeOrder());
IntBuffer bufhandle = fbb.asIntBuffer();
// General frame buffer
gl2.glGenFramebuffers(1, bufhandle);
int[] handles = new int[1];
bufhandle.position(0);
bufhandle.get(handles);
mFBOHandle = handles[0];
// Bind frame buffer
gl2.glBindFramebuffer(GL20.GL_FRAMEBUFFER, mFBOHandle);
// attach texture to frame buffer
gl2.glFramebufferTexture2D(GL20.GL_FRAMEBUFFER,
GL20.GL_DEPTH_ATTACHMENT, GL20.GL_TEXTURE_2D, textures[0], 0);
HUtil.checkError(gl2);
gl2.glFramebufferTexture2D(GL20.GL_FRAMEBUFFER,
GL20.GL_DEPTH_ATTACHMENT, GL20.GL_TEXTURE_2D, textures[1], 0);
HUtil.checkError(gl2);
int status = gl2.glCheckFramebufferStatus(GL20.GL_FRAMEBUFFER);
if (status == GL20.GL_FRAMEBUFFER_COMPLETE) {
Log.i(TAG, "Frame buffer created. Handle = " + mFBOHandle);
}else{
Log.e(TAG, "Frame buffer can not be created err = " + status);
}
gl2.glBindFramebuffer(GL20.GL_FRAMEBUFFER, 0);
The FBO creation IS successful. However, when I set the Texture handle to my Frag shader like this:
int texid = mFBOTexHandle;
if (texid > 0){
int loc = gl2.glGetUniformLocation(mProgram, "tex");
gl2.glUniform1i(loc, mFBOTexHandle);
HUtil.checkError(gl2, "Damn we got 1281");
}
I got 1281 error
For your information, I have set Texture width&height to 128 so it is power of 2 and it
Thanks for your time and any suggestion is really appreciated
Sorry I have to ask cause I
m pulling my hair off, some of which are already white. So, I m trying to get FBO working on Android. I have looked up the internet to write the following code:ByteBuffer tbb = ByteBuffer.allocateDirect(8);
tbb.order(ByteOrder.nativeOrder());
IntBuffer tb = tbb.asIntBuffer();
gl2.glGenTextures(2, tb);
HUtil.checkError(gl2);
int[] textures = new int[2];
tb.position(0);
tb.get(textures);
gl2.glBindTexture(GL20.GL_TEXTURE_2D, textures[0]);
HUtil.checkError(gl2);
gl2.glTexImage2D(GL20.GL_TEXTURE_2D, 0, GL20.GL_RGBA, FBO_WIDTH, FBO_HEIGHT, 0,
GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, null);
HUtil.checkError(gl2);
gl2.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MIN_FILTER,
GL20.GL_NEAREST);
gl2.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MAG_FILTER,
GL20.GL_NEAREST);
gl2.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_WRAP_S,
GL20.GL_CLAMP_TO_EDGE);
gl2.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_WRAP_T,
GL20.GL_CLAMP_TO_EDGE);
HUtil.checkError(gl2);
gl2.glBindTexture(GL20.GL_TEXTURE_2D, 0);
mFBOTexHandle = textures[0];
gl2.glBindTexture(GL20.GL_TEXTURE_2D, textures[1]);
gl2.glTexImage2D(GL20.GL_TEXTURE_2D, 0, GL20.GL_DEPTH_COMPONENT,
FBO_WIDTH, FBO_HEIGHT, 0,
GL20.GL_DEPTH_COMPONENT, GL20.GL_UNSIGNED_SHORT, null);
gl2.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MIN_FILTER,
GL20.GL_NEAREST);
gl2.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MAG_FILTER,
GL20.GL_NEAREST);
gl2.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_WRAP_S,
GL20.GL_CLAMP_TO_EDGE);
gl2.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_WRAP_T,
GL20.GL_CLAMP_TO_EDGE);
gl2.glBindTexture(GL20.GL_TEXTURE_2D, 0);
HUtil.checkError(gl2);
ByteBuffer fbb = ByteBuffer.allocateDirect(4);
fbb.order(ByteOrder.nativeOrder());
IntBuffer bufhandle = fbb.asIntBuffer();
// General frame buffer
gl2.glGenFramebuffers(1, bufhandle);
int[] handles = new int[1];
bufhandle.position(0);
bufhandle.get(handles);
mFBOHandle = handles[0];
// Bind frame buffer
gl2.glBindFramebuffer(GL20.GL_FRAMEBUFFER, mFBOHandle);
// attach texture to frame buffer
gl2.glFramebufferTexture2D(GL20.GL_FRAMEBUFFER,
GL20.GL_DEPTH_ATTACHMENT, GL20.GL_TEXTURE_2D, textures[0], 0);
HUtil.checkError(gl2);
gl2.glFramebufferTexture2D(GL20.GL_FRAMEBUFFER,
GL20.GL_DEPTH_ATTACHMENT, GL20.GL_TEXTURE_2D, textures[1], 0);
HUtil.checkError(gl2);
int status = gl2.glCheckFramebufferStatus(GL20.GL_FRAMEBUFFER);
if (status == GL20.GL_FRAMEBUFFER_COMPLETE) {
Log.i(TAG, "Frame buffer created. Handle = " + mFBOHandle);
}else{
Log.e(TAG, "Frame buffer can not be created err = " + status);
}
gl2.glBindFramebuffer(GL20.GL_FRAMEBUFFER, 0);
The FBO creation IS successful. However, when I set the Texture handle to my Frag shader like this:
int texid = mFBOTexHandle;
if (texid > 0){
int loc = gl2.glGetUniformLocation(mProgram, "tex");
gl2.glUniform1i(loc, mFBOTexHandle);
HUtil.checkError(gl2, "Damn we got 1281");
}
I got 1281 error
For your information, I have set Texture width&height to 128 so it is power of 2 and it
s so small that we should not run out of memory. And also I tried to gen mipmap mannually by
gl2.glGenerateMipmap(GL20.GL_TEXTURE_2D);
still doesn t workThanks for your time and any suggestion is really appreciated