SoSFString filename
SoSFImage image
常用的是filename,这样在iv里保存的是文件名称.如果使用image,则把图片内容保存到iv文件里.可以实现要求目标.
//------------------例子---------------------
int _tmain(int argc, _TCHAR* argv[])
{
//
Widget myWindow = SoXt::init(argv[0]);
if (myWindow == NULL)
exit(1);
SoSeparator *root = new SoSeparator;
root->ref();
unsigned char bytes[32*32];
int con=0;
for (int i=0;i<32;i++)
{
for (int j=0;j<32;j++)
{
bytes[con++]=80+60*sin(0.5*i)+60*cos(0.5*j);
}
}
SoTexture2 *texture=new SoTexture2;
texture->image.setValue(SbVec2s(32,32),1,bytes);
root->addChild(texture);
SoCoordinate3 *coord=new SoCoordinate3;
coord->point.set1Value(0,0,0,0);
coord->point.set1Value(1,0,1,0);
coord->point.set1Value(2,1,1,0);
coord->point.set1Value(3,1,0,0);
root->addChild(coord);
SoFaceSet *face=new SoFaceSet;
face->numVertices.setValue(4);
root->addChild(face);
// Set up viewer:
SoXtExaminerViewer *myViewer = new SoXtExaminerViewer(myWindow);
myViewer->setSceneGraph(root);
myViewer->setTitle("Examiner Viewer");
myViewer->show();
SoXt::show(myWindow);
SoXt::mainLoop();
SbString ivFile;
ivFile="demo.iv";
SoWriteAction wa;
wa.getOutput()->setBinary(true);
wa.getOutput()->openFile(ivFile.getString());
wa.apply(root);
wa.getOutput()->closeFile();
root->unref();
return 0;
}
http://tanghg678.blog.163.com/blog/static/1292320520070882813605/
最新评论