How to fill polygon with different color than boundary?

前端 未结 4 2325
暗喜
暗喜 2021-02-20 09:11

I need to draw a polygon that has the boundary lines with one color and fill the interior with another color. Is there an easy way to do this ? I currently draw two polygon

4条回答
  •  渐次进展
    2021-02-20 09:47

    You can switch the fill mode between polygons, lines and points, using glPolygonMode.

    In order to draw polygon lines in a different color you can do the following:

    glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
    draw_mesh( fill_color );
    glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
    glEnable(GL_POLYGON_OFFSET_LINE);
    glPolygonOffset(-1.f,-1.f);
    draw_mesh( line_color );
    

    Line offset may be needed, because OpenGL doesn't guarantee the edges of polygons will be rasterized in the exact same pixels as the lines. So, without explicit offset you may and up with lines being hidden by polygons, due to failed depth test.

提交回复
热议问题