@owlet wrote:
Hi, I'm trying to asign custom shaders to DrawNode to be able to aply some effects onto custom drawings.
My cpp code is :
class MyDrawNode : public DrawNode { public: ~MyDrawNode() { } static MyDrawNode * create() { MyDrawNode * ret = new (std::nothrow) MyDrawNode (); if (ret && ret->init()) { ret->autorelease(); auto glp = GLProgram::createWithFilenames("shaders/ccShader_PositionColorLengthTexture.vert", "shaders/ccShader_PositionColorLengthTexture.frag"); glp->retain(); glp->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::VERTEX_ATTRIB_POSITION); glp->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_COLOR, GLProgram::VERTEX_ATTRIB_COLOR); glp->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORDS); glp->link(); CHECK_GL_ERROR_DEBUG(); glp->updateUniforms(); CHECK_GL_ERROR_DEBUG(); GLProgramState* state = GLProgramState::getOrCreateWithGLProgram(glp); ret->setGLProgramState(state); ret->setShaderProgram(glp); glp->use(); } else { CC_SAFE_DELETE(ret); } return ret; } };
I copy default ccShader_PositionColorLengthTexture.vert and shaders/ccShader_PositionColorLengthTexture.frag from cocos folder (I'm using cocos2dx 3.13 if its important) and change only I line in fragment shader :
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
So I assume that after that line in fragment shader all my drawings call will be drawn in Red color.
And if I set shaders to Sprite or Texture2D instances via the same code, I've got completely Red textures and sprites. So I have a question - How I can set custom shader into a drawing node ?
Posts: 1
Participants: 1