]> git.tdb.fi Git - libs/gl.git/blob - source/material.h
Object model for Material and TexEnv
[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/loader.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::Loader
25         {
26         private:
27                 Material &mat;
28
29         public:
30                 Loader(Material &);
31                 Material &get_object() const { return mat; }
32         
33         private:
34                 void ambient(float, float, float, float);
35                 void diffuse(float, float, float, float);
36                 void specular(float, float, float, float);
37                 void emission(float, float, float, float);
38         };
39
40 private:
41         Color ambient;
42         Color diffuse;
43         Color specular;
44         Color emission;
45         float shininess;
46
47 public:
48         Material();
49         void set_ambient(const Color &a);
50         void set_diffuse(const Color &d);
51         void set_specular(const Color &s);
52         void set_emission(const Color &e);
53         void set_shininess(float s);
54         const Color &get_ambient() const { return ambient; }
55         const Color &get_diffuse() const { return diffuse; }
56         const Color &get_specular() const { return specular; }
57         const Color &get_emission() const { return emission; }
58         float get_shininess() const { return shininess; }
59         void bind() const;
60
61         static void unbind();
62 private:
63         static const Material *current;
64 };
65
66 } // namespace GL
67 } // namespace Msp
68
69 #endif