GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_light.h
Go to the documentation of this file.
1 /****************************************************************************
2 
3  This file is part of the GLC-lib library.
4  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
5  http://glc-lib.sourceforge.net
6 
7  GLC-lib is free software; you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  GLC-lib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with GLC-lib; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21 *****************************************************************************/
22 
24 
25 #ifndef GLC_LIGHT_H_
26 #define GLC_LIGHT_H_
27 
28 #include <QColor>
29 #include <QSet>
30 #include <QHash>
31 
32 #include "../glc_object.h"
33 #include "../maths/glc_vector3d.h"
34 
35 #include "../glc_config.h"
36 
37 class QGLContext;
38 
41 
45 
46 
48 {
49 public:
51  enum LightType
52  {
53  LightPosition= 0,
54  LightDirection= 1,
55  LightSpot= 2
56  };
58 
60 
61 public:
63 
64  GLC_Light(const QGLContext* pContext= NULL, const QColor& color= Qt::white);
65 
67 
68  GLC_Light(LightType lightType, const QGLContext* pContext= NULL, const QColor& color= Qt::white);
69 
71  GLC_Light(const GLC_Light& light);
72 
74  virtual ~GLC_Light(void);
76 
78 
80 
81 public:
83  static int maxLightCount();
84 
86  static int builtAbleLightCount(QGLContext* pContext);
87 
89  inline GLC_Point3d position(void) const
90  {return m_Position;}
91 
93  inline QColor ambientColor() const
94  {return m_AmbientColor;}
95 
97  inline QColor diffuseColor() const
98  { return m_DiffuseColor;}
99 
101  inline QColor specularColor() const
102  {return m_SpecularColor;}
103 
105  inline bool isTwoSided() const
106  {return m_TwoSided;}
107 
109  inline LightType type() const
110  {return m_LightType;}
111 
113  inline GLenum openglID() const
114  {return m_LightID;}
115 
117  inline GLfloat constantAttenuation() const
118  {return m_ConstantAttenuation;}
119 
121  inline GLfloat linearAttenuation() const
122  {return m_LinearAttenuation;}
123 
125  inline GLfloat quadraticAttenuation() const
126  {return m_QuadraticAttenuation;}
127 
129  inline GLC_Vector3d spotDirection() const
130  {return m_SpotDirection;}
131 
133  inline GLfloat spotCutoffAngle() const
134  {return m_SpotCutoffAngle;}
135 
137  inline GLfloat spotEponent() const
138  {return m_SpotExponent;}
140 
142 
144 
145 public:
147  void initForThisContext();
148 
150  void setPosition(const GLC_Point3d &pos);
151 
153  void setPosition(GLfloat x, GLfloat y, GLfloat z);
154 
156  void setAmbientColor(const QColor &color);
157 
159  void setDiffuseColor(const QColor &color);
160 
162  void setSpecularColor(const QColor &color);
163 
165  void setTwoSided(const bool mode);
166 
168  void setConstantAttenuation(GLfloat constantAttenuation);
169 
171  void setLinearAttenuation(GLfloat linearAttenuation);
172 
174  void setQuadraticAttenuation(GLfloat quadraticAttenuation);
175 
177  void setSpotDirection(const GLC_Vector3d& direction);
178 
180  void setSpotCutoffAngle(GLfloat cutoffAngle);
181 
183  void setSpotEponent(GLfloat exponent);
184 
186 
188 
190 
191 public:
192 
193  // Disable the light
194  void disable();
195 
197  virtual void glExecute();
199 
201 
203 
204 
205 private:
206 
207 
209 
211 // Private services fonction
213 private:
215  void addNewLight();
216 
218  void removeThisLight();
219 
221 // Private Members
223 private:
225  GLenum m_LightID;
226 
229 
236 
239 
242 
244  GLfloat m_SpotExponent;
245 
248 
251 
254 
257 
260 
261  // Static member
263  static GLint m_MaxLight;
264 
266  QGLContext* m_pContext;
267 
269  bool m_IsValid;
270 
272  static QHash<const QGLContext*, QSet<GLenum> > m_ContextToFreeLightSet;
273 };
274 #endif //GLC_LIGHT_H_

©2005-2013 Laurent Ribon