LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: blue_tomato on January 28, 2005, 03:53:13

Title: Drawing transparent PNGs
Post by: blue_tomato on January 28, 2005, 03:53:13
I have PNG images with an alpha channel, and I want to draw them to the screen, mixing each pixel to the screen according to it's alpha value.

Anyone know how to do this using LWGL?
Title: Drawing transparent PNGs
Post by: napier on January 28, 2005, 05:40:56
The general idea is to enable alpha blending and define how you want to blend:

       GL11.glEnable(GL11.GL_BLEND);
       GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

Load the image as RGBA pixels then draw it as a texture on a quad.

If you need more details I have a demo here
http://potatoland.org/code/gl/lwjgl_demoOrtho.zip
that draws a transparent gif over a scene.  Works the same way with a png.

Also a class http://potatoland.org/code/gl/GLImage.java
that loads png/gif/jpg as a java image then converts to RGBA for use in opengl.
Title: Never mind...
Post by: blue_tomato on January 28, 2005, 05:57:33
By simply enabling blend it works.. :)