]> git.tdb.fi Git - libs/gl.git/blob - source/material.cpp
Style update: add spaces around assignment operators
[libs/gl.git] / source / material.cpp
1 /* $Id$
2
3 This file is part of libmspgl
4 Copyright © 2007-2008  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include "gl.h"
9 #include "material.h"
10
11 namespace Msp {
12 namespace GL {
13
14 Material::Material():
15         ambient(0.2),
16         diffuse(0.8),
17         specular(0),
18         emission(0),
19         shininess(0)
20 { }
21
22 void Material::set_ambient(const Color &a)
23 {
24         ambient = a;
25 }
26
27 void Material::set_diffuse(const Color &d)
28 {
29         diffuse = d;
30 }
31
32 void Material::set_specular(const Color &s)
33 {
34         specular = s;
35 }
36
37 void Material::set_emission(const Color &e)
38 {
39         emission = e;
40 }
41
42 void Material::set_shininess(float s)
43 {
44         shininess = s;
45 }
46
47 void Material::bind() const
48 {
49         if(current!=this)
50         {
51                 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, &ambient.r);
52                 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, &diffuse.r);
53                 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &specular.r);
54                 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, &emission.r);
55                 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
56                 current = this;
57         }
58 }
59
60 void Material::unbind()
61 {
62         current = 0;
63 }
64
65 const Material *Material::current = 0;
66
67
68 Material::Loader::Loader(Material &m):
69         DataFile::ObjectLoader<Material>(m)
70 {
71         add("ambient",   &Loader::ambient);
72         add("diffuse",   &Loader::diffuse);
73         add("specular",  &Loader::specular);
74         add("emission",  &Loader::emission);
75         add("shininess", &Material::shininess);
76 }
77
78 void Material::Loader::ambient(float r, float g, float b, float a)
79 {
80         obj.ambient = GL::Color(r, g, b, a);
81 }
82
83 void Material::Loader::diffuse(float r, float g, float b, float a)
84 {
85         obj.diffuse = GL::Color(r, g, b, a);
86 }
87
88 void Material::Loader::specular(float r, float g, float b, float a)
89 {
90         obj.specular = GL::Color(r, g, b, a);
91 }
92
93 void Material::Loader::emission(float r, float g, float b, float a)
94 {
95         obj.emission = GL::Color(r, g, b, a);
96 }
97
98 } // namespace GL
99 } // namespace Msp