PDA

View Full Version : Opengl 1.1 and transparent textures



Devdept2
12-20-2010, 08:45 AM
Hi,

does Microsoft's implementation of OpenGL 1.1 support transparent textures?
In my application they don't seem to work, so I would like to know if it's a known limitation.
Thanks

Iulian B
12-20-2010, 11:30 AM
"transparent textures"... try glBlendFunc() with the corresponding blending coeficients that you want and then glEnable(GL_BLEND) before rendering the transparent primitives you want.

Also, take care about the depth testing (even though a texture is "transparent" it can still write to the depth buffer if you "let it", which might not be what you want, because it will "hide" everything behind it, be it transparent or not).


sum-up (just one incomplete example, play with the params):

glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE,GL_ONE);
glBegin(...);
glVertex...
... ...
... ...
glEnd();

Devdept2
12-21-2010, 01:04 AM
Hi,

my code works with hardware acceleration, but it doesn't work without it.

Here are the steps I do:

1) I clear the scene with a alpha 0

gl.ClearColor(0, 0, 0, 0);
gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);

2) draw some geometry

3) read it into a texture:

gl.BindTexture(gl.TEXTURE_2D, myTexture);

gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, texSize, texSize, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);

gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.CopyTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 0, 0, texSize, texSize);

4) clear again color and depth buffer

5) draw my real scene

6) draw the texture (created at step 3) over it:

gl.Enable(gl.BLEND);
gl.Disable(gl.DEPTH_TEST);
gl.Enable(gl.TEXTURE_2D);
gl.BindTexture(gl.TEXTURE_2D, myTexture);
// draw a Quad with the textures coordinates


The texture should be transparent in the empty areas (of step 2) but, if hdw acceleration if OFF, it is black and covers my scene.

With hdw acceleation on, the texture is correctly transparent.

ZbuffeR
12-21-2010, 01:55 AM
The code above can only provide transparent area if you have a destinaton alpha on the framebuffer.
If you don't ask for it explicitely, it may or may not be present.
See point here :
http://www.opengl.org/resources/faq/technical/transparency.htm#blen0050

Ie. with Microsoft software implementation of OpenGL 1.1, there is no destination alpha.

Try using mesa3D instead.

Devdept2
12-23-2010, 02:42 AM
Hi,

but I'm not using DST_ALPHA anywhere...

ZbuffeR
12-23-2010, 02:41 PM
Yes you do, indirectly :
2) draw some geometry
3) read it into a texture
... now DST_ALPHA from your first pass becomes SRC_ALPHA in the second pass.

Devdept2
12-29-2010, 08:31 AM
Ok, thank you