filled antialiased poly cocos2d

给你一囗甜甜゛ 提交于 2020-01-30 09:45:33

问题


How can I draw filled poly in Cocos2D framework?

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);
}

回答1:


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.

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.



来源:https://stackoverflow.com/questions/9257728/filled-antialiased-poly-cocos2d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!