create colored texture

Hi
I have a little problem creating a texture. I create a texture with the code shown below.
The method should create a 16*16 pixel-texture with color green. But if I display the texture,
it contains random data, or nothing (black).


public int createTexture(GL gl) {
// save index
IntBuffer texture = BufferUtils.newIntBuffer(1);

// do setup
gl.glGenTextures(1, texture);
gl.glShadeModel(GL.GL_SMOOTH);
gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
gl.glBindTexture(GL.GL_TEXTURE_2D, texture.get(0));
System.out.println("Saved @ Index: " + texture.get(0));

// create and initialize texture-buffer
ByteBuffer bb = ByteBuffer.allocateDirect(16 * 16 * 3);
for (int i = 0; i < 16 * 16; i++) {
     bb.put((byte)0x00);
     bb.put((byte)0xff);
     bb.put((byte)0x00);
}

// create texture @ index
gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, 16, 16,  0, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, bb);

// setup texture-env and filter
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);

// return the index of created texture
return texture.get(0);
}

You need to rewind the byte buffer before the glTexImage2D call.

Thanks, :slight_smile: