Newer
Older
cg / sources / light.cpp
@glproj03 glproj03 on 1 Feb 2006 1 KB added material
#include "light.h"

#include <GL/gl.h>
#include <GL/glu.h>

Light::Light() {
  //TODO: this class should be abstract
  printf("light not initialized");
}

void Light::enable() {
  enabled = true;
  glEnable(num);
}

void Light::disable() {
  enabled = false;
  glDisable(num);
}

void Light::flip() {
  if (enabled)
	disable();
  else
	enable();
}


DiffuseLight::DiffuseLight(Vec& _pos, Color& _color, GLenum _lightnum) {  
  pos = _pos.clone();
  col = _color.clone();
  num = _lightnum;

  glLightfv(num, GL_DIFFUSE, col->v());		
  GLfloat LightPosition[]= { pos->x(), pos->y(), pos->z(), 1.0f }; 
  glLightfv(num, GL_POSITION,LightPosition);	
  enable();
}



SpecularLight::SpecularLight(Vec& _pos, Color& _color, GLenum _lightnum) {  
  pos = _pos.clone();
  col = _color.clone();
  num = _lightnum;

  glLightfv(num, GL_SPECULAR, col->v());		
  GLfloat LightPosition[]= { pos->x(), pos->y(), pos->z(), 1.0f }; 
  glLightfv(num, GL_POSITION,LightPosition);	
  enable();
}



AmbientLight::AmbientLight(Color& _color, GLenum _lightnum) {
  col = _color.clone();
  num = _lightnum;
  glLightfv(num, GL_AMBIENT, col->v());
  enable();
}