]> git.jsancho.org Git - lugaru.git/blob - Source/Lights.cpp
Added GPL license and headers.
[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         static float qattenuation[]={0.0002f};
27         static float cattenuation[]={1.5f};
28         static float lattenuation[]={0.5f};
29         static float zattenuation[]={0.0f};
30
31         //Initialize lights
32
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         }
44
45         if(whichlight==1){
46                 GLfloat LightAmbient[]=         { 0, 0, 0, 1.0f};
47                 GLfloat LightDiffuse[]=         { whichsource->color[0], whichsource->color[1], whichsource->color[2], 1.0f };
48                 GLfloat LightPosition[]=        { whichsource->location.x, whichsource->location.y, whichsource->location.z, 1.0f };
49
50                 glLightfv(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, qattenuation);
51                 glLightfv(GL_LIGHT1, GL_POSITION, LightPosition);
52                 glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);         
53                 glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);         
54                 glEnable(GL_LIGHT1);    
55         }
56
57         if(whichlight==2){
58                 GLfloat LightAmbient[]=         { 0, 0, 0, 1.0f};
59                 GLfloat LightDiffuse[]=         { whichsource->color[0], whichsource->color[1], whichsource->color[2], 1.0f };
60                 GLfloat LightPosition[]=        { whichsource->location.x, whichsource->location.y, whichsource->location.z, 1.0f };
61
62                 glLightfv(GL_LIGHT2, GL_QUADRATIC_ATTENUATION, qattenuation);
63                 glLightfv(GL_LIGHT2, GL_POSITION, LightPosition);
64                 glLightfv(GL_LIGHT2, GL_AMBIENT, LightAmbient);         
65                 glLightfv(GL_LIGHT2, GL_DIFFUSE, LightDiffuse);         
66                 glEnable(GL_LIGHT2);    
67         }
68
69         if(whichlight==3){
70                 GLfloat LightAmbient[]=         { 0, 0, 0, 1.0f};
71                 GLfloat LightDiffuse[]=         { whichsource->color[0], whichsource->color[1], whichsource->color[2], 1.0f };
72                 GLfloat LightPosition[]=        { whichsource->location.x, whichsource->location.y, whichsource->location.z, 1.0f };
73
74                 glLightfv(GL_LIGHT3, GL_QUADRATIC_ATTENUATION, qattenuation);
75                 glLightfv(GL_LIGHT3, GL_POSITION, LightPosition);
76                 glLightfv(GL_LIGHT3, GL_AMBIENT, LightAmbient);         
77                 glLightfv(GL_LIGHT3, GL_DIFFUSE, LightDiffuse);         
78                 glEnable(GL_LIGHT3);    
79         }
80
81         if(whichlight==4){
82                 GLfloat LightAmbient[]=         { 0, 0, 0, 1.0f};
83                 GLfloat LightDiffuse[]=         { whichsource->color[0], whichsource->color[1], whichsource->color[2], 1.0f };
84                 GLfloat LightPosition[]=        { whichsource->location.x, whichsource->location.y, whichsource->location.z, 1.0f };
85
86                 glLightfv(GL_LIGHT4, GL_QUADRATIC_ATTENUATION, qattenuation);
87                 glLightfv(GL_LIGHT4, GL_POSITION, LightPosition);
88                 glLightfv(GL_LIGHT4, GL_AMBIENT, LightAmbient);         
89                 glLightfv(GL_LIGHT4, GL_DIFFUSE, LightDiffuse);         
90                 glEnable(GL_LIGHT4);    
91         }
92
93         if(whichlight==5){
94                 GLfloat LightAmbient[]=         { 0, 0, 0, 1.0f};
95                 GLfloat LightDiffuse[]=         { whichsource->color[0], whichsource->color[1], whichsource->color[2], 1.0f };
96                 GLfloat LightPosition[]=        { whichsource->location.x, whichsource->location.y, whichsource->location.z, 1.0f };
97
98                 glLightfv(GL_LIGHT5, GL_QUADRATIC_ATTENUATION, qattenuation);
99                 glLightfv(GL_LIGHT5, GL_POSITION, LightPosition);
100                 glLightfv(GL_LIGHT5, GL_AMBIENT, LightAmbient);         
101                 glLightfv(GL_LIGHT5, GL_DIFFUSE, LightDiffuse);         
102                 glEnable(GL_LIGHT5);    
103         }
104
105         if(whichlight==6){
106                 GLfloat LightAmbient[]=         { 0, 0, 0, 1.0f};
107                 GLfloat LightDiffuse[]=         { whichsource->color[0], whichsource->color[1], whichsource->color[2], 1.0f };
108                 GLfloat LightPosition[]=        { whichsource->location.x, whichsource->location.y, whichsource->location.z, 1.0f };
109
110                 glLightfv(GL_LIGHT6, GL_QUADRATIC_ATTENUATION, qattenuation);
111                 glLightfv(GL_LIGHT6, GL_POSITION, LightPosition);
112                 glLightfv(GL_LIGHT6, GL_AMBIENT, LightAmbient);         
113                 glLightfv(GL_LIGHT6, GL_DIFFUSE, LightDiffuse);         
114                 glEnable(GL_LIGHT6);    
115         }
116
117         if(whichlight==7){
118                 GLfloat LightAmbient[]=         { 0, 0, 0, 1.0f};
119                 GLfloat LightDiffuse[]=         { whichsource->color[0], whichsource->color[1], whichsource->color[2], 1.0f };
120                 GLfloat LightPosition[]=        { whichsource->location.x, whichsource->location.y, whichsource->location.z, 1.0f };
121
122                 glLightfv(GL_LIGHT7, GL_QUADRATIC_ATTENUATION, qattenuation);
123                 glLightfv(GL_LIGHT7, GL_POSITION, LightPosition);
124                 glLightfv(GL_LIGHT7, GL_AMBIENT, LightAmbient);         
125                 glLightfv(GL_LIGHT7, GL_DIFFUSE, LightDiffuse);         
126                 glEnable(GL_LIGHT7);    
127         }
128 }
129
130 void SetUpMainLight(Light* whichsource, int whichlight, float ambientr, float ambientg, float ambientb){
131         static float qattenuation[]={0.0f};
132
133         //Initialize lights
134
135         if(whichlight==0){
136                 GLfloat LightAmbient[]=         { ambientr, ambientg, ambientb, 1.0f};
137                 GLfloat LightDiffuse[]=         { whichsource->color[0], whichsource->color[1], whichsource->color[2], 1.0f };
138                 GLfloat LightPosition[]=        { whichsource->location.x, whichsource->location.y, whichsource->location.z, 1.0f };
139
140                 glLightfv(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, qattenuation);
141                 glLightfv(GL_LIGHT0, GL_POSITION, LightPosition);
142                 glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient);         
143                 glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse);         
144                 glEnable(GL_LIGHT0);    
145         }
146 }