-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLight.cpp
110 lines (88 loc) · 1.92 KB
/
Light.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "Light.h"
#include <iostream>
#include <GL/glut.h>
using namespace std;
Light::Light() {
light_num = 0;
light = GL_LIGHT0;
}
Light::Light(int num) {
light_num = num;
switch (num) {
case 0:
light = GL_LIGHT0;
break;
case 1:
light = GL_LIGHT1;
break;
case 2:
light = GL_LIGHT2;
break;
case 3:
light = GL_LIGHT3;
break;
case 4:
light = GL_LIGHT4;
break;
case 5:
light = GL_LIGHT5;
break;
case 6:
light = GL_LIGHT6;
break;
case 7:
light = GL_LIGHT7;
break;
}
this->enable();
}
void Light::enable() {
glEnable(light);
glLightfv(light, GL_AMBIENT, ambient);
glLightfv(light, GL_DIFFUSE, diffuse);
glLightfv(light, GL_SPECULAR, specular);
cout << "enabled GL_LIGHT" << light_num << "\n";
}
void Light::disable() {
glDisable(light);
GLfloat black[] = {0, 0, 0, 0};
glLightfv(light, GL_DIFFUSE, black);
glLightfv(light, GL_SPECULAR, black);
cout << "disabled GL_LIGHT" << light_num << "\n";
}
void Light::setAmbient(GLfloat *v) {
for (int i=0; i<4; i++)
ambient[i] = v[i];
glLightfv(light, GL_AMBIENT, v);
}
void Light::setDiffuse(GLfloat *v) {
for (int i=0; i<4; i++)
diffuse[i] = v[i];
glLightfv(light, GL_DIFFUSE, v);
}
void Light::setSpecular(GLfloat *v) {
for (int i=0; i<4; i++)
specular[i] = v[i];
glLightfv(light, GL_SPECULAR, v);
}
void Light::setPosition(GLfloat *v) {
glLightfv(light, GL_POSITION, v);
}
void Light::setSpotDirection(GLfloat *v) {
glLightfv(light, GL_SPOT_DIRECTION, v);
}
void Light::setSpotExponent(GLfloat n) {
glLightf(light, GL_SPOT_EXPONENT, n);
}
void Light::setSpotCutoff(GLfloat n) {
glLightf(light, GL_SPOT_CUTOFF, n);
}
void Light::setConstantAttenuation(GLfloat n) {
glLightf(light, GL_CONSTANT_ATTENUATION, n);
}
void Light::setLinearAttenuation(GLfloat n) {
glLightf(light, GL_LINEAR_ATTENUATION, n);
}
void Light::setQuadraticAttenuation(GLfloat n) {
glLightf(light, GL_QUADRATIC_ATTENUATION, n);
}