]> git.tdb.fi Git - libs/gl.git/blob - source/light.cpp
Bugfixes to Light
[libs/gl.git] / source / light.cpp
1 /* $Id$
2
3 This file is part of libmspgl
4 Copyright © 2007  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include "light.h"
9 #include "misc.h"
10
11 namespace Msp {
12 namespace GL {
13
14 Light::Light():
15         ambient(0),
16         diffuse(1),
17         specular(1),
18         x(0), y(0), z(1), w(0),
19         sdx(0), sdy(0), sdz(-1),
20         spot_exp(0),
21         spot_cutoff(180)
22 { }
23
24 void Light::set_ambient(const Color &c)
25 {
26         ambient=c;
27 }
28
29 void Light::set_diffuse(const Color &c)
30 {
31         diffuse=c;
32 }
33
34 void Light::set_specular(const Color &c)
35 {
36         specular=c;
37 }
38
39 void Light::set_position(float x_, float y_, float z_, float w_)
40 {
41         x=x_;
42         y=y_;
43         z=z_;
44         w=w_;
45 }
46
47 void Light::apply() const
48 {
49         apply_to(current);
50 }
51
52 void Light::apply_to(unsigned l) const
53 {
54         l+=GL_LIGHT0;
55         enable(l);
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 }
61
62 unsigned Light::current=0;
63
64 } // namespace GL
65 } // namespace Msp