I'm trying to apply BlendModes to a GreyScale image in order to have reusable static resources
I've been searching in the internet for hours and I did my own tests but I didn't find any solution.
I started with this image:
And the basic idea was to draw a rectangle over it in a certain color and apply a blending mode to the image only where the alpha is 1.0
Here is the Code (this is part of a Cocos2d project although I think it can be applied to generic OGL ES):
-(void)draw
{
[super draw];
glBlendColor(0,255,0,255);
glBlendFunc(GL_ZERO, GL_SRC_COLOR);
glColor4ub(255, 0, 255, 255);
glLineWidth(2);
CGPoint vertices2[] = { ccp(0,100), ccp(100,100), ccp(100,0) };
[ DrawingHelper drawPolygonWithPoints:vertices2 points:3 closePolygon:YES];
}
*Draw helper is the logic to draw the triangle.
+(void)drawPolygonWithPoints:(CGPoint *)poli points:(int)points closePolygon:(BOOL)closePolygon
{
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, poli);
if( closePolygon )
glDrawArrays(GL_TRIANGLE_FAN, 0, points);
else
glDrawArrays(GL_LINE_STRIP, 0, points);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_TEXTURE_2D);
}
And here some results:
As you can see is a good approximation but this two images has error:
OpenGL error 0x0502 in -[EAGLView swapBuffers]
My Questions are:
- How can I remove or fix this error?
- How can keep only the alpha of the image (shield) and apply the blend overlay color?
[Update]This is an example of what I would like (with the correct blends):
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…