]> git.jsancho.org Git - lugaru.git/blob - Source/Lights.cpp
5761c4f30c1ad60d0d42c014ea268093d7f4d3de
[lugaru.git] / Source / Lights.cpp
1 /**> HEADER FILES <**/
2 #include "Lights.h"
3
4 void SetUpLight(Light* whichsource, int whichlight){
5         static float qattenuation[]={0.0002f};
6         static float cattenuation[]={1.5f};
7         static float lattenuation[]={0.5f};
8         static float zattenuation[]={0.0f};
9
10         //Initialize lights
11
12         if(whichlight==0){
13                 GLfloat LightAmbient[]=         { whichsource->ambient[0], whichsource->ambient[1], whichsource->ambient[2], 1.0f};
14                 GLfloat LightDiffuse[]=         { whichsource->color[0], whichsource->color[1], whichsource->color[2], 1.0f };
15                 GLfloat LightPosition[]=        { whichsource->location.x, whichsource->location.y, whichsource->location.z, 0.0f };
16
17                 //glLightfv(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, qattenuation);
18                 glLightfv(GL_LIGHT0, GL_POSITION, LightPosition);
19                 glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient);         
20                 glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse);         
21                 glEnable(GL_LIGHT0);    
22         }
23
24         if(whichlight==1){
25                 GLfloat LightAmbient[]=         { 0, 0, 0, 1.0f};
26                 GLfloat LightDiffuse[]=         { whichsource->color[0], whichsource->color[1], whichsource->color[2], 1.0f };
27                 GLfloat LightPosition[]=        { whichsource->location.x, whichsource->location.y, whichsource->location.z, 1.0f };
28
29                 glLightfv(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, qattenuation);
30                 glLightfv(GL_LIGHT1, GL_POSITION, LightPosition);
31                 glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);         
32                 glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);         
33                 glEnable(GL_LIGHT1);    
34         }
35
36         if(whichlight==2){
37                 GLfloat LightAmbient[]=         { 0, 0, 0, 1.0f};
38                 GLfloat LightDiffuse[]=         { whichsource->color[0], whichsource->color[1], whichsource->color[2], 1.0f };
39                 GLfloat LightPosition[]=        { whichsource->location.x, whichsource->location.y, whichsource->location.z, 1.0f };
40
41                 glLightfv(GL_LIGHT2, GL_QUADRATIC_ATTENUATION, qattenuation);
42                 glLightfv(GL_LIGHT2, GL_POSITION, LightPosition);
43                 glLightfv(GL_LIGHT2, GL_AMBIENT, LightAmbient);         
44                 glLightfv(GL_LIGHT2, GL_DIFFUSE, LightDiffuse);         
45                 glEnable(GL_LIGHT2);    
46         }
47
48         if(whichlight==3){
49                 GLfloat LightAmbient[]=         { 0, 0, 0, 1.0f};
50                 GLfloat LightDiffuse[]=         { whichsource->color[0], whichsource->color[1], whichsource->color[2], 1.0f };
51                 GLfloat LightPosition[]=        { whichsource->location.x, whichsource->location.y, whichsource->location.z, 1.0f };
52
53                 glLightfv(GL_LIGHT3, GL_QUADRATIC_ATTENUATION, qattenuation);
54                 glLightfv(GL_LIGHT3, GL_POSITION, LightPosition);
55                 glLightfv(GL_LIGHT3, GL_AMBIENT, LightAmbient);         
56                 glLightfv(GL_LIGHT3, GL_DIFFUSE, LightDiffuse);         
57                 glEnable(GL_LIGHT3);    
58         }
59
60         if(whichlight==4){
61                 GLfloat LightAmbient[]=         { 0, 0, 0, 1.0f};
62                 GLfloat LightDiffuse[]=         { whichsource->color[0], whichsource->color[1], whichsource->color[2], 1.0f };
63                 GLfloat LightPosition[]=        { whichsource->location.x, whichsource->location.y, whichsource->location.z, 1.0f };
64
65                 glLightfv(GL_LIGHT4, GL_QUADRATIC_ATTENUATION, qattenuation);
66                 glLightfv(GL_LIGHT4, GL_POSITION, LightPosition);
67                 glLightfv(GL_LIGHT4, GL_AMBIENT, LightAmbient);         
68                 glLightfv(GL_LIGHT4, GL_DIFFUSE, LightDiffuse);         
69                 glEnable(GL_LIGHT4);    
70         }
71
72         if(whichlight==5){
73                 GLfloat LightAmbient[]=         { 0, 0, 0, 1.0f};
74                 GLfloat LightDiffuse[]=         { whichsource->color[0], whichsource->color[1], whichsource->color[2], 1.0f };
75                 GLfloat LightPosition[]=        { whichsource->location.x, whichsource->location.y, whichsource->location.z, 1.0f };
76
77                 glLightfv(GL_LIGHT5, GL_QUADRATIC_ATTENUATION, qattenuation);
78                 glLightfv(GL_LIGHT5, GL_POSITION, LightPosition);
79                 glLightfv(GL_LIGHT5, GL_AMBIENT, LightAmbient);         
80                 glLightfv(GL_LIGHT5, GL_DIFFUSE, LightDiffuse);         
81                 glEnable(GL_LIGHT5);    
82         }
83
84         if(whichlight==6){
85                 GLfloat LightAmbient[]=         { 0, 0, 0, 1.0f};
86                 GLfloat LightDiffuse[]=         { whichsource->color[0], whichsource->color[1], whichsource->color[2], 1.0f };
87                 GLfloat LightPosition[]=        { whichsource->location.x, whichsource->location.y, whichsource->location.z, 1.0f };
88
89                 glLightfv(GL_LIGHT6, GL_QUADRATIC_ATTENUATION, qattenuation);
90                 glLightfv(GL_LIGHT6, GL_POSITION, LightPosition);
91                 glLightfv(GL_LIGHT6, GL_AMBIENT, LightAmbient);         
92                 glLightfv(GL_LIGHT6, GL_DIFFUSE, LightDiffuse);         
93                 glEnable(GL_LIGHT6);    
94         }
95
96         if(whichlight==7){
97                 GLfloat LightAmbient[]=         { 0, 0, 0, 1.0f};
98                 GLfloat LightDiffuse[]=         { whichsource->color[0], whichsource->color[1], whichsource->color[2], 1.0f };
99                 GLfloat LightPosition[]=        { whichsource->location.x, whichsource->location.y, whichsource->location.z, 1.0f };
100
101                 glLightfv(GL_LIGHT7, GL_QUADRATIC_ATTENUATION, qattenuation);
102                 glLightfv(GL_LIGHT7, GL_POSITION, LightPosition);
103                 glLightfv(GL_LIGHT7, GL_AMBIENT, LightAmbient);         
104                 glLightfv(GL_LIGHT7, GL_DIFFUSE, LightDiffuse);         
105                 glEnable(GL_LIGHT7);    
106         }
107 }
108
109 void SetUpMainLight(Light* whichsource, int whichlight, float ambientr, float ambientg, float ambientb){
110         static float qattenuation[]={0.0f};
111
112         //Initialize lights
113
114         if(whichlight==0){
115                 GLfloat LightAmbient[]=         { ambientr, ambientg, ambientb, 1.0f};
116                 GLfloat LightDiffuse[]=         { whichsource->color[0], whichsource->color[1], whichsource->color[2], 1.0f };
117                 GLfloat LightPosition[]=        { whichsource->location.x, whichsource->location.y, whichsource->location.z, 1.0f };
118
119                 glLightfv(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, qattenuation);
120                 glLightfv(GL_LIGHT0, GL_POSITION, LightPosition);
121                 glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient);         
122                 glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse);         
123                 glEnable(GL_LIGHT0);    
124         }
125 }