]> git.tdb.fi Git - libs/gl.git/blob - source/material.h
Inherit Loaders from the ObjectLoader classes
[libs/gl.git] / source / material.h
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 #ifndef MSP_GL_MATERIAL_H_
9 #define MSP_GL_MATERIAL_H_
10
11 #include <msp/datafile/objectloader.h>
12 #include "color.h"
13
14 namespace Msp {
15 namespace GL {
16
17 /**
18 Stores OpenGL material properties.  Since OpenGL does not support material
19 objects, application of material is done with several calls to glMaterial.
20 */
21 class Material
22 {
23 public:
24         class Loader: public DataFile::ObjectLoader<Material>
25         {
26         public:
27                 Loader(Material &);
28         
29         private:
30                 void ambient(float, float, float, float);
31                 void diffuse(float, float, float, float);
32                 void specular(float, float, float, float);
33                 void emission(float, float, float, float);
34         };
35
36 private:
37         Color ambient;
38         Color diffuse;
39         Color specular;
40         Color emission;
41         float shininess;
42
43 public:
44         Material();
45         void set_ambient(const Color &a);
46         void set_diffuse(const Color &d);
47         void set_specular(const Color &s);
48         void set_emission(const Color &e);
49         void set_shininess(float s);
50         const Color &get_ambient() const { return ambient; }
51         const Color &get_diffuse() const { return diffuse; }
52         const Color &get_specular() const { return specular; }
53         const Color &get_emission() const { return emission; }
54         float get_shininess() const { return shininess; }
55         void bind() const;
56
57         static void unbind();
58 private:
59         static const Material *current;
60 };
61
62 } // namespace GL
63 } // namespace Msp
64
65 #endif