[solved] fillPolygon does not seem to work with a background

SDK: Macos pdc version 2.3.1

I have some code that looks like the following snippet. I tried drawing a plain black background and then fill white polygons on top of it, however it the white polygons do not show up. When I tried dithering patterns instead, the white polygons were just clear and I saw the dithering pattern through them. The snippet should be runnable to reproduce my issue.

local gfx <const> = playdate.graphics
function playdate.update()
  gfx.setDitherPattern(0.5, gfx.image.kDitherTypeBayer8x8)
  gfx.fillRect(0, 0, 400, 240)

  gfx.fillPolygon(10, 10, 20, 10, 20, 20, 20, 10)
  gfx.fillRect(10, 30, 20, 20)

  gfx.fillPolygon(50, 50, 80, 50, 80, 80, 80, 50)
  gfx.fillRect(50, 100, 20, 20)

As you should see in the examples, the rectangles appear but the polygons do not.

Make sure your polygon is closed. I'm not sure that will fix this, I can't run the code right now.

Also setting colour will switch off the current dither, so you'd need to set it again after each colour set. Finally, dither value works opposite with white vs black, why is explained in the docs.

Okay so it seems like I was just doing my coordinates incorrectly. I made a rect helper to do it in a standard way and found out I was doing this:

gfx.fillPolygon(10, 10, 20, 10, 20, 20, 20, 10)

When I should have these coords. My mess up!

gfx.fillPolygon(10, 10, 20, 10, 20, 20, 10, 20)
1 Like