Commits

Anonymous committed b29d67c

trying to patch transparent color bug; fixed incorrect mouse Y (it's now 1 pixel lower)

Comments (0)

Files changed (10)

trunk/Slick/lib/slick-examples.jar

Binary file added.

trunk/Slick/lib/slick.jar

Binary file added.

trunk/Slick/src/org/newdawn/slick/Input.java

 	 * @return The absolute y position of the mouse cursor
 	 */
 	public int getAbsoluteMouseY() {
-		return height - Mouse.getY();
+		return height - Mouse.getY() - 1;
 	}
 	   
 	/**
 	 * @return The y position of the mouse cursor
 	 */
 	public int getMouseY() {
-		return (int) (((height-Mouse.getY()) * scaleY)+yoffset);
+		return (int) (((height-Mouse.getY() - 1) * scaleY)+yoffset);
 	}
 	
 	/**

trunk/Slick/src/org/newdawn/slick/opengl/ImageData.java

 
         /** he format for RGB images with alpha. */
         RGBA(4, 32, true, SGL.GL_RGBA),
+        
+        /** The format for alpha-only images. */
+        ALPHA(1, 8, true, SGL.GL_ALPHA),
 
         /** he format for grayscale images (no alpha). */
         GRAY(1, 8, false, SGL.GL_LUMINANCE),

trunk/Slick/src/org/newdawn/slick/opengl/InternalTextureLoader.java

         texture.setWidth(width);
         texture.setHeight(height);
         texture.setImageFormat(format);
-
+        
         if (holdTextureData) {
         	texture.setTextureData(srcPixelFormat, componentCount, minFilter, magFilter, textureBuffer);
         }
      * If the internalFormat is not null, then that will override the default pixel
      * format described by this InternalTextureLoader (either GL_RGBA16 or GL_RGBA8
      * depending on the is16BitMode() value). This parameter can be independent
-     * of the format of the file -- OpenGL will convert the file's format (e.g. BGRA)
-     * to the given internalFormat (e.g. RGB).
+     * of the format of ImageData -- OpenGL will convert the ImageData format (e.g. BGRA)
+     * to the given internalFormat (e.g. RGB). Note that internalFormat is more limited
+     * than the ImageData's format; i.e. BGRA as an internal storage format is only 
+     * supported if GL_ext_bgra is present.
      * 
      * After calling this, the texture will be bound and the target (e.g. GL_TEXTURE_2D)
      * will be enabled. If you are using a higher priority target, such as 3D textures,
      * you should disable that afterwards to ensure compatibility with Slick.
      * 
-     * @param data the image data holding width, height, format
-     * @param buffer the actual data to send to GL
+     * The ByteBuffer data is assumed to match getTexWidth/getTexHeight in ImageData.
+     * 
+     * @param data the image data holding width, height, format (ImageData byte buffer is ignored)
+     * @param buffer the actual data to send to GL 
      * @param ref The name to give the TextureImpl
      * @param target The texture target we're loading this texture into
      * @param minFilter The scaling down filter
  
         int width = data.getWidth();
         int height = data.getHeight();
-        int texWidth = width;
-        int texHeight = height;
+        int texWidth = data.getTexWidth();
+        int texHeight = data.getTexHeight();
         
         boolean usePOT = !isNPOTSupported() || isForcePOT();
         if (usePOT) {
         	genMipmaps = false;
         }
         
-        //if we only need one call to glTexImage2D
-        if (texWidth==width && texHeight==height) {
-        	GL.glTexImage2D(target, 0, dstFmt, texWidth, texHeight, 
-        			0, srcFmt, SGL.GL_UNSIGNED_BYTE, buffer);
-        } else {
-        	//Slick2D decodes NPOT image data into padded byte buffers.
-        	//Once we make the shift to decoding NPOT image data, then we can clean this up
-        	GL.glTexImage2D(target, 0, dstFmt, texWidth, texHeight, 
-        			0, srcFmt, SGL.GL_UNSIGNED_BYTE, buffer);
-        	
-        	//first create the full texture
-        	//we could also use a null ByteBuffer but this seems to be buggy with certain machines
-//        	ByteBuffer empty = BufferUtils.createByteBuffer(texWidth * texHeight * 4);
-//        	GL.glTexImage2D(target, 0, dstFmt, texWidth, texHeight,
-//        			0, SGL.GL_RGBA, SGL.GL_UNSIGNED_BYTE, empty);
-//        	//then upload the sub image
-//        	GL.glTexSubImage2D(target, 0, 0, 0, width, height, srcFmt, SGL.GL_UNSIGNED_BYTE, buffer);
-        }
+        //For now, just assume Slick has decoded image data into POT
+        GL.glTexImage2D(target, 0, dstFmt, texWidth, texHeight, 0, srcFmt, SGL.GL_UNSIGNED_BYTE, buffer);
         
-        // TODO: abstract mipmap generation in SGL
+//        if (texWidth==width && texHeight==height) {
+//        	GL.glTexImage2D(target, 0, dstFmt, texWidth, texHeight, 
+//        			0, srcFmt, SGL.GL_UNSIGNED_BYTE, buffer);
+//        } else {
+//        	//Slick2D decodes NPOT image data into padded byte buffers.
+//        	//Once we make the shift to decoding NPOT image data, then we can clean this up
+//        	GL.glTexImage2D(target, 0, dstFmt, texWidth, texHeight, 
+//        			0, srcFmt, SGL.GL_UNSIGNED_BYTE, buffer);
+//        	
+//        	//first create the full texture
+//        	//we could also use a null ByteBuffer but this seems to be buggy with certain machines
+////        	ByteBuffer empty = BufferUtils.createByteBuffer(texWidth * texHeight * 4);
+////        	GL.glTexImage2D(target, 0, dstFmt, texWidth, texHeight,
+////        			0, SGL.GL_RGBA, SGL.GL_UNSIGNED_BYTE, empty);
+////        	//then upload the sub image
+////        	GL.glTexSubImage2D(target, 0, 0, 0, width, height, srcFmt, SGL.GL_UNSIGNED_BYTE, buffer);
+//        }
+        
         if (genMipmaps) {
         	GL11.glEnable(target); //fixes ATI bug
         	if (cx.OpenGL30)
     }
     
     /**
-     * Get a texture from a image file
+     * Get a texture from an image file. 
      * 
      * @param dataSource The image data to generate the texture from
      * @param filter The filter to use when scaling the texture

trunk/Slick/src/org/newdawn/slick/opengl/PNGImageData.java

 		height = decoder.getHeight();
 		texWidth = get2Fold(width);
 		texHeight = get2Fold(height);
-		
+		//get the decoder's format
 		final PNGDecoder.Format decoderFormat = decoder.decideTextureFormat(PNGDecoder.Format.LUMINANCE);
 		if (decoderFormat == PNGDecoder.Format.RGB) {
 		    format = Format.RGB;
 			}
 		}
 		boolean hasAlpha = format.hasAlpha();
-		if (!hasAlpha && forceAlpha) {
+		if (forceAlpha) {
 		    final int orgComp = format.getColorComponents();
 		    final int newComp = orgComp + 1;
 			ByteBuffer temp = BufferUtils.createByteBuffer(texWidth * texHeight * newComp);

trunk/Slick/src/org/newdawn/slick/opengl/renderer/SGL.java

 	/** OpenGL Enum - @url http://www.opengl.org/documentation */
 	public static final int GL_RGBA = GL11.GL_RGBA;
 	/** OpenGL Enum - @url http://www.opengl.org/documentation */
+	public static final int GL_ALPHA = GL11.GL_ALPHA;
+	/** OpenGL Enum - @url http://www.opengl.org/documentation */
 	public static final int GL_RGB = GL11.GL_RGB;
     /** OpenGL Enum - @url http://www.opengl.org/documentation */
     public static final int GL_LUMINANCE = GL11.GL_LUMINANCE;

trunk/Slick/src/org/newdawn/slick/tests/TransparentColorTest.java

 package org.newdawn.slick.tests;
 
+import java.nio.IntBuffer;
+
+import org.lwjgl.BufferUtils;
+import org.lwjgl.LWJGLException;
+import org.lwjgl.input.Cursor;
+import org.lwjgl.input.Mouse;
 import org.newdawn.slick.AppGameContainer;
 import org.newdawn.slick.BasicGame;
 import org.newdawn.slick.Color;
 import org.newdawn.slick.Graphics;
 import org.newdawn.slick.Image;
 import org.newdawn.slick.SlickException;
+import org.newdawn.slick.geom.Rectangle;
 
 /**
  * A test for transparent colour specification
 	/** The image we're currently displaying */
 	private Image timage;
 	
+	private Image gifImage, gifTImage;
+	private Image tgaImage, tgaTImage;
+	
 	/**
 	 * Create a new image rendering test
 	 */
 	public void init(GameContainer container) throws SlickException {
 		image = new Image("testdata/transtest.png");
 		timage = new Image("testdata/transtest.png",new Color(94,66,41,255));
+		
+		gifImage = new Image("testdata/logo.gif");
+		gifTImage = new Image("testdata/logo.gif", new Color(254, 255, 252));
 	}
 
 	/**
 	 * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 	 */
 	public void render(GameContainer container, Graphics g) {
-		g.setBackground(Color.red);
-		image.draw(10,10);
-		timage.draw(10,310);
+		g.setBackground(Color.lightGray);
+//		image.draw(0,0, inside ? Color.red : Color.white);
+//		timage.draw(10,310);
+		
+		image.draw();
+		timage.draw(image.getWidth(), 0);
 	}
 
 	/**
 	 * @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
 	 */
 	public void update(GameContainer container, int delta) {
+		int mx = container.getInput().getMouseX();
+		int my = container.getInput().getMouseY();
+		try {
+			Color c =image.getColor(mx, my);
+			System.out.println(c.getRed()+" "+c.getBlue()+" "+c.getGreen());
+		} catch (Exception e) {}
 	}
 
 	/**

trunk/Slick/src/version

-#Sun, 20 May 2012 12:09:33 -0400
+#Wed, 30 May 2012 12:10:54 -0400
 #Sun May 11 20:17:03 BST 2008
-build=243
+build=245

trunk/Slick/testdata/transtest.png

Old
Old image
New
New image