24 void Light::set_ambient(const Color &c)
29 void Light::set_diffuse(const Color &c)
34 void Light::set_specular(const Color &c)
39 void Light::set_position(const Vector4 &p)
44 void Light::set_spot_direction(const Vector3 &d)
49 void Light::set_spot_exponent(float e)
54 void Light::set_spot_cutoff(float c)
59 void Light::set_attenuation(float c, float l, float q)
66 void Light::bind() const
68 if(current_lights[current_unit]!=this)
70 GLenum l = GL_LIGHT0+current_unit;
72 glLightfv(l, GL_AMBIENT, &ambient.r);
73 glLightfv(l, GL_DIFFUSE, &diffuse.r);
74 glLightfv(l, GL_SPECULAR, &specular.r);
75 glLightfv(l, GL_POSITION, &position.x);
76 glLightfv(l, GL_SPOT_DIRECTION, &spot_dir.x);
77 glLightf(l, GL_SPOT_EXPONENT, spot_exp);
78 glLightf(l, GL_SPOT_CUTOFF, spot_cutoff);
79 glLightf(l, GL_CONSTANT_ATTENUATION, attenuation[0]);
80 glLightf(l, GL_LINEAR_ATTENUATION, attenuation[1]);
81 glLightf(l, GL_QUADRATIC_ATTENUATION, attenuation[2]);
82 current_lights[current_unit] = this;
86 void Light::bind_to(unsigned i) const
92 void Light::activate(unsigned i)
94 static unsigned max_lights = get_i(GL_MAX_LIGHTS);
97 throw out_of_range("Light::activate");
99 if(i>=current_lights.size())
100 current_lights.resize(i+1);
107 if(current_lights[current_unit])
109 disable(GL_LIGHT0+current_unit);
110 current_lights[current_unit] = 0;
114 void Light::unbind_from(unsigned i)
120 unsigned Light::current_unit = 0;
121 vector<const Light *> Light::current_lights(1);