ofLight with ofGLProgrammableRenderer

Hi there, Im drawing a large ofMesh like this:

void ofApp::setup(){

ofSetVerticalSync(true);
ofSetFrameRate(60);
ofBackground(30, 30, 30);
ofEnableDepthTest();
ofEnableLighting();

int planeWidth = 10000;
int planeHeight = 10000;
int planeColums = 300;
int planeRows = 300;
plane.set(planeWidth, planeHeight, planeColums, planeRows, OF_PRIMITIVE_TRIANGLES);
plane.rotate(90, 1, 0, 0);
verts = plane.getMesh().getVertices();

light.setSpecularColor(ofColor(255.f, 255.f, 255.f));
light.setDiffuseColor( ofColor(255.f, 255.f, 255.f));
light.setSpotlight();
ofSetSmoothLighting(true);
lightColor.setBrightness( 180.f );
lightColor.setSaturation( 150.f );
lightColor.setBrightness(255);
lightColor.setSaturation(255);

material.setShininess( 128 );
materialColor.setHue(colorHue);
materialColor.setBrightness(500.f);
materialColor.setSaturation(400);
materialColor.set(0, 255, 0, .5);
}


void ofApp::draw(){

ofSetColor(0, 0, 255);
ofDrawBitmapString(ofToString(ofGetFrameRate())+"fps", 10, 15);

cam.begin();
//    shader.begin();
light.enable();
light.draw();


material.begin();
plane.drawWireframe();
ofFill();

ofPushMatrix();
ofRotate(90, 1, 0, 0);
ofPopMatrix();

material.end();
light.disable();
//    shader.end();
cam.end();

}

Without calling ofSetCurrentRenderer(ofGLProgrammableRenderer::TYPE) in main, my framerate is about 3fps. If I call ofSetCurrentRenderer(ofGLProgrammableRenderer::TYPE), my framerate is a solid 60fps. However, enabling the programmable renderer means that my ofLight no longer works. I’ve been looking around the forum and have seen some similar questions, but no clear answers.

Can someone point me to some information about how I get my ofLight to draw with the programmable renderer? I get the impression I need to pass information to my shader, but I’m not sure where to start with that exactly.

Thanks!

ofLight won’t work with the programmable renderer in 0.8.4 since lights don’t exist anymore in opengl 3+.

if you use the nigtly builds, ofLight already works there by using shaders to do the lighting, to enable the programmable renderer using the nightly builds instead of using ofSetCurrentRenderer... you have to use:

int main(){
    ofGLWindowSettings settings;
    settings.setGLVersion(3,2);
    ofCreateWindow(settings);
    return ofRunApp(new ofApp);
}

Hi arturo, thanks for the reply that’s very helpful.

Just so I know what’s going on here, with this build ofMaterial seems to no longer decide what color an object is. i.e. if I set my ofLight to white, and my material to blue, the object is white. However, if I change my light colour to blue, the object is blue.

If this is the case, how do I make an object translucent now? Previously I could just define ofSetColor to a value with alpha, but that no longer works…

Thanks!

ps here’s the code:

void ofApp::setup(){

#ifdef TARGET_OPENGLES
shader.load("shadersES2/shader");
#else
if(ofIsGLProgrammableRenderer()){
    shader.load("shadersGL3/shader");
}else{
    shader.load("shadersGL2/shader");
}
#endif
//    ofSetVerticalSync(true);
ofSetFrameRate(60);
ofBackground(150, 150, 150);
ofEnableDepthTest();
ofEnableLighting();
//    ofEnableAlphaBlending();

int planeWidth = 1000;
int planeHeight = 1000;
int planeColums = 70;
int planeRows = 70;
plane.set(planeWidth, planeHeight, planeColums, planeRows, OF_PRIMITIVE_TRIANGLES);
plane.rotate(90, 1, 0, 0);
verts = plane.getMesh().getVertices();

light.setSpecularColor(ofColor(0, 0, 255.f));
light.setDiffuseColor( ofColor(0, 0, 255.f));
light.setSpotlight();
ofSetSmoothLighting(true);


material.setShininess( 128 );
materialColor.setHue(170);
materialColor.setBrightness(500.f);
materialColor.setSaturation(400);
materialColor.set(ofColor(0,0,0,255));
material.setColors(170, 0, 0, 0);

light.setAttenuation(1.f, 0, 0.00005f);
}


void ofApp::draw(){

//    ofSetColor(255, 255, 255);
ofDrawBitmapString(ofToString(ofGetFrameRate())+"fps", 10, 15);

cam.begin();
shader.begin();
plane.drawWireframe();
shader.end();

material.begin();
light.enable();
light.draw();
ofPushMatrix();
ofSetColor(0, 0, 255, 100);
ofRotate(90, 1, 0, 0);
    for (int i = 0; i < verts.size(); i++) {
        ofDrawBox(verts[i].x, verts[i].y, verts[i].z, 5);
    }
ofFill();
ofPopMatrix();
material.end();

light.disable();
cam.end();
}