Quantcast
Channel: Cocos Forums - Latest topics
Viewing all articles
Browse latest Browse all 17076

What are the default Cocos2d-x Vertex and Fragment shaders?

$
0
0

@komyg wrote:

Hi,

I am creating a game using Cocos2d-X 3.10 and I want to use shaders to do the following:

1 - Whenever the player clicks the menu button, all of my sprites will become grayscale.
2 - If the player decides to return to the game, then all the sprites will return to display their own default color, using the default shader.

To do this, I've created two functions:

void ShaderHelper::applyDefaultFragShader(Node *node)
{    
    node->setGLProgram(ShaderCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_A8_COLOR));
    node->getGLProgram()->use();
}

void ShaderHelper::applyGrayscaleFragShader(Node *node)
{
    GLProgram *shader;
    const GLchar *fragmentShader;

    shader = GLProgram::createWithByteArrays(ccPositionTextureA8Color_vert, ccPositionTexture_GrayScale_frag);

    shader->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::VERTEX_ATTRIB_POSITION);
    shader->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_COLOR, GLProgram::VERTEX_ATTRIB_COLOR);
    shader->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORDS);

    shader->link();
    CHECK_GL_ERROR_DEBUG();

    shader->updateUniforms();
    CHECK_GL_ERROR_DEBUG();

    node->setGLProgram(shader);
    node->getGLProgram()->use();
}

The grayscale frag shader seems to be working fine, however my sprites vanish when I apply the SHADER_NAME_POSITION_TEXTURE_A8_COLOR shader.

Is this the default one? If not, how do I reset my sprites' shaders to the default one used by Cocos2d-X?

Posts: 3

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 17076

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>