glTexImage2D not loading my data
- by Clyde
Can anyone suggest why this code doesn't work? When I draw using this texture all I get is black. If I use GLUtils.texImage2D() to load a png file, it works correctly.
ByteBuffer bb = ByteBuffer.allocateDirect(128*128*4).order(ByteOrder.nativeOrder());
bb.position(0);
for(int row = 0; row != 128; row++) {
for(int i = 0 ; i != 128 ; i++) {
bb.put((byte)0x80);
bb.put((byte)0xFF);
bb.put((byte)0xFF);
bb.put((byte)i);
}
}
int[] handle = new int[1];
GLES20.glEnable(GLES20.GL_TEXTURE_2D);
GLES20.glGenTextures(1, handle, 0);
DrawAdapter.checkGlError("Gen textures");
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, handle[0]);
DrawAdapter.checkGlError("Bind textures");
bb.position(0);
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 128, 128, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, bb);
DrawAdapter.checkGlError("glTexImage2D");
return handle[0];