ccDrawLine不透明度? [英] ccDrawLine opacity?
问题描述
我对所有OpenGL调用都很新,但是幸运的是cocos2d很容易让我在屏幕上画线,如下:
- (void)draw {
glColor4f(255,255,255,255);
ccDrawLine(ccp(150,110),ccp(280,230));
}
我得到一个白线。
但现在,我想让它有点透明,所以我把alpha值改为100.但是,线仍然明亮和白色。然后我假设值实际上可以从0.0到1.0。
您肯定需要先启用混合:
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glColor4ub(255,255,255,100);
ccDrawLine(ccp(0,110),ccp(280,230));另外请注意,glColor4ub接受无符号字节(每个参数为0-255),而
祝你好运!
I am very new to all those OpenGL calls, but fortunately cocos2d will easily let me draw lines on the screen, like this:
-(void)draw {
glColor4f(255, 255, 255,255);
ccDrawLine(ccp(150,110), ccp(280,230));
}
And I get a white line.
But now, I want to make it a bit transparent, so I change the alpha value to 100. However, the line is still bright and white. Then I assumed that the values could actually range from 0.0 to 1.0. I set it to 0.2 but still no change.
Why is that?
解决方案 You definitely need to enable blending first:
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4ub(255, 255, 255,100);
ccDrawLine(ccp(0,110), ccp(280,230));
Also note that "glColor4ub" takes in unsigned bytes (0-255 for each parameter) while
"glColor4f" takes in 4 floats (0-1.0 for each parameter). Use whichever you are comfortable with.
Good luck!
这篇关于ccDrawLine不透明度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!