Allolib  1.0
C++ Components For Interactive Multimedia
al_Light.hpp
1 #ifndef INCLUDE_AL_LIGHT_HPP
2 #define INCLUDE_AL_LIGHT_HPP
3 
4 #include "al/types/al_Color.hpp"
5 
6 namespace al {
7 
12 struct Light {
13  Light& pos(float x, float y, float z) {
14  mPos[0] = x;
15  mPos[1] = y;
16  mPos[2] = z;
17  mPos[3] = 1;
18  return *this;
19  }
20  Light& dir(float x, float y, float z) {
21  mPos[0] = x;
22  mPos[1] = y;
23  mPos[2] = z;
24  mPos[3] = 0;
25  return *this;
26  }
27  Light& ambient(const Color& v) {
28  mAmbient = v;
29  return *this;
30  }
31  Light& diffuse(const Color& v) {
32  mDiffuse = v;
33  return *this;
34  }
35  Light& specular(const Color& v) {
36  mSpecular = v;
37  return *this;
38  }
39  // Light& attenuation(float c0, float c1=0, float c2=0);
40 
41  const float* pos() const { return mPos; }
42  // const float * dir() const { return mPos; }
43  const Color& ambient() const { return mAmbient; }
44  const Color& diffuse() const { return mDiffuse; }
45  const Color& specular() const { return mSpecular; }
46  // const float * attenuation() const { return mAtten; }
47 
48  static void globalAmbient(const Color& v) { mGlobalAmbient = v; }
49  static const Color& globalAmbient() { return mGlobalAmbient; };
50 
51  private:
52  // initial values are values from fixed pipeline defaults
53  // https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glLight.xml
54  Color mAmbient{0.0f};
55  Color mDiffuse{1.0f};
56  Color mSpecular{1.0f};
57  float mPos[4]{0.0f, 0.0f, 1.0f, 0.0f};
58  // float mAtten[4];
59 
60  static Color mGlobalAmbient; // {0.2, 0.2, 0.2, 1.0}
61 };
62 
67 struct Material {
68  Material& ambient(const Color& v) {
69  mAmbient = v;
70  return *this;
71  }
72  Material& diffuse(const Color& v) {
73  mDiffuse = v;
74  return *this;
75  }
76  // Material& emission(const Color& v) { mEmission = v; return *this; }
77  Material& specular(const Color& v) {
78  mSpecular = v;
79  return *this;
80  }
81  Material& shininess(float v) {
82  mShine = v;
83  return *this;
84  }; // [0, 128]
85 
86  const Color& ambient() const { return mAmbient; }
87  const Color& diffuse() const { return mDiffuse; }
88  // const Color& emission() const { return mEmission; }
89  const Color& specular() const { return mSpecular; }
90  float shininess() const { return mShine; }
91 
92  private:
93  // initial values are values from fixed pipeline defaults
94  // https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glMaterial.xml
95  Color mAmbient{0.2f};
96  Color mDiffuse{0.8f};
97  // Color mEmission {0};
98  Color mSpecular{0.0f};
99  float mShine = 5.0f;
100 };
101 
102 } // namespace al
103 
104 #endif
Definition: al_App.hpp:23
Light class.
Definition: al_Light.hpp:12
Material class.
Definition: al_Light.hpp:67