vrheights

diff src/material.cc @ 8:3f221bdc9bab

mesh loading walk polys
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 03 Oct 2014 04:16:16 +0300
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/material.cc	Fri Oct 03 04:16:16 2014 +0300
     1.3 @@ -0,0 +1,27 @@
     1.4 +#include "material.h"
     1.5 +#include "opengl.h"
     1.6 +
     1.7 +Material::Material()
     1.8 +	: diffuse(1, 1, 1)
     1.9 +{
    1.10 +	alpha = 1.0;
    1.11 +	shininess = 60.0;
    1.12 +	tex = 0;
    1.13 +}
    1.14 +
    1.15 +void Material::setup() const
    1.16 +{
    1.17 +	float diff[] = {diffuse.x, diffuse.y, diffuse.z, alpha};
    1.18 +	float spec[] = {specular.x, specular.y, specular.z, 1.0};
    1.19 +
    1.20 +	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, diff);
    1.21 +	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, spec);
    1.22 +	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess > 128.0f ? 128.0f : shininess);
    1.23 +
    1.24 +	if(tex) {
    1.25 +		glEnable(GL_TEXTURE_2D);
    1.26 +		glBindTexture(GL_TEXTURE_2D, tex);
    1.27 +	} else {
    1.28 +		glDisable(GL_TEXTURE_2D);
    1.29 +	}
    1.30 +}