]> git.jsancho.org Git - lugaru.git/blob - Source/Lights.cpp
9a351c9ae070b7a02fd1e02a18df53f99d0d4a08
[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         if(whichlight==0){
33                 GLfloat LightAmbient[]=         { whichsource->ambient[0], whichsource->ambient[1], whichsource->ambient[2], 1.0f};
34                 GLfloat LightDiffuse[]=         { whichsource->color[0], whichsource->color[1], whichsource->color[2], 1.0f };
35                 GLfloat LightPosition[]=        { whichsource->location.x, whichsource->location.y, whichsource->location.z, 0.0f };
36
37                 //glLightfv(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, qattenuation);
38                 glLightfv(GL_LIGHT0, GL_POSITION, LightPosition);
39                 glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient);         
40                 glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse);         
41                 glEnable(GL_LIGHT0);    
42         }else{
43                 GLenum lightselect=GL_LIGHT1;
44                 switch (whichlight){
45                         case 2:
46                                 lightselect=GL_LIGHT2;
47                                 break;
48                         case 3:
49                                 lightselect=GL_LIGHT3;
50                                 break;
51                         case 4:
52                                 lightselect=GL_LIGHT4;
53                                 break;
54                         case 5:
55                                 lightselect=GL_LIGHT5;
56                                 break;
57                         case 6:
58                                 lightselect=GL_LIGHT6;
59                                 break;
60                         case 7:
61                                 lightselect=GL_LIGHT7;
62                                 break;
63                 }
64                 
65                 GLfloat LightAmbient[]=         { 0, 0, 0, 1.0f};
66                 GLfloat LightDiffuse[]=         { whichsource->color[0], whichsource->color[1], whichsource->color[2], 1.0f };
67                 GLfloat LightPosition[]=        { whichsource->location.x, whichsource->location.y, whichsource->location.z, 1.0f };
68
69                 glLightfv(lightselect, GL_QUADRATIC_ATTENUATION, qattenuation);
70                 glLightfv(lightselect, GL_POSITION, LightPosition);
71                 glLightfv(lightselect, GL_AMBIENT, LightAmbient);               
72                 glLightfv(lightselect, GL_DIFFUSE, LightDiffuse);               
73                 glEnable(lightselect);  
74                 
75                 }       
76 }
77
78 void SetUpMainLight(Light* whichsource, int whichlight, float ambientr, float ambientg, float ambientb){
79         static float qattenuation[]={0.0f};
80
81         //Initialize lights
82
83         if(whichlight==0){
84                 GLfloat LightAmbient[]=         { ambientr, ambientg, ambientb, 1.0f};
85                 GLfloat LightDiffuse[]=         { whichsource->color[0], whichsource->color[1], whichsource->color[2], 1.0f };
86                 GLfloat LightPosition[]=        { whichsource->location.x, whichsource->location.y, whichsource->location.z, 1.0f };
87
88                 glLightfv(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, qattenuation);
89                 glLightfv(GL_LIGHT0, GL_POSITION, LightPosition);
90                 glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient);         
91                 glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse);         
92                 glEnable(GL_LIGHT0);    
93         }
94 }