Commit de3e7a0d authored by Jan Möbius's avatar Jan Möbius
Browse files

Moved Color Material from MeshNode to MaterialNode and adopted QtMaterialDialog

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5768 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 152be7e7
......@@ -12,12 +12,12 @@
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
//
......@@ -55,14 +55,14 @@
#include <QSlider>
//== NAMESPACES ==============================================================
//== NAMESPACES ==============================================================
namespace ACG {
namespace QtWidgets {
//== IMPLEMENTATION ==========================================================
//== IMPLEMENTATION ==========================================================
QtMaterialDialog::QtMaterialDialog( QWidget * _parent,
......@@ -88,6 +88,7 @@ QtMaterialDialog::QtMaterialDialog( QWidget * _parent,
blending_ = bak_blending_ = node_->blending();
blendParam1_ = bak_blendParam1_ = node_->blending_param1();
blendParam2_ = bak_blendParam2_ = node_->blending_param2();
colorMaterial_ = bak_colorMaterial_ = node_->colorMaterial();
baseColorActive_ = bak_baseColorActive_ = node_->applyProperties() & SceneGraph::MaterialNode::BaseColor;
materialActive_ = bak_materialActive_ = node_->applyProperties() & SceneGraph::MaterialNode::Material;
......@@ -97,6 +98,7 @@ QtMaterialDialog::QtMaterialDialog( QWidget * _parent,
alphaTestActive_ = bak_alphaTestActive_ = node_->applyProperties() & SceneGraph::MaterialNode::AlphaTest;
blendingActive_ = bak_blendingActive_ = node_->applyProperties() & SceneGraph::MaterialNode::Blending;
backfaceCullingActive_ = bak_backfaceCullingActive_ = node_->applyProperties() & SceneGraph::MaterialNode::BackFaceCulling;
colorMaterialActive_ = bak_colorMaterialActive_ = node_->applyProperties() & SceneGraph::MaterialNode::ColorMaterial;
setButtonColor( ui_.baseColorButton, color_ );
setButtonColor( ui_.ambientColorButton, ambient_ );
......@@ -111,6 +113,7 @@ QtMaterialDialog::QtMaterialDialog( QWidget * _parent,
ui_.alphaTest->setChecked( alphaTest_ );
ui_.alpha->setValue((int) alphaValue_ * 100.0f );
ui_.blending->setChecked( blending_ );
ui_.colorMaterial->setChecked( colorMaterial_ );
for (int i=0; i < ui_.blendParam1->count(); i++)
if ( ui_.blendParam1->itemText(i) == paramToStr(blendParam1_) )
......@@ -130,6 +133,7 @@ QtMaterialDialog::QtMaterialDialog( QWidget * _parent,
ui_.alphaTestActive->setChecked( alphaTestActive_ );
ui_.blendingActive->setChecked( blendingActive_ );
ui_.backfaceCullingActive->setChecked( backfaceCullingActive_ );
ui_.colorMaterialActive->setChecked( colorMaterialActive_ );
connect( ui_.baseColorButton, SIGNAL( clicked() ), this, SLOT( enableProperty() ) );
connect( ui_.ambientColorButton, SIGNAL( clicked() ), this, SLOT( enableProperty() ) );
......@@ -142,6 +146,7 @@ QtMaterialDialog::QtMaterialDialog( QWidget * _parent,
connect( ui_.backfaceCulling, SIGNAL( pressed() ), this, SLOT( enableProperty() ) );
connect( ui_.alphaTest, SIGNAL( pressed() ), this, SLOT( enableProperty() ) );
connect( ui_.blending, SIGNAL( pressed() ), this, SLOT( enableProperty() ) );
connect( ui_.colorMaterial, SIGNAL( pressed() ), this, SLOT( enableProperty() ) );
connect( ui_.baseColorButton, SIGNAL( clicked() ),
this, SLOT( changeBaseColor() ) );
......@@ -166,6 +171,8 @@ QtMaterialDialog::QtMaterialDialog( QWidget * _parent,
this, SLOT( changeAlphaTest(bool) ) );
connect( ui_.alpha, SIGNAL( valueChanged(int) ),
this, SLOT( changeAlphaValue(int) ) );
connect( ui_.colorMaterial, SIGNAL( toggled(bool) ),
this, SLOT( changeColorMaterial(bool) ) );
connect( ui_.blending, SIGNAL( toggled(bool) ),
this, SLOT( changeBlending(bool) ) );
connect( ui_.blendParam1, SIGNAL( currentIndexChanged(const QString&) ),
......@@ -173,6 +180,7 @@ QtMaterialDialog::QtMaterialDialog( QWidget * _parent,
connect( ui_.blendParam2, SIGNAL( currentIndexChanged(const QString&) ),
this, SLOT( changeBlendingParam2(const QString&) ) );
connect( ui_.baseColorActive, SIGNAL( toggled(bool) ),
this, SLOT( changeActive(bool) ) );
connect( ui_.materialActive, SIGNAL( toggled(bool) ),
......@@ -187,7 +195,7 @@ QtMaterialDialog::QtMaterialDialog( QWidget * _parent,
this, SLOT( changeActive(bool) ) );
connect( ui_.blendingActive, SIGNAL( toggled(bool) ),
this, SLOT( changeActive(bool) ) );
connect( ui_.backfaceCullingActive, SIGNAL( toggled(bool) ),
connect( ui_.colorMaterialActive, SIGNAL( toggled(bool) ),
this, SLOT( changeActive(bool) ) );
connect( ui_.alphaTest, SIGNAL( toggled(bool) ),
......@@ -197,6 +205,7 @@ QtMaterialDialog::QtMaterialDialog( QWidget * _parent,
connect( ui_.blending, SIGNAL( toggled(bool) ),
ui_.blendParam2, SLOT( setEnabled(bool) ) );
ui_.alpha->setEnabled( ui_.alphaTest->isChecked() );
ui_.blendParam1->setEnabled( ui_.blending->isChecked() );
ui_.blendParam2->setEnabled( ui_.blending->isChecked() );
......@@ -209,6 +218,7 @@ QtMaterialDialog::QtMaterialDialog( QWidget * _parent,
ui_.alphaTestActive->setChecked(alphaTestActive_);
ui_.blendingActive->setChecked(blendingActive_);
ui_.backfaceCullingActive->setChecked(backfaceCullingActive_);
ui_.colorMaterialActive->setChecked(colorMaterialActive_);
connect( ui_.okButton, SIGNAL( clicked() ),
this, SLOT( accept() ) );
......@@ -235,7 +245,7 @@ QtMaterialDialog::setButtonColor( QPushButton * _button,
//-----------------------------------------------------------------------------
QColor
QColor
QtMaterialDialog::convertColor( Vec4f _color)
{
return QColor ((int)(_color[0]*255.0),
......@@ -248,12 +258,12 @@ QtMaterialDialog::convertColor( Vec4f _color)
//-----------------------------------------------------------------------------
Vec4f
Vec4f
QtMaterialDialog::convertColor( QColor _color)
{
return Vec4f (_color.redF(),
_color.greenF(),
_color.blueF(),
_color.greenF(),
_color.blueF(),
_color.alphaF() );
}
......@@ -284,6 +294,7 @@ void QtMaterialDialog::applyChanges()
if (alphaTestActive_) properties = properties | SceneGraph::MaterialNode::AlphaTest;
if (blendingActive_) properties = properties | SceneGraph::MaterialNode::Blending;
if (backfaceCullingActive_) properties = properties | SceneGraph::MaterialNode::BackFaceCulling;
if (colorMaterialActive_) properties = properties | SceneGraph::MaterialNode::ColorMaterial;
node_->applyProperties(properties);
......@@ -311,6 +322,11 @@ void QtMaterialDialog::applyChanges()
else
node_->disable_blending();
if ( colorMaterial_ )
node_->enable_color_material();
else
node_->disable_color_material();
// this is not optimal !
if(round_points_)
node_->enable_alpha_test(0.5);
......@@ -342,6 +358,7 @@ void QtMaterialDialog::undoChanges()
if (bak_alphaTestActive_) properties = properties | SceneGraph::MaterialNode::AlphaTest;
if (bak_blendingActive_) properties = properties | SceneGraph::MaterialNode::Blending;
if (bak_backfaceCullingActive_) properties = properties | SceneGraph::MaterialNode::BackFaceCulling;
if (bak_colorMaterialActive_) properties = properties | SceneGraph::MaterialNode::ColorMaterial;
node_->applyProperties(properties);
......@@ -369,6 +386,11 @@ void QtMaterialDialog::undoChanges()
else
node_->disable_blending();
if ( bak_colorMaterial_ )
node_->enable_color_material();
else
node_->disable_color_material();
setButtonColor( ui_.diffuseColorButton, diffuse_ );
setButtonColor( ui_.ambientColorButton, ambient_ );
setButtonColor( ui_.specularColorButton, specular_ );
......@@ -511,6 +533,14 @@ QtMaterialDialog::changeAlphaTest(bool _b)
//-----------------------------------------------------------------------------
void
QtMaterialDialog::changeColorMaterial(bool _b)
{
colorMaterial_ = (bool)_b;
applyChanges();
}
//-----------------------------------------------------------------------------
void
QtMaterialDialog::changeAlphaValue(int _new)
......@@ -594,6 +624,7 @@ QtMaterialDialog::changeActive(bool /*toggle*/)
roundPointsActive_ = ui_.roundPointsActive->isChecked();
blendingActive_ = ui_.blendingActive->isChecked();
backfaceCullingActive_ = ui_.backfaceCullingActive->isChecked();
colorMaterialActive_ = ui_.colorMaterialActive->isChecked();
applyChanges();
}
......@@ -614,6 +645,7 @@ QtMaterialDialog::enableProperty(int /*i*/)
else if (sender() == ui_.backfaceCulling) ui_.backfaceCullingActive->setChecked( true );
else if (sender() == ui_.alphaTest) ui_.alphaTestActive->setChecked( true );
else if (sender() == ui_.blending) ui_.blendingActive->setChecked( true );
else if (sender() == ui_.colorMaterial) ui_.colorMaterialActive->setChecked( true );
}
//-----------------------------------------------------------------------------
......@@ -633,6 +665,7 @@ QtMaterialDialog::enableProperty()
else if (sender() == ui_.backfaceCulling) ui_.backfaceCullingActive->setChecked( true );
else if (sender() == ui_.alphaTest) ui_.alphaTestActive->setChecked( true );
else if (sender() == ui_.blending) ui_.blendingActive->setChecked( true );
else if (sender() == ui_.colorMaterial) ui_.colorMaterialActive->setChecked( true );
}
......
......@@ -116,6 +116,7 @@ private slots:
void changeBlending(bool _b);
void changeBlendingParam1(const QString& _name);
void changeBlendingParam2(const QString& _name);
void changeColorMaterial(bool _b);
void changeActive(bool toggle);
......@@ -149,6 +150,7 @@ private:
bool blending_, bak_blending_;
GLenum blendParam1_, bak_blendParam1_;
GLenum blendParam2_, bak_blendParam2_;
bool colorMaterial_, bak_colorMaterial_;
bool baseColorActive_, bak_baseColorActive_;
bool materialActive_, bak_materialActive_;
......@@ -158,6 +160,7 @@ private:
bool alphaTestActive_, bak_alphaTestActive_;
bool blendingActive_, bak_blendingActive_;
bool backfaceCullingActive_, bak_backfaceCullingActive_;
bool colorMaterialActive_, bak_colorMaterialActive_;
SceneGraph::MaterialNode * node_;
......
......@@ -5,8 +5,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>524</width>
<height>538</height>
<width>616</width>
<height>601</height>
</rect>
</property>
<property name="sizePolicy" >
......@@ -405,7 +405,7 @@
</item>
</layout>
</item>
<item row="2" column="0" >
<item row="3" column="0" >
<widget class="QCheckBox" name="blending" >
<property name="layoutDirection" >
<enum>Qt::LeftToRight</enum>
......@@ -415,7 +415,7 @@
</property>
</widget>
</item>
<item row="3" column="1" >
<item row="4" column="1" >
<widget class="QComboBox" name="blendParam1" >
<property name="currentIndex" >
<number>1</number>
......@@ -492,7 +492,7 @@
</item>
</widget>
</item>
<item row="4" column="1" >
<item row="5" column="1" >
<widget class="QComboBox" name="blendParam2" >
<item>
<property name="text" >
......@@ -566,6 +566,13 @@
</item>
</widget>
</item>
<item row="2" column="0" >
<widget class="QCheckBox" name="colorMaterial" >
<property name="text" >
<string>Color Material</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
......@@ -646,6 +653,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="colorMaterialActive" >
<property name="text" >
<string>Color Material</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
......
......@@ -43,6 +43,7 @@
#include "MaterialNode.hh"
#include "DrawModes.hh"
//== NAMESPACES ===============================================================
......@@ -72,6 +73,7 @@ MaterialNode::MaterialNode( BaseNode* _parent,
blending_(false),
blend_param1_(GL_ONE),
blend_param2_(GL_ZERO),
color_material_(true),
backface_culling_(false)
{}
......@@ -79,7 +81,7 @@ MaterialNode::MaterialNode( BaseNode* _parent,
//----------------------------------------------------------------------------
void MaterialNode::enter(GLState& _state, unsigned int /* _drawmode */ )
void MaterialNode::enter(GLState& _state, unsigned int _drawmode )
{
if (applyProperties_ & BaseColor)
{
......@@ -171,7 +173,21 @@ void MaterialNode::enter(GLState& _state, unsigned int /* _drawmode */ )
glEnable( GL_CULL_FACE );
else
glDisable( GL_CULL_FACE );
}
}
if ( ( applyProperties_ & ColorMaterial ) && ( (_drawmode & DrawModes::SOLID_FACES_COLORED_FLAT_SHADED) ||
(_drawmode & DrawModes::SOLID_2DTEXTURED_FACE_SHADED) ) )
{
color_material_backup_ = glIsEnabled(GL_COLOR_MATERIAL);
if (color_material_ ) {
glDisable( GL_COLOR_MATERIAL );
glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
glEnable( GL_COLOR_MATERIAL );
} else
glDisable( GL_COLOR_MATERIAL );
}
}
//----------------------------------------------------------------------------
......@@ -191,7 +207,7 @@ void MaterialNode::leavePick(GLState& /*_state*/,
//----------------------------------------------------------------------------
void MaterialNode::leave(GLState& _state, unsigned int /* _drawmode */ )
void MaterialNode::leave(GLState& _state, unsigned int _drawmode )
{
if (applyProperties_ & BaseColor)
{
......@@ -267,6 +283,16 @@ void MaterialNode::leave(GLState& _state, unsigned int /* _drawmode */ )
else
glDisable( GL_CULL_FACE );
}
if ( ( applyProperties_ & ColorMaterial ) && ( (_drawmode & DrawModes::SOLID_FACES_COLORED_FLAT_SHADED) ||
(_drawmode & DrawModes::SOLID_2DTEXTURED_FACE_SHADED) ) )
{
if (color_material_backup_ ) {
glEnable( GL_COLOR_MATERIAL );
} else
glDisable( GL_COLOR_MATERIAL );
}
}
......
......@@ -90,78 +90,130 @@ public:
/// use blending
Blending=64,
/// backface culling
BackFaceCulling=128
BackFaceCulling=128,
/// Color Material ( Only when a drawmode using shading and lighting is enabled )
ColorMaterial=256
};
/// Default constructor. Applies all properties.
MaterialNode( BaseNode* _parent = 0,
const std::string& _name = "<MaterialNode>",
unsigned int _applyProperties = (All &
~BackFaceCulling));
const std::string& _name = "<MaterialNode>",
unsigned int _applyProperties = (All & ~BackFaceCulling));
/// Destructor.
virtual ~MaterialNode() {};
ACG_CLASSNAME(MaterialNode);
/// read MaterialFile
void read( std::istream & _is);
//===========================================================================
/** @name Scenegraph functions
* @{ */
//===========================================================================
ACG_CLASSNAME(MaterialNode);
/// set current GL-color and GL-material
void enter(GLState& _state, unsigned int _drawmode);
/// restores original GL-color and GL-material
void leave(GLState& _state, unsigned int _drawmode);
/// set current GL-color and GL-material
void enter(GLState& _state, unsigned int _drawmode);
/// restores original GL-color and GL-material
void leave(GLState& _state, unsigned int _drawmode);
/** \brief Do nothing in picking
*/
void enterPick(GLState& _state, PickTarget _target, unsigned int _drawMode );
/** \brief Do nothing in picking
*/
void leavePick(GLState& _state, PickTarget _target, unsigned int _drawMode );
/** \brief Do nothing in picking*/
void enterPick(GLState& _state, PickTarget _target, unsigned int _drawMode );
/** \brief Do nothing in picking */
void leavePick(GLState& _state, PickTarget _target, unsigned int _drawMode );
/// get properties that will be applied (OR'ed ApplyProperties)
unsigned int applyProperties() const { return applyProperties_; }
/// set properties that will be applied (OR'ed ApplyProperties)
void applyProperties(unsigned int _applyProperties) {
applyProperties_ = _applyProperties;
}
/** @} */
//===========================================================================
/** @name Color settings ( Applied to all objects below this node )
* @{ */
//===========================================================================
/// set color (base, ambient, diffuse, specular) based on _c
void set_color(const Vec4f& _c) {
Vec4f c;
set_base_color(_c);
c = _c * 0.2f; c[3]=_c[3]; set_ambient_color(c);
c = _c * 0.6f; c[3]=_c[3]; set_diffuse_color(c);
c = _c * 0.8f; c[3]=_c[3]; set_specular_color(c);
}
/// set color (base, ambient, diffuse, specular) based on _c
void set_color(const Vec4f& _c) {
Vec4f c;
set_base_color(_c);
c = _c * 0.2f; c[3]=_c[3]; set_ambient_color(c);
c = _c * 0.6f; c[3]=_c[3]; set_diffuse_color(c);
c = _c * 0.8f; c[3]=_c[3]; set_specular_color(c);
}
/// set the base color
void set_base_color(const Vec4f& _c) { base_color_ = _c;}
/// get the base color
const Vec4f& base_color() const { return base_color_; }
/// set the ambient color.
void set_ambient_color(const Vec4f& _a) { ambient_color_ = _a; }
/// get the ambient color.
const Vec4f& ambient_color() const { return ambient_color_; }
/// set the diffuse color.
void set_diffuse_color(const Vec4f& _d) { diffuse_color_ = _d; }
/// get the diffuse color.
const Vec4f& diffuse_color() const { return diffuse_color_; }
/// set the specular color
void set_specular_color(const Vec4f& _s) { specular_color_ = _s; }
/// get the specular color
const Vec4f& specular_color() const { return specular_color_; }
/// Set colorMaterial
void colorMaterial( const bool _colorMaterial) { color_material_ = _colorMaterial; }
/// Enable Color Material
void enable_color_material() { color_material_ = true; }
/// Disable Color Material
void disable_color_material() { color_material_ = false; }
/// get colorMaterial state
bool colorMaterial() { return color_material_; }
/** @} */
//===========================================================================
/** @name Point/Line controls
* @{ */
//===========================================================================
/// set point size (default: 1.0)
void set_point_size(float _sz) { point_size_ = _sz; }
/// get point size
float point_size() const { return point_size_; }
/// set line width (default: 1.0)
void set_line_width(float _sz) { line_width_ = _sz; }
/// get line width
float line_width() const { return line_width_; }
/// set: round points enabled
void set_round_points(bool _b) { round_points_ = _b; }
/// get: round points enabled
bool round_points() const { return round_points_; }
/// set the base color
void set_base_color(const Vec4f& _c) { base_color_ = _c;}
/// get the base color
const Vec4f& base_color() const { return base_color_; }
/** @} */
/// set the ambient color.
void set_ambient_color(const Vec4f& _a) { ambient_color_ = _a; }
/// get the ambient color.
const Vec4f& ambient_color() const { return ambient_color_; }
//===========================================================================
/** @name Tests
* @{ */
//===========================================================================
/// enable alpha test (draw pixels if alpha >= _clip)
void enable_alpha_test(float _clip) {
alpha_test_ = true; alpha_clip_ = _clip;
}
/// disable alpha test
void disable_alpha_test() { alpha_test_ = false; }
/// Return state of Alpha test
bool alpha_test() { return alpha_test_; };
/** @} */
/// set the diffuse color.
void set_diffuse_color(const Vec4f& _d) { diffuse_color_ = _d; }
/// get the diffuse color.
const Vec4f& diffuse_color() const { return diffuse_color_; }
/// set the specular color
void set_specular_color(const Vec4f& _s) { specular_color_ = _s; }
/// get the specular color
const Vec4f& specular_color() const { return specular_color_; }
/// set shininess
void set_shininess(float _s) { shininess_ = _s; }
......@@ -169,33 +221,10 @@ public:
float shininess() const { return shininess_; }
/// set point size (default: 1.0)
void set_point_size(float _sz) { point_size_ = _sz; }
/// get point size
float point_size() const { return point_size_; }
/// set line width (default: 1.0)
void set_line_width(float _sz) { line_width_ = _sz; }
/// get line width
float line_width() const { return line_width_; }
/// set: round points enabled
void set_round_points(bool _b) { round_points_ = _b; }
/// get: round points enabled
bool round_points() const { return round_points_; }
/// enable alpha test (draw pixels if alpha >= _clip)
void enable_alpha_test(float _clip) {
alpha_test_ = true; alpha_clip_ = _clip;
}
/// disable alpha test
void disable_alpha_test() { alpha_test_ = false; }
///get current alpha value for alpha_test
float alpha_value(){ return alpha_clip_; };
bool alpha_test() { return alpha_test_; };
bool blending() { return blending_; };
GLenum blending_param1() { return blend_param1_; };
......@@ -215,6 +244,13 @@ public:
/// disable backface culling (not active by default, see applyProperties)
void disable_backface_culling() { backface_culling_ = false; }
/// get properties that will be applied (OR'ed ApplyProperties)
unsigned int applyProperties() const { return applyProperties_; }
/// set properties that will be applied (OR'ed ApplyProperties)
void applyProperties(unsigned int _applyProperties) {
applyProperties_ = _applyProperties;
}
private:
......@@ -239,6 +275,7 @@ private:
GLenum blend_param1_, blend_param1_backup_;
GLenum blend_param2_, blend_param2_backup_;
bool color_material_,color_material_backup_;
bool backface_culling_, backface_culling_backup_;
};
......
......@@ -699,22 +699,13 @@ draw(GLState& _state, unsigned int _drawMode)
if ( ( _drawMode & DrawModes::SOLID_FACES_COLORED_FLAT_SHADED ) && mesh_.has_face_colors() && mesh_.has_face_normals())
{
Vec4f base_color_backup = _state.base_color();
GLboolean colMaterial;
glEnable(GL_LIGHTING);
colMaterial = glIsEnabled(GL_COLOR_MATERIAL);
glColorMaterial( GL_FRONT_AND_BACK,</