ofLight also affects ofxGui

Hey folks, I’ve got a query regarding ofLight and it’s interactions on other objects. It seems that calling ofLight::enable() has some sort of global effect which is leading to undesired results.

This is my current setup for testing, I have a cuboid and an icosphere drawn, the former is being lit the latter is outside and appears flat grey. I also have a GUI being drawn outside of the camera and depth test. Why are these elements not being drawn as they would be if ofLight::enable() hadn’t been called, perhaps there’s an easy fix I’m missing.

void ofApp::draw(){
	ofClear(0);
	ofEnableDepthTest();
	light.enable();
	camera.begin();
	ofDrawSphere(lightPosition->x, lightPosition->y, lightPosition->z, 16);
	ofDrawBox(0.0f, 0.0f, 0.0f, 256.0f, 128.0f, 128.0f);
	light.disable();
	ofDrawIcoSphere(300, 0.0f, 0.0f, 64.0f);
	camera.end();
	ofDisableDepthTest();
	gui.draw();
}

Many thanks!

maybe put light. enable and disable like this

void ofApp::draw(){
ofClear(0);
ofEnableDepthTest();
camera.begin();
light.enable();
ofDrawSphere(lightPosition->x, lightPosition->y, lightPosition->z, 16);
ofDrawBox(0.0f, 0.0f, 0.0f, 256.0f, 128.0f, 128.0f);
ofDrawIcoSphere(300, 0.0f, 0.0f, 64.0f);
light.disable();
camera.end();
ofDisableDepthTest();
gui.draw();

I think its turning on alpha blending, try adding ofDisableAlphaBlending() once your lit stuff is done.

there is also the global ofDisableLighting() which might do something too.

1 Like

Thanks Dizzy, ofDisableLighting() after I finished all the lighting did the trick :slight_smile:

1 Like