labyrinth

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/opengl.c	Thu Jan 15 14:59:38 2015 +0200
     1.3 @@ -0,0 +1,66 @@
     1.4 +#include "opengl.h"
     1.5 +
     1.6 +static void set_light_param(int idx, unsigned int p, float x, float y, float z)
     1.7 +{
     1.8 +	float v[4];
     1.9 +	v[0] = x;
    1.10 +	v[1] = y;
    1.11 +	v[2] = z;
    1.12 +	v[3] = 1.0f;
    1.13 +	glLightfv(GL_LIGHT0 + idx, p, v);
    1.14 +}
    1.15 +
    1.16 +void set_light_position(int idx, float x, float y, float z)
    1.17 +{
    1.18 +	set_light_param(idx, GL_POSITION, x, y, z);
    1.19 +}
    1.20 +
    1.21 +void set_light_color(int idx, float r, float g, float b)
    1.22 +{
    1.23 +	set_light_param(idx, GL_DIFFUSE, r, g, b);
    1.24 +	set_light_param(idx, GL_SPECULAR, r, g, b);
    1.25 +}
    1.26 +
    1.27 +void set_light_attenuation(int idx, float constant, float linear, float quad)
    1.28 +{
    1.29 +	glLightf(GL_LIGHT0 + idx, GL_CONSTANT_ATTENUATION, constant);
    1.30 +	glLightf(GL_LIGHT0 + idx, GL_LINEAR_ATTENUATION, linear);
    1.31 +	glLightf(GL_LIGHT0 + idx, GL_QUADRATIC_ATTENUATION, quad);
    1.32 +}
    1.33 +
    1.34 +
    1.35 +void set_mtl_diffuse(float r, float g, float b, float a)
    1.36 +{
    1.37 +	float color[4];
    1.38 +	color[0] = r;
    1.39 +	color[1] = g;
    1.40 +	color[2] = b;
    1.41 +	color[3] = a;
    1.42 +	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
    1.43 +}
    1.44 +
    1.45 +void set_mtl_specular(float r, float g, float b)
    1.46 +{
    1.47 +	float color[4];
    1.48 +	color[0] = r;
    1.49 +	color[1] = g;
    1.50 +	color[2] = b;
    1.51 +	color[3] = 1.0f;
    1.52 +	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, color);
    1.53 +}
    1.54 +
    1.55 +void set_mtl_shininess(float shin)
    1.56 +{
    1.57 +	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shin > 128.0 ? 128.0 : shin);
    1.58 +}
    1.59 +
    1.60 +
    1.61 +void set_mtl_emission(float r, float g, float b)
    1.62 +{
    1.63 +	float color[4];
    1.64 +	color[0] = r;
    1.65 +	color[1] = g;
    1.66 +	color[2] = b;
    1.67 +	color[3] = 1.0f;
    1.68 +	glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, color);
    1.69 +}