|
本帖最后由 rubby 于 2014-7-16 13:55 编辑
各位大哥:
我在编写程序的时候发现:
osg color颜色值 与 windows 颜色编辑对话框明显不同。
比如:
在windows 颜色编辑对话框中,RGB值分别是 255,128,0 的颜色如附件(windows颜色对话框.jpg)
中所示。
而osg中osg::vec4 color(255,128,0,255) 颜色 如附件 (osg color.jpg)所示,两者颜色明显不一样。
两个颜色:一个是桔红色,一个是偏黄色。
我的测试程序如下,在osg中将颜色设置为 osg::vec4 color(255,128,0,255) :
- #include <osgViewer/ViewerEventHandlers>
- #include <osgGA/StateSetManipulator>
- #include<osgDB/ReadFile>
- #include <osgDB/Registry>
- #include <osgDB/WriteFile>
- #include <osg/MatrixTransform>
- #include <osg/StateSet>
- #include <osg/StateAttribute>
- #include <osg/ShadeModel>
- #include<osg/CullFace>
- #include <osg/PolygonMode>
- #include <osg/LineWidth>
- #include <osg/Material>
- #include <osg/Light>
- #include <osg/NodeCallback>
- #include <osg/LightSource>
- #include <osg/Notify>
- #include <osg/CullFace>
- #include <osg/Point>
- #include<osgText/Font>
- #include <osgText/Text>
- #include <osg/AlphaFunc>
- #include<osg/BlendFunc>
- #include<osg/Texture>
- #include <osgutil/SmoothingVisitor>
- #include <osgViewer/CompositeViewer>
- #include <osg/ImageSequence>
- #include <osg/PositionAttitudeTransform>
- #include <osg/AutoTransform>
- #include <osg/LOD>
- #include <osg/DrawPixels>
- void setupTextPro2(osgText::Text &textObject, osgText::Font* font, float size, const osg::Vec3& vec3){
- textObject.setFont(font);
- textObject.setCharacterSize(size);
- textObject.setPosition(vec3);
- textObject.setColor(osg::Vec4(0.0,0.0,1.0,1.0));
- textObject.setAlignment(osgText::Text::CENTER_BOTTOM);
- textObject.setAxisAlignment(osgText::Text::XZ_PLANE);
- }
- void createText2(osgText::Text&textObject, const char* string){
- int requiredSize = mbstowcs(NULL,string,0);
- wchar_t* wtext = new wchar_t[requiredSize+1];
- mbstowcs(wtext,string,requiredSize+1);
- textObject.setText(wtext);
- delete wtext;
- }
- /************************************************************************/
- /* 测试RGB颜色在OSG中的显示 */
- /************************************************************************/
- int main(){
- setlocale(LC_ALL,".936");
- const char* titleString ="Test Color";
- const char* textString ={"3D"};
- osgText::Font* fontHei= osgText::readFontFile("Fonts/simhei.ttf");
- osgText::Font* fontKai = osgText::readFontFile("Fonts/simkai.ttf");
- osg::ref_ptr<osgText::Text> title = new osgText::Text;
- setupTextPro2(*title, fontHei, 20.0f, osg::Vec3(0.0,0.0,0.0));
- createText2(*title,titleString);
- osg::ref_ptr<osgText::Text> text = new osgText::Text;
- setupTextPro2(*text, fontKai, 15.0f, osg::Vec3(0.0,0.0,-80.0));
- createText2(*text,textString);
- osg::ref_ptr<osg::Geode> geode = new osg::Geode;
- osg::ref_ptr<osg::Geometry> geom = osg::createTexturedQuadGeometry(osg::Vec3(-150.0,0.0,-100.0), //左下角,不是corner
- osg::Vec3(300.0,0.0,0.0),
- osg::Vec3(0.0,0.0,200.0), 1.0,1.0);
- osg::ref_ptr<osg::Vec4Array> color = new osg::Vec4Array;
- color->push_back(osg::Vec4(255,128,0,255)); //=========================此处为我设置的颜色
- geom->setColorArray(color.get());
- geom->setColorBinding(osg::Geometry::BIND_OVERALL);
- geode->addDrawable(geom);
- geode->addDrawable(title.get());
- geode->addDrawable(text.get()); //不增加这个,否则导致
- //无光照
- osg::StateSet* state = geode->getOrCreateStateSet();
- state->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
- state->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);//关闭深度测试
- //打开GL_BLEND混合模式(以保证Alpha纹理正确)
- state->setMode(GL_BLEND,osg::StateAttribute::ON);
-
- osgViewer::Viewer viewer;
- viewer.addEventHandler(new osgViewer::WindowSizeHandler);
- viewer.setSceneData(geode.get());
- return viewer.run();
- }
复制代码
哪位大哥帮我看下,这是什么原因,用什么方式可以是他们保持一致呢?
|
|