Problem manipulating a Texture in code

Hy All!

The experts among you will probably cry in horror as you read the code below, beware!

So, I’m trying to create a game similar to “Curiosity - what’s inside the box?”. Basically it’s a 40004000 box composed of 40004000 boxes. I’ve got everything set up except for one thing. The trick in managing these many boxes is simply not rendering them when the user zooms out enough. Instead, a larger box replaces them, coloring its texture to make it appear as though the tiny boxes are being removed.

To elaborate:

You have a 1616 plane composed of boxes one against another. Under it, there is another plane with a 1616 texture. Both the boxes and the texture are completely green. The illusion here is when you click on a box, it disappears, revealing the plane under it. If I could manage 4000*4000 boxes in memory I could simply make the plane red, thus making it obvious which box has been removed. Because I can’t, I need the texture to remain green where there are boxes, and turn red where there are none. This way, when a user zooms out far enough, the boxes can be removed from rendering, and the texture still makes it look like they are there.

The problem? I cannot seem to find a good way to manipulate the texture on the fly. Here’s what I’ve tried so far:

Reading the image into a BufferedImage, then writing the stream into a ByteArrayOutputStream, and writing that into a byte array. The code is as follows:
[java]
BufferedImage backImage = ImageIO.read(new File(“assets/textures/frontSide.jpg”));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(backImage, “jpg”, baos);
baos.flush();
byte[] imageInByte = baos.toByteArray();
baos.close();

    ByteBuffer buffer = BufferUtils.createByteBuffer(imageInByte);
    Image image = new Image(Format.RGB8, 1024,1024,buffer);
    image.setData(buffer);

[/java]

The texture image is 1024*1024 pixels in size.

Here I get an error telling me the buffer holds too little elements (I suspect it’s because of encoding or compression, but RGB8 is the smallest, isn’t it?). So that failed. I’ve been googling around for most of the day, only to find little bits that are either useless or too complicated for me to understand (I am no professional and fairly new to java).

Does anybody have any idea on how to tackle this? If there is any other way of acomplishing the illusion I am all ears, just keep in mind that the fiels is extremely large to cover with polygons and whatnot. I have no clue what shaders actually are. Just a heads up. Thank you all in advance!