i'm trying draw bezier line on texture created rendertexture, line not showing, texture
this tutorial followed
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 vec2 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 copied drawnode should (int = 0; < 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);
here's screenshot: http://postimg.org/image/cvy46wtwv/
any appreciated! ps: i'm not using drawnode's function because want know more this
edit: got it! needed use custom command opengl code not working cocos2dx- 3.0 vs2013 cpp
in function create @ end ,put addchild(sprite) this:
auto sprite = sprite::createwithtexture(rt->getsprite()->gettexture()); addchild(sprite); return sprite;
Comments
Post a Comment