]> git.jsancho.org Git - lugaru.git/blob - Source/Environment/Lights.cpp
315181509de7103d9cd89d58be1758089de90f46
[lugaru.git] / Source / Environment / Lights.cpp
1 /*
2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
4
5 This file is part of Lugaru.
6
7 Lugaru is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 Lugaru 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 General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "Environment/Lights.hpp"
22
23 void SetUpLight(Light* whichsource, int whichlight)
24 {
25     static float qattenuation[] = { 0.0002f };
26
27     //Initialize lights
28     if (whichlight == 0) {
29         GLfloat LightAmbient[] = { whichsource->ambient[0], whichsource->ambient[1], whichsource->ambient[2], 1.0f };
30         GLfloat LightDiffuse[] = { whichsource->color[0], whichsource->color[1], whichsource->color[2], 1.0f };
31         GLfloat LightPosition[] = { whichsource->location.x, whichsource->location.y, whichsource->location.z, 0.0f };
32
33         glLightfv(GL_LIGHT0, GL_POSITION, LightPosition);
34         glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient);
35         glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse);
36         glEnable(GL_LIGHT0);
37     } else {
38         GLenum lightselect = GL_LIGHT1;
39         switch (whichlight) {
40             case 2:
41                 lightselect = GL_LIGHT2;
42                 break;
43             case 3:
44                 lightselect = GL_LIGHT3;
45                 break;
46             case 4:
47                 lightselect = GL_LIGHT4;
48                 break;
49             case 5:
50                 lightselect = GL_LIGHT5;
51                 break;
52             case 6:
53                 lightselect = GL_LIGHT6;
54                 break;
55             case 7:
56                 lightselect = GL_LIGHT7;
57                 break;
58         }
59
60         GLfloat LightAmbient[] = { 0, 0, 0, 1.0f };
61         GLfloat LightDiffuse[] = { whichsource->color[0], whichsource->color[1], whichsource->color[2], 1.0f };
62         GLfloat LightPosition[] = { whichsource->location.x, whichsource->location.y, whichsource->location.z, 1.0f };
63
64         glLightfv(lightselect, GL_QUADRATIC_ATTENUATION, qattenuation);
65         glLightfv(lightselect, GL_POSITION, LightPosition);
66         glLightfv(lightselect, GL_AMBIENT, LightAmbient);
67         glLightfv(lightselect, GL_DIFFUSE, LightDiffuse);
68         glEnable(lightselect);
69     }
70 }