填充抗锯齿聚cocos2d

问题描述:

如何在Cocos2D框架中绘制填充poly?

How can I draw filled poly in Cocos2D framework?

下面的代码绘制了poly但没有antialiasing.What应该更改?

Code below draws poly but without antialiasing.What should I change?

void ccFillPoly( CGPoint *poli, int points, BOOL closePolygon )
{
    // Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
    // Needed states: GL_VERTEX_ARRAY,
    // Unneeded states: GL_TEXTURE_2D, GL_TEXTURE_COORD_ARRAY, GL_COLOR_ARRAY
    glDisable(GL_TEXTURE_2D);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);

    glVertexPointer(2, GL_FLOAT, 0, poli);
    if( closePolygon )
        //   glDrawArrays(GL_LINE_LOOP, 0, points);
        glDrawArrays(GL_TRIANGLE_FAN, 0, points);
    else
        glDrawArrays(GL_LINE_STRIP, 0, points);

    // restore default state
    glEnableClientState(GL_COLOR_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnable(GL_TEXTURE_2D);
}


是在你的多边形周围添加透明顶点。
这种方法是快速和精细的,但是很难实现。
这是抗锯齿线的解决方案

One good approach to emulate antialiasing is to add transparent vertices around your polygon. This method is fast and fine-looking, but is little hard to implement. Here is solution for antialiased lines.

如果你不担心性能,你可以多次渲染多边形有一些透明度和偏移1像素。这将适用于没有纹理的多边形。

If you don't worry about performance, you may render the polygon multiple times with some transparency and offset by 1 pixel. This would work for not textured polygons.