Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

2D openGL drawing lines that don't exactly fit pixel raster

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?

like image 732
Philipp Avatar asked Nov 20 '25 20:11

Philipp


2 Answers

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.

like image 133
Skizz Avatar answered Nov 23 '25 11:11

Skizz


Use multisampling (Multisampling specs).

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

like image 25
Luca Avatar answered Nov 23 '25 10:11

Luca



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!