3

I am trying to display a byte array in an OpenGL GLSurfaceView.

So I have a GLRendererclass implementing Renderer and a method onSurfaceCreated

byte[] data = new byte[512*512];
            for (int i = 0; i < 512*512; i++) {
                data[i] = 100;
            }
            ByteBuffer buffer = ByteBuffer.allocateDirect(512*512);
            buffer.put(data);
            buffer.position(0);

            GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 512, 512, 0,
                    GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, buffer);

But nothing is displayed on the screen. FYI, there is no special code in onSurfaceChanged and onDrawFrame method.

3
  • You need 4 bytes of data per pixel if you're using unsigned byte RGBA format. Also what do you mean there is no special code in onDrawFrame? How do you bind the texture? Commented Sep 13, 2016 at 9:53
  • Use the GL_RED color format then, and go back to 1 byte per pixel. Commented Sep 13, 2016 at 12:36
  • @pleluron thank you for your response, it worked. Could you post the answer ? Commented Sep 13, 2016 at 12:58

1 Answer 1

1

The format and data size don't match. GL_RGBA takes up 4*sizeof(type) per texel so you need to scale the buffer accordingly. However, if you only want a single channel texture, use GL_RED instead.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.