ofMaterial and ofLight

Hi,
I’m trying to make a red box using ofLight, ofMaterial and ofBoxPrimitive. Here’s my
ofApp::setup:

ofSetSmoothLighting(true);

ofEnableDepthTest() 


box.setResolution(300, 300, 300);

box.setPosition(ofVec3f(ofGetWidth()/2,ofGetHeight()/2,0));
box.set(500);

easyCam.setVFlip(false);
easyCam.setPosition(ofGetWidth()/2, ofGetHeight()/2,700);
easyCam.setTarget(box.getPosition());
easyCam.setDistance(1400);

light.setSpotlight();
light.setSpotlightCutOff(50);

light.setDiffuseColor(ofColor::white);

light.setPosition(ofGetWidth()/2, 0, 100);
light.lookAt(box.getPosition());

material.setDiffuseColor(ofColor::red);
material.setAmbientColor(ofColor::red);
material.setSpecularColor(ofColor::white);

material.setShininess(128);

and here is my ofApp::draw();

ofBackground(0);

easyCam.begin();

light.enable();

material.begin();

box.draw();

material.end();
light.disable();

easyCam.end();

from what I understand, I should have a red box with a strong white spot. But all I get is a white box. If I change the color of the light, the box becomes exactly the same color as the light, always.

What am I doing wrong?

Maybe try calling:

ofEnableLighting();
light.enable();
...

light.disable();
ofDisableLighting();

Don’t forget to call ofEnableDepthTest() in either setup or draw

I’m calling ofEnableDepthTest() already, don’t know why I didn’t include it.
Doing those changes did nothing =/

probably you light is too near to the object and what you are seeing is just the specular? try bringing it further away

Tried multiple values always getting similar results
here’s a sample of what I’m seeing

with

 light.setPosition(ofGetWidth()/2, ofGetHeight(), 1000);

i get

mmh, yes, seems a bug in ofMaterial are you using 0.9 or 0.8.4? with the programmable renderer i’m getting the right behaviour:

i’ve just fixed it in master for the fixed pipeline but there’s a discrepancy now between the fixed and programmable renderers in how the light behaves, i’m looking into it.

I’m using 0.9 RC1
Tried to change the renderer but
ofSetCurrentRenderer(ofGLProgrammableRenderer::TYPE);
don’t seem to work anymore, Is there a new way to do it in 0.9?

yes:

ofGLWindowSettings settings;
settings.setGLVersion(3,2);
ofCreateWindow(settings);
ofRunApp(new ofApp);

as i said it’s also fixed in master now and will be in tonight’s nightlies.

Ok, thanks a lot! This was especially helpful because I intended to use the programmable renderer and completely forgot about it…

I’m try to update some OF 0.8.0 projects to 0.9.0 but I’m having problems with the lights and color. When I compile the projects in 0.9 everything is black and white.

Is it possible to get lights and colored objects without using materials?? Because I made this light test using this simple code: `

void ofApp::draw(){

ofEnableDepthTest();

ofEnableLighting();
light.enable();

cam.begin();

ofDrawAxis(500);

ofSetColor(255,0,0);
ofDrawBox(0, 0, 0, 250);

cam.end();

light.disable();

ofDisableLighting();

}

In 0.8.0 I get:

But in 0.9.0 I get:

I’m also having problems when drawing coloured meshes. When enabling the ofLight the mesh turns greyscale coloured.

As I’m trying to update large projects to 0.9.0 which would be the easiest way of solving this issue?

Thanks

i’m testing this and it’s working for me fine in 0.9.2 with this code:

    void setup(){
        ofEnableLighting();
        ofEnableDepthTest();
        light.setup();
        light.enable();
        light.setPosition(-200,200,200);
    }

    void draw(){
        cam.begin();
        ofSetColor(255,0,0);
        ofDrawBox(0,0,0,100);
        cam.end();
    }

in both linux and osx, can you test my example and see if that works? also are you doing something else in your test or only drawing the cube? have you positioned the light?