OpenGL 场景顶部的反色文本
我有一个字体纹理,用于在 OpenGL 场景之上绘制文本。 问题是场景的颜色变化很大,以至于我使用的任何纯色都难以阅读。是否可以用反转颜色绘制我的字体纹理?
调用 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
只会用纯色绘制它,调用 glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
会反转绘制它,但会忽略纹理的 alpha 值,因此您只会看到一个倒置的矩形而不是字母。
我需要的是相当于 glBlendFunc(GL_SRC_ALPHA * GL_ONE_MINUS_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA);
可以在不使用着色器的情况下以某种方式实现这一点吗?
I have a font texture which I use in order to draw text on top of my OpenGL scene.
The problem is that the scene's colors vary so much that any solid color I use is hard to read. Is it possible to draw my font texture with inverted colors?
A call to glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
would just draw it with a solid color, A call to glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
would draw it inverted, but would disregard the alpha values of the texture so you'd just see an inverted rectangle instead of the letters.
What I need is something equivalent toglBlendFunc(GL_SRC_ALPHA * GL_ONE_MINUS_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA);
Can this be achieved somehow without using shaders ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据戴夫的评论:
我不使用 GL_ALPHA 纹理,而是生成每个像素相等的 GL_RGBA 纹理:
(alpha, alpha, alpha, 0xff)(这是灰度图像而不是亮度图像)。
然后我使用此纹理:
结果为:
(1 - dest_color) x "src_alpha" + dest_color x (1 - "src_alpha")
这正是我所需要的。
Following dave's comment:
Instead of using a GL_ALPHA texture I generate a GL_RGBA texture where each pixel is equal:
(alpha, alpha, alpha, 0xff) (this is a greyscale image instead of a luminance image).
Then I use this texture with:
The result is:
(1 - dest_color) x "src_alpha" + dest_color x (1 - "src_alpha")
which is exactly what I needed.
复制您想要覆盖的屏幕部分,您可以使用 CPU 反转该复制的部分。使用文本作为蒙版将新制作的反转纹理绘制到屏幕上。
请注意,这很慢,毫无疑问着色器会快得多。
Copy the subsection of the screen you want to overwrite, you can use the CPU to invert this copied portion. Draw your newly made inverted texture to the screen using the text as a mask.
Note that this is slow, there's no doubt that shaders would be much faster.