Premultiplied Textures

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Premultiplied Textures

Sebastian Greif
Hi all,

we are using jogl in our project already for a long time.
Recently i tried to switch from a previous Jogl 2.x version (from march) to the latest jogl 2.0-rc9 libs.
Everything works fine, except that the textures seems to be not premultiplied anymore.
Rendering textures with alpha values with blend option gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE_MINUS_SRC_ALPHA) ( which is the correct way to use with pre multiplied textures) does result in white areas where the transparent pixels should be.
Are there some changes in the ways how jogl handles textures and alpha values?

Thanks in advance and best regards.
Sebastian
Reply | Threaded
Open this post in threaded view
|

Re: Premultiplied Textures

Sebastian Greif
I forgot to mention that i am using awt as the window-system.
Does anybody facing the same issues with the latest jogl2.0 rc?
Reply | Threaded
Open this post in threaded view
|

Re: Premultiplied Textures

Sebastian Greif
Nobody an idea where the problem could be in my case?
It is a bit weired for me.
Reply | Threaded
Open this post in threaded view
|

Re: Premultiplied Textures

Pixelapp
What do you mean by premultiply?

What is it that you want to achieve? Please elaborate. Do you want to simply have the transparent parts of a texture to be invisible and that's it?
Reply | Threaded
Open this post in threaded view
|

Re: Premultiplied Textures

Demoscene Passivist
Administrator
"premultiplied alpha" generally means that a constant color (e.g. the background color) is mixed with the normal RGB values of the pixel beforehand. The amount of mix is determined by the value of the alphachannel.

Its generally regarded as a compatibility fallback method for uses where translucency is not available.

Nowadays I would generally discourage using premultiplied alpha and use "real" direct alpha which (at least from my experience) works flawlessly with jogl.

Maybe you could elaborate a little bit more on your problem as I doubt that the blending modes do not work correctly. Maybe the problem is application specific on your side ?
Reply | Threaded
Open this post in threaded view
|

Re: Premultiplied Textures

Sebastian Greif
I thought that jogl uses premultiplied alpha for textures as default.
It always does in the past.
When i load a texture with alpha values with the TextureIO of jogl it transforms the texture to be premultiplied as default in the past.
Take a look at the javadoc at
http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/opengl/util/texture/Texture.html

"To make things easier for developers, the Texture class will automatically convert non-premultiplied image data into premultiplied data when storing it into an OpenGL texture."

Or is this not true anymore?
I have simple png images which alpha channel e.g. to mask round corners.
In the past i always setup blending equation to match premultiplied alpha textures. But in the new version this does not work anymore.
So does jogl changes the way it loads the textures?
Reply | Threaded
Open this post in threaded view
|

Re: Premultiplied Textures

Pixelapp
To make the transparent parts of a png invisible all I do is turn on alpha testing and enable blending. That would be only three lines of code.

Sure there are many other ways to do it, but this is the fastest and shortest one.
Reply | Threaded
Open this post in threaded view
|

Re: Premultiplied Textures

Demoscene Passivist
Administrator
In reply to this post by Sebastian Greif
I'm using .png with alpha-channel myself and everything works fine here.

To load the texture I use:

Texture tTexture = TextureIO.newTexture(new BufferedInputStream((new Object()).getClass().getResourceAsStream(inFileName)),true,null);

And the blending mode is:

inGL.glEnable(GL_BLEND);
inGL.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_COLOR);
Reply | Threaded
Open this post in threaded view
|

Re: Premultiplied Textures

Sebastian Greif
I know how to use alpha blending in this way. And it would be no big deal to change my code to use
inGL.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_COLOR);
instead of
inGL.glBlendFunc(GL_SRC_ONE, GL_ONE_MINUS_SRC_COLOR); (which i have to use in case of premultiplied alpha).

I only wanted to know if JOGL changes its default behaviour when loading png images as texture.
As written in the javadoc ot should automatically create premultiplied images everytime, and so it does in the past.

I have to change a lot of code to chnage my alpha blending. SO i just wanted to be sure.

Thanks in advance
Sebastian
Reply | Threaded
Open this post in threaded view
|

Re: Premultiplied Textures

gouessej
Administrator
If you're right, it is a regression but as far as I know, this behavior has not been modified (I have just looked at the history of TextureIO). Please can you try with some older builds of JOGL 2.0?
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Premultiplied Textures

Sven Gothel
Administrator
In reply to this post by Sebastian Greif
On 07/29/2012 11:19 PM, Sebastian Greif [via jogamp] wrote:

> I thought that jogl uses premultiplied alpha for textures as default.
> It always does in the past.
> When i load a texture with alpha values with the TextureIO of jogl it
> transforms the texture to be premultiplied as default in the past.
> Take a look at the javadoc at
> http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/opengl/util/texture/Texture.html
>
> "To make things easier for developers, the Texture class will automatically
> convert non-premultiplied image data into premultiplied data when storing it
> into an OpenGL texture."
>
> Or is this not true anymore?
> I have simple png images which alpha channel e.g. to mask round corners.
> In the past i always setup blending equation to match premultiplied alpha
> textures. But in the new version this does not work anymore.
> So does jogl changes the way it loads the textures?
PNG images are now loaded using PNGJ, which does not depend on AWT anymore.

In case the image contains alpha, the resulting Texture is in RGBA mode,
not per-multiplied, since this would disallow proper GL usage here w/ other
normal RGBA sources.

Even though this might be a regression compared to previous AWT behavior
of loading PNG images _and_ the documentation, this IMHO is the way it should be.
Using OpenGL >= 2.0 and OpenGL ES 2.0, RGBA pixel format is usually the default.

Pls. add a bug report and we will fix the documentation in this regard.

AFAIK (while reading / modding code) other formats like TGA etc will
provide an RGBA Texture as well if the source is RGBA.

~Sven


signature.asc (910 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Premultiplied Textures

gouessej
Administrator
It's a good piece of news, it means that I will have almost nothing to do to use Ardor3D without AWT even for loading PNG images :)
Julien Gouesse | Personal blog | Website