When using the built-in keyboard, the console is flooded with a warning/error message, inverted rect in LCD_addUpdateRect()!, though it doesn''t seem to affect actual keyboard behaviour.
Error is reproducible using a minimum example, as shown in the below GIF:
On the GIF, you can see that a minimum example which only imports the keyboard and then brings it up results in the messages being printed.
I’m pretty sure it comes from pd→graphics→fillPolygon() in my case. Does the winding order need to be a specific one (e.g. CCW)? It’s a bit unclear to me from the documentation.
Actually scratch that, it most likely comes from pd→graphics→drawLine(). I’m even more puzzled…
At the moment I only have my actual game where this is happening, but I could try extracting the code to a standalone app if needed.
In the meantime, here is the relevant (abridged) code:
V2 pos_iso_to_screen(V2 v)
{
// converts an isometric position to a screen position
V2 scr = v2(
GRID_X0 + TILE_HALFWIDTH * (v.x + v.y),
GRID_Y0 + TILE_HALFHEIGHT * (v.y - v.x));
return scr;
}
void make_tile_poly(f32 x, f32 y, i32 *points)
{
// constructs a polygon for an isometric tile at position (x, y)
V2 topleft = v2(x - 0.5f, y - 0.5f);
V2 topright = v2_add(topleft, v2(1, 0));
V2 botright = v2_add(topleft, v2(1, 1));
V2 botleft = v2_add(topleft, v2(0, 1));
V2i scr_topleft = pos_iso_to_screen(topleft);
V2i scr_topright = pos_iso_to_screen(topright);
V2i scr_botright = pos_iso_to_screen(botright);
V2i scr_botleft = pos_iso_to_screen(botleft);
points[0] = scr_topleft.x; points[1] = scr_topleft.y;
points[2] = scr_topright.x; points[3] = scr_topright.y;
points[4] = scr_botright.x; points[5] = scr_botright.y;
points[6] = scr_botleft.x; points[7] = scr_botleft.y;
}
void draw_poly(i32 *points, i32 n_points, Camera *camera)
{
// NOTE: these are the arguments to the latest pd->graphics->setDrawOffset()
i32 offx = camera->draw_off.x;
i32 offy = camera->draw_off.y;
for (i32 i = 0; i < 2 * n_points; i += 2) {
i32 x = points[i] + offx;
i32 y = points[i + 1] + offy;
i32 nx = points[(i + 2) % (2 * n_points)] + offx;
i32 ny = points[(i + 3) % (2 * n_points)] + offy;
pd->graphics->drawLine(x, y, nx, ny, 3, kColorWhite);
}
}
Basically I’m calling draw_poly() with polygons resulting from make_tile_poly(). Sometimes (not always) this causes the error message to appear (depending on which tiles are drawn and/or where my “camera” is in respect to them).
The resulting polygons look like this on screen (the red ones):