ofxUI light


#1

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:

Setup:

  
    img = new ofImage();  
    img->loadImage("logo.png");  
    gui = new ofxUICanvas(10, 10, length+xInit, ofGetHeight());  
    gui->addWidgetDown(new ofxUIImage(img->width*.6, img->height*.6, img, "3D Environments"));  
    gui->setDrawBack(true);  

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:

  
glDisable(GL_LIGHTING);  
ofxUI.draw();  
glEnable(GL_LIGHTING);  

If I do this in setup function it doesn’t work, last parameter is simply taken to be the real one and that’s it.


#2

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:

  
    virtual void draw()  
    {  
        ofPushStyle();  
        glDisable(GL_LIGHTING);  
        ofEnableBlendMode(OF_BLENDMODE_ALPHA);  
  
        drawPadded();  
        drawPaddedOutline();  
  
        drawBack();  
  
        drawOutline();  
        drawOutlineHighlight();  
  
        drawFill();  
        drawFillHighlight();  
        glEnable(GL_LIGHTING);  
        ofPopStyle();  
    }  

This will make sure your user interfaces are not affected by gl lights.


#3

Thanks for letting me know, I fixed this in ofxUICanvas before all the widgets are drawn, I call

glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);

will push the changes to github soon.


#4

Heh, then this is beter solution. I didn’t really knew where the roots of this library are. Amazing GUI by the way, compiled on windows codeblocks, runs smoothly. Take care!


#5

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.


#6

Tough call…I prefer the convenience of not having to call the update and draw methods, because I can always make sure to enable depth testing and lighting myself…

I understand it might be a hard problem to track down unless you know what a 2D UI/HUD usually does to render itself.

Any other opinions on this?


#7

well, last time I was rummaging around to find out how ofxUI draws itself, with no entries in the update or draw routines. Gave up after a while, so I can definitely see how this can be confusing. :wink:


#8

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…:wink: 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) :wink: 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 ;))