OpenSceneGraph 3.6.5
Light
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSG_LIGHT
15#define OSG_LIGHT 1
16
17#include <osg/StateAttribute>
18#include <osg/Vec3>
19#include <osg/Vec4>
20
21#ifndef GL_LIGHT0
22 #define GL_LIGHT0 0x4000
23 #define GL_LIGHT1 0x4001
24 #define GL_LIGHT2 0x4002
25 #define GL_LIGHT3 0x4003
26 #define GL_LIGHT4 0x4004
27 #define GL_LIGHT5 0x4005
28 #define GL_LIGHT6 0x4006
29 #define GL_LIGHT7 0x4007
30#endif
31
32#ifndef GL_LIGHTING
33 #define GL_LIGHTING 0x0B50
34#endif
35
36namespace osg {
37
40{
41 public :
42
44
45 Light(unsigned int lightnum);
46
61
62 virtual osg::Object* cloneType() const { return new Light(_lightnum); }
63 virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new Light(*this,copyop); }
64 virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const Light *>(obj)!=NULL; }
65 virtual const char* libraryName() const { return "osg"; }
66 virtual const char* className() const { return "Light"; }
67 virtual Type getType() const { return LIGHT; }
68
70 virtual int compare(const StateAttribute& sa) const
71 {
72 // check the types are equal and then create the rhs variable
73 // used by the COMPARE_StateAttribute_Parameter macros below.
75
76 // compare each parameter in turn against the rhs.
88
89 return 0; // passed all the above comparison macros, must be equal.
90 }
91
92 virtual unsigned int getMember() const { return _lightnum; }
93
94 virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
95 {
97 return true;
98 }
99
100
101
103 void setLightNum(int num);
104
106 int getLightNum() const { return _lightnum; }
107
109 inline void setAmbient( const Vec4& ambient ) { _ambient = ambient; }
110
112 inline const Vec4& getAmbient() const { return _ambient; }
113
115 inline void setDiffuse( const Vec4& diffuse ) { _diffuse = diffuse; }
116
118 inline const Vec4& getDiffuse() const { return _diffuse; }
119
121 inline void setSpecular( const Vec4& specular ) { _specular = specular; }
122
124 inline const Vec4& getSpecular() const { return _specular; }
125
127 inline void setPosition( const Vec4& position ) { _position = position; }
128
130 inline const Vec4& getPosition() const { return _position; }
131
133 inline void setDirection( const Vec3& direction ) { _direction = direction; }
134
136 inline const Vec3& getDirection() const { return _direction; }
137
139 inline void setConstantAttenuation( float constant_attenuation ) { _constant_attenuation = constant_attenuation; }
140
142 inline float getConstantAttenuation() const { return _constant_attenuation; }
143
145 inline void setLinearAttenuation ( float linear_attenuation ) { _linear_attenuation = linear_attenuation; }
146
148 inline float getLinearAttenuation () const { return _linear_attenuation; }
149
151 inline void setQuadraticAttenuation ( float quadratic_attenuation ) { _quadratic_attenuation = quadratic_attenuation; }
152
154 inline float getQuadraticAttenuation() const { return _quadratic_attenuation; }
155
157 inline void setSpotExponent( float spot_exponent ) { _spot_exponent = spot_exponent; }
158
160 inline float getSpotExponent() const { return _spot_exponent; }
161
163 inline void setSpotCutoff( float spot_cutoff ) { _spot_cutoff = spot_cutoff; }
164
166 inline float getSpotCutoff() const { return _spot_cutoff; }
167
172
174 virtual void apply(State& state) const;
175
176 protected :
177
178 virtual ~Light();
179
181 void init();
182
183 int _lightnum; // OpenGL light number
184
185 Vec4 _ambient; // r, g, b, w
186 Vec4 _diffuse; // r, g, b, w
187 Vec4 _specular; // r, g, b, w
188 Vec4 _position; // x, y, z, w
189 Vec3 _direction; // x, y, z
190 float _constant_attenuation; // constant
191 float _linear_attenuation; // linear
192 float _quadratic_attenuation; // quadratic
193 float _spot_exponent; // exponent
194 float _spot_cutoff; // spread
195};
196
197}
198
199#endif
#define GL_LIGHT0
Definition Light:22
#define COMPARE_StateAttribute_Parameter(parameter)
COMPARE_StateAttribute_Parameter macro is a helper for implementing the StatateAtribute::compare(....
Definition StateAttribute:69
#define COMPARE_StateAttribute_Types(TYPE, rhs_attribute)
COMPARE_StateAttribute_Types macro is a helper for implementing the StateAtribute::compare(....
Definition StateAttribute:57
The core osg library provides the basic scene graph classes such as Nodes, State and Drawables,...
Definition AlphaFunc:19
Vec3f Vec3
Definition Vec3:21
Vec4f Vec4
Definition Vec4:21
Copy Op(erator) used to control whether shallow or deep copy is used during copy construction and clo...
Definition CopyOp:41
@ SHALLOW_COPY
Definition CopyOp:47
virtual ~Light()
void setAmbient(const Vec4 &ambient)
Set the ambient component of the light.
Definition Light:109
const Vec4 & getAmbient() const
Get the ambient component of the light.
Definition Light:112
Vec4 _position
Definition Light:188
float getSpotExponent() const
Get the spot exponent of the light.
Definition Light:160
float _spot_cutoff
Definition Light:194
void setLinearAttenuation(float linear_attenuation)
Set the linear attenuation of the light.
Definition Light:145
void setSpotCutoff(float spot_cutoff)
Set the spot cutoff of the light.
Definition Light:163
float _linear_attenuation
Definition Light:191
virtual int compare(const StateAttribute &sa) const
Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.
Definition Light:70
virtual osg::Object * cloneType() const
Clone the type of an attribute, with Object* return type.
Definition Light:62
Vec3 _direction
Definition Light:189
const Vec4 & getDiffuse() const
Get the diffuse component of the light.
Definition Light:118
float _quadratic_attenuation
Definition Light:192
const Vec3 & getDirection() const
Get the direction of the light.
Definition Light:136
virtual const char * className() const
Return the name of the attribute's class type.
Definition Light:66
float getSpotCutoff() const
Get the spot cutoff of the light.
Definition Light:166
void setSpotExponent(float spot_exponent)
Set the spot exponent of the light.
Definition Light:157
float getQuadraticAttenuation() const
Get the quadratic attenuation of the light.
Definition Light:154
void init()
Initialize the light's settings with some decent defaults.
float _constant_attenuation
Definition Light:190
void setDirection(const Vec3 &direction)
Set the direction of the light.
Definition Light:133
int _lightnum
Definition Light:183
float getConstantAttenuation() const
Get the constant attenuation of the light.
Definition Light:142
virtual Type getType() const
Return the Type identifier of the attribute's class type.
Definition Light:67
Light(unsigned int lightnum)
void setQuadraticAttenuation(float quadratic_attenuation)
Set the quadratic attenuation of the light.
Definition Light:151
Vec4 _ambient
Definition Light:185
virtual void apply(State &state) const
Apply the light's state to the OpenGL state machine.
virtual bool getModeUsage(StateAttribute::ModeUsage &usage) const
Return the modes associated with this StateAttribute.
Definition Light:94
int getLightNum() const
Get which OpenGL light this osg::Light operates on.
Definition Light:106
virtual unsigned int getMember() const
Return the member identifier within the attribute's class type.
Definition Light:92
virtual const char * libraryName() const
Return the name of the attribute's library.
Definition Light:65
virtual osg::Object * clone(const osg::CopyOp &copyop) const
Clone an attribute, with Object* return type.
Definition Light:63
virtual bool isSameKindAs(const osg::Object *obj) const
Return true if this and obj are of the same kind of object.
Definition Light:64
void setLightNum(int num)
Set which OpenGL light to operate on.
void captureLightState()
Capture the lighting settings of the current OpenGL state and store them in this object.
float _spot_exponent
Definition Light:193
void setSpecular(const Vec4 &specular)
Set the specular component of the light.
Definition Light:121
const Vec4 & getPosition() const
Get the position of the light.
Definition Light:130
const Vec4 & getSpecular() const
Get the specular component of the light.
Definition Light:124
float getLinearAttenuation() const
Get the linear attenuation of the light.
Definition Light:148
Light(const Light &light, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
Copy constructor using CopyOp to manage deep vs shallow copy.
Definition Light:48
void setPosition(const Vec4 &position)
Set the position of the light.
Definition Light:127
Vec4 _specular
Definition Light:187
void setDiffuse(const Vec4 &diffuse)
Set the diffuse component of the light.
Definition Light:115
Vec4 _diffuse
Definition Light:186
void setConstantAttenuation(float constant_attenuation)
Set the constant attenuation of the light.
Definition Light:139
Base class/standard interface for objects which require IO support, cloning and reference counting.
Definition Object:61
Encapsulates the current applied OpenGL modes, attributes and vertex arrays settings,...
Definition State:80
Type
Type identifier to differentiate between different state types.
Definition StateAttribute:124
@ LIGHT
Definition StateAttribute:137
Definition StateAttribute:308
virtual void usesMode(GLMode mode)=0
#define NULL
Definition Export:55
#define OSG_EXPORT
Definition Export:39

osg logo
Generated at Sun Jul 20 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.