10 unsigned Light::current_unit = 0;
11 vector<const Light *> Light::current_lights(1);
27 void Light::set_ambient(const Color &c)
32 void Light::set_diffuse(const Color &c)
37 void Light::set_specular(const Color &c)
42 void Light::set_position(const Vector4 &p)
47 void Light::set_spot_direction(const Vector3 &d)
52 void Light::set_spot_exponent(float e)
57 void Light::set_spot_cutoff(float c)
62 void Light::set_attenuation(float c, float l, float q)
69 void Light::bind() const
71 if(current_lights[current_unit]!=this)
73 GLenum l = GL_LIGHT0+current_unit;
75 glLightfv(l, GL_AMBIENT, &ambient.r);
76 glLightfv(l, GL_DIFFUSE, &diffuse.r);
77 glLightfv(l, GL_SPECULAR, &specular.r);
78 glLightfv(l, GL_POSITION, &position.x);
79 glLightfv(l, GL_SPOT_DIRECTION, &spot_dir.x);
80 glLightf(l, GL_SPOT_EXPONENT, spot_exp);
81 glLightf(l, GL_SPOT_CUTOFF, spot_cutoff);
82 glLightf(l, GL_CONSTANT_ATTENUATION, attenuation[0]);
83 glLightf(l, GL_LINEAR_ATTENUATION, attenuation[1]);
84 glLightf(l, GL_QUADRATIC_ATTENUATION, attenuation[2]);
85 current_lights[current_unit] = this;
89 void Light::bind_to(unsigned i) const
95 void Light::activate(unsigned i)
97 static unsigned max_lights = get_i(GL_MAX_LIGHTS);
100 throw out_of_range("Light::activate");
102 if(i>=current_lights.size())
103 current_lights.resize(i+1);
110 if(current_lights[current_unit])
112 disable(GL_LIGHT0+current_unit);
113 current_lights[current_unit] = 0;
117 void Light::unbind_from(unsigned i)