ofDrawLine issue with light in OpenGL

Hello,

I’m digging into openGL and light in openframeworks and i noticed something that seems a bug to me. When I draw an array of lines and I lit them with a spot light, only half of the light is showed.

Here is the code

void ofApp::draw(){
ofBackground(230);
spotLight1.setSpotlight();

spotLight1.setPosition (50, -20, 50);
spotLight1.lookAt(ofVec3f(50, 0, 50));
spotLight1.setSpotConcentration(0);
spotLight1.setAttenuation(0.1);
spotLight1.setSpotlightCutOff(50);

spotLight1.enable();

camera.begin();
ofEnableDepthTest();
ofSetColor(0, 0, 255);
for(int x=0;x<100;x++){
    for(int y=0; y<100;y++){
        ofDrawLine(x,0,y,x,-25,y);
    }
}
ofDrawAxis(200);
ofDisableDepthTest();
camera.end();
}

Hello,

And sorry to ask again, but I don’t understand what happen with the spotlight class, indeed, the correct light reflection on lines depends of the orientation of the lines as you can see bellow. Anyone can explain me what happen ?

Thanks a lot !

Hi !

Nobody have an idea about this strange behavior ? do I have to create an issue on github or is it not relevant ?

Best,

Just to inform people who have the same question, this light issue is the consequence of the normals orientation of the lines : when you use ofDrawline, the lines have no specified normals, so OpenGL use the default normal (0,0,1). So to draw line along the z axis (like the right part of the capture) and get the right lightning it’s better to use the pushMatrix > rotate > draw > popMatrix or create an ofMesh / of3Dprimitive full of lines to manage the normals, than drawing of lines like :

for(int x=0;x<100;x++){
        for(int y=0; y<100;y++){
            ofDrawLine(x,0,y,x,-10,y);
        }
    }