//-------------------------------------------------------------- static void release(ofLight & light){ int id = light.getLightID(); if(id==-1) return; bool lastRef=false; if(getIds().find(id)!=getIds().end()){ getIds()[id]--; if(getIds()[id]==0){ lastRef=true; getIds().erase(id); } }else{ ofLog(OF_LOG_WARNING,"ofLight: releasing id not found, this shouldn't be happening releasing anyway"); lastRef=true; } if(lastRef){ light.setAmbientColor(ofColor(0,0,0,255)); if(id>0){ light.setDiffuseColor(ofColor(0,0,0,255)); light.setSpecularColor(ofColor(0,0,0,255)); }else{ light.setDiffuseColor(ofColor(255,255,255,255)); light.setSpecularColor(ofColor(255,255,255,255)); } GLfloat cc[] = {0,0,1, 0}; glLightfv(GL_LIGHT0 + id, GL_POSITION, cc); light.disable(); getActiveLights()[id] = false; } }
//---------------------------------------- void ofLight::setup() { if(glIndex==-1){ bool bLightFound = false; // search for the first free block for(int i=0; i<OF_MAX_LIGHTS; i++) { if(getActiveLights()[i] == false) { glIndex = i; retain(glIndex); bLightFound = true; break; } } if( !bLightFound ){ ofLog(OF_LOG_ERROR, "ofLight : Trying to create too many lights: " + ofToString(glIndex)); } if(bLightFound) { // run this the first time, since it was not found before // onPositionChanged(); setAmbientColor( getAmbientColor() ); setDiffuseColor( getDiffuseColor() ); setSpecularColor( getSpecularColor() ); setAttenuation( getAttenuationConstant(), getAttenuationLinear(), getAttenuationQuadratic() ); if(getIsSpotlight()) { setSpotlightCutOff(getSpotlightCutOff()); setSpotConcentration(getSpotConcentration()); } if(getIsSpotlight() || getIsDirectional()) { onOrientationChanged(); } } } }
//-------------------------------------------------------------- static void retain(int id){ if(id==-1) return; getActiveLights()[id] = true; if(getIds().find(id)!=getIds().end()){ getIds()[id]++; }else{ getIds()[id]=1; } }
//---------------------------------------- void ofLight::enable() { if(glIndex==-1){ // search for the first free block for(int i=0; i<OF_MAX_LIGHTS; i++) { if(getActiveLights()[i] == false) { glIndex = i; retain(glIndex); enable(); return; } } } if(glIndex!=-1) { ofEnableLighting(); glEnable(GL_LIGHT0 + glIndex); }else{ ofLog(OF_LOG_ERROR, "Trying to create too many lights: " + ofToString(glIndex)); } }
//---------------------------------------- void ofLight::enable() { if(glIndex==-1){ bool bLightFound = false; // search for the first free block for(int i=0; i<OF_MAX_LIGHTS; i++) { if(getActiveLights()[i] == false) { glIndex = i; retain(glIndex); bLightFound = true; break; } } if( !bLightFound ){ ofLog(OF_LOG_ERROR, "ofLight : Trying to create too many lights: " + ofToString(glIndex)); } } ofEnableLighting(); glEnable(GL_LIGHT0 + glIndex); }
//-------------------------------------------------------------- static void setInactiveLight( int id ) { if (id < 0 || id >= OF_MAX_LIGHTS) return; getActiveLights()[id] = false; }