views:

2311

answers:

4

I want to know how the glBlendFunc works. For example, i have 2 gl textures, where the alpha is on tex1, i want to have alpha in my final image. Where the color is on tex1, i want the color from tex2 to be.

+1  A: 

glBlendFunc applies only to how the final color fragment gets blended with the frame buffer. I think what you want is multitexturing, to combine the two textures by blending the texture stages using glTexEnv, or using a fragment shader to combine the the two textures.

Lee Baldwin
Does this require use of ARB extension?
DavidG
DavidG: If the technique uses ARB_texture_env_combine, or shaders it will. Both are widely supported.
luke
+1  A: 

Sorry, can't do this with simple blending. We for instance used to do the same thing using frament shaders.

akalenuk
+1  A: 

Seconding the shaders. If you can use a shader its much easier to just do what you want with the data rather than messing with arcane blending functions.

BigSandwich
A: 

Sadly, this is for openGL ES on the iPhone, so no shaders, but point taken. My problem was a very simplified version of the questions, i needed to apply a simple color ( incl alpha ), to a part of a defined texture. As Lee pointed out, texture blending is to allow alpha to show up on the framebuffer. The solution was to insist that the artist makes the "action bit" of the texture white, and then assigning a color to the vertices that i render. Something like this.

glTexCoordPointer( 2, GL_FLOAT, 0, sprite->GetTexBuffer() );
glVertexPointer( 3, GL_FLOAT, 0, sprite->GetVertexBuffer() );
glColorPointer( 4, GL_FLOAT, 0, sprite->GetColorBuffer() );
glDrawArrays( GL_TRIANGLES, 0, 6 ); // Draw 2 triangles

Where even tho it has a texture, having the color means it adds to the texture's color, so where it's an alpha, it remains alpha, and where it is white ( as i had to make it ), it becomes the color of the color pointer at the point.

DavidG
What does "action bit" mean? Does what you describe here solve your problem?
Jim Buck
yeah, that solved my problem. "action bit" is the part that i want drawn in a different color. basically if i want a single texture ( maybe like a font set ) where each non transparent bit needs a custom color, i used this.
DavidG