Reputation: 1270
I am very new in OpenGL.
How can I create an offscreen texture, so that I can get some Informations of it (e.g. PixelColor by clicking on view texture) ?
I tried many many things for example FBO, but it did't work. I have no imagination how to load the Bitmap to a offscreen texture and get information of it. I am very frustated :/
Edit:
Took this Tutorial as Example, don't know if it fits to my problem. createFramebuffer
public void createFramebuffer(GL10 gl) {
FloatBuffer uvBuffer2;
int texture[] = new int[1];
GLES20.glGenTextures(1, texture, 0);
GLES20.glBindTexture(GLES20.GL_TEXTURE0, texture[0]);
float uvs2[] = {
0.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.0f,
1.0f, 0.0f
};
ByteBuffer bb = ByteBuffer.allocateDirect(uvs2.length * 4);
bb.order(ByteOrder.nativeOrder());
uvBuffer2 = bb.asFloatBuffer();
uvBuffer2.put(uvs2);
uvBuffer2.position(0);
gl.glTexCoordPointer(2, GLES20.GL_BYTE, 0, uvBuffer2);
//load image
int idTest = mContext.getResources().getIdentifier("drawable/testgroesse", null, mContext.getPackageName());
Bitmap wood = BitmapFactory.decodeResource(mContext.getResources(), idTest);
GLES20.glTexParameterf(GLES20.GL_TEXTURE0, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
GLES20.glTexParameterf(GLES20.GL_TEXTURE0, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
GLUtils.texImage2D(GLES20.GL_TEXTURE0, 0, wood, 0);
GLES20.glEnable(GLES20.GL_TEXTURE0);
gl.glEnableClientState(GLES20.GL_TEXTURE0);
//color picking background start
ByteBuffer bytePickedColor = ByteBuffer.allocate(4);
bytePickedColor.order(ByteOrder.nativeOrder());
GLES20.glFlush();
GLES20.glReadPixels(touchXint, touchYint, 1, 1, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, bytePickedColor);
byte b[] = new byte[4];
bytePickedColor.get(b);
String key = "" + b[0] + " " + b[1] + " " + b[2] + " " + b[3];
Log.d("Color_Farbe: ", key);
bytePickedColor.rewind();
//color picking background end
}
Upvotes: 0
Views: 1649
Reputation: 16774
To oversimplify:
The FBO you created is a BUFFER that contains RGBA + 16-bit depth. By attaching a texture to it you can then reuse the texture as it will have the same RGBA data as the FBO. At the beginning the buffer itself is still empty, you still need to clear it and draw to it as with any other render buffer.
So to put the image/texture on to that buffer you need to create the texture (with that image) and draw a textured rectangle on this FBO.
It would seem this is not what you are after:
glReadPixels
).It looks like all you are looking for is glReadPixels
to get the colour values from the current buffer. If this is not the case please rephrase your question and explain what is your goal here.
Upvotes: 2