2D openGL 绘图线不完全适合像素光栅

发布于 2024-10-07 19:08:11 字数 701 浏览 0 评论 0原文

我正在用 OpenGL 绘制类似于 LED VU 表的东西。结果应该像这样的垂直条:

Animated vmeters

不幸的是,我的绘图空间受到限制,我必须完全适合上面有 18 个酒吧。这样条形之间的间距为 3.6 像素。

绘制时,这会导致线条之间的间隙存在明显差异,因为间隙的宽度为 2 或 1 像素。我正在寻找一种使用子像素渲染的解决方案,而不是通过某种抗锯齿“伪造”线条,以便所有间隙都具有相同的宽度。

这是到目前为止我的代码

glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH, GL_NICEST);
for (int i = 0; i < 18; ++i) {
            float bBottom = barBottom + i*3.6f;
            glBegin(GL_LINES);
            glLineWidth(2);
            glVertex2f(bRight,bBottom);
            glVertex2f(bLeft,bBottom);
            glEnd();
}
glDisable(GL_LINE_SMOOTH);

不幸的是,打开线平滑没有显示出明显的效果。有什么建议吗?

I'm drawing something similar to a LED VU meter in OpenGL. Result should be like on vertical bar of this:

Animated vumeters

Unfortunately, my drawing space is restricted, and I have to fit exactly 18 bars on it. That yields a spacing between bars of 3.6 pixels.

When drawn, this causes visible differences in the gaps between lines, because the gaps are either 2 or 1 pixel wide. I'm looking for a solution to use subpixel rendering and than "fake" the lines by some kind of anti-aliasing, so that all gaps appear of the same width.

This is my code so far

glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH, GL_NICEST);
for (int i = 0; i < 18; ++i) {
            float bBottom = barBottom + i*3.6f;
            glBegin(GL_LINES);
            glLineWidth(2);
            glVertex2f(bRight,bBottom);
            glVertex2f(bLeft,bBottom);
            glEnd();
}
glDisable(GL_LINE_SMOOTH);

Unfortunately, turning on line smoothing showed no visible effect. Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

挽心 2024-10-14 19:08:11

两个想法:

  1. 将所有条形绘制到一个大的屏幕外纹理,使得间隙和宽度都相等,然后使用双线性过滤将结果blit到所需的屏幕位置和大小。

  2. 请一位美术师绘制所有完全照亮的条形,以便看起来不错,然后从每个条形的顶部向下绘制带有 Alpha 通道的黑色矩形,以使图像的所需部分变暗。

Two ideas:

  1. Draw all the bars to a large off screen texture such that the gaps and widths are all equal and then use bilinear filtering to blit the result to the required screen position and size.

  2. Get an artist to draw all the fully lit bars so that the look good, then draw black rectangles with an alpha channel from the top of each bar downwards to darken the required parts of the image.

夏夜暖风 2024-10-14 19:08:11

使用多重采样(多重采样规范)。

此外,我会使用四边形(而不是线)来渲染这些块。

Use multisampling (Multisampling specs).

Additionally, I would use quads (and not lines) for rendering those blocks.

忘你却要生生世世 2024-10-14 19:08:11

如果您无法为 OpenGL 上下文启用抗锯齿功能,您可以模拟它 - 使用如此简单的图形很容易。当需要绘制10.6像素高的矩形时,先用其颜色绘制10像素,然后绘制中间颜色的单像素线(矩形颜色的0.6和背景颜色的0.4)。

If you can't enable antialiasing for your OpenGl context, you can emulate it - it's easy with such simple graphics. When you need to draw rectangle 10.6 pixels high, draw it 10 pixels with its color and then single pixel line of intermediate color (0.6 of rectangle color and 0.4 of background color).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文