@@ -190,13 +190,29 @@ pub fn (ctx &Context) draw_rect_empty(x f32, y f32, w f32, h f32, c gx.Color) {
190190 sgl.load_pipeline (ctx.pipeline.alpha)
191191 }
192192 sgl.c4b (c.r, c.g, c.b, c.a)
193-
194- sgl.begin_line_strip ()
195- sgl.v2f (x * ctx.scale, y * ctx.scale)
196- sgl.v2f ((x + w) * ctx.scale, y * ctx.scale)
197- sgl.v2f ((x + w) * ctx.scale, (y + h) * ctx.scale)
198- sgl.v2f (x * ctx.scale, (y + h) * ctx.scale)
199- sgl.v2f (x * ctx.scale, (y - 1 ) * ctx.scale)
193+ // The small offsets here, are to make sure, that the start and end points will be
194+ // inside pixels, and not on their borders. That in turn, makes it much more likely
195+ // that different OpenGL implementations will render them identically, for example
196+ // Mesa, with `LIBGL_ALWAYS_SOFTWARE=1` renders the same as HD4000.
197+ mut toffset := f32 (0.1 )
198+ mut boffset := f32 (- 0.1 )
199+ tleft_x := toffset + x * ctx.scale
200+ tleft_y := toffset + y * ctx.scale
201+ bright_x := boffset + (x + w) * ctx.scale
202+ bright_y := boffset + (y + h) * ctx.scale
203+ sgl.begin_lines () // more predictable, compared to sgl.begin_line_strip, at the price of more vertexes send
204+ // top:
205+ sgl.v2f (tleft_x, tleft_y)
206+ sgl.v2f (bright_x, tleft_y)
207+ // left:
208+ sgl.v2f (tleft_x, tleft_y)
209+ sgl.v2f (tleft_x, bright_y)
210+ // right:
211+ sgl.v2f (bright_x, tleft_y)
212+ sgl.v2f (bright_x, bright_y)
213+ // bottom:
214+ sgl.v2f (tleft_x, bright_y)
215+ sgl.v2f (bright_x, bright_y)
200216 sgl.end ()
201217}
202218
0 commit comments