]> git.tdb.fi Git - libs/gl.git/blob - source/light.cpp
Add Lights
[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
10 namespace Msp {
11 namespace GL {
12
13 Light::Light():
14         ambient(0),
15         diffuse(1),
16         specular(1),
17         x(0), y(0), z(1), w(0),
18         sdx(0), sdy(0), sdz(-1),
19         spot_exp(0),
20         spot_cutoff(180)
21 { }
22
23 void Light::set_ambient(const Color &c)
24 {
25         ambient=c;
26 }
27
28 void Light::set_diffuse(const Color &c)
29 {
30         diffuse=c;
31 }
32
33 void Light::set_specular(const Color &c)
34 {
35         specular=c;
36 }
37
38 void Light::set_position(float x_, float y_, float z_, float w_)
39 {
40         x=x_;
41         y=y_;
42         z=z_;
43         w=w_;
44 }
45
46 void Light::apply()
47 {
48         apply_to(current);
49 }
50
51 void Light::apply_to(unsigned l)
52 {
53         l+=GL_LIGHT0;
54         glLightfv(l, GL_AMBIENT, &ambient.r);
55         glLightfv(l, GL_DIFFUSE, &diffuse.r);
56         glLightfv(l, GL_SPECULAR, &specular.r);
57         glLightfv(l, GL_POSITION, &x);
58 }
59
60 unsigned Light::current=0;
61
62 } // namespace GL
63 } // namespace Msp