-
Notifications
You must be signed in to change notification settings - Fork 0
/
setlight.cpp
44 lines (42 loc) · 1.79 KB
/
setlight.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
void
SetPointLight( int ilight, float x, float y, float z, float r, float g, float b )
{
glLightfv( ilight, GL_POSITION, Array3( x, y, z ) );
glLightf( ilight, GL_SPOT_CUTOFF, 180.f );
glLightfv( ilight, GL_AMBIENT, MulArray3( 0.1f, 1.f, 1.f, 1.f ) );
glLightfv( ilight, GL_DIFFUSE, MulArray3( 0.6f, r, g, b ) );
glLightfv( ilight, GL_SPECULAR, MulArray3( 0.4f, 1.f, 1.f, 1.f ) );
glLightf ( ilight, GL_CONSTANT_ATTENUATION, 1. );
glLightf ( ilight, GL_LINEAR_ATTENUATION, 0. );
glLightf ( ilight, GL_QUADRATIC_ATTENUATION, 0. );
glEnable( ilight );
}
void
SetSpotLight( int ilight, float x, float y, float z, float xdir, float ydir, float zdir, float r, float g, float b )
{
glLightfv( ilight, GL_POSITION, Array3( x, y, z ) );
glLightfv( ilight, GL_SPOT_DIRECTION, Array3(xdir,ydir,zdir) );
glLightf( ilight, GL_SPOT_EXPONENT, 1.f );
glLightf( ilight, GL_SPOT_CUTOFF, 45.f );
glLightfv( ilight, GL_AMBIENT, Array3( 0., 0., 0. ) );
glLightfv( ilight, GL_DIFFUSE, Array3( r, g, b ) );
glLightfv( ilight, GL_SPECULAR, Array3( r, g, b ) );
glLightf ( ilight, GL_CONSTANT_ATTENUATION, 1. );
glLightf ( ilight, GL_LINEAR_ATTENUATION, 0. );
glLightf ( ilight, GL_QUADRATIC_ATTENUATION, 0. );
glEnable( ilight );
}
void
SetSunLight( int ilight, float x, float y, float z, float r, float g, float b )
{
float pos[4] = {x, y, z, 0.f};
glLightfv( ilight, GL_POSITION, pos );
glLightf( ilight, GL_SPOT_CUTOFF, 180.f );
glLightfv( ilight, GL_AMBIENT, MulArray3( 0.1f, 1.f, 1.f, 1.f ) );
glLightfv( ilight, GL_DIFFUSE, MulArray3( 0.6f, r, g, b ) );
glLightfv( ilight, GL_SPECULAR, MulArray3( 0.4f, 1.f, 1.f, 1.f ) );
glLightf ( ilight, GL_CONSTANT_ATTENUATION, 1. );
glLightf ( ilight, GL_LINEAR_ATTENUATION, 0. );
glLightf ( ilight, GL_QUADRATIC_ATTENUATION, 0. );
glEnable( ilight );
}