openFrameworks icon indicating copy to clipboard operation
openFrameworks copied to clipboard

issue with simple line drawing

Open stephanschulz opened this issue 6 years ago • 13 comments

I’m on macOS 10.12.6 with Xcode Version 9.2 beta (9C32c) with MBP Retina display running this simple code

    ofBackground(0);
    int _h = mouseX;
    ofSetColor(255);
    for(int i=0; i<1000; i++){
        
        ofDrawLine(i, _h,i, _h+20);
    }

produces this image where lines should have been drawn one beside the next but for some reason some are on top of each other. I have seen this in previous versions too.

screen shot 2018-05-04 at 9 23 15 am

stephanschulz avatar May 04 '18 14:05 stephanschulz

I had a similar issue a few months ago on a MacBook pro (15inch with retina display from mid 2015), on macOS Sierra 10.12.6. I tried the code on Xcode Version 9.2 (9C40b), Xcode Version 8.0 (8A218a) and Qt Creator as well as different versions of openFrameworks (of_v0.9.8_osx, of_v20170714_osx, 0.10.0) I just run it again trying the new of0.10.0_RC4 on Xcode Version 9.2 (9C40b) with the same results.

This was the code to create a gradient by drawing vertical lines:

 
    ofBackground(0);
    for (int i = 0; i < ofGetWidth(); i++)
    {
        int grey = ofWrap(i, 0, 255);
        ofSetColor(grey);
        ofDrawLine(i, 0, i, 255);
    }

And this was the output screen shot 2018-05-04 at 12 55 26 pm

I was able to “fake” the desired output by setting the lineWidth to 2.


    ofBackground(0);
    for (int i = 0; i < ofGetWidth(); i++)
    {
        int grey = ofWrap(i, 0, 255);
        ofSetColor(grey);
	ofSetLineWidth(2);
        ofDrawLine(i, 0, i, 255);
    }

This is the result: screen shot 2018-05-04 at 12 56 08 pm

However, when drawing horizontal lines the issue did not occur, although the gradient did not go all the way to white (which it did when setting the line width to 2 again):


    ofBackground(0);
    for (int i = 0; i < ofGetWidth(); i++)
    {
        int grey = ofWrap(i, 0, 255);
        ofSetColor(grey);
        ofDrawLine(0, i, 255, i);
    }

screen shot 2018-05-04 at 12 57 02 pm

m-uv avatar May 04 '18 18:05 m-uv

To add another data point:

  • oF Master (RC4)
  • macOS 10.13.4
  • MacBook Pro (15-inch, 2017) (retina)
  • Xcode Version 9.2 (9C40b)
 ofApp::draw() {
    ofBackground(0);
    for (int i = 0; i < ofGetWidth(); i++)
    {
        int grey = ofWrap(i, 0, 255);
        ofSetColor(grey);
        ofDrawLine(i, 0, i, 255);
    }
}
ofapp_cpp

bakercp avatar May 04 '18 18:05 bakercp

To add another data point:

oF Master (RC4) macOS 10.13.4 MacBook Pro (15-inch, 2017) (retina) QTCreator 4.5.1

blank_skitch_document

I also tried to open the same app in low res mode with the same results. test_debug_app_info

blank_skitch_document

bakercp avatar May 04 '18 18:05 bakercp

Also, it doesn't seem to matter what GL version is used main.cpp:

#include "ofApp.h"

int main()
{
    ofGLWindowSettings settings;
    settings.setSize(1024, 768);
//    settings.setGLVersion(2, 1);
//    settings.setGLVersion(3, 2);
//    settings.setGLVersion(4, 1);
    settings.windowMode = OF_WINDOW;
    auto window = ofCreateWindow(settings);
    auto app = std::make_shared<ofApp>();
    ofRunApp(window, app);
    return ofRunMainLoop();
}

bakercp avatar May 04 '18 18:05 bakercp

Have you tried disabling antialiasing? in main set window settings numSamples to 0 or in setup call ofDisableAntialiasing()

arturoc avatar May 05 '18 08:05 arturoc

This is with 0.9.8 but there are differences in Release/Debug so may offer a clue

Release: image

Debug: image

jvcleave avatar May 05 '18 08:05 jvcleave

@arturoc ofDisableSmoothing() has no effect.

Playing with numSamples also doesn't seem to have an effect.

int main()
{
    ofGLFWWindowSettings settings;
    settings.setSize(1024, 768);
    //    settings.setGLVersion(4, 1);
    settings.numSamples = 4;
    settings.windowMode = OF_WINDOW;
    auto window = ofCreateWindow(settings);
    auto app = std::make_shared<ofApp>();
    ofRunApp(window, app);
    return ofRunMainLoop();
}

bakercp avatar May 05 '18 13:05 bakercp

Could this be a GL driver bug on macOS?

bakercp avatar May 05 '18 13:05 bakercp

no, ofDisableSmoothing is a different thing and is disabled by default, i was saying ofDisableAntialiasing() but numSamples=0 should have the same effect

arturoc avatar May 05 '18 14:05 arturoc

@bakercp looks like a GL driver issue to me. It could be that with Mac OS Sierra and onwards OpenGL calls are routed/emulated through Metal, and that line drawing + overdraw trip up their driver. A way to check this hypothesis would be to test the code on a Mac with older OS...

For comparison, here's how linux draws the above:

screenshot from 2018-05-10 12-00-15

tgfrerer avatar May 10 '18 11:05 tgfrerer

I'm on Sierra screen shot 2018-05-10 at 09 53 30

And I dont see the artifacts described. Im using xcode 8.3.2 and OF's current github master screen shot 2018-05-10 at 09 52 22

I used the following code

void ofApp::draw(){
	
	ofBackground(0);
	for (int i = 0; i < ofGetWidth(); i++)
	{
		int grey = ofWrap(i, 0, 255);
		ofSetColor(grey);
		ofDrawLine(i, 0, i, 255);
	}
}

roymacdonald avatar May 10 '18 12:05 roymacdonald

I suspect this has something to do with the macOS AMD graphics card driver.

bakercp avatar May 10 '18 13:05 bakercp

I think it is amd related too no artifacts on M1 here

dimitre avatar Jul 27 '22 12:07 dimitre

I suppose this issue won't be addressed because it seems to be OS related. should we close it?

dimitre avatar Mar 23 '23 03:03 dimitre