如何在 cocos2d-x 中用颜色绘制圆形填充
How to draw circle fill with color in cocos2d-x?
我是cocos2d-x的新手,我正在尝试在其中绘制带有颜色的圆圈。我在网上搜索,找到了一些代码。我尝试了下面的代码,但它只绘制带有颜色边框的圆圈。我的cocos2d-x版本是2.1.5,我正在将其用于Android。我还尝试使用此方法更改边框的宽度:glLineWidth(2); 但是在我的 cocos2d-x 中找不到这种方法。如何在圆形中添加颜色以及如何更改圆形边框的宽度。
cocos2d::ccDrawColor4B(0, 255, 255, 255);
cocos2d::ccDrawColor4F(0, 255, 255, 255);
cocos2d::ccDrawCircle( ccp(100/2, 100/2), 50, CC_DEGREES_TO_RADIANS(90), 50, false);
在CCDrawNode类中,您可以绘制圆,线和多边形。
void drawDot(const CCPoint & pos,float radius, const ccColor4F & color)
在给定半径和颜色的位置绘制填充圆
不确定哪个
cocos2d-x
版本可用,但您应该有一个绘制实心圆的特定方法。
void drawSolidCircle( const Point& center, float radius, float angle, unsigned int segments, float scaleX, float scaleY);
看看每晚的CCDrawingPrimitives.cpp课程。
只需在 CCDrawingPrimitives 中添加一个新方法即可。 它与ccDrawCircle
相同,只是glDrawArrays
使用GL_TRIANGLE_FAN
而不是GL_LINE_STRIP
在标题中,添加:
void CC_DLL ccDrawSolidCircle( const CCPoint& center, float radius, float angle, unsigned int segments, bool drawLineToCenter);
在.cpp文件中,添加:
void ccDrawSolidCircle( const CCPoint& center, float radius, float angle, unsigned int segments, bool drawLineToCenter)
{
lazy_init();
float scaleX = 1;
float scaleY = 1;
int additionalSegment = 1;
if (drawLineToCenter)
additionalSegment++;
const float coef = 2.0f * (float)M_PI/segments;
GLfloat *vertices = (GLfloat*)calloc( sizeof(GLfloat)*2*(segments+2), 1);
if( ! vertices )
return;
for(unsigned int i = 0;i <= segments; i++) {
float rads = i*coef;
GLfloat j = radius * cosf(rads + angle) * scaleX + center.x;
GLfloat k = radius * sinf(rads + angle) * scaleY + center.y;
vertices[i*2] = j;
vertices[i*2+1] = k;
}
vertices[(segments+1)*2] = center.x;
vertices[(segments+1)*2+1] = center.y;
s_pShader->use();
s_pShader->setUniformsForBuiltins();
s_pShader->setUniformLocationWith4fv(s_nColorLocation, (GLfloat*) &s_tColor.r, 1);
ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );
#ifdef EMSCRIPTEN
setGLBufferData(vertices, sizeof(GLfloat)*2*(segments+2));
glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, 0);
#else
glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, vertices);
#endif // EMSCRIPTEN
glDrawArrays(GL_TRIANGLE_FAN, 0, (GLsizei) segments+additionalSegment);
free( vertices );
CC_INCREMENT_GL_DRAWS(1);
}
相关文章:
- 在c++中用vector填充一个简单的动态数组
- 如何使用用户输入在C++中正确填充2D数组
- 如何找到大小'x'数组是否完全填充,在C++?
- Cuda C++:设备上的Malloc类,并用来自主机的数据填充它
- 通过for循环使用用户输入填充列表
- QuadTree只在窗口的右上角绘制
- 绘制旋转的三角形
- 在现代OpenGL中,绘制GL_TRIANGLE奇怪的z轴行为的填充圆
- DirectX11只绘制填充索引和顶点缓冲区中的一半顶点
- 如何在QGraphicsScene上绘制填充多边形
- 如何在 cpp 中绘制带有图案的填充正方形
- C++OpenGL坐标阵列来绘制线条/边界和填充矩形
- SDL2 绘制和填充形状
- OpenGL绘制圆圈 /椭圆(填充)无GLBEGIN
- 无法用SDL2 GFX绘制一个填充的圆圈
- 绘制点或填充圆圈
- 如何使用 SDL 2 和 C++ 绘制椭圆的填充扇区
- 如何在 cocos2d-x 中用颜色绘制圆形填充
- 如何在Qt中绘制由画笔填充的开放曲线
- 在c++中绘制填充立方体,崩溃,没有有用的错误可以跟踪