0
\$\begingroup\$

This question already has an answer here:

I have to draw texture with transparent areas on square. But I don't want this transparencies to take color from this polygon, but from the background. Do you have any good tutorial to achieve it?

--EDIT--

   glColor4f(1,0,0,1);

  glBegin(GL_QUADS);

  glTexCoord2f(0,0); glVertex3f(-0.5, -0.5, -1);
         glTexCoord2f(1,0); glVertex3f(1, -1, -1);
         glTexCoord2f(1,1); glVertex3f(0.5, 0.5, -1);
         glTexCoord2f(0,1); glVertex3f(-0.5, 0.5, -1);

  glEnd();

I just takes color from polygon. How to make this polygon transparent.

\$\endgroup\$

marked as duplicate by Anko, Josh Mar 31 '14 at 16:31

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1
\$\begingroup\$

OpenGL provides blending function.

glEnable(GL_BLEND);// you enable blending function
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
// then you will set flags to achieve desired blending effect.

For further different usage, read http://www.opengl.org/sdk/docs/man/html/glBlendFunc.xhtml

However for your particular case, the desired effect, applying transparency, I believe you want...

"...Examples Transparency is best implemented using blend function (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) with primitives sorted from farthest to nearest. Note that this transparency calculation does not require the presence of alpha bitplanes in the frame buffer."

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.