I want to draw an opaque texture (legacy openGL - so no shaders) on a quad with a transparency value so it blends to a certain extend with the background, making the quad transparent.
What's the trick? Searching for drawing stuff with transparency mostly results in tutorials for textures that already are transparent by enabling and setting the blend function ...
EDIT: considering the commentaries, it seems like this is it:
drawTranparentSprite(TextureInformation t, ImageInformation i){
glBindTexture(t.target, t.textureID);
glBegin(GL_QUAD);
{
glColor4f(1,1,1,i.alpha)
glTexCoord2d(t.x, t.y);
glVertex3d(i.x, i.y, 0);
glTexCoord2d(t.x, t.y + t.h);
glVertex3d(i.x, i.y + i.h, 0);
glTexCoord2d(t.x + t.w, t.y + t.h);
glVertex3d(i.x + i.w, i.y + i.h, 0);
glTexCoord2d(t.x + t.w, t.y);
glVertex3d(i.x + i.w, i.y, 0);
}
glEnd();
}
Though you are welcome to correct me ... (TextureInformation and ImageInformation are here random abstractions of things you need to handle glTexture and random image data to draw to a surface ...)
Also the programming language is completly irrelevant here ...
glBlendFunc (GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA), it will blend the new (source color) with the old (destination color) -- modulated by the new (source alpha). - Andon M. ColemanglColor4f (1.0f, 1.0f, 1.0f, 0.5f), for instance. Though this may require you to enableGL_COLOR_MATERIAL. You may also be using vertex arrays, it is not clear from the question - but what you want is either material or per-vertex alpha. - Andon M. Coleman