3 This file is part of libmspgl
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
31 void Light::set_ambient(const Color &c)
36 void Light::set_diffuse(const Color &c)
41 void Light::set_specular(const Color &c)
46 void Light::set_position(const Vector4 &p)
51 void Light::set_spot_direction(const Vector3 &d)
56 void Light::set_spot_exponent(float e)
61 void Light::set_spot_cutoff(float c)
66 void Light::set_attenuation(float c, float l, float q)
73 void Light::bind() const
75 if(current_lights[current_unit]!=this)
77 GLenum l = GL_LIGHT0+current_unit;
79 glLightfv(l, GL_AMBIENT, &ambient.r);
80 glLightfv(l, GL_DIFFUSE, &diffuse.r);
81 glLightfv(l, GL_SPECULAR, &specular.r);
82 glLightfv(l, GL_POSITION, &position.x);
83 glLightfv(l, GL_SPOT_DIRECTION, &spot_dir.x);
84 glLightf(l, GL_SPOT_EXPONENT, spot_exp);
85 glLightf(l, GL_SPOT_CUTOFF, spot_cutoff);
86 glLightf(l, GL_CONSTANT_ATTENUATION, attenuation[0]);
87 glLightf(l, GL_LINEAR_ATTENUATION, attenuation[1]);
88 glLightf(l, GL_QUADRATIC_ATTENUATION, attenuation[2]);
89 current_lights[current_unit] = this;
93 void Light::bind_to(unsigned i) const
99 void Light::activate(unsigned i)
101 static unsigned max_lights = get_i(GL_MAX_LIGHTS);
104 throw InvalidParameterValue("Light unit index out of range");
106 if(i>=current_lights.size())
107 current_lights.resize(i+1);
114 if(current_lights[current_unit])
116 disable(GL_LIGHT0+current_unit);
117 current_lights[current_unit] = 0;
121 unsigned Light::current_unit = 0;
122 vector<const Light *> Light::current_lights(1);