no aplha of png file in lwjgl

Started by prich, October 11, 2009, 08:05:00

Previous topic - Next topic

prich

hello there!

i have some problems concerning AngelCodeFont. Because in lwjgl there is no such thing i want to read a png file (see picture default.png).
But when i read the picture with:
BufferedImage bi = ImageIO.read(new File(img));

and cast it into byte[] with:
byte[] rawdata  = ((DataBufferByte) bi.getRaster().getDataBuffer()).getData();

and upload it correctly i get a weired result:


can somebody help?
maybe a wrong alpha test? i used also the code of slick2D but in slick it works :(

thx prich

kappa

you have to switch on alpha blending in OpenGL, something like
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);


prich

thx alot!
can you also explain me why? because i would like to understand why i have to use blending!

thx prich

Evil-Devil

Slick may activate blending by itself, when it discovers an image with transparency. OpenGL will only do the things you say you want it to do.

Ciardhubh

Quote from: prich on October 11, 2009, 18:03:08
thx alot!
can you also explain me why? because i would like to understand why i have to use blending!

thx prich

Without active blending (GL11.glEnable(GL11.GL_BLEND);) OpenGL will just take the colour from the texture and overwrite what's currently in the framebuffer. The alpha channel is ignored. Every pixel of a character in your font is basically white. The smooth edges are white too, with a lower alpha value. So if there's no blending, you get these ugly non-smooth blobs. Plus you background is just black.

With GL11.glEnable(GL11.GL_BLEND); OpenGL takes the incoming texture colour and blends it with the existing framebuffer colour based on the function defined with GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);.

There's a lot more to blending (when to turn on/off, which order to draw objects, when to disable depth testing and so on), though.

prich

thx alot, i really appreciate your help!

prich