I want to draw a figure like one in a game. It needs to be “masked” and also semi-transparent (see-though). I have tried so many things to get it to work without a halo of the interpolated transparency color around the figure. I know I can use NEAREST interpolation but I need quality. Here is my code:
byte blendingEna= glIsEnabled(GL_BLEND);
//byte alphaTestEna= glIsEnabled(GL_ALPHA_TEST);
byte texture2DEna= glIsEnabled(GL_TEXTURE_2D);
if(!texture2DEna)
glEnable(GL_TEXTURE_2D); //slows down fps but necessary
if(drawAlpha)
{
float a= (float)alpha/255.0f;
glColor4f(1.0f, 1.0f, 1.0f, a);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
if(drawMask)
{
//if(drawMask)
{glDepthMask(0); glDisable(GL_DEPTH_TEST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_ENV, GL_MODULATE);
//glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
//glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
//glEnable(GL_ALPHA_TEST);
//glAlphaFunc(GL_GREATER, .9f); //leavs no transparency color but creats blockiness at edges but does not work with drawAlpha is below .9f.
//glAlphaFunc(GL_NOTEQUAL, 0);
if(!drawAlpha)
{
glColor4f(1,1,1,1); glEnable(GL_BLEND); //GL_MODULATE uses GL_BLEND
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //helps smooth edges
//glEnable(GL_POLYGON_SMOOTH); glPolygonMode(GL_POLYGON_MODE, GL_POLYGON_SMOOTH);
//glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE);
}
}
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
else if(HighQualDrawing)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
else
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
//glColorMask(1,1,1,0); //use it to turn off mask (if there is one) disables alpha channel.
glBindTexture(GL_TEXTURE_2D, abmp.pTex->id);
glBegin(GL_QUADS);
//top left
glTexCoord2f(abmp.pTex->coordX, abmp.pTex->coordY); glVertex2i(loc.x, loc.y);
//bottom left
glTexCoord2f(abmp.pTex->coordX, abmp.pTex->coordB); glVertex2i(loc.x, loc.y+abmp.Bounds.h);
//bottom right
glTexCoord2f(abmp.pTex->coordR, abmp.pTex->coordB); glVertex2i(loc.x+loc.w, loc.y+loc.h);
//top right
glTexCoord2f(abmp.pTex->coordR, abmp.pTex->coordY); glVertex2i(loc.x+loc.w, loc.y);
glEnd();
if(drawAlpha)
{
if(!blendingEna)
glDisable(GL_BLEND);
}
if(drawMask)
{
if(!blendingEna)
glDisable(GL_BLEND);
//if(!alphaTestEna)
//glDisable(GL_ALPHA_TEST);
}
if(!texture2DEna)
glDisable(GL_TEXTURE_2D);
return 1;