Newer
Older
cg / sources / light.cpp
@glproj03 glproj03 on 29 Jan 2006 946 bytes Added delta angle.
#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;

  GLfloat LightDiffuse[]= { col->r, col->g, col->b, 1.0f };
  glLightfv(num, GL_DIFFUSE, LightDiffuse);		
  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;
  GLfloat LightAmbient[]= { 0.1f, 0.1f, 0.1f, 1.0f };
  glLightfv(num, GL_AMBIENT, LightAmbient);
  enable();
}