rev |
line source |
nuclear@0
|
1 #include "opengl.h"
|
nuclear@0
|
2
|
nuclear@0
|
3 static void set_light_param(int idx, unsigned int p, float x, float y, float z)
|
nuclear@0
|
4 {
|
nuclear@0
|
5 float v[4];
|
nuclear@0
|
6 v[0] = x;
|
nuclear@0
|
7 v[1] = y;
|
nuclear@0
|
8 v[2] = z;
|
nuclear@0
|
9 v[3] = 1.0f;
|
nuclear@0
|
10 glLightfv(GL_LIGHT0 + idx, p, v);
|
nuclear@0
|
11 }
|
nuclear@0
|
12
|
nuclear@0
|
13 void set_light_position(int idx, float x, float y, float z)
|
nuclear@0
|
14 {
|
nuclear@0
|
15 set_light_param(idx, GL_POSITION, x, y, z);
|
nuclear@0
|
16 }
|
nuclear@0
|
17
|
nuclear@0
|
18 void set_light_color(int idx, float r, float g, float b)
|
nuclear@0
|
19 {
|
nuclear@0
|
20 set_light_param(idx, GL_DIFFUSE, r, g, b);
|
nuclear@0
|
21 set_light_param(idx, GL_SPECULAR, r, g, b);
|
nuclear@0
|
22 }
|
nuclear@0
|
23
|
nuclear@0
|
24 void set_light_attenuation(int idx, float constant, float linear, float quad)
|
nuclear@0
|
25 {
|
nuclear@0
|
26 glLightf(GL_LIGHT0 + idx, GL_CONSTANT_ATTENUATION, constant);
|
nuclear@0
|
27 glLightf(GL_LIGHT0 + idx, GL_LINEAR_ATTENUATION, linear);
|
nuclear@0
|
28 glLightf(GL_LIGHT0 + idx, GL_QUADRATIC_ATTENUATION, quad);
|
nuclear@0
|
29 }
|
nuclear@0
|
30
|
nuclear@0
|
31
|
nuclear@0
|
32 void set_mtl_diffuse(float r, float g, float b, float a)
|
nuclear@0
|
33 {
|
nuclear@0
|
34 float color[4];
|
nuclear@0
|
35 color[0] = r;
|
nuclear@0
|
36 color[1] = g;
|
nuclear@0
|
37 color[2] = b;
|
nuclear@0
|
38 color[3] = a;
|
nuclear@0
|
39 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
|
nuclear@0
|
40 }
|
nuclear@0
|
41
|
nuclear@0
|
42 void set_mtl_specular(float r, float g, float b)
|
nuclear@0
|
43 {
|
nuclear@0
|
44 float color[4];
|
nuclear@0
|
45 color[0] = r;
|
nuclear@0
|
46 color[1] = g;
|
nuclear@0
|
47 color[2] = b;
|
nuclear@0
|
48 color[3] = 1.0f;
|
nuclear@0
|
49 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, color);
|
nuclear@0
|
50 }
|
nuclear@0
|
51
|
nuclear@0
|
52 void set_mtl_shininess(float shin)
|
nuclear@0
|
53 {
|
nuclear@0
|
54 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shin > 128.0 ? 128.0 : shin);
|
nuclear@0
|
55 }
|
nuclear@0
|
56
|
nuclear@0
|
57
|
nuclear@0
|
58 void set_mtl_emission(float r, float g, float b)
|
nuclear@0
|
59 {
|
nuclear@0
|
60 float color[4];
|
nuclear@0
|
61 color[0] = r;
|
nuclear@0
|
62 color[1] = g;
|
nuclear@0
|
63 color[2] = b;
|
nuclear@0
|
64 color[3] = 1.0f;
|
nuclear@0
|
65 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, color);
|
nuclear@0
|
66 }
|