PDA

View Full Version : Changing color opacity



mg2387
10-10-2008, 09:07 PM
I have a program with a function that sets the color to draw with a color taken from an original Point source. I want the function to set the color so that the opacity is changed depending on the given alpha value. I'm not sure what I'm doing wrong because when I run my program the opacity of the colors doesn't change. Any ideas?

void ImpBrush::SetColor (const Point source)
{
ImpressionistDoc* pDoc = GetDocument();

float alpha = pDoc->getAlpha(); // gets the specified alpha value
GLubyte ubyte = static_cast<GLubyte>(alpha * 255.f); // converts the alpha value to a GLubyte

GLubyte color[4]; // array to hold the RGBA values

memcpy ( color, pDoc->GetOriginalPixel( source ), 3 ); // copies the RGB values from the original Point into the array

color[3] = ubyte; // sets the last element in the array to the alpha GLubyte value

glEnable (GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glColor4ubv( color );

}

dletozeun
10-11-2008, 06:08 AM
Try: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); instead.

mg2387
10-12-2008, 09:24 AM
tried glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); but still can't get it to work

_NK47
10-13-2008, 06:44 AM
maybe glAlphaFunc is messed up