Problem with lighting and 3d shapes in openframeworks 9

I just migrated over to OF 9 and noticed something is not working as before with the lighting in one of my apps. I’ve isolated the problem into a small test program which you can see below:

void ofApp::setup(){
    mPointLight.setPosition(100,100, 500);
    
    mPointLight.setSpecularColor( ofFloatColor(1.f, 1.f, 1.f) );
    mPointLight.setDiffuseColor(  ofFloatColor(1.f, 1.f, 1.f) );
    mPointLight.setSpotConcentration(5.0);
    
    mPointLight.setPointLight();
    
    glEnable(GL_DEPTH_TEST);
    ofEnableLighting();
    mPointLight.enable();
}

//--------------------------------------------------------------
void ofApp::update(){
    
}

//--------------------------------------------------------------
void ofApp::draw(){
    
    ofBackground(ofColor::gray);
    ofEnableLighting();
    mPointLight.enable();
    ofSetColor(ofRandom(255));
    ofDrawSphere(ofGetWidth()/2, ofGetHeight()/2, -50, 105);
    
    
    mPointLight.disable();
    ofDisableLighting();
    
}

With OF 8.4 this draws a sphere with some lighting that randomly changes colour each frame(which is what I want), but on OF 9 the spheres colour stays the same?

Can anyone advice on what i’m doing wrong?

Thanks.

Hi, there was some light strangeness fixed for 0.9, think it was this issue here: https://github.com/openframeworks/openFrameworks/issues/3942

Maybe your problem is related?

If I set the colour of the light in draw then it updates the lighting which fixes the problem

mPointLight.setSpecularColor( ofFloatColor(1.f, 1.f, 1.f) );
mPointLight.setDiffuseColor( ofFloatColor(1.f, 1.f, 1.f) );

Hi @lorenzo_p !

You can use ofSetGlobalAmbientColor. Mind it passes an ofFloatColor.

For more control, you can use an ofMaterial, like so (there are more parameters, it’s just a quick example):

// Update
material.setEmissiveColor(ofFloatColor(sin(ofGetElapsedTimef()), 0, 0));
material.setDiffuseColor(ofFloatColor(0, 0, (float)mouseX / ofGetWidth()));
material.setSpecularColor(ofFloatColor(0, (float)mouseY / ofGetHeight(), 0));

// Draw
ofBackground(ofColor::gray);
ofEnableLighting();

material.begin();
mPointLight.enable();

ofDrawSphere(ofGetWidth()/2, ofGetHeight()/2, -50, 105);

material.end();
mPointLight.disable();

ofDisableLighting();

Never the less, ofSetColor() should work. Maybe @arturo knows best.

I’m having this same problem with of 0.9. I Can’t get any colors when drawing 3d objects with lights and wihtout any material. I’m trying to draw a coloured 3d mesh and I get only greyscale colors.

Anyone could solve this issue?

Hi @lzmmrman, I’ve opened this issue on Github. Can you also leave a comment there? Thanks!