PDA

View Full Version : Transparent OpenGL textures



BANE
05-25-2000, 03:47 AM
Hi,
Does anybody know how to make transparent textures in OpenGL without using the glMaterial calls ??? I tried to set the alpha coef with calls to glColor and then drawinmg a texture but that gives nothing at all. The texture is still drawn with full alpha. I am using an alpha plane of 4 bits, the textures are RGBA and I enable blending.

It only seems to work with color drawing not with texture drawing.

Any idea ???

Dan.

Eric
05-25-2000, 03:55 AM
You say you enabled blending. Did you specify your blending function as well ? Moreover, if you are trying to achieve some kind of transparency, did you sort your primitives from far to near ?

I must say I am a PC developper so your problem might be a Mac driver issue... Can you post your initializations so that we can have a look ?

Best regards.

Eric

P.S. : unless you think it is a driver issue, you might as well have posted your message in the Beginner or Advanced forum.

Eric
05-25-2000, 04:05 AM
Oooooops sorry !

I have just re-read your message.
You said you set the transparency using glColor...
With an RGBA texture, you should specify the alpha values in the texture itself.
For example :

GLubyte image[4*Width*Height];

for (i=0;i<Width*Height;i++)
image[i*4+3]=128; // Sets alpha to 128 //

That should solve your problem.

Regards.

Eric

BANE
05-25-2000, 04:10 AM
Thanks. That's what I was thinking but it seemed a bit wasteful memory-wise. When my editor starts up it loads all the textures and creates non transparent OGL textures objects. Now I will probably have to manage textures on a face by face basis since I want to be able to make any texture transparent. So I will have to recreate/destroy transparent textures as I go.

Or I could load all my textures in 2 sets opaque and transparent. That's a load of textures (around than 130) and loads of memory space taken. I wonder....

Dan.

Eric
05-25-2000, 04:58 AM
Yes I agree with you, this thing is annoying... Perhaps you should post in the Advanced forum to see if someone comes with a brilliant idea but I think there is no workaround...

Good luck !

Eric

Kosta
05-25-2000, 05:57 AM
Originally posted by BANE:

Or I could load all my textures in 2 sets opaque and transparent. That's a load of textures (around than 130) and loads of memory space taken. I wonder....

You can load a transparent texture from a RGBA-image like this:

glTexImage2D(GL_TEXTURE_2D, *, GL_RGBA, *, *, *, GL_RGBA, GL_UNSIGNED_BYTE, *);

But you can also load a non-transparent texture from the same RGBA-image like this (ignoring all alpha-values of the RGBA-image):

glTexImage2D(GL_TEXTURE_2D, *, GL_RGB, *, *, *, GL_RGBA, GL_UNSIGNED_BYTE, *);

Note the usage of GL_RGB for the internal format parameter!

I don't know if this is an answer to your question, but I hope it helps anyway! :-)

Kosta

Morgan
05-25-2000, 04:56 PM
Does that work? I've had problems doing that (you get extra rows of data which mess up the image). You can load RGB images that way, but not RGBA, AFAIK. Correct me if I'm wrong.

Morgan

BANE
05-25-2000, 10:55 PM
Morgan,

I have never had any problem with using the GL_RGBA format. You just need to make sure you requested a alpha plane in AGL. I load all my textures this way a per the Red Book http://www.opengl.org/discussion_boards/ubb/smile.gif.

Dan.

[This message has been edited by BANE (edited 05-26-2000).]

Morgan
05-26-2000, 04:24 AM
I think I didn't say that right. When I try to load an RGBA as an RGB it comes out all messed up, is that what you were answering to?

Morgan

BANE
05-26-2000, 05:38 AM
Originally posted by Morgan:
I think I didn't say that right. When I try to load an RGBA as an RGB it comes out all messed up, is that what you were answering to?

Morgan


Yep! I never tried that either. I think you are right. I do not think this should work.

Dan.