labyrinth

view src/opengl.c @ 0:8ba79034e8a6

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