[solved]Texture.updateSubImage() questions...

Okay so I was wondering, if you update the sub-image of a texture your using with a buffered image, shouldn’t it put the buffered image inside of the texture your using actively???

Ex: Say I have a bullet whole picture and a white wall. I get the place on the texture where the collision occurs. then I used a code similar to this :

	public void updateSubTexture(GL gl, float xf, float yf) {
		ClassLoader loader = Box.class.getClassLoader();
        BufferedImage sourceImage;
		try {
			sourceImage = ImageIO.read(loader.getResource("Splat3.gif"));
			//TextureData splat = new TextureData(GL.GL_RGB, 0, false, sourceImage);
			TextureData splat = TextureIO.newTextureData(sourceImage, false ); 
			int x = (int)(xf * 512f);
			int y = (int)(512f - (yf * 512f));
			myTexture.bind();
			myTexture.updateSubImage(splat, 0, x, y);
		
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

Shouldn’t I get this “Splat3.gif”'s contents onto my textures surface?? Or is does this do something completely different. Right now it kind of works, but the image that is showing up is entirely black box(possibly appropriate to the image size) and just not what I have drawn. Any ideas? Graphics card issue maybe?

:EDIT: Here’s a picture for better visualization haha

Right now I am just painting walls haha, it’s pretty fun but it’s not exactly what I had in mind…

Okay now I have the bullet whole thing working. But the transparent parts of the updated texture when they hit the wall or whatever then update that region of the wall to be transparent. Which is not exactly what I want… I need to figure out a way for the transparent parts of the texture to just not change the wall texture at all… Is that possible?

\EDIT: I just figured out a way it’s possible but I’m not exactly sure how. I need to read the texture bullet wholes pixel data and create a new texture image by replacing the Alpha 1.0 colors by the corresponding colors in the selected region of the base-texture for the wall? Is this sensible?

I think this would only be sensible, without reading the texture back. You can for example draw the bullet onto a cached BufferedImage version and then send the already combined splat to the texture via updateSubImage or you can use multitexturing with an appropriate, where the second texture does only contain the splats and is compined with the first one yb the mutlitexturing hardware.

but then wouldn’t the splats overlap? hmm, I guess they wouldnt? I think I’ll look into it. Thanks again cylab.
/edit/if I don’t find a multi-texture example could someone link me to one or explain some of the syntax involved it’d be greatly appreciated.

What’s all this that people are doing using the ByteBuffers to read/alter texture data. Is that a slow process? Is it complicated?

Alright so I got the multitexturing to work and the bullet-whole image’s transparent colors still overlap the already drawn colors of previous bulletwholes. Now they aren’t transparent on the plane though they are just the other texture. Which is cool but I found out what I need to do.

I need to find a way to load a BufferedImage into the ByteBuffer the same way TextureData holds image information, then alter it by code. Anyone got a link or a hint to help me out a little?

here’s what I found out so far…

[quote]1.BufferedImage provides access to pixel data in a variety of formats.
2.JOGL prefers java.nio direct buffers.
3.ByteBuffer.allocateDirect( nBytes );
4.Unpack pixels from BufferedImage and pack into ByteBuffer.
5.BufferedImage.getRGB(row,col) returns int pixel in ARGB format.
[/quote]

You know what. I didn’t listen and I just did it using Graphics2D and it works relatively fine…


   public void updateTextureWithSplatter(int xf, int yf) {          
            BufferedImage image = myTextureBI;
            Graphics g2d = image.createGraphics();
            g2d.drawImage(splatBI, xf, yf, null);
            g2d.dispose();
            myTexture = TextureIO.newTexture(image, false);
    }

Here’s a little video of a test-run: Lol right now I call it “Sponge Painter” hahaha.