X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fmaterial.cpp;h=310834f3554a50619dcc404f066a269ca952d666;hb=50e504e2171295d5922ddf87b358e0024db3ce40;hp=58cd15cb8e122169803ce5015be54681df948173;hpb=cea3c333797cadd9629aefaa5b82243173a02d16;p=libs%2Fgl.git diff --git a/source/material.cpp b/source/material.cpp index 58cd15cb..310834f3 100644 --- a/source/material.cpp +++ b/source/material.cpp @@ -1,10 +1,11 @@ /* $Id$ This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2007-2008 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ +#include "gl.h" #include "material.h" namespace Msp { @@ -43,13 +44,55 @@ void Material::set_shininess(float s) shininess=s; } -void Material::apply() const +void Material::bind() const { - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, &ambient.r); - glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, &diffuse.r); - glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &specular.r); - glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, &emission.r); - glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess); + if(current!=this) + { + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, &ambient.r); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, &diffuse.r); + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &specular.r); + glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, &emission.r); + glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess); + current=this; + } +} + +void Material::unbind() +{ + current=0; +} + +const Material *Material::current=0; + + +Material::Loader::Loader(Material &m): + mat(m) +{ + add("ambient", &Loader::ambient); + add("diffuse", &Loader::diffuse); + add("specular", &Loader::specular); + add("emission", &Loader::emission); + add("shininess", &Material::shininess); +} + +void Material::Loader::ambient(float r, float g, float b, float a) +{ + mat.ambient=GL::Color(r, g, b, a); +} + +void Material::Loader::diffuse(float r, float g, float b, float a) +{ + mat.diffuse=GL::Color(r, g, b, a); +} + +void Material::Loader::specular(float r, float g, float b, float a) +{ + mat.specular=GL::Color(r, g, b, a); +} + +void Material::Loader::emission(float r, float g, float b, float a) +{ + mat.emission=GL::Color(r, g, b, a); } } // namespace GL