OpenGL填充多边形颜色“渗色". [英] OpenGL filled polygon color "bleeding"

查看:116
本文介绍了OpenGL填充多边形颜色“渗色".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在openGL(Java)中绘制一个5角的星形形状,该形状既填充又概述了轮廓.我用来绘制的代码

I'm trying to draw a 5 pointed star shape in openGL (Java) that is both filled and outlined. The code i'm using to draw it

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

执行此操作时,星形轮廓会完美绘制,但填充颜色会在轮廓边缘外渗出(如果我绘制时没有轮廓,多边形看起来也不会很清晰).有什么想法吗?

When I do this, the outline of the star draws perfectly, but the fill color bleeds outside the edges of the outline (if I draw it without the outline, the polygon looks does not look crisp either). Any ideas why?

我添加了显示问题的屏幕截图

I added a screenshot showing the problem

谢谢, 杰夫

推荐答案

取决于您所说的星形"是什么,请记住

Depending on what you mean by "star shape", remember that GL_POLYGON can only render convex polygons correctly:

GL_POLYGON:

绘制单个凸多边形. 顶点1到N定义了这个 多边形.

Draws a single, convex polygon. Vertices 1 through N define this polygon.

这篇关于OpenGL填充多边形颜色“渗色".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆