把纹理和模型一起打成.IV包(打在包里面的不光是索引)

本文介绍如何使用SoTexture2在iv文件中存储纹理信息。主要通过设置SoTexture2的filename或image属性来实现,其中使用image属性可直接将图片内容嵌入到iv文件内。示例代码展示了创建纹理并将其应用于基本图形的过程。

对于纹理,SoTexture2有几个属性:

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/

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值