Drawing transparent PNGs

Started by blue_tomato, January 28, 2005, 03:53:13

Previous topic - Next topic

blue_tomato

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?

napier

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.
penGL/Java/LWJGL demos and code: http://potatoland.org/code/gl

blue_tomato

By simply enabling blend it works.. :)