"pygame.draw.polygon" fails to draw polygon on all edges of shape.

Issue #313 resolved
Former user created an issue

As shown in the attached image, when drawing a Pygame polygon (using the


function) the polygon is mostly filled correctly apart from one edge. Switching the drawing function to lines drew all the edges correctly (but had no polygon fill which I want). To see the problem better, I added code that drew red dots in the Pygame windows on the vertices of the polygon edge (with and without fill) and a black alignment square which should have 1 white pixel (gap) between it's top left sides and the shape. In the attached image there is also the relevant code (which I have added, simplified, below). It seems quite clear that this is a Pygame problem (as using the lines function worked) so please take a look and see if you can fix it.
Additional case information: Pygame version: 1.9.2a0, Python version: 3.5.1. Pygame Python module polygon vertices to content drawing issue.png Simplified example code (full, to run as a file with Python 3.5.1 and Pygame 1.9.2):

import pygame, sys
surface = pygame.display.set_mode((335, 80))
pygame.display.set_caption("Demonstration of Pygame bug")
border, rect = {"width": 5}, pygame.Rect((0,0,60,60)) # Defined here for debug.
while True:
    surface_2 = pygame.Surface((60,60))
    surface_2.fill((255,255,255)) # White is contrasting with black shape.
    for index in range(1):#2):
        path_data = [({0:0,1:rect.width-1}[index],{0:0,1:rect.height
            -1}[index]),(rect.width-1,0), (rect.width-border[
            1,rect.height-border["width"]), (0, rect.height-1)]
        #pygame.draw.lines(surface_2,(0,0,0),True,path_data) # Normal function.
        pygame.draw.polygon(surface_2,(0,0,0),path_data) # Function with bug.
        for dot in path_data: # Draw vertices for debugging.
            pygame.draw.line(surface_2, (255,0,0), dot, dot)
        pygame.draw.polygon(surface_2, (0,0,0), [(border["width"]+1, border[
            "width"]+1), (border["width"]*2, border["width"]+1), (border[
            "width"]*2, border["width"]*2), (1+border["width"], border["width"]
    surface.blit(surface_2, (10,10))
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:

Comments (3)

  1. Log in to comment