我正在尝试在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();
}
调用列表的创建如下所示:
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();
当我这样做时,星形轮廓完美地绘制,但填充颜色在轮廓边缘外渗出(如果我在没有轮廓的情况下绘制它,则多边形看起来也不会看起来很清晰)。有什么想法吗?
编辑:我添加了一个显示问题的屏幕截图
感谢, 杰夫