Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (580)
games submitted by our members
Games in WIP (499)
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 753 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: 51
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.

 

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 (44 views)
2014-04-15 18:08:23

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

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

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

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

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

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

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

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

CJLetsGame (205 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!