木其网络科技专业程序员代写http://www.xmsydw.com
程序员学历擅长经验网店链接
apenny硕士ASP.NET PHP 电子 通信设计 图像 编程 网络5年进入店铺
zheng_qianqian本科C语言 C++面向对象 Java5年进入店铺
guoguanl本科Java Web项目 JSP Hibernate Struts Mysql5年进入店铺

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 方法有很大的区别,要注意区分~

posted @ 2012-12-18 14:06  程序流程图  阅读(370)  评论(0编辑  收藏  举报
木其网络科技专业程序员代写http://www.xmsydw.com
程序员学历擅长经验网店链接
apenny硕士ASP.NET PHP 电子 通信设计 图像 编程 网络5年进入店铺
zheng_qianqian本科C语言 C++面向对象 Java5年进入店铺
guoguanl本科Java Web项目 JSP Hibernate Struts Mysql5年进入店铺