Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (710)
Games in Android Showcase (212)
games submitted by our members
Games in WIP (784)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [solved]Texture.updateSubImage() questions...  (Read 2625 times)
0 Members and 1 Guest are viewing this topic.
Offline Cakey

Junior Devvie

« Posted 2009-03-11 21:58:08 »

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 ="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.updateSubImage(splat, 0, x, y);
      } catch (IOException e) {

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..

Offline Cakey

Junior Devvie

« Reply #1 - Posted 2009-03-13 02:57:19 »

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?

Offline cylab

JGO Kernel

Medals: 162

« Reply #2 - Posted 2009-03-13 10:32:48 »

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.

Mathias - I Know What [you] Did Last Summer!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Cakey

Junior Devvie

« Reply #3 - Posted 2009-03-13 16:30:03 »

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?

Offline Cakey

Junior Devvie

« Reply #4 - Posted 2009-03-16 16:58:46 »

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..
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.

Offline Cakey

Junior Devvie

« Reply #5 - Posted 2009-03-16 17:37:01 »

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);
            myTexture = TextureIO.newTexture(image, false);

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

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

theagentd (98 views)
2017-02-18 13:42:33

theagentd (102 views)
2017-02-18 13:35:16

h.pernpeintner (1267 views)
2017-01-24 22:39:11

h.pernpeintner (1256 views)
2017-01-24 22:38:32

Galdo (1816 views)
2017-01-12 13:44:09

Archive (1920 views)
2017-01-02 05:31:41

0AndrewShepherd0 (2458 views)
2016-12-16 03:58:39

0AndrewShepherd0 (2297 views)
2016-12-15 21:50:57

Lunch (2376 views)
2016-12-06 16:01:40

ral0r2 (2155 views)
2016-11-23 16:08:26
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!