From: Mikko Rasa Date: Tue, 2 Oct 2007 15:25:55 +0000 (+0000) Subject: Add Material class X-Git-Tag: 0.9~38 X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=commitdiff_plain;h=4c89817d6e060323ec1ddd275f3265cea688c650 Add Material class --- diff --git a/source/color.h b/source/color.h new file mode 100644 index 00000000..0fc303a2 --- /dev/null +++ b/source/color.h @@ -0,0 +1,29 @@ +/* $Id$ + +This file is part of libmspgl +Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + +#ifndef MSP_GL_COLOR_H_ +#define MSP_GL_COLOR_H_ + +#include + +namespace Msp { +namespace GL { + +struct Color +{ + float r, g, b, a; + + Color(): r(1), g(1), b(1), a(1) { } + Color(float v): r(v), g(v), b(v), a(1) { } + Color(float r_, float g_, float b_): r(r_), g(g_), b(b_), a(1) { } + Color(float r_, float g_, float b_, float a_): r(r_), g(g_), b(b_), a(a_) { } +}; + +} // namespace GL +} // namespace Msp + +#endif diff --git a/source/material.cpp b/source/material.cpp new file mode 100644 index 00000000..25c21ff2 --- /dev/null +++ b/source/material.cpp @@ -0,0 +1,56 @@ +/* $Id$ + +This file is part of libmspgl +Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + +#include "material.h" + +namespace Msp { +namespace GL { + +Material::Material(): + ambient(0.2), + diffuse(0.8), + specular(0), + emission(0), + shininess(0) +{ } + +void Material::set_ambient(const Color &a) +{ + ambient=a; +} + +void Material::set_diffuse(const Color &d) +{ + diffuse=d; +} + +void Material::set_specular(const Color &s) +{ + specular=s; +} + +void Material::set_emission(const Color &e) +{ + emission=e; +} + +void Material::set_shininess(float s) +{ + shininess=s; +} + +void Material::apply() +{ + 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); +} + +} // namespace GL +} // namespace Msp diff --git a/source/material.h b/source/material.h new file mode 100644 index 00000000..b2ea995e --- /dev/null +++ b/source/material.h @@ -0,0 +1,38 @@ +/* $Id$ + +This file is part of libmspgl +Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + +#ifndef MSP_GL_MATERIAL_H_ +#define MSP_GL_MATERIAL_H_ + +#include "color.h" + +namespace Msp { +namespace GL { + +class Material +{ +private: + Color ambient; + Color diffuse; + Color specular; + Color emission; + float shininess; + +public: + Material(); + void set_ambient(const Color &a); + void set_diffuse(const Color &d); + void set_specular(const Color &s); + void set_emission(const Color &e); + void set_shininess(float s); + void apply(); +}; + +} // namespace GL +} // namespace Msp + +#endif diff --git a/source/matrix.cpp b/source/matrix.cpp index dc855d2b..7a910786 100644 --- a/source/matrix.cpp +++ b/source/matrix.cpp @@ -1,3 +1,10 @@ +/* $Id$ + +This file is part of libmspgl +Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + #include "matrix.h" namespace Msp {