//Habilita (con glEnable) una fuente de luz OpenGL, configurándola con los parámetros que hay en la instancia.
void FuenteLuz::activar( int i ){
	// activar la i-esima fuente de luz
	glEnable(GL_LIGHT0+i); //glEnable (GL_LIGHTi) activa la i-esima fuente de luz
	
	glEnable(GL_LIGHTING); //activa evaluacion del MIL
	
	// Configuración de colores de una fuente de luz
	glLightfv(GL_LIGHT0 + i, GL_AMBIENT, colores[0]);
	glLightfv(GL_LIGHT0 + i, GL_DIFFUSE, colores[1]);
	glLightfv(GL_LIGHT0 + i, GL_SPECULAR, colores[2]);
	
	// Configuración de posición/dirección de una fuente de luz
	if (posvec(4) == 1){ // fuentes posicionales
		glLightfv(GL_LIGHT0 + i, GL_POSITION, posvec);
	}
	else if (posvec(4) == 0){ // fuentes direccionales
		glLightfv(GL_LIGHT0 + i, GL_POSITION, posvec);
		
		//Posición u orientación de la fuente
		//glRotatef(longitud, 0.0, 1.0, 0.0);
		//glRotatef(lat, -1.0, 0.0, 0.0);
		//glLightf(GL_LIGHTi, GL_POSITION, ejeZ);
	}
	
	
}
Example #2
0
// Doc in parent
void
SoVRMLSpotLight::GLRender(SoGLRenderAction * action)
{
  if (!this->on.getValue()) return;

  SoState * state = action->getState();
  int idx = SoGLLightIdElement::increment(state);

  if (idx < 0) {
#if COIN_DEBUG
    SoDebugError::post("SoSpotLight::GLRender()",
                       "Max # lights exceeded :(\n");
#endif // COIN_DEBUG
    return;
  }

  GLenum light = (GLenum) (idx + GL_LIGHT0);

  SbVec3f att = this->attenuation.getValue();

  glLightf(light, GL_CONSTANT_ATTENUATION, att[0]);
  glLightf(light, GL_LINEAR_ATTENUATION, att[1]);
  glLightf(light, GL_QUADRATIC_ATTENUATION, att[2]);

  SbColor4f lightcolor(0.0f, 0.0f, 0.0f, 1.0f);
  lightcolor.setRGB(this->color.getValue());
  lightcolor *= this->ambientIntensity.getValue();
  glLightfv(light, GL_AMBIENT, lightcolor.getValue());

  lightcolor.setRGB(this->color.getValue());
  lightcolor *= this->intensity.getValue();

  glLightfv(light, GL_DIFFUSE, lightcolor.getValue());
  glLightfv(light, GL_SPECULAR, lightcolor.getValue());

  SbVec3f loc = this->location.getValue();

  // point (or spot) light when w = 1.0
  SbVec4f posvec(loc[0], loc[1], loc[2], 1.0f);
  glLightfv(light, GL_POSITION, posvec.getValue());
  glLightfv(light, GL_SPOT_DIRECTION, this->direction.getValue().getValue());

  float cutoff = SbClamp(this->cutOffAngle.getValue(), 0.0f, float(M_PI)*0.5f) * 180.0f / float(M_PI);
  glLightf(light, GL_SPOT_EXPONENT, 0.0f);
  glLightf(light, GL_SPOT_CUTOFF, cutoff);

  // FIXME: consider radius and beamWidth
}