diff --git a/examples/osgterrain/osgterrain.cpp b/examples/osgterrain/osgterrain.cpp index ceb420842..3f60f8ab9 100644 --- a/examples/osgterrain/osgterrain.cpp +++ b/examples/osgterrain/osgterrain.cpp @@ -164,6 +164,28 @@ int main(int argc, char** argv) } } + float minValue, maxValue; + if (arguments.read("--tf",minValue, maxValue)) + { + readParameter = true; + + osg::ref_ptr tf = new osg::TransferFunction1D; + + tf->setInputRange(minValue, maxValue); + + tf->allocate(6); + tf->setValue(0, osg::Vec4(1.0,1.0,1.0,1.0)); + tf->setValue(1, osg::Vec4(1.0,0.0,1.0,1.0)); + tf->setValue(2, osg::Vec4(1.0,0.0,0.0,1.0)); + tf->setValue(3, osg::Vec4(1.0,1.0,0.0,1.0)); + tf->setValue(4, osg::Vec4(0.0,1.0,1.0,1.0)); + tf->setValue(5, osg::Vec4(0.0,1.0,0.0,1.0)); + + osg::notify(osg::NOTICE)<<"--tf "<setColorTransferFunction(tf.get()); + } + } while (readParameter); diff --git a/include/osg/TransferFunction b/include/osg/TransferFunction index 763881ea6..b1af8bae9 100644 --- a/include/osg/TransferFunction +++ b/include/osg/TransferFunction @@ -63,7 +63,7 @@ class OSG_EXPORT TransferFunction1D : public osg::TransferFunction unsigned int getNumberCellsX() const { return _colors.size(); } - osg::Vec4& getValue(unsigned int i) { return _colors[i]; } + void setValue(unsigned int i, const osg::Vec4& color) { _colors[i] = color; if (_image.valid()) _image->dirty(); } const osg::Vec4& getValue(unsigned int i) const { return _colors[i]; } protected: diff --git a/src/osg/TransferFunction.cpp b/src/osg/TransferFunction.cpp index c9ad121af..a68655f80 100644 --- a/src/osg/TransferFunction.cpp +++ b/src/osg/TransferFunction.cpp @@ -46,6 +46,8 @@ void TransferFunction1D::setInputRange(float minimum, float maximum) void TransferFunction1D::allocate(unsigned int numX) { _colors.resize(numX); + _image = new osg::Image; + _image->setImage(numX,1,1,GL_RGBA, GL_RGBA, GL_FLOAT, (unsigned char*)&_colors[0], osg::Image::NO_DELETE); } void TransferFunction1D::clear(const osg::Vec4& color)