的Cocos2D-X 3.8 - 渲染纹理,OpenGL的不渲染

问题描述:

我试图借鉴与渲染纹理质地创建一个贝塞尔线,但该线没有显示,只有质地的Cocos2D-X 3.8 - 渲染纹理,OpenGL的不渲染

this是教程我也跟着

Bezier.h:

class Bezier : public Node 
{ 
private: 
    Color4F genRandomBrightColor(); 

public: 
    Sprite* create(float width, float height); 
}; 

Bezier.cpp:

Sprite* Bezier::create(float width, float height){ 
    auto rt = RenderTexture::create(width, height); 

    auto randomColor = genRandomBrightColor(); 
    //rt->begin(); 
    rt->beginWithClear(randomColor.r, randomColor.g, randomColor.b, randomColor.a); 

    //draw bezier line 

    int segments = 50; 
    //tried with Vec2 too 
    Vertex2F vertices[51]; 
    Color4F colors[51]; 
    float t = 0; 

    Point startPoint = Point(0, CCRANDOM_0_1()*height); 
    Point anchor1 = Point(CCRANDOM_0_1()*width/2, CCRANDOM_0_1()*height); 
    Point anchor2 = Point((CCRANDOM_0_1()*width/2) + (width/2), CCRANDOM_0_1()*height); 
    Point endPoint = Point(width, CCRANDOM_0_1()*height); 

    //this i copied from DrawNode so it should be good 
    for (int i = 0; i < segments; i++){ 
     colors[i] = Color4F::WHITE; 
     vertices[i] = Vertex2F(powf(1 - t, 3) * startPoint.x + 3.0f * powf(1 - t, 2) * t * anchor1.x + 3.0f * (1 - t) * t * t * anchor2.x + t * t * t * endPoint.x, 
         powf(1 - t, 3) * startPoint.y + 3.0f * powf(1 - t, 2) * t * anchor1.y + 3.0f * (1 - t) * t * t * anchor2.y + t * t * t * endPoint.y); 
     t += 1.0f/segments; 
    } 
    vertices[segments] = Vertex2F(endPoint.x, endPoint.y); 

    ////////////////////////////////////////////////////////////////////////// 
    auto shaderProgram = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_COLOR); 
    setShaderProgram(shaderProgram); 
    CC_NODE_DRAW_SETUP(); 
    GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POSITION | GL::VERTEX_ATTRIB_FLAG_COLOR); 
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices); 
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_FLOAT, GL_FALSE, 0, colors); 
    glDrawArrays(GL_TRIANGLE_STRIP, 0, segments); 

    rt->end(); 

    auto sprite = Sprite::createWithTexture(rt->getSprite()->getTexture()); 
    return sprite; 
} 

Color4F Bezier::genRandomBrightColor(){ 
    while (true){ 
     float r = CCRANDOM_0_1(); 
     float g = CCRANDOM_0_1(); 
     float b = CCRANDOM_0_1(); 
     if ((r < 0.25) && (g > 0.5) && (b > 0.75) || (r > 0.75) && (g > 0.5) && (b<0.25)){ 
      return Color4F(r,g,b,1); 
     } 
    } 
} 

GameScene.cpp:

#include <Bezier.h> 
.... 
auto dl = new Bezier(); 
auto sprite = dl->create(visibleSize.width, visibleSize.height/2); 
sprite->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/4 + origin.y)); 
this->addChild(sprite); 

这里的截图:http://postimg.org/image/cvy46wtwv/

任何帮助,将不胜感激! PS:我没有使用DrawNode的功能,因为我想知道更多关于这个

编辑:去吧!我需要使用自定义命令 OpenGl code is not working for cocos2dx- 3.0 with VS2013 CPP

函数创建末,放的addChild(精灵)是这样的:

auto sprite = Sprite::createWithTexture(rt->getSprite()->getTexture()); 
addChild(sprite); 
    return sprite; 
+0

好,我试过了,但还没有工作,似乎是唯一的办法就是自定义命令。 – someRandomDude

+0

或至少在v3.8中 – someRandomDude