GL line blend/antialias issue

Hi,

I made an app that does several kinds of visualizations, also line drawings. On osx I get proper lines, and ‘hard’ edges between colors. But on Windows I cannot get rid of the blending, it looks something like this:

image

This is a snippet of the code:
glBegin(GL_LINE_STRIP);
for(int i = 0; i < screen; i++) {
int y = ofMap(curve[i], min, max, scale, 0);
if( color == 0 ){
glVertex2f(i, y);
glColor4f( colR, colG, colB, colAlpha);
}
else{
glVertex2f(i, y);
glColor4f( col1R, col1G, col1B, col1Alpha);
}
}
glEnd();

I’m just using 2 colors here, but I want to use multiple in the end.

I tried the following already with no success:
ofDisableSmoothing();
ofDisableBlendMode();
glDisable(GL_LINE_SMOOTH);
glDisable(GL_BLEND);

The GL documentation on OF is pretty short, any idea what I can try next?

Maybe setting everything inside an fbo with a high samplenum? Then drawing the fbo.
Or if you want the opposite, setting the maxSampleNum to 0

I haven’t used fbo previously, but setting the maxsamplenum to zero there, isn’t that the same as no antialiasing?

Yes, I think so.
It is not complicated to use FBO.
first create an ofFbo in your .h

ofFbo fbo;

then in your .cpp:

setup(){
  fbo.allocate(width, height, GL_RGB, samples); 
draw(){
  fbo.begin();
  //HERE YOU CAN DRAW WHATEVER YOU WANT
  fbo.end();
  ofSetColor(255);
  fbo.draw(0,0)

And that’s it. By default the sampleNum of FBOs is zero but you can modify it with the 4th parameter in the allocate() function.

Maybe there is some way to change the default video buffer samples, but I just know how to modify it on FBOs

ok I figured it out I think. On my windows machine the resolution was much higher, but the effect also appears on osx. It is dues to the GL_line_strip function connecting 2 ‘dots’, if there’s more pixels in between it will create this kind of fade. I fixed it by adding in more dots to minimize the fade effect.

2 Likes