I have a strange problem and I kind of understand why this happens, but I wonder if it is possible to solve this. I’m mostly working in 3d environment with lights turned on and I’ve integrated ofxUI to my application. I use this code in my setup function to load png logo and some text:
img = new ofImage();
gui = new ofxUICanvas(10, 10, length+xInit, ofGetHeight());
gui->addWidgetDown(new ofxUIImage(img->width*.6, img->height*.6, img, "3D Environments"));
If I enable light in setup function, my logo and text get darker. If i do not enable it, it’s all right. You can see it in the picture.
The thing is that if I enable light anywhere in the draw function, the same thing happens. As I understand, ofxUI starts drawing it’s contents from setup function itself and I can’t seem to be able to find a way to catch it’s contents. I guess I would like to do something like this in the draw function:
Ok, I’ve found the problem myself. I think it is a good solution. If anyone’s stuck on this, you should go to addons/ofxUI/src and find ofxUIWidget.h file. I suggest correcting draw function like that:
You probably want to call the gui draw function yourself so that you can enable/disable everything.
So in setup() call gui1->disableAppEventCallbacks();
in update() gui1->update();
and in draw() glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); gui1->draw();
I don’t think disabling functionality should be placed inside ofxUI since it will start turning on and off gl features that will be difficult to track down.
Thank you guys for further discussion. Will definitely try Nick’s proposal as it seems a bit more intuitive, thanks for sharing this. I agree that it’s a bit confusing to imagine how to handle 2D UI that isn’t drawn in draw function, especially if one is used to the basic way OF works, but other than that I’m fine with it, as long as it works. I guess it is not a big price to pay in order to get ofxUI beauty… As I understand glDisable/glEnable cancels each other out if used in the right way, so it doesn’t mess up rendering process. This is at least my experience with that (which is pretty short) So I don’t mind having it placed inside UI itself, but possibility to control when and how UI is drawn in the application could probably be useful for other purposes. Lets say if one wants some objects in the pipeline to be rendered on top of UI, others behind, etc… But people who need that probably will know how to tweak the code to get this result ;))