Using Cocos2d to draw a thicker circle:
glLineWidth(20);
ccDrawCircle(self.ripplePosition, _radius, 0, 50, NO);
But this is what shows up(notice how it looks like it’s created from 4 different segments):
https://i.stack.imgur.com/jYW4s.png
I tried increasing the number of segments to larger values but the result is the same.
Is this a bug in Cocos2D? Any ideas on how to achieve a “perfect” circle?
Here is the implementation of ccDrawCircle from cocos2d 2.0rc2:
void ccDrawCircle( CGPoint center, float r, float a, NSUInteger segs, BOOL drawLineToCenter)
{
lazy_init();
int additionalSegment = 1;
if (drawLineToCenter)
additionalSegment++;
const float coef = 2.0f * (float)M_PI/segs;
GLfloat *vertices = calloc( sizeof(GLfloat)*2*(segs+2), 1);
if( ! vertices )
return;
for(NSUInteger i = 0;i <= segs; i++) {
float rads = i*coef;
GLfloat j = r * cosf(rads + a) + center.x;
GLfloat k = r * sinf(rads + a) + center.y;
vertices[i*2] = j;
vertices[i*2+1] = k;
}
vertices[(segs+1)*2] = center.x;
vertices[(segs+1)*2+1] = center.y;
[shader_ use];
[shader_ setUniformForModelViewProjectionMatrix];
[shader_ setUniformLocation:colorLocation_ with4fv:(GLfloat*) &color_.r count:1];
ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );
glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, vertices);
glDrawArrays(GL_LINE_STRIP, 0, (GLsizei) segs+additionalSegment);
free( vertices );
CC_INCREMENT_GL_DRAWS(1);
}
I went with a slightly modified version of ccDrawCircle and it works pretty well (performs a lot better than using and resizing a sprite):