Commit 024833db authored by Jan Möbius's avatar Jan Möbius

Added additional overlay color to material stuff and glstate

The overlay color should be used for overlays such as wireframe over flat shaded meshes.

closes #1369

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@16052 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 83923f64
......@@ -67,7 +67,8 @@ const Vec4f GLState::default_base_color(0.0, 0.0, 0.0, 1.0);
const Vec4f GLState::default_ambient_color(0.2, 0.2, 0.2, 1.0);
const Vec4f GLState::default_diffuse_color(0.50, 0.53, 0.6, 1.0);
const Vec4f GLState::default_specular_color(0.75, 0.8, 0.85, 1.0);
const float GLState::default_shininess(100.0);
const Vec4f GLState::default_overlay_color(0.0, 0.0, 0.0, 1.0);
const float GLState::default_shininess(100.0);
//-----------------------------------------------------------------------------
......@@ -171,6 +172,7 @@ void GLState::initialize()
set_ambient_color(default_ambient_color);
set_diffuse_color(default_diffuse_color);
set_specular_color(default_specular_color);
set_overlay_color(default_overlay_color);
set_shininess(default_shininess);
......@@ -209,7 +211,7 @@ void GLState::setState ()
glClearColor(clear_color_[0], clear_color_[1], clear_color_[2], clear_color_[3]);
// base color
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, ambient_color_.data());
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, base_color_.data());
// ambient color
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT , ambient_color_.data());
......@@ -632,11 +634,11 @@ void GLState::mult_matrix( const GLMatrixd& _m, const GLMatrixd& _inv_m,
void GLState::update_matrices()
{
forward_projection_ = window2viewport_;
forward_projection_ *= projection_;
forward_projection_ *= modelview_;
forward_projection_ = window2viewport_;
forward_projection_ *= projection_;
forward_projection_ *= modelview_;
backward_projection_ = inverse_modelview_;
backward_projection_ = inverse_modelview_;
backward_projection_ *= inverse_projection_;
backward_projection_ *= inverse_window2viewport_;
}
......@@ -747,6 +749,15 @@ void GLState::set_specular_color(const Vec4f& _col)
makeCurrent();
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, _col.data());
}
}
//-----------------------------------------------------------------------------
void GLState::set_overlay_color(const Vec4f& _col)
{
overlay_color_ = _col;
}
......
......@@ -818,8 +818,10 @@ public:
static const Vec4f default_ambient_color;
/// default value for diffuse color
static const Vec4f default_diffuse_color;
/// default value for speculat color
/// default value for specular color
static const Vec4f default_specular_color;
/// default value for overlay color
static const Vec4f default_overlay_color;
/// default value for shininess
static const float default_shininess;
......@@ -828,7 +830,7 @@ public:
void set_color(const Vec4f& _col);
/// set color
const Vec4f& color(const Vec4f& _col) { return color_; };
const Vec4f& color() { return color_; };
/// set background color
void set_clear_color(const Vec4f& _col);
......@@ -855,6 +857,20 @@ public:
/// get specular color
const Vec4f& specular_color() const { return specular_color_; }
/** \brief set overlay color
*
* This color does not set an opengl state but can be used to store an additional
* color for a wireframe
*/
void set_overlay_color(const Vec4f& _col);
/** \brief Get overlay color
*
* This color does not set an opengl state but can be used to store an additional
* color for a wireframe.
*/
const Vec4f& overlay_color() const { return overlay_color_; }
/// set specular shininess (must be in [0, 128])
void set_shininess(float _shininess);
/// get specular shininess (must be in [0, 128])
......@@ -1082,6 +1098,8 @@ private: //--------------------------------------------------------------------
Vec4f ambient_color_; //< The ambient color of an Object
Vec4f diffuse_color_; //< The diffuse color of an Object
Vec4f specular_color_; //< The specular color of an Object
Vec4f overlay_color_; //< An additional color that can be used to color e.g. a wireframe overlay
float shininess_;
......
......@@ -88,6 +88,7 @@ QtMaterialDialog::QtMaterialDialog( QWidget * _parent,
ambient_ = bak_ambient_ = node_->ambient_color();
diffuse_ = bak_diffuse_ = node_->diffuse_color();
specular_ = bak_specular_ = node_->specular_color();
overlay_ = bak_overlay_ = node_->overlay_color();
shine_ = bak_shine_ = node_->shininess();
point_size_ = bak_point_size_ = node_->point_size();
line_width_ = bak_line_width_ = node_->line_width();
......@@ -120,10 +121,11 @@ QtMaterialDialog::QtMaterialDialog( QWidget * _parent,
ui_.alpha ->setEnabled(false);
}
setButtonColor( ui_.baseColorButton, color_ );
setButtonColor( ui_.ambientColorButton, ambient_ );
setButtonColor( ui_.diffuseColorButton, diffuse_ );
setButtonColor( ui_.baseColorButton, color_ );
setButtonColor( ui_.ambientColorButton, ambient_ );
setButtonColor( ui_.diffuseColorButton, diffuse_ );
setButtonColor( ui_.specularColorButton, specular_ );
setButtonColor( ui_.overlayColorButton, overlay_ );
ui_.shininessSlider->setValue((int)shine_);
ui_.shininessBox->setValue((int)shine_);
......@@ -164,6 +166,7 @@ QtMaterialDialog::QtMaterialDialog( QWidget * _parent,
connect( ui_.ambientColorButton, SIGNAL( clicked() ), this, SLOT( enableProperty() ) );
connect( ui_.diffuseColorButton, SIGNAL( clicked() ), this, SLOT( enableProperty() ) );
connect( ui_.specularColorButton, SIGNAL( clicked() ), this, SLOT( enableProperty() ) );
connect( ui_.overlayColorButton, SIGNAL( clicked() ), this, SLOT( enableProperty() ) );
connect( ui_.shininessSlider, SIGNAL( sliderPressed() ), this, SLOT( enableProperty() ) );
connect( ui_.shininessBox, SIGNAL( valueChanged(int) ), this, SLOT( enableProperty(int) ) );
connect( ui_.pointSizeSpinBox, SIGNAL( valueChanged(int) ), this, SLOT( enableProperty(int) ) );
......@@ -184,6 +187,8 @@ QtMaterialDialog::QtMaterialDialog( QWidget * _parent,
this, SLOT( changeDiffuseColor(QColor) ) );
connect( ui_.specularColorButton, SIGNAL( colorChanged(QColor) ),
this, SLOT( changeSpecularColor(QColor) ) );
connect( ui_.overlayColorButton, SIGNAL( colorChanged(QColor) ),
this, SLOT( changeOverlayColor(QColor) ) );
connect( ui_.shininessSlider, SIGNAL( valueChanged(int) ),
this, SLOT( changeShine(int) ) );
......@@ -342,6 +347,7 @@ void QtMaterialDialog::applyChanges()
node_->set_ambient_color(ambient_);
node_->set_diffuse_color(diffuse_);
node_->set_specular_color(specular_);
node_->set_overlay_color(overlay_);
node_->set_shininess(shine_);
node_->set_point_size(point_size_);
node_->set_line_width(line_width_);
......@@ -379,10 +385,11 @@ void QtMaterialDialog::applyChanges()
// else
// node_->disable_alpha_test();
setButtonColor( ui_.diffuseColorButton, diffuse_ );
setButtonColor( ui_.ambientColorButton, ambient_ );
setButtonColor( ui_.diffuseColorButton, diffuse_ );
setButtonColor( ui_.ambientColorButton, ambient_ );
setButtonColor( ui_.specularColorButton, specular_ );
setButtonColor( ui_.baseColorButton, color_ );
setButtonColor( ui_.overlayColorButton, overlay_ );
setButtonColor( ui_.baseColorButton, color_ );
emit signalNodeChanged(node_);
}
......@@ -414,6 +421,7 @@ void QtMaterialDialog::undoChanges()
node_->set_ambient_color(bak_ambient_);
node_->set_diffuse_color(bak_diffuse_);
node_->set_specular_color(bak_specular_);
node_->set_overlay_color(bak_overlay_);
node_->set_shininess(bak_shine_);
node_->set_point_size(bak_point_size_);
node_->set_line_width(bak_line_width_);
......@@ -445,10 +453,11 @@ void QtMaterialDialog::undoChanges()
else
node_->disable_multisampling();
setButtonColor( ui_.diffuseColorButton, diffuse_ );
setButtonColor( ui_.ambientColorButton, ambient_ );
setButtonColor( ui_.diffuseColorButton, diffuse_ );
setButtonColor( ui_.ambientColorButton, ambient_ );
setButtonColor( ui_.specularColorButton, specular_ );
setButtonColor( ui_.baseColorButton, color_ );
setButtonColor( ui_.overlayColorButton, overlay_ );
setButtonColor( ui_.baseColorButton, color_ );
emit signalNodeChanged(node_);
}
......@@ -484,6 +493,15 @@ void QtMaterialDialog::changeSpecularColor(QColor _newColor)
applyChanges();
}
//-----------------------------------------------------------------------------
void QtMaterialDialog::changeOverlayColor(QColor _newColor)
{
overlay_ = convertColor( _newColor );
applyChanges();
}
//-----------------------------------------------------------------------------
......@@ -714,6 +732,7 @@ QtMaterialDialog::enableProperty(int /*i*/)
else if (sender() == ui_.ambientColorButton) ui_.materialActive->setChecked( true );
else if (sender() == ui_.diffuseColorButton) ui_.materialActive->setChecked( true );
else if (sender() == ui_.specularColorButton) ui_.materialActive->setChecked( true );
else if (sender() == ui_.overlayColorButton) ui_.materialActive->setChecked( true );
else if (sender() == ui_.shininessSlider) ui_.materialActive->setChecked( true );
else if (sender() == ui_.shininessBox) ui_.materialActive->setChecked( true );
else if (sender() == ui_.pointSizeSpinBox) ui_.pointSizeActive->setChecked( true );
......@@ -737,6 +756,7 @@ QtMaterialDialog::enableProperty()
else if (sender() == ui_.ambientColorButton) ui_.materialActive->setChecked( true );
else if (sender() == ui_.diffuseColorButton) ui_.materialActive->setChecked( true );
else if (sender() == ui_.specularColorButton) ui_.materialActive->setChecked( true );
else if (sender() == ui_.overlayColorButton) ui_.materialActive->setChecked( true );
else if (sender() == ui_.shininessSlider) ui_.materialActive->setChecked( true );
else if (sender() == ui_.shininessBox) ui_.materialActive->setChecked( true );
else if (sender() == ui_.pointSizeSpinBox) ui_.pointSizeActive->setChecked( true );
......
......@@ -116,6 +116,7 @@ private slots:
void changeAmbientColor(QColor _newColor);
void changeDiffuseColor(QColor _newColor);
void changeSpecularColor(QColor _newColor);
void changeOverlayColor(QColor _newColor);
void changeShine(int _new);
void changePointSize(int _new);
void changeLineWidth(int _new);
......@@ -151,7 +152,8 @@ private:
Vec4f color_, bak_color_,
ambient_, bak_ambient_,
diffuse_, bak_diffuse_,
specular_, bak_specular_;
specular_, bak_specular_,
overlay_, bak_overlay_;
float shine_, bak_shine_;
float point_size_, bak_point_size_;
float line_width_, bak_line_width_;
......
......@@ -193,7 +193,7 @@
</property>
</widget>
</item>
<item row="4" column="1">
<item row="5" column="1">
<widget class="QLabel" name="label_5">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
......@@ -206,7 +206,7 @@
</property>
</widget>
</item>
<item row="4" column="0">
<item row="5" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QSlider" name="shininessSlider">
......@@ -226,6 +226,29 @@
</item>
</layout>
</item>
<item row="4" column="1">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Overlay Color</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QtColorChooserButton" name="overlayColorButton">
<property name="toolTip">
<string>Overlay color</string>
</property>
<property name="statusTip">
<string>Overlay color</string>
</property>
<property name="whatsThis">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Additional Overlay color.&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;This is mainly used for overlays, such as wireframe&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="2">
......
......@@ -91,11 +91,13 @@ void MaterialNode::enter(GLState& _state, const DrawModes::DrawMode& _drawmode
materialBackup_.ambientColor_ = _state.ambient_color();
materialBackup_.diffuseColor_ = _state.diffuse_color();
materialBackup_.specularColor_ = _state.specular_color();
materialBackup_.shininess_ = _state.shininess();
materialBackup_.overlayColor_ = _state.overlay_color();
materialBackup_.shininess_ = _state.shininess();
_state.set_ambient_color(material_.ambientColor_);
_state.set_diffuse_color(material_.diffuseColor_);
_state.set_specular_color(material_.specularColor_);
_state.set_overlay_color(material_.overlayColor_);
_state.set_shininess(material_.shininess_);
}
......@@ -254,6 +256,7 @@ void MaterialNode::leave(GLState& _state, const DrawModes::DrawMode& _drawmode )
_state.set_ambient_color(materialBackup_.ambientColor_);
_state.set_diffuse_color(materialBackup_.diffuseColor_);
_state.set_specular_color(materialBackup_.specularColor_);
_state.set_overlay_color(materialBackup_.overlayColor_);
_state.set_shininess(materialBackup_.shininess_);
}
......@@ -395,6 +398,14 @@ MaterialNode::read(std::istream& _is)
material_.specularColor(Vec4f(x, y, z, u));
}
}
// OverlayColor
else if (specifier == "OverlayColor") {
buffer >> x >> y >> z >> u;
if (buffer.good()) {
material_.overlayColor(Vec4f(x, y, z, u));
}
}
// Shininess
else if (specifier == "Shininess") {
buffer >> x;
......
......@@ -83,6 +83,7 @@ public:
ambientColor_(GLState::default_ambient_color),
diffuseColor_(GLState::default_diffuse_color),
specularColor_(GLState::default_specular_color),
overlayColor_(GLState::default_overlay_color),
shininess_(GLState::default_shininess),
reflectance_(0.0),
pointSize_(1.0),
......@@ -107,6 +108,7 @@ public:
ambientColor_(_m.ambientColor_),
diffuseColor_(_m.diffuseColor_),
specularColor_(_m.specularColor_),
overlayColor_(_m.overlayColor_),
shininess_(_m.shininess_),
reflectance_(_m.reflectance_),
pointSize_(_m.pointSize_),
......@@ -132,6 +134,7 @@ public:
void color(const Vec4f& _c) {
Vec4f c(0.0,0.0,0.0,1.0);
baseColor(c);
overlayColor(c);
c = _c * 0.2f; c[3]=_c[3]; ambientColor(c);
c = _c * 0.6f; c[3]=_c[3]; diffuseColor(c);
c = _c * 0.8f; c[3]=_c[3]; specularColor(c);
......@@ -165,6 +168,11 @@ public:
/// get the specular color
const Vec4f& specularColor() const { return specularColor_; }
/// set the overlay color (This can be used to render overlays e.g. additional wireframes in a different color)
void overlayColor(const Vec4f& _s) { overlayColor_ = _s; }
/// get the overlay color (This can be used to render overlays e.g. additional wireframes in a different color)
const Vec4f& overlayColor() const { return overlayColor_; }
/// Set colorMaterial
void colorMaterial( const bool _cm) { colorMaterial_ = _cm; }
/// Enable Color Material
......@@ -263,6 +271,7 @@ protected:
Vec4f ambientColor_;
Vec4f diffuseColor_;
Vec4f specularColor_;
Vec4f overlayColor_;
float shininess_;
double reflectance_;
......@@ -396,6 +405,11 @@ public:
/// get the specular color
const Vec4f& specular_color() const { return material_.specularColor(); }
/// set the overlay color
void set_overlay_color(const Vec4f& _s) { material_.overlayColor(_s); }
/// get the overlay color
const Vec4f& overlay_color() const { return material_.overlayColor(); }
/// Set colorMaterial
void colorMaterial( const bool _cm) { material_.colorMaterial(_cm); }
/// Enable Color Material
......
......@@ -261,8 +261,14 @@ draw(GLState& _state, const DrawModes::DrawMode& _drawMode) {
/// \todo We can render also wireframe shaded and with vertex colors
if (_drawMode & DrawModes::WIREFRAME)
{
// enable_arrays( VERTEX_ARRAY | LINE_INDEX_ARRAY );
_state.set_color( _state.specular_color() );
const Vec4f oldColor = _state.color();
// If the mode is atomic, we use the specular, otherwise we take the overlay color
if (_drawMode.isAtomic() )
_state.set_color( _state.specular_color() );
else
_state.set_color( _state.overlay_color() );
ACG::GLState::disable(GL_LIGHTING);
ACG::GLState::shadeModel(GL_FLAT);
......@@ -270,6 +276,8 @@ draw(GLState& _state, const DrawModes::DrawMode& _drawMode) {
drawMesh_->disableColors();
draw_lines();
_state.set_color(oldColor);
}
if (_drawMode & DrawModes::HIDDENLINE)
......@@ -670,7 +678,11 @@ void ACG::SceneGraph::MeshNodeT<Mesh>::getRenderObjects( IRenderer* _renderer, G
drawMesh_->disableColors();
// use specular color for lines
ro.emissive = ro.specular;
if (_drawMode.isAtomic() )
ro.emissive = ro.specular;
else
ro.emissive = OpenMesh::color_cast<ACG::Vec3f>(_state.overlay_color());
add_line_RenderObjects(_renderer, &ro);
}
......
......@@ -174,6 +174,8 @@ void BaseObjectData::initializeScenegraphNodes() {
materialNode_->set_base_color(colorV);
materialNode_->set_color(colorV);
// We take the brightest color component for overlays to get best contrast
materialNode_->set_overlay_color(materialNode_->specular_color());
}
}
......
......@@ -100,6 +100,9 @@ void INIPlugin::parseIniFile(INIFile& _ini, BaseObjectData* _object) {
if ( _ini.get_entryVecf( col, _object->name() , "SpecularColor" ) )
_object->materialNode()->set_specular_color(col);
if ( _ini.get_entryVecf( col, _object->name() , "OverlayColor" ) )
_object->materialNode()->set_overlay_color(col);
double shininess;
if ( _ini.get_entry( shininess, _object->name() , "Shininess" ) )
_object->materialNode()->set_shininess(shininess);
......@@ -141,6 +144,9 @@ void INIPlugin::saveIniFile(INIFile& _ini, BaseObjectData* _object) {
_ini.add_entryVec( _object->name() ,
"SpecularColor" ,
_object->materialNode()->specular_color());
_ini.add_entryVec( _object->name() ,
"OverlayColor" ,
_object->materialNode()->overlay_color());
_ini.add_entry( _object->name() ,
"Shininess" ,
_object->materialNode()->shininess());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment