root/OpenSceneGraph/trunk/src/osg/LightModel.cpp @ 13041

Revision 13041, 2.1 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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
20using namespace osg;
21
22
23LightModel::LightModel():
24          StateAttribute(),
25          _ambient(0.2f,0.2f,0.2f,1.0f),
26          _colorControl(LightModel::SINGLE_COLOR),
27          _localViewer(false),
28          _twoSided(false)
29{
30}
31
32
33LightModel::~LightModel()
34{
35}
36
37// need to define if gl.h version < 1.2.
38#ifndef GL_LIGHT_MODEL_COLOR_CONTROL
39#define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8
40#endif
41
42#ifndef GL_SINGLE_COLOR
43#define GL_SINGLE_COLOR 0x81F9
44#endif
45
46#ifndef GL_SEPARATE_SPECULAR_COLOR
47#define GL_SEPARATE_SPECULAR_COLOR 0x81FA
48#endif
49
50
51void LightModel::apply(State&) const
52{
53#ifdef OSG_GL_FIXED_FUNCTION_AVAILABLE
54
55    #ifdef OSG_GLES1_AVAILABLE
56    #define glLightModeli glLightModelx
57    #endif
58
59    glLightModelfv(GL_LIGHT_MODEL_AMBIENT,_ambient.ptr());
60
61    static bool s_separateSpecularSupported = strncmp((const char*)glGetString(GL_VERSION),"1.2",3)>=0;
62    if (s_separateSpecularSupported)
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#else
80    OSG_NOTICE<<"Warning: LightModel::apply(State&) - not supported."<<std::endl;
81#endif
82}
Note: See TracBrowser for help on using the browser.