I'm trying to add some efects to the camera in android, I found some things on internet but I got stuck when creating the texture,
I use the funcion decodeYUV420SP() that returns me a int[width*height] RGB array with the hex values into each array position,
Now, I want to create an openGL texture of this array but i dont know how, I can convert each hex value to its R_G_B separated and put it into opengl but it doesn't work I do something like this:
mNewTexture = new int[width*height*4]
for(int i=0; i<mRGB.length; i=i+4){
mNewTexture[i] = getR(mRGB[i]) ; //R
mNewTexture[i+1] = getG(mRGB[i]) ; //G
mNewTexture[i+2] = getB(mRGB[i]) ; //B
mNewTexture[i+3] = getA(mRGB[i]); //A
}
To convert the hex value to RGBA (from 0 to 255)
And i do this to convert it to the openGL texture:
gl.glBindTexture(GL10.GL_TEXTURE_2D, tex);
gl.glTexImage2D(GL10.GL_TEXTURE_2D, 0, GL10.GL_RGBA, 1024, 512, 0, GL10.GL_RGBA, GL10.GL_FLOAT, FloatBuffer.wrap(mNewTexture));
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
However something is worng, cause it doesn't work...
Any idea?
Why do you try to wrap your int array as a FloatBuffer? Most of your conversions are unnecessary.
Just take your original texture, wrap it in a bytebuffer, and pass it to glTexImage with the type GL_UNSIGNED_BYTE. There's no need to create a new array from what you already have.
gl.glTexImage2D(GL10.GL_TEXTURE_2D, 0, GL10.GL_RGBA, 1024, 512, 0, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, ByteBuffer.wrap(mRGB));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With