在 OpenGL 中绘制带阴影的文本 + FTGL
我正在使用 FTGL 库在 OpenGL 中绘制文本,一切正常,但是我想向文本添加阴影。我尝试的是用黑色绘制相同的文本,然后用正常颜色在上面绘制文本,如下所示(伪代码):
glColor3f(0, 0, 0); // outline color
DrawText(x-1, y-1, str);
DrawText(x+1, y-1, str);
DrawText(x+1, y+1, str);
DrawText(x-1, y+1, str);
glColor3f(1, 1, 1); // primary color
DrawText(x,y,str);
但是我必须绘制文本 5 次,它看起来仍然不是很好。
我想得到类似屏幕截图
的内容
I'm drawing text in OpenGL using FTGL library and everything works just fine, however I would like to add shadow to the text. What I tried is drawing same text with black color and then draw text above that with normal color like this (pseudocode):
glColor3f(0, 0, 0); // outline color
DrawText(x-1, y-1, str);
DrawText(x+1, y-1, str);
DrawText(x+1, y+1, str);
DrawText(x-1, y+1, str);
glColor3f(1, 1, 1); // primary color
DrawText(x,y,str);
But I have to draw the text 5 times and it still does not look very good.
I would like to get something like on the screenshot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能有很多方法可以实现这一目标 - 有些方法的质量比其他方法更高。
这就是我要做的:
对模糊图像应用陡峭的色调曲线,因此亮度范围 [0.0, 0.9] 映射到接近 0.0。这使得它不再模糊,结果是文本的“肥厚”版本。色调曲线应如下所示:
此外,您可以根据您想要的阴影的柔和程度使用不同的色调曲线。线性色调曲线会产生非常柔和的阴影。
There are probably a lot of ways to achieve that - some with higher quality than others.
Here's what I would do:
apply a steep tone-curve to the blurred image, so the luminance range [0.0, 0.9] is mapped to nearly 0.0. This makes it stop being blurry, and the result is a "fattened" version of the text. The tone curve should look something like this:
Also, you can use different tone-curves depending on how soft a shadow you want. A linear tone-curve would give a very soft shadow.
我通常这样做:
它看起来相当不错,您可以通过渲染列表和翻译来加快速度。
请参阅此处:https://i.sstatic.net/Dh68y.png
I am usually doing it this way:
It looks quite good, and you can speed it up with render list and translations.
see here: https://i.sstatic.net/Dh68y.png