Cocos2d-x 3.8 - RenderTexture ,OpenGL not rendering
Cocos2d-x 3.8 - RenderTexture ,OpenGL not rendering
我试图在RenderTexture创建的纹理上画一条bezier线,但是线没有显示,只有纹理
这是我遵循的教程
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代码不能在cocos2dx- 3.0与VS2013 CPP下工作在create函数的最后,像这样添加addchild(精灵):
auto sprite = Sprite::createWithTexture(rt->getSprite()->getTexture());
addChild(sprite);
return sprite;
相关文章:
- OpenGL - 在抛出"__gnu_cxx::recursive_init_error"实例后终止调用?
- 了解 GLM- openGL 中的相机转换
- 如何在全屏模式下(在OpenGL中)使背景透明
- OpenMP卸载说'fatal error: could not find accel/nvptx-none/mkoffload'
- 为什么我不能使用 EGL 创建无头 OpenGl 上下文?
- OpenGL大的3D纹理(>2GB)非常慢
- OpenGl glm rotate
- OpenGL GL_TEXTURE1 not displaying
- 在 OpenGL 中在 Mac 上编译着色器时出现"version not supported"错误
- MAC OpenGL 着色器错误:"version '150' is not supported "
- c++ cuda opengl not rendering vbo
- Qt OpenGL DrawElements not Drawing the second triangle
- SDL2 + OpenGL = Gnome 3 错误地抱怨"Program not responding"
- OpenGL Basic IBO/VBO Not Working
- OpenGL : glRotatef not working?
- OpenGL glRectf() not displaying
- Cocos2d-x 3.8 - RenderTexture ,OpenGL not rendering
- Anttweakbar glfw3 OpenGL 3.2 not drawing
- OpenGL VBO not working (C++)
- OpenGL VBO not working