如何使用glDrawArray()绘制的贝塞尔曲线的各个点平滑地改变宽度
当用户用手指绘制时(我修改了glpaint),我成功地实时渲染了贝塞尔曲线。我可以在绘图之前调整线条的宽度。这导致整个线条绘制在这个新的宽度,但在线条的整个过程中保持恒定。但我希望在这一行的整个过程中有一个平滑的宽度变化。我还可以在用户绘制时动态调整画笔宽度,但是由于以下原因,这会产生斑点线。
I am successfully rendering a bezier curve in real-time as the user draws with a finger (I modified glpaint). I can adjust the width of the line just prior to drawing. This results in the whole line drawing at this new width, but remaining constant at this width over the course of the line. But I want a smooth variance of width across the course of this one line. I can also adjust the brush width dynamically as the user draws, however this results in a blotchy line for the following reasons.
使用glDrawArray()以曲线渲染曲线。当用户绘制时,对于大约每几个接触点,我的bezier函数可能计算数百个要渲染的点,此时它将这些点发送到要渲染的gldrawarray函数中。问题是宽度变化确实需要动态地沿着这些点绘制,并且必须能够在这些传递点的绘制过程中改变画笔宽度,但是因为它们作为整个组被发送到函数中以进行绘制到目前为止,通过glDrawArray实现整个生产线的平滑宽度变化已经证明是难以捉摸的。
The curve is rendered in points using glDrawArray(). As the user draws, for about every few touchpoints my bezier function calculates potentially hundreds of points to render, at which point it sends these points into the gldrawarray function to be rendered. The problem is that the width varyiance really needs to be plotted along these points dynamically and must be able to change brush width over the course of the drawing of these passed points, but because they are sent into the function as a whole group to be drawn at once via glDrawArray achieving smooth width varyiance across the overall line has proven elusive thus far.
你知道一种实现不同刷宽的方法吗?一个用点绘制的贝塞尔曲线,理想情况下用glDrawArray()绘制,而不使用三角形等?
Do you know of a way to achieve a varying brush width in real time, across one bezier curve drawn with points, and ideally drawn with glDrawArray(), and without resorting to using triangles, etc?
AFAIK实现此目的的唯一方法是创建一个填充多边形,其中骨架由原始路径确定,宽度沿长度变化,方法是移动与路径相切的每一边的顶点。
AFAIK the only way to achieve this is to create a filled polygon, where the skeleton is determined by your original path, and the width is varied along the length by displacing vertices for each side tangential to the path.
所以你最终围绕贝塞尔曲线建立了一条封闭的路径,因此:
So you end up constructing a closed path around your bézier curve, thus:
每个控制点的宽度因两边之间的距离而变化,以绿色显示。
The width at each control point is varied by the distance between each side, shown in green.
我希望这张粗略的图表能够澄清上面的描述!
I hope this rough diagram clarifies the description above!