Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (407)
games submitted by our members
Games in WIP (293)
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  
  Edit for Transparency  (Read 645 times)
0 Members and 1 Guest are viewing this topic.
Offline MickeyB

Senior Member




my game will work, my game will work!


« Posted 2004-10-22 18:40:00 »

below is the nehe snippet for loading textures.  what changes need to be made to add transparncy to them?
I tried switching to TYPE_4BYTE_BGRA  but to no success.

Thanks
Smiley

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
/**
       * Texture loading directly from LWJGL examples
       */

      private static final int loadTexture(String path) {
            Image image = (new javax.swing.ImageIcon(path)).getImage();

            // Exctract The Image
           BufferedImage tex = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_3BYTE_BGR);
            Graphics2D g = (Graphics2D) tex.getGraphics();
            g.drawImage(image, null, null);
            g.dispose();

            // Flip Image
           AffineTransform tx = AffineTransform.getScaleInstance(1, -1);
            tx.translate(0, -image.getHeight(null));
            AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
            tex = op.filter(tex, null);

            // Put Image In Memory
           ByteBuffer scratch = ByteBuffer.allocateDirect(4 * tex.getWidth() * tex.getHeight());

            byte data[] = (byte[]) tex.getRaster().getDataElements(0, 0, tex.getWidth(), tex.getHeight(), null);
            scratch.clear();
            scratch.put(data);
            scratch.rewind();

            // Create A IntBuffer For Image Address In Memory  
           IntBuffer buf = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
            GL11.glGenTextures(buf); // Create Texture In OpenGL  

            GL11.glBindTexture(GL11.GL_TEXTURE_2D, buf.get(0));
            // Typical Texture Generation Using Data From The Image

            // Linear Filtering
           GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
            // Linear Filtering
           GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
            // Generate The Texture
           GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, tex.getWidth(), tex.getHeight(), 0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, scratch);

            return buf.get(0); // Return Image Address In Memory
     }

MickeyB

Current Project: http://www22.brinkster.com/mbowles/
Offline Funkapotamus

Junior Member




wo shuo han yu


« Reply #1 - Posted 2004-10-22 18:48:48 »

Change :
1  
2  
// Generate The Texture
 GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, tex.getWidth(), tex.getHeight(), 0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, scratch);

To:
1  
2  
// Generate The Texture
 GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, tex.getWidth(), tex.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, scratch);


Basically change RGB to RGBA.  A is the alpha layer, or, the transparancy layer.  
Offline MickeyB

Senior Member




my game will work, my game will work!


« Reply #2 - Posted 2004-10-25 18:54:34 »

still no transparency.  Can't get a simple color to be transluscent either


1  
2  
3  
4  
5  
                        GL11.glDisable(GL11.GL_TEXTURE_2D);
                        GL11.glColor4f(1.0f, 0.4f, 0.3f, 0.2f);
                        shield.draw(1.0f, 20, 16);
                        GL11.glEnable(GL11.GL_TEXTURE_2D);
                        GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);


Is just solid orange still....I am obviously missing something larger here.  Smiley

MickeyB

Current Project: http://www22.brinkster.com/mbowles/
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Orangy Tang

JGO Kernel


Medals: 48
Projects: 11


Monkey for a head


« Reply #3 - Posted 2004-10-25 19:13:51 »

Did you glEnable(GL_BLENDING) and set a suitable blend fuction up via glBlendFunc?

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline MickeyB

Senior Member




my game will work, my game will work!


« Reply #4 - Posted 2004-10-25 19:20:28 »

Thanks OT, had this:

1  
GL11.glBlendFunc(GL11.GL_SRC_ALPHA,GL11.GL_ONE);


but not this:
1  
GL11.glEnable(GL11.GL_BLEND);


Now my shield sphere is translucent!!!

You guys rock!

MickeyB

Current Project: http://www22.brinkster.com/mbowles/
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (88 views)
2013-05-17 21:29:12

alaslipknot (96 views)
2013-05-16 21:24:48

gouessej (128 views)
2013-05-16 00:53:38

gouessej (123 views)
2013-05-16 00:17:58

theagentd (131 views)
2013-05-15 15:01:13

theagentd (119 views)
2013-05-15 15:00:54

StreetDoggy (161 views)
2013-05-14 15:56:26

kutucuk (184 views)
2013-05-12 17:10:36

kutucuk (185 views)
2013-05-12 15:36:09

UnluckyDevil (191 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.199 seconds with 20 queries.