如何画一条小于 1 像素宽的线

How can I draw a line less than 1 pixel wide

在 opengl 的上下文中阅读此内容我找到了 2 个解决方案:

  1. 如果线比 1 像素细,则绘制 1 像素的线,但使用 alpha 混合使其部分可见。 +更好的结果 -z 缓冲问题(您必须对行进行排序)

  2. 绘制 GL_QUAD 而不是直线 - 您必须自己计算 4 个顶点坐标 - 在应用程序中或使用顶点着色器。 +使用亚像素精度正确绘制的细线 -line 可能会出现 'dashed',因为片段在屏幕上适合 'between' 两个像素,因此不会被绘制。"

https://www.opengl.org/discussion_boards/showthread.php/146742-Line-width-less-than-1-pixel

在处理过程中我该如何做?

您可以只使用 strokeWeight() 函数并传入一个小于 1:

的值
strokeWeight(.5);
line(0, 0, width, height);

可以在 the reference 中找到更多信息。

或者,如果您想更紧密地与 OpenGL 方法保持一致...

If line is thiner than 1 pixel, draw 1-pixel line but use alpha blending to make it partially visible.

只需将 stroke() 设置为包含字母的值。像这样:

stroke(0, 128);
line(0, 0, width, height);

可以在 the reference 中找到更多信息。

Draw a GL_QUAD instead of line - you'll have to compute 4 vertex coordinates yourself - in application or using vertex shader. +thin line properly drawn using subpixel accuracy -line can appear 'dashed' because of fragments fitting 'between' two pixels on the screen and thus not being drawn."

可以使用beginShape()函数,传入参数QUADS来绘制四边形。像这样:

beginShape(QUADS);
vertex(0, 0);
vertex(0, 0);
vertex(width, height);
vertex(width, height);
endShape();

同样,可以在 the reference 中找到更多信息。

然后您可以使用各种着色器函数来使用着色器。您猜对了:可以在 the reference

中找到更多信息

除了将您指向 Google 和 the reference 之外,很难回答一般 "how do I do this" 类型的问题。参考应该是您的第一站。通读它并寻找设置 alpha 值、绘制四边形或使用着色器的函数。 Stack Overflow 更适合特定的 "I tried X, expected Y, but got Z instead" 类型的问题,所以你能做的最好的事情就是 尝试一些东西 和 post 一个 MCVE 如果卡住了。祝你好运。