nuclear@0: #include "opengl.h" nuclear@0: nuclear@0: static void set_light_param(int idx, unsigned int p, float x, float y, float z) nuclear@0: { nuclear@0: float v[4]; nuclear@0: v[0] = x; nuclear@0: v[1] = y; nuclear@0: v[2] = z; nuclear@0: v[3] = 1.0f; nuclear@0: glLightfv(GL_LIGHT0 + idx, p, v); nuclear@0: } nuclear@0: nuclear@0: void set_light_position(int idx, float x, float y, float z) nuclear@0: { nuclear@0: set_light_param(idx, GL_POSITION, x, y, z); nuclear@0: } nuclear@0: nuclear@0: void set_light_color(int idx, float r, float g, float b) nuclear@0: { nuclear@0: set_light_param(idx, GL_DIFFUSE, r, g, b); nuclear@0: set_light_param(idx, GL_SPECULAR, r, g, b); nuclear@0: } nuclear@0: nuclear@0: void set_light_attenuation(int idx, float constant, float linear, float quad) nuclear@0: { nuclear@0: glLightf(GL_LIGHT0 + idx, GL_CONSTANT_ATTENUATION, constant); nuclear@0: glLightf(GL_LIGHT0 + idx, GL_LINEAR_ATTENUATION, linear); nuclear@0: glLightf(GL_LIGHT0 + idx, GL_QUADRATIC_ATTENUATION, quad); nuclear@0: } nuclear@0: nuclear@0: nuclear@0: void set_mtl_diffuse(float r, float g, float b, float a) nuclear@0: { nuclear@0: float color[4]; nuclear@0: color[0] = r; nuclear@0: color[1] = g; nuclear@0: color[2] = b; nuclear@0: color[3] = a; nuclear@0: glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color); nuclear@0: } nuclear@0: nuclear@0: void set_mtl_specular(float r, float g, float b) nuclear@0: { nuclear@0: float color[4]; nuclear@0: color[0] = r; nuclear@0: color[1] = g; nuclear@0: color[2] = b; nuclear@0: color[3] = 1.0f; nuclear@0: glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, color); nuclear@0: } nuclear@0: nuclear@0: void set_mtl_shininess(float shin) nuclear@0: { nuclear@0: glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shin > 128.0 ? 128.0 : shin); nuclear@0: } nuclear@0: nuclear@0: nuclear@0: void set_mtl_emission(float r, float g, float b) nuclear@0: { nuclear@0: float color[4]; nuclear@0: color[0] = r; nuclear@0: color[1] = g; nuclear@0: color[2] = b; nuclear@0: color[3] = 1.0f; nuclear@0: glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, color); nuclear@0: }