PDA

View Full Version : Enabling blending clips texture ?



Peter Maarssen
10-16-2008, 12:29 AM
I use the following to render a texture font to an fbo(which I later render to another fbo):



glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
..
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0f, width, height,0f, -1f, 1f);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);

glClear(GL_COLOR_BUFFER_BIT); // (0f,0f,0f,0f)

glDisable(GL_BLEND);
glWrite(0f, i*16f, line);
glEnable(GL_BLEND);

glViewport( 0, 0, vPort[2], vPort[3]);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
..


With the above code all the letters miss the right 4 pixels. The letters appear in full when gldisable is commented out. Why is this? :p (the letters are on the same pixels both ways)
Thanks.

Peter Maarssen
10-17-2008, 01:35 AM
glWrite just needs an x, y and a line (char[]) and works like a charm everywhere except on that fbo when blending is disabled.

glWrite is alike nehe's texture font write function.

What could disabling blending do to make part of the letters(textures) not show up?

Peter Maarssen
10-26-2008, 12:19 AM
Why the 4 pixels still showed up is still a mystery to me, but here the solution:

In stead of glDisable(GL_BLEND), using glBlendFunc(GL_ONE,GL_ONE) worked like a charm :)

What does disabling blending exactly do? does set rendering to ignore the alpha channel?

dletozeun
10-26-2008, 11:23 AM
When you disable blending, newly computed fragments color will replace the last fragments color stored in the framebuffer. When you enable blending, incoming fragments color can be blended with the fragment color that are already in the framebuffer using the operation set with glBlendFunc.

Using GL_ONE as source and destination will add the incoming fragment color to the one already stored in the framebuffer. You may quickly obtain saturated renderings.

If you use glBlendFunc(GL_ONE,GL_ZERO) it would behave as if blending is disabled.

Peter Maarssen
10-27-2008, 02:31 AM
Ok, this is how I thought it would work.
Is there anything special in this regard when rendering to fbo-binded textures to other fbo's?

glBlendFunc(GL_ONE,GL_ZERO);
fbo.bind(); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
writeText("text");
fbo.unbind();

= clipped letters, (GL_ONE, GL_ONE) works correct...
I must be doing something really stupid :(