LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: MBRPascoe on July 19, 2004, 14:53:16

Title: loading textures causes dimness
Post by: MBRPascoe on July 19, 2004, 14:53:16
hello all, im playing around with some of the lwjgl ports on nehe.gamedev. I find that if i run the a program i created form these ports without loading any textures it runs fine, the cube and pyramid spin, but if i load any textures it still works but everyting is a lot darker. Even if i dont ever render the textures, the code im using to load the textures is as follows


   public final int loadTexture(String path) {
       BufferedImage image = null;
       try{
           image = javax.imageio.ImageIO.read(getClass().getResource(path));
       }catch(IOException IOEx){
           System.out.println("must put exception trap here");
           System.exit(1);
       }
       if(image == null){
           System.out.println("null image");
           System.exit(1);
       }
       // 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
   }


Any ideas why this is happening.

Any help is appreciated

pascoe
Title: loading textures causes dimness
Post by: cfmdobbie on July 19, 2004, 15:52:23
Do you disable GL_TEXTURE_2D before drawing non-textured objects?

I would guess that it's left enabled, and OpenGL is supplying a default texture coordinate of (0, 0) to all your vertices, so the bottom-left pixel of your image  is being added to the colours in your scene.

A little more investigation is required to be sure, however.  Try disabling texturing or loading a bright red texture instead, and see what happens.
Title: loading textures causes dimness
Post by: MBRPascoe on July 21, 2004, 03:40:16
thanks, that was the problem