opengles 2.0 移植之路

mvp相关链接:
http://www.raywenderlich.com/forums//viewtopic.php?f=20&t=512&start=40#p23610

相关代码:

void TestDbgDraw::rtWithColor(ccColor4F bgColor, float textureSize) {
    // 1: Create new CCRenderTexture
    m_pRt = CCRenderTexture::create(textureSize, textureSize);

    // 2: Call CCRenderTexture:begin
    m_pRt->beginWithClear(bgColor.r, bgColor.g, bgColor.b, bgColor.a);

    // 3: Draw into the texture
    CCSprite* t_pSpNoise = CCSprite::create("blocks.png");
    t_pSpNoise->setBlendFunc((ccBlendFunc){GL_DST_COLOR, GL_ZERO});
    t_pSpNoise->setPosition(ccp(textureSize/2, textureSize/2));
    t_pSpNoise->visit();

    //openGL gradient
    float gradientAlpha = 1.0f;

    /**
     * Added by Bruce Yang on 2012.12.18.13.45~
     * 症结所在,耗费我 n 多个小时(将 CCPoint 换成 CGPoint,也可以换成 b2Vec2)~
     */
    CGPoint vertices[4];
    ccColor4F colors[4];
    int nVertices = 0;

    vertices[nVertices] = CGPointMake(0, 0);
    colors[nVertices ++] = (ccColor4F){1, 0, 0, 0};
    vertices[nVertices] = CGPointMake(textureSize, 0);
    colors[nVertices ++] = (ccColor4F){0, 1, 0, 0};
    vertices[nVertices] = CGPointMake(0, textureSize);
    colors[nVertices ++] = (ccColor4F){0, 0, 1, gradientAlpha};
    vertices[nVertices] = CGPointMake(textureSize, textureSize);
    colors[nVertices ++] = (ccColor4F){1, 1, 0, gradientAlpha};

    CC_NODE_DRAW_SETUP();
    glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, vertices);
    glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_FLOAT, GL_FALSE, 0, colors);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)nVertices);

    // 4: Call CCRenderTexture:end
    m_pRt->end();
    m_pRt->setPosition(64.0f, 64.0f);

    ccTexParams tp = {GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT};
    m_pRt->getSprite()->getTexture()->setTexParameters(&tp);

    // 6: Create a new Sprite from the texture
    addChild(m_pRt);
}

注意点:
1.m_pRt 是 CCRenderTexture* 类型的成员变量~
2.在 cocos2d-x v2.0 里面,不能随意将 CGPoint 换成 CCPoint,
此次就是因为没有注意到这点让我吃足了苦头。
如果使用 cocos2d-x v2.0 的话,要继续使用 CGPoint 可以引入头文件 <CoreGraphics/CGGeometry.h>
当然,CoreGraphics 是 iOS sdk 的专属,是不适用于 andriod 平台的。
不过也不要紧,如果是想移植到 andriod 平台,也可以用 b2Vec2 来代替 CGPoint 类型,
总之,就是不要用 CCPoint!!(CCPoint 本身就是一个 class 类型而非简单的结构体,这就是症结所在!)~
3.CCRenderTexture 的 clear 和 beginWithClear 方法有很大的区别,要注意区分~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值