我正在尝试在openGL(Java)中绘制一个五角星形状,它既有填充也有轮廓.我用来绘制它的代码
gl.glPushAttrib(GL.GL_ALL_ATTRIB_BITS);
try {
// set attributes for filling the shape
Color fillColor = Color.GREEN;
float[] rgb = fill.getRGBColorComponents(null);
gl.glColor4f(rgb[0], rgb[1], rgb[2], 1f);
gl.glEnable(GL.GL_POLYGON_SMOOTH);
gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL);
gl.glEnable(GL.GL_POLYGON_OFFSET_FILL);
gl.glCallList(this.glListId);
// set attributes for outlining the shape
gl.glEnable(GL.GL_LINE_SMOOTH);
Color outline = Color.RED;
float[] rgb = outline.getRGBColorComponents(null);
gl.glColor4f(rgb[0], rgb[1], rgb[2], 1f);
gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);
gl.glLineWidth(5);
gl.glCallList(this.glListId);
}
finally {
gl.glPopAttrib();
}
Run Code Online (Sandbox Code Playgroud)
调用列表的创建看起来像:
gl.glNewList(this.glListId, GL.GL_COMPILE);
gl.glBegin(GL.GL_POLYGON);
for (int j = 0; j < xCoords.length; j++) {
// 2d polygon
gl.glVertex2d(xCoords[j], yCoords[j]);
}
gl.glEnd();
Run Code Online (Sandbox Code Playgroud)
当我这样做,明星的轮廓绘制完美,但轮廓的边缘外的填充颜色出血(如果我画它没有轮廓,多边形的外观看起来不脆或者).有什么想法吗?
编辑:我添加了一个显示问题的屏幕截图

谢谢,杰夫
根据"星形"的含义,请记住GL_POLYGON只能正确渲染凸多边形:
GL_POLYGON:绘制单个凸多边形.顶点1到N定义此多边形.