PDA

View Full Version : Alpha Texture + Color



Victor Hugo
06-03-2009, 02:24 PM
Hi All,

I'm trying to render some AA lines, so far I 've created a texture (RGBA) with a filled circle and a smooth boundary.

I get a good result with this, however the lines get the texture color, and I want if possible, to use this texture as a Alpha Pattern, and get the RGB channels from the glColor4x primitive.

I'm using GL_MODULATE, and from the documentation I read that it will mix the texture color with the light or primitive color.

My lack of knowledge is:

how to create an alpha texture, and if it will work after updating the texture with GL_ALPHA definition.

basically something like this,



glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
// get a free texture
glGenTextures(1, &textureId);
// bind texture
glBindTexture(GL_TEXTURE_2D, textureId);
// send buffer to opengl
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 128, 128, 0, GL_ALPHA, GL_UNSIGNED_BYTE, circle->getBitmap());


glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameterx(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R, GL_NEAREST);
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterx(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);


Because I've tried to use the current RGBA texture uploaded as GL_ALPHA but it didn't work.

Thanks in advance,

Victor

ZbuffeR
06-04-2009, 12:51 AM
Then either change the external texture format to match the RGBA you have :
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, circle->getBitmap());

Or build an alpha-only texture, and do :
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 128, 128, 0, GL_ALPHA, GL_UNSIGNED_BYTE, alphaTexture);

dletozeun
06-04-2009, 01:46 AM
Sticking to your first idea, with your RGBA texture. If the disc color is uniformly white you can directly affect the line color by setting the current color with glColor. The default GL_TEXTURE_ENV_MODE is GL_MODULATE so you should easily modulate the current color with the texture one.

Victor Hugo
06-04-2009, 02:02 AM
Hi,

Thanks for your help.

My circle is uniform, however it has a smooth boundary from 100% opacity to 10%.

I will try both.

Thanks,

Victor

Victor Hugo
06-04-2009, 02:06 AM
Hi,

The first approach doesn't work. I have my triangle strip ( box + 2 quads for start and end caps)

I've mapped a semi-circle in one caps and other semi-circle on the end caps.

But with first approach my start and end caps are totally filled so I get a full rectangle.

Should I change my glBlendFunc () ?

Thanks,

Victor