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
#ifndef MSP_GL_MATERIAL_H_
#define MSP_GL_MATERIAL_H_
+#include <msp/datafile/loader.h>
#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;
void Object::Loader::material_inline()
{
- throw Exception("material_inline not supported yet");
- /*RefPtr<Material> mat=new Material;
+ RefPtr<Material> 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)