简体   繁体   English

如何使用glDrawArray()平滑改变贝塞尔曲线的各个点的宽度

[英]How to smoothly vary width at various points of a bezier curve drawn using glDrawArray()

I am successfully rendering a bezier curve in real-time as the user draws with a finger (I modified glpaint). 当用户用手指绘制时,我成功地实时绘制了贝塞尔曲线(我修改了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. 我还可以在用户绘制时动态调整画笔的宽度,但是由于以下原因,这会导致斑点出现。

The curve is rendered in points using glDrawArray(). 使用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. 当用户绘制时,我的bezier函数大约每隔几个接触点就会计算出数百个要渲染的点,然后将这些点发送到gldrawarray函数中进行渲染。 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? 您是否知道一种实时实现变化的笔刷宽度,跨点绘制的贝塞尔曲线,理想情况下使用glDrawArray()绘制且无需求助于三角形等方法的方法?

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. AFAIK实现此目的的唯一方法是创建一个填充的多边形,其中的骨骼由您的原始路径确定,并且通过移动与该路径相切的每侧的顶点来沿长度改变宽度。

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! 我希望这个粗略的图可以澄清上面的描述!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM