Textures

I have this code from the LWJGL examples:

public Texture loadImage(String filename) throws Exception {
        Texture texture = null;
        BufferedImage tmpImg = null;
        
        /* normally I would use StringUtils.isValid(String) from the 
           jakarta commons lib, but thats beyond the scope of this lesson */
        if ((filename != null) && (filename.trim() != "")) {
            try {
                InputStream is = getClass().getResourceAsStream(filename);
                tmpImg = (BufferedImage) ImageIO.read(is);
                if (tmpImg == null) {
                    throw new Exception("Error: Got null from ImageIO.read()");
                }
                texture = new Texture(tmpImg);
            }
            catch ( Exception e ) {
                throw new Exception("Problem loading bitmap", e);
            }
        } else {
            throw new Exception("Error: file name is not valid!");
        }
        return texture;
    }

And it has problems finding bmps, but not pngs. Is there a reason for this? And what settings do I need on the png for it to show up?

Thanks.

http://www.puppygames.net/forums/viewtopic.php?t=73&highlight=png+textures

If I use certain textures, any polygon that’s not texture mapped disappears. Anyone know why this happens?

Thanks.

I just had a problem like this.

Are you turning off texture mapping when drawing the other polygons? If not, then all the vertices will inherit the previous texture coord, which could be black - depending on the image - and nothing appears.

What’s the line of code to disable texturing? And where do I put it? If you can, use the following as an example:


float[][] triangle1={{20.0f, 30.0f, 200.0f},
                                      {20.0f, 40.0f, 0.0f},
                                      {60.0f, 30.0f, -20.0f}};
        crossProduct=GraphicsUtil.unitCrossProduct(triangle1);
        gl.begin(GL.TRIANGLES);
              gl.normal3f(crossProduct[0], crossProduct[1], crossProduct[2]);
              gl.texCoord2f(0.0f, 0.86f);
            gl.vertex3f(20.0f, 30.0f, 200.0f);
            gl.normal3f(crossProduct[0], crossProduct[1], crossProduct[2]);
            gl.texCoord2f(0.77f, 1.0f);
            gl.vertex3f(20.0f, 40.0f, 0.0f);
            gl.normal3f(crossProduct[0], crossProduct[1], crossProduct[2]);
            gl.texCoord2f(0.88f, 0.86f);
            gl.vertex3f(60.0f, 30.0f, -20.0f);
        gl.end();

        float[][] triangle2={{20.0f, 30.0f, 200.0f},
                                      {60.0f, 30.0f, -20.0f},
                                      {40.0f, -20.0f, -10.0f}};
            crossProduct=GraphicsUtil.unitCrossProduct(triangle2);
        gl.begin(GL.TRIANGLES);
              gl.normal3f(crossProduct[0], crossProduct[1], crossProduct[2]);
              gl.vertex3f(20.0f, 30.0f, 200.0f);
              gl.normal3f(crossProduct[0], crossProduct[1], crossProduct[2]);
              gl.vertex3f(60.0f, 30.0f, -20.0f);
              gl.normal3f(crossProduct[0], crossProduct[1], crossProduct[2]);
              gl.vertex3f(40.0f, -20.0f, -10.0f);
        gl.end();

I tried putting the line: gl.disable(GL.TEXTURE_2D);
right after the first gl.end(), but then no textures show up.

Edit: If I edit it, and press save, then the tabbing on the code fixes itself.

Now it gets really bizarre. All I did was add a different filter to it on Photoshop, and now everything appears normally.

[quote]I tried putting the line: gl.disable(GL.TEXTURE_2D);
right after the first gl.end(), but then no textures show up.
[/quote]
It will remember the last state set between frames, so you’ll need to enable textures again before drawing any.