From: Mikko Rasa Date: Fri, 9 Nov 2007 17:13:31 +0000 (+0000) Subject: Support for loading materials from datafiles X-Git-Tag: 0.9~21 X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=5c59a04e253bf7868796fc0dc8e9768ad1988b33;p=libs%2Fgl.git Support for loading materials from datafiles --- diff --git a/source/material.cpp b/source/material.cpp index 58cd15cb..f165c744 100644 --- a/source/material.cpp +++ b/source/material.cpp @@ -52,5 +52,36 @@ void Material::apply() const glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess); } + +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 } // namespace Msp diff --git a/source/material.h b/source/material.h index babf2676..0e0033b4 100644 --- a/source/material.h +++ b/source/material.h @@ -8,13 +8,35 @@ Distributed under the LGPL #ifndef MSP_GL_MATERIAL_H_ #define MSP_GL_MATERIAL_H_ +#include #include "color.h" namespace Msp { namespace GL { +/** +Stores OpenGL material properties. Since OpenGL does not support material +objects, application of material is done with several calls to glMaterial. +*/ class Material { +public: + class Loader: public DataFile::Loader + { + private: + Material &mat; + + public: + Loader(Material &); + Material &get_object() const { return mat; } + + private: + void ambient(float, float, float, float); + void diffuse(float, float, float, float); + void specular(float, float, float, float); + void emission(float, float, float, float); + }; + private: Color ambient; Color diffuse; diff --git a/source/object.cpp b/source/object.cpp index 3ba2d64c..19abe36b 100644 --- a/source/object.cpp +++ b/source/object.cpp @@ -164,11 +164,10 @@ void Object::Loader::lod_mesh(unsigned l, const string &n) void Object::Loader::material_inline() { - throw Exception("material_inline not supported yet"); - /*RefPtr mat=new Material; + RefPtr mat=new Material; load_sub(*mat); coll.add(format("%p%p", &obj, mat.get()), mat.get()); - obj.material=mat.release();*/ + obj.material=mat.release(); } void Object::Loader::mesh(const string &n)