X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fmaterial.cpp;h=0359ab3f332fd41b90590d229efe0391c7c22c70;hb=f14435e58bfa0fa697a06ba9a454bb30cd37d9d8;hp=f165c744fcdf06277c362977954b800c06e6e6df;hpb=5c59a04e253bf7868796fc0dc8e9768ad1988b33;p=libs%2Fgl.git diff --git a/source/material.cpp b/source/material.cpp index f165c744..0359ab3f 100644 --- a/source/material.cpp +++ b/source/material.cpp @@ -1,10 +1,4 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - +#include "gl.h" #include "material.h" namespace Msp { @@ -20,41 +14,49 @@ 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::bind() const +{ + if(set_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); + } } -void Material::apply() const +void Material::unbind() { - 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); + set_current(0); } Material::Loader::Loader(Material &m): - mat(m) + DataFile::ObjectLoader(m) { add("ambient", &Loader::ambient); add("diffuse", &Loader::diffuse); @@ -65,22 +67,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