24 void Light::update_parameter(int mask, int index) const
28 LightUnit *unit = LightUnit::find_unit(this);
32 index = unit->get_index();
35 GLenum l = GL_LIGHT0+index;
37 glLightfv(l, GL_DIFFUSE, &diffuse.r);
39 glLightfv(l, GL_SPECULAR, &specular.r);
41 glLightfv(l, GL_POSITION, &position.x);
43 glLightfv(l, GL_SPOT_DIRECTION, &spot_dir.x);
45 glLightf(l, GL_SPOT_EXPONENT, spot_exp);
47 glLightf(l, GL_SPOT_CUTOFF, spot_cutoff);
50 glLightf(l, GL_CONSTANT_ATTENUATION, attenuation[0]);
51 glLightf(l, GL_LINEAR_ATTENUATION, attenuation[1]);
52 glLightf(l, GL_QUADRATIC_ATTENUATION, attenuation[2]);
56 void Light::set_diffuse(const Color &c)
59 update_parameter(DIFFUSE);
62 void Light::set_specular(const Color &c)
65 update_parameter(SPECULAR);
68 void Light::set_position(const Vector4 &p)
71 update_parameter(POSITION);
74 void Light::set_spot_direction(const Vector3 &d)
77 update_parameter(SPOT_DIR);
80 void Light::set_spot_exponent(float e)
83 update_parameter(SPOT_EXP);
86 void Light::set_spot_cutoff(float c)
89 update_parameter(SPOT_CUTOFF);
92 void Light::set_attenuation(float c, float l, float q)
97 update_parameter(ATTENUATION);
100 void Light::bind_to(unsigned i) const
102 LightUnit &unit = LightUnit::get_unit(i);
103 if(unit.set_light(this))
105 enable(GL_LIGHT0+unit.get_index());
106 update_parameter(-1, unit.get_index());
110 const Light *Light::current(unsigned i)
112 return LightUnit::get_unit(i).get_light();
115 void Light::unbind_from(unsigned i)
117 LightUnit &unit = LightUnit::get_unit(i);
118 if(unit.set_light(0))
119 disable(GL_LIGHT0+unit.get_index());