Exemple #1
0
void Utils::setGray(Node *node)
{
    return;
    USING_NS_CC;
    do
    {
        const GLchar* pszFragSource =
        "#ifdef GL_ES \n \
        precision mediump float; \n \
        #endif \n \
        uniform sampler2D u_texture; \n \
        varying vec2 v_texCoord; \n \
        varying vec4 v_fragmentColor; \n \
        void main(void) \n \
        { \n \
        // Convert to greyscale using NTSC weightings \n \
        vec4 col = texture2D(u_texture, v_texCoord); \n \
        float grey = dot(col.rgb, vec3(0.299, 0.587, 0.114)); \n \
        gl_FragColor = vec4(grey, grey, grey, col.a); \n \
        }";
        
        GLProgram* pProgram = new GLProgram();
        pProgram->initWithByteArrays(ccPositionTextureColor_noMVP_vert, pszFragSource);
        node->setGLProgram(pProgram);
        node->getGLProgram()->link();
        node->getGLProgram()->updateUniforms();
        CHECK_GL_ERROR_DEBUG();
    }while(0);
}
GLProgram* TestFilter::loadShader()
{
	GLProgram* p = new GLProgram();
	CCLOG("TestFilter::loadShader, program: %p", p);
	p->initWithByteArrays(ccFilterShader_test_vert,
		ccFilterShader_test_frag);
	return p;
}
Exemple #3
0
void Skin::setSkinEffectShaderProgram()
{
	switch (_effectType)
	{
	case cocostudio::SkinEffect_None: setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP));break;
	case cocostudio::SkinEffect_Grey:
		{
			const GLchar* fragSource = SkinEffectShader_Grey;
			GLProgram* program = new GLProgram();
			program->initWithByteArrays(ccPositionTextureColor_vert, fragSource);
			setShaderProgram(program);
			program->release();

			CHECK_GL_ERROR_DEBUG();

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

			CHECK_GL_ERROR_DEBUG();

			program->link();

			CHECK_GL_ERROR_DEBUG();

			program->updateUniforms();

			CHECK_GL_ERROR_DEBUG();
		}
		break;
	case cocostudio::SkinEffect_Elite:
		{
			const GLchar* fragSource = SkinEffectShader_Elite;
			GLProgram* program = new GLProgram();
			program->initWithByteArrays(ccPositionTextureColor_vert, fragSource);
			setShaderProgram(program);
			program->release();

			CHECK_GL_ERROR_DEBUG();

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

			CHECK_GL_ERROR_DEBUG();

			program->link();

			CHECK_GL_ERROR_DEBUG();

			program->updateUniforms();

			CHECK_GL_ERROR_DEBUG();
		}
		break;
	case cocostudio::SkinEffect_HighLight:
		{
			const GLchar* fragSource = SkinEffectShader_HighLight;
			GLProgram* program = new GLProgram();
			program->initWithByteArrays(ccPositionTextureColor_vert, fragSource);
			setShaderProgram(program);
			program->release();

			CHECK_GL_ERROR_DEBUG();

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

			CHECK_GL_ERROR_DEBUG();

			program->link();

			CHECK_GL_ERROR_DEBUG();

			program->updateUniforms();

			CHECK_GL_ERROR_DEBUG();
		}
		break;
	default:
		break;
	}
}