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 #include <string.h>
14 #include <string>
15 
16 #include <osg/GL>
17 #include <osg/LightModel>
18 #include <osg/Notify>
19 #include <osg/State>
20 
21 using namespace osg;
22 
23 
LightModel()24 LightModel::LightModel():
25           StateAttribute(),
26           _ambient(0.2f,0.2f,0.2f,1.0f),
27           _colorControl(LightModel::SINGLE_COLOR),
28           _localViewer(false),
29           _twoSided(false)
30 {
31 }
32 
33 
~LightModel()34 LightModel::~LightModel()
35 {
36 }
37 
38 #ifdef OSG_GL_FIXED_FUNCTION_AVAILABLE
39 
40 // need to define if gl.h version < 1.2.
41 #ifndef GL_LIGHT_MODEL_COLOR_CONTROL
42 #define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8
43 #endif
44 
45 #ifndef GL_SINGLE_COLOR
46 #define GL_SINGLE_COLOR 0x81F9
47 #endif
48 
49 #ifndef GL_SEPARATE_SPECULAR_COLOR
50 #define GL_SEPARATE_SPECULAR_COLOR 0x81FA
51 #endif
52 
apply(State & state) const53 void LightModel::apply(State& state) const
54 {
55 
56     #ifdef OSG_GLES1_AVAILABLE
57     #define glLightModeli glLightModelx
58     #endif
59 
60     glLightModelfv(GL_LIGHT_MODEL_AMBIENT,_ambient.ptr());
61 
62     if (state.get<GLExtensions>()->glVersion>=1.2)
63     {
64         if (_colorControl==SEPARATE_SPECULAR_COLOR)
65         {
66             glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR);
67         }
68         else
69         {
70             glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SINGLE_COLOR);
71         }
72     }
73 
74     #ifndef OSG_GLES1_AVAILABLE
75     glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,_localViewer);
76     #endif
77 
78     glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,_twoSided);
79 }
80 
81 #else
82 
apply(State &) const83 void LightModel::apply(State&) const
84 {
85     OSG_NOTICE<<"Warning: LightModel::apply(State&) - not supported."<<std::endl;
86 }
87 
88 #endif
89 
90