OpenGL filled polygon color "bleeding"

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

The creation of the call list just looks like:

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?

EDIT: I added a screenshot showing the problem

thanks, Jeff


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


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

Category:opengl Time:2011-04-13 Views:0
Tags: opengl

Related post

  • {R grid}: how to create a polygon half filled with color? 2010-07-06

    (This question might be too difficult, and maybe not worth the hassle to solve - however, if there is an easy solution - I would be curious to know) Let's say I create an image (using the grid package) which looks like this: require(grid) grid.newpag

  • OpenGL ES - How to Draw a filled Polygon? 2010-10-06

    I tried googling and searching on stack but I didn't find anything :-( ( ) I want to draw a filled polygon in OpenGL ES on iPad

  • Fill-in color on triangle using mouse click 2009-04-08

    I was wondering how to fill in a triangle shape with color when a user click on the triangle. So far I am using txt file as input file to read the coordinate of the triangle to be drawn on screen. --------------Solutions------------- I did something

  • How to draw filled polygon? 2010-01-12

    How to draw filled polygon in Android ? --------------Solutions------------- You need to set the paint object to FILL Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); Then you can draw whatever you want, and it will be filled. canvas.draw

  • How to draw filled polygon using c++? 2011-10-01

    I'm new to C++. I am using Visual studio Professional 2010. I learned to draw lines, but I need to draw filled polygon this time. The way that I drew lines is below: private: System::Void Form1_Paint(System::Object^ sender, System::Windows::Forms::Pa

  • how to fill contour colors and write axes names in RSM (R) 2011-10-28

    I have following data ct<-structure(list(Conc = c(50L, 100L, 150L, 50L, 100L, 150L, 50L, 100L, 150L, 100L, 100L, 100L), kGy = c(10L, 10L, 10L, 15L, 15L, 15L, 20L, 20L, 20L, 15L, 15L, 15L), CT.Y. = c(75L, 65L, 51L, 87L, 93L, 89L, 81L, 86L, 78L, 92L

  • OpenCv : draw a white filled polygon 2012-01-31

    I'd like to draw a white filled polygon, with arbitrary angle, in a black IplImage. I know there exists function such as createCircle, but I can't find something similar for polygons. I found this , but the use of it is awful, I mean I shouldn't have

  • Fill the color in List box Circle in C#.Net in Winforms 2009-09-08

    i have to List box one have Listbox have circle and its value i m dynamically create Circle as Per size come from database ..... i want to fill color in List box where circle is draw from another List box where Items have color like Red,blue, in one

  • Preventing color bleeding with StateImageList on TreeView 2009-12-08

    Does anyone have a solution for the color bleeding when using a StateImageList with a Windows Forms TreeView? Using the same ImageList with assigned to the TreeView's ImageList property, results in correct rendering as can be seen by the following im

  • Is it possible to use "Fill with color" function on Delphi's Image component? 2011-02-15

    I have a TImage component on the form. I need to implement the following functionality: (If mouse pointer is over point with red color, then apply "Fill with color green" to that point) Here by "Fill with color" I mean Paint's function "Fill with col

  • extjs: fill red color in holidays 2011-03-23

    I am testing with Extjs demo. I have some holidays: for examples 2011-03-23, 2011-04-11,... I want to fill red color that holidays How I can do? Thank you. --------------Solutions-------

  • Fill gradient color in area under line chart in Protovis 3.2 2011-09-28

    In my project, I use Protovis 3.2 to render line chart. I want to fill gradient color in the area under line chart. Although I have tried available color functions in Protovis but they did not work. Is there any simple solution for this problem? Belo

  • MS Paint "fill with color" tool does not work. :( 2013-01-20

    In paint, my "fill with color" tool (the pouring paint can) does not work. I click the can, I click a different color, the icon changes to the can, but when I click on a space like say an empty circle, it does not do anything. Right click, nothing, l

  • How to fill polygon with different color than boundary? 2011-02-28

    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 polygons one for the interior color and 1 for the boundary. I think there must be a b

  • Drawing a polygon with color in OpenGL causes texture colors to change 2012-03-04

    I'm working on a simulation program that draws points and other primitives on top of a large 2D rectangle with a texture mapped onto it. The problem is, when I draw a polygon and specify a color for the vertices using glColor3f, that color appears to

  • Changing google-maps polygon color/fill on click 2011-05-09

    I have the following code which has been passed on to me and creates polygons: <script type="text/javascript"> var map; function initialize() { var myLatlng = new google.maps.LatLng(-36.42,145.710); var myOptions = { zoom: 15, center: myLatlng,

  • Opengl irregular shape color filling 2009-11-11

    I am drawing a 5 corner star with GL_LINES. When I use the GL_POLYGON, it distorts the shape of star and connects the first and last vertex. Help please :( ? --------------Solutions------------- Modern graphics cards can't draw 3D polygons; they draw

  • opengl set texture color with vertex color 2008-10-28

    Because I need to display a that move independently, I need to render a label in pyglet to a texture (otherwise updating the vertex list for each glyph is too slow). I have a solution to do this, but my problem is that the texture that contains the g

  • How can I create a filled polygon from unordered edge data in MATLAB? 2010-12-08

    I want to create a polygon using edge data (X,Y coordinates of each point of edge) that is unordered, and I want to fill that polygon with some color. Any suggestions how I can accomplish this? --------------Solutions------------- If your polygon is

Copyright (C), All Rights Reserved.

processed in 1.097 (s). 13 q(s)