opengles 2.0 移植之路
2012-12-18 14:06
495 查看
mvp相关链接:
http://www.raywenderlich.com/forums//viewtopic.php?f=20&t=512&start=40#p23610
相关代码:
注意点:
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 方法有很大的区别,要注意区分~
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 方法有很大的区别,要注意区分~
相关文章推荐
- opengles 2.0 移植之路
- opengles 2.0 点精灵 多边形偏移等备忘
- opengles2.0 帧缓存对象(FBO)
- Android Opengles2.0 多纹理融合
- OpenGLES 2.0 在 NDK-r15b上的编译问题
- 浅学OpenGLES2.0
- linux 下 opencv2.0 的移植 (ARM9)
- 将OpenGL代码移植成OpenGLES
- 基于.NET 2.0的GIS开源项目SharpMap分析手记(六):SharpMap的功能扩展之路
- Android——4.2 - 3G移植之路之libusb (一)
- cocos 游戏移植到 Windows10 之路 -- 环境搭建
- 在Android下使用openGLES2.0的初步过程
- 佳域G4厚电标准版刷机包 移植ColorOS 2.0全网首发 流畅体验
- Android框架之路——Retrofit2.0的初窥(包含Gson)
- 性能追求之路——MaxCompute2.0的前世今生
- opencv2.0移植过程中zlib,jpeg,png库的交叉编译
- OpenGLes2.0 什么是Pbuffer
- Android——4.2 - 3G移植之路之 APN (五)
- Angular2.0开发之路资料收集
- Vue2.0 探索之路——生命周期和钩子函数的一些理解