LWJGL Forum

Programming => OpenGL => Topic started by: moe46 on July 29, 2009, 04:47:47

Title: transparent background
Post by: moe46 on July 29, 2009, 04:47:47
hi
im super new to game development
and the project im working on is atleast in part to help develop my coding skills
so thanks in advance for your patience.

my problem is that when i bring my images(png files) in to my program and display them
instead of a transparent background they all have black backgrounds

the file i use that does said importing is the TextureLoader.java from the spaceinvaders example

Thank You


PS if someone hasd a good place that has a basic explanation how all the opengl coding works
and could post me a link id be super grateful.
Title: Re: transparent background
Post by: Ciardhubh on July 29, 2009, 07:59:12
If you do not enable blending (GL11.glEnable(GL11.GL_BLEND)), there is no blending. That means alpha values get ignored and a colour of (0,0,0,0) is just black and not invisible.

There are lots of tutorials around. Nehe's OpenGL tuturials (http://nehe.gamedev.net/) are quite famous.

I recommend getting a book about OpenGL. In my opinion, it's better to read through one, than to piece together random bits of information from tutorials. I started with the red book: http://www.opengl.org/documentation/red_book/ (there's an older version for free) and ported its examples to Java/LWJGL (in case you want to see how to do them in LWJGL): http://ciardhubh.de/node/13

The OpenGL.org homepage also has lots of interesting information: http://www.opengl.org/documentation/
It's always a good idea to have the API reference pages handy: http://www.opengl.org/sdk/docs/man/
Title: Re: transparent background
Post by: broumbroum on July 29, 2009, 15:40:41
Quote from: moe46 on July 29, 2009, 04:47:47...
my problem is that when i bring my images(png files) in to my program and display them
instead of a transparent background they all have black backgrounds...
This issue comes out when you render in a manner that things get on screen at various depths. You may check that you render the GL objects from the farthest to the nearest (usually z is involved -z gets in the background while +z gets in the foreground).
Solution is that you disable GL_DEPTH_TEST or order your GL-calls in depth-value.
Title: Re: transparent background
Post by: bobjob on July 29, 2009, 21:45:05
make sure you make these openGL calls (maybe along with your init code):

GL11.glEnable(GL11.GL_BLEND); // Enabled blending
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); // selects blending method
GL11.glEnable(GL11.GL_ALPHA_TEST); // allows alpha channels or transperancy
GL11.glAlphaFunc(GL11.GL_GREATER, 0.1f); // sets aplha function

something else to make sure of is that the TextureLoader is loading the image as RGBA, not RGB.
hopefully the loader is decent, so it should hopefully work if you include those methods.
Title: Re: transparent background
Post by: moe46 on July 30, 2009, 05:08:19
perfect guys its working now.
took some googleing to figure out where to add all the stuff
but i managed to get it working

thx you all so much

O also is there a way to do collision detection with GL stuff

example
im trying to place circles close to each other but not overlaping
but my collision detection checks the square that the image is in

id like to be able to check if non-transparent pixels over lap.
is it even possible?


thx