在 OpenGL 中绘制抖动线
假设我在 OpenGL 中画了一些简单的线条,如下所示:
glBegin(GL_LINES);
glVertex2f(1, 5);
glVertex2f(0, 1);
glEnd();
如何使线条看起来不稳定,就像是手绘或手绘的一样?
Suppose I drew some simple lines in OpenGL like this:
glBegin(GL_LINES);
glVertex2f(1, 5);
glVertex2f(0, 1);
glEnd();
How do I make the line look jittery, like it was being sketched or drawn with hand?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试将线路分成几段,然后使用 rand() 添加一些随机噪声。
这是一些丑陋但希望有些有用的代码。您可以根据需要重构它:
我将循环增加 2,并在没有随机扰动的情况下绘制每隔一个点,以便线段全部连接在一起。
您可能想知道 glBegin/glEnd 样式被称为“立即模式”并且效率不是很高。某些移动平台甚至不支持它。如果您发现您的东西运行缓慢,请考虑使用顶点数组。
为了使线条看起来更漂亮,您可能还需要使其更粗并使用抗锯齿功能。
You could try breaking your line up into segments then adding some random noise with rand().
Here's some ugly but hopefully somewhat useful code. You can refactor this as needed:
I increment the loop by 2 and draw every other point without random perturbation so that the line segments are all joined together.
You might want to be aware of the fact that the glBegin/glEnd style is called "immediate mode" and is not very efficient. It's not even supported on some mobile platforms. If you find your stuff is sluggish look at using vertex arrays.
To make the line look hand-drawn and nicer you might also want to make it fatter and use anti-aliasing.