]> git.tdb.fi Git - libs/gl.git/blob - source/material.cpp
Windows compatibility:
[libs/gl.git] / source / material.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 "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::apply() const
48 {
49         glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, &ambient.r);
50         glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, &diffuse.r);
51         glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &specular.r);
52         glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, &emission.r);
53         glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
54 }
55
56
57 Material::Loader::Loader(Material &m):
58         mat(m)
59 {
60         add("ambient",   &Loader::ambient);
61         add("diffuse",   &Loader::diffuse);
62         add("specular",  &Loader::specular);
63         add("emission",  &Loader::emission);
64         add("shininess", &Material::shininess);
65 }
66
67 void Material::Loader::ambient(float r, float g, float b, float a)
68 {
69         mat.ambient=GL::Color(r, g, b, a);
70 }
71
72 void Material::Loader::diffuse(float r, float g, float b, float a)
73 {
74         mat.diffuse=GL::Color(r, g, b, a);
75 }
76
77 void Material::Loader::specular(float r, float g, float b, float a)
78 {
79         mat.specular=GL::Color(r, g, b, a);
80 }
81
82 void Material::Loader::emission(float r, float g, float b, float a)
83 {
84         mat.emission=GL::Color(r, g, b, a);
85 }
86
87 } // namespace GL
88 } // namespace Msp