Ok, so after a lot of research, I decided not to use a bufferedImage and instead use a ByteBuffer and directly render that to the Display.
here is the code that I use to do it:
private ByteBuffer textureBuffer;
private int textureID;
public Terrain() {
textureBuffer = BufferUtils.createByteBuffer(512*512*4);
textureBuffer.order(ByteOrder.nativeOrder()); //is this line necessary. I remove it and it does nothing!
textureID = GL11.glGenTextures();
for (int i = 0; i < 512*512; i ++) {
textureBuffer.put((byte) 0);
textureBuffer.put((byte) 0);
textureBuffer.put((byte) 255);
textureBuffer.put((byte) 255);
}
textureBuffer.flip();
GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, 512, 512, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, textureBuffer);
}
private void render() {
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0, 0);
GL11.glVertex2i(0, 0);
GL11.glTexCoord2f(1, 0);
GL11.glVertex2i(512, 0);
GL11.glTexCoord2f(1, 1);;
GL11.glVertex2i(512, 512);
GL11.glTexCoord2f(0, 1);
GL11.glVertex2i(0, 512);
GL11.glEnd();
}
There is one line in there that I am not sure what it does "textureBuffer.order(ByteOrder.nativeOrder());" is it necessary? I have also seen in various forums about this same topic, people using Byte arrays and setting the ByteBuffer to the array. Would it be better to do this? At the moment to change a pixel all I do is this:
textureBuffer.put(index, (byte) 255);
would change either the r, g, b, or a value.
Thankyou.