X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fmaterial.cpp;h=eee1ebc6152057d8799db1a118fa3dcda2bfcd2c;hb=b617c5d7b5283ad260a77f01e42e6170cabbc03d;hp=0b888ef519404e164ac32be278f3593fb85edc0e;hpb=a4ec5410595ddf37bfbc0e85ad87d31a9cbf94f1;p=libs%2Fgl.git diff --git a/source/material.cpp b/source/material.cpp index 0b888ef5..eee1ebc6 100644 --- a/source/material.cpp +++ b/source/material.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2007-2008 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -21,41 +21,52 @@ Material::Material(): void Material::set_ambient(const Color &a) { - ambient=a; + ambient = a; } void Material::set_diffuse(const Color &d) { - diffuse=d; + diffuse = d; } void Material::set_specular(const Color &s) { - specular=s; + specular = s; } void Material::set_emission(const Color &e) { - emission=e; + emission = e; } void Material::set_shininess(float s) { - shininess=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) + DataFile::ObjectLoader(m) { add("ambient", &Loader::ambient); add("diffuse", &Loader::diffuse); @@ -66,22 +77,22 @@ Material::Loader::Loader(Material &m): void Material::Loader::ambient(float r, float g, float b, float a) { - mat.ambient=GL::Color(r, g, b, a); + obj.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); + obj.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); + obj.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); + obj.emission = GL::Color(r, g, b, a); } } // namespace GL