3 This file is part of libmspgl
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
21 x(0), y(0), z(1), w(0),
22 sdx(0), sdy(0), sdz(-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(float x_, float y_, float z_, float w_)
50 void Light::bind() const
52 if(current_lights[current_unit]!=this)
54 GLenum l=GL_LIGHT0+current_unit;
56 glLightfv(l, GL_AMBIENT, &ambient.r);
57 glLightfv(l, GL_DIFFUSE, &diffuse.r);
58 glLightfv(l, GL_SPECULAR, &specular.r);
59 glLightfv(l, GL_POSITION, &x);
60 current_lights[current_unit]=this;
64 void Light::bind_to(unsigned i) const
70 void Light::activate(unsigned i)
72 static unsigned max_lights=get_i(GL_MAX_LIGHTS);
75 throw InvalidParameterValue("Light unit index out of range");
77 if(i>=current_lights.size())
78 current_lights.resize(i+1);
85 if(current_lights[current_unit])
87 disable(GL_LIGHT0+current_unit);
88 current_lights[current_unit]=0;
92 unsigned Light::current_unit=0;
93 vector<const Light *> Light::current_lights(1);