Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (581)
games submitted by our members
Games in WIP (500)
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 1396 times)
0 Members and 1 Guest are viewing this topic.
Offline Cakey

Junior Member





« Posted 2009-03-11 22: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 :
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
   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..

Offline Cakey

Junior Member





« Reply #1 - Posted 2009-03-13 03: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 Knight


Medals: 34



« Reply #2 - Posted 2009-03-13 11: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 Member





« Reply #3 - Posted 2009-03-13 17: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 Member





« Reply #4 - Posted 2009-03-16 17: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..
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.

Offline Cakey

Junior Member





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

You know what. I didn't listen and I just did it using Graphics2D and it works relatively fine...
1  
2  
3  
4  
5  
6  
7  
   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.
http://www.youtube.com/watch?v=006OQRwrL-4

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

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (55 views)
2014-04-15 18:08:23

BurntPizza (53 views)
2014-04-15 03:46:01

UprightPath (66 views)
2014-04-14 17:39:50

UprightPath (49 views)
2014-04-14 17:35:47

Porlus (66 views)
2014-04-14 15:48:38

tom_mai78101 (90 views)
2014-04-10 04:04:31

BurntPizza (151 views)
2014-04-08 23:06:04

tom_mai78101 (246 views)
2014-04-05 13:34:39

trollwarrior1 (204 views)
2014-04-04 12:06:45

CJLetsGame (211 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org 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‑gaming.org
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!