cocos2dx V3.2 customer draw method

http://discuss.cocos2d-x.org/t/solved-texture-mapping-in-cocos2dx-3-2/16687/10

in V3.0

Works fine in 3.0:

void JellyLogic::draw(Renderer *renderer, const kmMat4 &transform, bool transformUpdated) {
    kmGLPushMatrix();
    GL::bindTexture2D(texture->getName());
    texture->getShaderProgram()->use();
    texture->getShaderProgram()->setUniformsForBuiltins();
    GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POSITION | GL::VERTEX_ATTRIB_FLAG_TEX_COORDS);
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, triangleStripPos);
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORDS, 2, GL_FLOAT, GL_FALSE, 0, textCoords);
    glDrawArrays(GL_TRIANGLE_STRIP, 0,  NUM_VERTEX);
    kmGLPopMatrix();
}

I guess I need to change the texture->getShaderProgram()->use() to texture->getGlProgram()->use() in 3.2
The code compiles fine but no images is showing.



in V3.2

uses a command queue to render nodes and thus custom drawing routines should be wrapped with the command.


o we need to use customCommand to do this.

CustomCommand _customCommand; // in header or wherever makes sense for you

 _customCommand.init(_globalZOrder);

_customCommand.func = CC_CALLBACK_0(JellyLogic::onDraw, this, transform, flags);

renderer->addCommand(&_customCommand);

create JellyLogic::onDraw(...) and put that code above in it.



void JellyLogic::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
    _customCommand.init(_globalZOrder);
    _customCommand.func = CC_CALLBACK_0(JellyLogic::onDraw, this, transform, flags);
    renderer->addCommand(&_customCommand);
}

void JellyLogic::onDraw(const Mat4 &transform, uint32_t flags) {
    kmGLPushMatrix();
    GL::bindTexture2D(texture->getName());
    texture->getGLProgram()->use();
    texture->getGLProgram()->setUniformsForBuiltins();
    GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POSITION | GL::VERTEX_ATTRIB_FLAG_TEX_COORD);
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, triangleStripPos);
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORDS, 2, GL_FLOAT, GL_FALSE, 0, textCoords);
    glDrawArrays(GL_TRIANGLE_STRIP, 0,  NUM_VERTEX);
    kmGLPopMatrix();
}

综合以上例子跟下面的图表,可以非常清楚看到这个新的Render 机制。   rendering Node during vist will not call into OpengGL anymore

pic1





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值