NGL  6.5
The NCCA Graphics Library
Material.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 Jon Macey
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 #ifndef MATERIAL_H_
18 #define MATERIAL_H_
19 // must include types.h first for Real and GLEW if required
20 #include "Colour.h"
21 #include "Types.h"
22 #include <string>
23 
35 
36 
37 namespace ngl
38 {
39 //----------------------------------------------------------------------------------------------------------------------
49 //----------------------------------------------------------------------------------------------------------------------
50 
51 //----------------------------------------------------------------------------------------------------------------------
54 //----------------------------------------------------------------------------------------------------------------------
55 
56 enum class STDMAT : int { BLACKPLASTIC,BRASS,BRONZE,CHROME,COPPER,GOLD,PEWTER,SILVER,POLISHEDSILVER};
57 
58 //----------------------------------------------------------------------------------------------------------------------
60 //----------------------------------------------------------------------------------------------------------------------
61 const static Real s_materials [9][10]=
62  {
63  { 0.0f,0.0f,0.0f,0.01f,0.01f,0.01f,0.50f,0.50f,0.50f,32.0f}, //Black plastic
64  { 0.329412f,0.223529f,0.027451f,0.780392f,0.568627f,0.113725f,0.992157f,
65  0.941176f,0.807843f,27.8974f}, //Brass
66  { 0.2125f,0.1275f,0.054f,0.714f,0.4284f,0.18144f,0.393548f,0.271906f,
67  0.166721f,25.6f}, // Bronze
68  { 0.25f,0.25f,0.25f,0.4f,0.4f,0.4f,0.774597f,0.774597f,0.774597f,76.8f}, //Chrome
69  { 0.19125f,0.0735f,0.0225f,0.7038f,0.27048f,0.0828f,0.256777f,0.137622f,
70  0.086014f,12.8f}, // Copper
71  { 0.274725f,0.1995f,0.0745f,0.75164f,0.60648f,0.22648f,0.628281f,
72  0.555802f,0.3666065f,51.2f}, // Gold
73  { 0.10588f,0.058824f,0.113725f,0.427451f,0.470588f,0.541176f,
74  0.3333f,0.3333f,0.521569f,9.84615f}, // Pewter
75  { 0.19225f,0.19225f,0.19225f,0.50754f,0.50754f,0.50754f,0.508273f,
76  0.508273f,0.508273f,51.2f}, // Silver
77  { 0.23125f,0.23125f,0.23125f,0.2775f,0.2775f,0.2775f,0.77391f,
78  0.77391f,0.77391f,89.6f} // PolishedSilver
79  };
80 //----------------------------------------------------------------------------------------------------------------------
81 
82 
83 class NGL_DLLEXPORT Material
84 {
85 public :
86 
87  //----------------------------------------------------------------------------------------------------------------------
89  //----------------------------------------------------------------------------------------------------------------------
90  void setDefault() noexcept;
91  //----------------------------------------------------------------------------------------------------------------------
94  //----------------------------------------------------------------------------------------------------------------------
95  void set( const Material &_m ) noexcept;
96 
97  //----------------------------------------------------------------------------------------------------------------------
100  //----------------------------------------------------------------------------------------------------------------------
101  void change( const STDMAT _mat ) noexcept;
102  //----------------------------------------------------------------------------------------------------------------------
108  //----------------------------------------------------------------------------------------------------------------------
109  Material( Colour _amb=0.0f, Colour _dif=0.5f, Colour _spec=1.0f ) noexcept:
110  m_ambient(_amb),
111  m_diffuse(_dif),
112  m_specular(_spec)
113  {;}
114 
115  //----------------------------------------------------------------------------------------------------------------------
118  //----------------------------------------------------------------------------------------------------------------------
119  Material(STDMAT _mat) noexcept;
120 
121  //----------------------------------------------------------------------------------------------------------------------
124  //----------------------------------------------------------------------------------------------------------------------
125  Material( int _mat ) noexcept;
126 
127  //----------------------------------------------------------------------------------------------------------------------
130  //----------------------------------------------------------------------------------------------------------------------
131  Material( const std::string &_fName ) noexcept;
132  //----------------------------------------------------------------------------------------------------------------------
135  //----------------------------------------------------------------------------------------------------------------------
136  void load( const std::string &_fName ) noexcept;
137  //----------------------------------------------------------------------------------------------------------------------
140  //----------------------------------------------------------------------------------------------------------------------
141  void setAmbient(const Colour &_c) noexcept{ m_ambient = _c;}
142  Colour getAmbient() const noexcept {return m_ambient;}
143  //----------------------------------------------------------------------------------------------------------------------
146  //----------------------------------------------------------------------------------------------------------------------
147  void setDiffuse(const Colour &_c) noexcept{ m_diffuse = _c;}
148  Colour getDiffuse() const noexcept {return m_diffuse;}
149  //----------------------------------------------------------------------------------------------------------------------
152  //----------------------------------------------------------------------------------------------------------------------
153  void setSpecular(const Colour &_c) noexcept{ m_specular = _c;}
154  Colour getSpecular() const noexcept{return m_specular;}
155  //----------------------------------------------------------------------------------------------------------------------
158  //----------------------------------------------------------------------------------------------------------------------
159  void setSpecularExponent(Real _s) noexcept{ m_specularExponent=_s;}
160  Real getSpecularExponent()const noexcept{ return m_specularExponent;}
161 
162  Real getTransparency()const noexcept{ return m_transparency;}
163 
164  //----------------------------------------------------------------------------------------------------------------------
167  //----------------------------------------------------------------------------------------------------------------------
168  void setRoughness(Real _r) noexcept{m_surfaceRoughness=_r;}
169  Real getRoughness()const noexcept{return m_surfaceRoughness;}
170 
171  //----------------------------------------------------------------------------------------------------------------------
181  //----------------------------------------------------------------------------------------------------------------------
182  void loadToShader( std::string _uniformName )const noexcept;
183 
184 protected :
185  //----------------------------------------------------------------------------------------------------------------------
187  //----------------------------------------------------------------------------------------------------------------------
188  Colour m_ambient;
189  //----------------------------------------------------------------------------------------------------------------------
191  //----------------------------------------------------------------------------------------------------------------------
192  Colour m_diffuse;
193  //----------------------------------------------------------------------------------------------------------------------
195  //----------------------------------------------------------------------------------------------------------------------
196  Colour m_specular;
197  //----------------------------------------------------------------------------------------------------------------------
199  //----------------------------------------------------------------------------------------------------------------------
200  Real m_specularExponent;
201  //----------------------------------------------------------------------------------------------------------------------
203  //----------------------------------------------------------------------------------------------------------------------
204  Real m_transparency;
205  //----------------------------------------------------------------------------------------------------------------------
207  //----------------------------------------------------------------------------------------------------------------------
208  Real m_surfaceRoughness;
209 
210 }; // end of Material
211 
212 
213 }
214 
215 #endif // MATERIAL
216 //----------------------------------------------------------------------------------------------------------------------
217 
a simple colour class for RGBA colour
main definition of types and namespace
#define NGL_DLLEXPORT
Definition: Types.h:65
implementation files for RibExport class
Definition: AABB.cpp:22
PRECISION Real
create a variable called Real which is the main data type we use (GLfloat for most cases) ...
Definition: Types.h:127
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
GLsizei const GLchar *const * string
Definition: glew.h:1847
GLclampf f
Definition: glew.h:3511