]> git.jsancho.org Git - lugaru.git/blob - Source/Lights.cpp
b8332c34fdab27e95fd5f30e86feb684ec70dffa
[lugaru.git] / Source / Lights.cpp
1 /*
2 Copyright (C) 2003, 2010 - Wolfire Games
3
4 This file is part of Lugaru.
5
6 Lugaru is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
15 See the GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 */
21
22 /**> HEADER FILES <**/
23 #include "Lights.h"
24
25 void SetUpLight(Light* whichsource, int whichlight)
26 {
27     static float qattenuation[] = {0.0002f};
28     static float cattenuation[] = {1.5f};
29     static float lattenuation[] = {0.5f};
30     static float zattenuation[] = {0.0f};
31
32     //Initialize lights
33     if (whichlight == 0) {
34         GLfloat LightAmbient[] = { whichsource->ambient[0], whichsource->ambient[1], whichsource->ambient[2], 1.0f};
35         GLfloat LightDiffuse[] = { whichsource->color[0], whichsource->color[1], whichsource->color[2], 1.0f };
36         GLfloat LightPosition[] = { whichsource->location.x, whichsource->location.y, whichsource->location.z, 0.0f };
37
38         //glLightfv(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, qattenuation);
39         glLightfv(GL_LIGHT0, GL_POSITION, LightPosition);
40         glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient);
41         glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse);
42         glEnable(GL_LIGHT0);
43     } else {
44         GLenum lightselect = GL_LIGHT1;
45         switch (whichlight) {
46         case 2:
47             lightselect = GL_LIGHT2;
48             break;
49         case 3:
50             lightselect = GL_LIGHT3;
51             break;
52         case 4:
53             lightselect = GL_LIGHT4;
54             break;
55         case 5:
56             lightselect = GL_LIGHT5;
57             break;
58         case 6:
59             lightselect = GL_LIGHT6;
60             break;
61         case 7:
62             lightselect = GL_LIGHT7;
63             break;
64         }
65
66         GLfloat LightAmbient[] = { 0, 0, 0, 1.0f};
67         GLfloat LightDiffuse[] = { whichsource->color[0], whichsource->color[1], whichsource->color[2], 1.0f };
68         GLfloat LightPosition[] = { whichsource->location.x, whichsource->location.y, whichsource->location.z, 1.0f };
69
70         glLightfv(lightselect, GL_QUADRATIC_ATTENUATION, qattenuation);
71         glLightfv(lightselect, GL_POSITION, LightPosition);
72         glLightfv(lightselect, GL_AMBIENT, LightAmbient);
73         glLightfv(lightselect, GL_DIFFUSE, LightDiffuse);
74         glEnable(lightselect);
75
76     }
77 }
78
79 void SetUpMainLight(Light* whichsource, int whichlight, float ambientr, float ambientg, float ambientb)
80 {
81     static float qattenuation[] = {0.0f};
82
83     //Initialize lights
84
85     if (whichlight == 0) {
86         GLfloat LightAmbient[] = { ambientr, ambientg, ambientb, 1.0f};
87         GLfloat LightDiffuse[] = { whichsource->color[0], whichsource->color[1], whichsource->color[2], 1.0f };
88         GLfloat LightPosition[] = { whichsource->location.x, whichsource->location.y, whichsource->location.z, 1.0f };
89
90         glLightfv(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, qattenuation);
91         glLightfv(GL_LIGHT0, GL_POSITION, LightPosition);
92         glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient);
93         glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse);
94         glEnable(GL_LIGHT0);
95     }
96 }