Thank you very much for your kind help.
Here's is what I'm doing :
1) I first draw the scene to a BufferedImage and fill a 2-dimensional int array. I draw each pixel of the scene coming from a large number of PNG's. This operation is done using AWT's setRGB(...) method while reading each pixel of each PNG. I also store each pixel state/behaviour in the 2-dimensional int array for further collision detection and game mechanics. These 2 operations are admittedly but are executed only once (level initialization).
2) I load the BufferedImage into a texture. Note this BufferedImage contains transparent areas.
Rendering the whole game level to the screen uses these "layers" (from the rear to the front) :
1) animated indestructible background sprites (water, lava, ...) = textured quads
2) main scene = the big scene quad textured with the BufferedImage created earlier
3) animated indestructible foreground sprites (doors, ...) = textured quads
4) the lemmings sprites = textured quads
Since the scene BufferedImage won't be changed after its creation, I can keep it as a backup copy (maybe useful if the player would like to restart the level).
When a lemming destroys the scene or builds stairs, I update the corresponding pixels directly in the texture using glTexSubImage2D(...). I have to process each altered pixels separately since stairs and holes are not always rectangles. I mean there can be transparent pixels around the object in the original image so I have to bypass these transparent pixels otherwise it would erase pixels in the main scene.
To do this, I use such the following method after binding :
private void setPixel (int x, int y, int red, int green, int blue, int alpha) {
byte[] temp = new byte[]{(byte)red, (byte)green, (byte)blue, (byte)alpha};
ByteBuffer subImageBuffer = (ByteBuffer) BufferUtils.createByteBuffer(temp.length).put(temp).flip();
GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, x, y, 1, 1, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, subImageBuffer);
}
I can use such a method to draw new pixels as much as to erase existing ones (drawing stairs and destroying terrain).
What do you think about this?
> wolf_m : could explain me how to create and handle such a destruction (alpha) map? Since my scene texture already has transparent pixels (where there is no terrain), does this alpha map only handles terrain "destruction"? Could you tell and explain me the opengl methodsused for this?
> Ciardhubh :
Removing destroyed terrain could be done with Alpha Testing (e.g. glAlphaFunc with GL_GREATER = 0.5) and a texture that is transparent in the area of the explosion (disable blending, write over background)
Do you mean using an additional texture with only "holes" over the current scene texture? Could you also tell me and explain me the opengl syntax to use in your example?
> bobjob : could you go further with your ideas and explanations? (how you handle destruction in the depth buffer, how you draw steps, how to update e texture using FBO's...).
Thank you very much
