cocos2d / cocos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
https://www.cocos.com/en/cocos2d-x
18.24k stars 7.06k forks source link

How to use glBlendFuncSeparate for render texture #16899

Open waqas19921 opened 7 years ago

waqas19921 commented 7 years ago

i have used

TrianglesCommand *trianglesCommand = new TrianglesCommand();
        trianglesCommand->init(getGlobalZOrder(), textureID, getGLProgramState(),
                               BlendFunc::ALPHA_PREMULTIPLIED,
                               {&(std::vector<V3F_C4B_T2F>(_vertices))[0],
                                &(std::vector<unsigned short>(_indices))[0],
                                static_cast<int>(_vertices.size()),
                                static_cast<int>(_indices.size())}, transform, 0);

where BlendFunc::ALPHA_PREMULTIPLIED is equivalent to glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

but how can i achieve this glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

minggo commented 7 years ago

You can create an instance of BlendFunc by your self.

glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

Why it has 4 parameters?

waqas19921 commented 7 years ago

i want to user glBlendFuncSeparate how to use that with above params in triangle command.

waqas19921 commented 7 years ago

@minggo i didn't understand your suggestion calling glBlendFuncSeparate() does not effect at all. you have provided setBlendFunc() with two parameters for sprite but it should also have an glBlendFuncSeparate() with four parameters so that one can set different blending modes for colors and alpha channels.