Skip to content

Instantly share code, notes, and snippets.

@curioustorvald
Created March 1, 2017 13:22
Show Gist options
  • Save curioustorvald/109fb5ae06726ee5eee2ff79e1996fd0 to your computer and use it in GitHub Desktop.
Save curioustorvald/109fb5ae06726ee5eee2ff79e1996fd0 to your computer and use it in GitHub Desktop.
Tricks to properly drawing semi-transparent images in Slick2d
  1. Use TGA with Alpha instead of PNG. Grab yourself Paint.NET or GIMP and export the image as 32-bit TGA (no compression). Note that Photoshop can't do the job.
  2. Try this code as blend mode, this code must precede your drawing jobs:
import org.lwjgl.opengl.*

...

GL11.glEnable(GL11.GL_BLEND);
GL11.glColorMask(true, true, true, true);
GL14.glBlendFuncSeparate(
            GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, // blend func for RGB channels
            GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA // blend func for alpha channels
    );
    
<<your Image.draw goes here...>>>

// NOTE: not tested for semitransparent over semitransparent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment