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 (406)
games submitted by our members
Games in WIP (290)
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  
  funky color mode problem  (Read 671 times)
0 Members and 1 Guest are viewing this topic.
Offline weston

Junior Member





« Posted 2005-01-08 06:07:28 »

I'm having a problem with images that I load in to use as textures, it seems like no alpha information is being used.  Its not just that my textures have opaque backgrounds, but it seems like they are using indexed color mode or something, if I load in a texture that uses alpha blending for smooth edges or something I get weird artifacts, but an 8-bit png works perfect (still has an opaque background though...). Here are a couple screens of a texture created from a 24-bit png with anti-aliased (translucent) edges:

I'm using glTexEnvi(blah, blah, GL_DECAL) on this one:


and GL_MODULATE on this one:


here is the code for loading the image

1  
image = ImageIO.read(new BufferedInputStream(ImageUtils.class.getClassLoader().getResourceAsStream(resource)));


this converts the image to use opengl's color model (from kevglass/matzon's texture loader)
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  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
private static ByteBuffer convertImageData(BufferedImage bufferedImage,Texture texture) { 
        ByteBuffer imageBuffer = null;
        WritableRaster raster;
        BufferedImage texImage;
       
        int texWidth = 2;
        int texHeight = 2;
       
        // find the closest power of 2 for the width and height

        // of the produced texture

        while (texWidth < bufferedImage.getWidth()) {
            texWidth *= 2;
        }
        while (texHeight < bufferedImage.getHeight()) {
            texHeight *= 2;
        }
       
        texture.setTextureHeight(texHeight);
        texture.setTextureWidth(texWidth);
       
        // create a raster that can be used by OpenGL as a source

        // for a texture

        if (bufferedImage.getColorModel().hasAlpha()) {
            raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,texWidth,texHeight,4,null);
            texImage = new BufferedImage(glAlphaColorModel,raster,false,new Hashtable());
        } else {
            raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,texWidth,texHeight,3,null);
            texImage = new BufferedImage(glColorModel,raster,false,new Hashtable());
        }
           
        // copy the source image into the produced image

        Graphics g = texImage.getGraphics();
        g.setColor(new Color(0f,0f,0f,0f));
        g.fillRect(0,0,texWidth,texHeight);
        g.drawImage(bufferedImage,0,0,null);
       
        // build a byte buffer from the temporary image

        // that be used by OpenGL to produce a texture.

        byte[] data = ((DataBufferByte) texImage.getRaster().getDataBuffer()).getData();

        imageBuffer = ByteBuffer.allocateDirect(data.length);
        imageBuffer.order(ByteOrder.nativeOrder());
        imageBuffer.put(data, 0, data.length);
        imageBuffer.flip();
       
        return imageBuffer;
    }


I've tried forcing it to use glAlphaColorModel, but the texture is still opaque.

not sure whate else there is to show, I've just enabled GL_TEXTURE_2D and blending and tried messing with glTexEnvi, but I've run out of ideas. Could I have changed some ogl state to make it act this way? or do you think it is in the image loading? I'll mess around with DevIL some more tommorow, that should eliminate the possibility of the problem being in the image loading.

Any ideas?

for(int i = 1; i > 0; i++)
{
System.out.println(i+" cups of java downed");
}
Offline weston

Junior Member





« Reply #1 - Posted 2005-01-08 22:33:26 »

figured it out. I was did all my opengl init after a method call to startGame() which umm, didn't return until the game ended Embarrassed So yeah, enabling blending did the trick.

for(int i = 1; i > 0; i++)
{
System.out.println(i+" cups of java downed");
}
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!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

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 (62 views)
2013-05-17 21:29:12

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

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

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

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

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

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

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

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

UnluckyDevil (175 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.169 seconds with 20 queries.