Open Inventor显示纹理相对OpenGL简单许多,SoTexture2节点可以非常方便的完成复杂的纹理操作,一下是一个纹理演示的例子,虽然比较简单,但是纹理的功能已经表现出来了。代码如下
#define COIN_DLL
#define SOWIN_DLL
// 加载COIN库文件
#ifdef _DEBUG
#pragma comment(lib, "SoWin1d.lib")
#pragma comment(lib, "Coin3d.lib")
#else
#pragma comment(lib, "SoWin1.lib")
#pragma comment(lib, "Coin3.lib")
#endif
// 添加COIN头文件-Window操作显示库和节点库
#include <Inventor/Win/SoWin.h>
#include <Inventor/Win/viewers/SoWinExaminerViewer.h>
#include <Inventor/nodes/SoCube.h>
#include <Inventor/nodes/SoRotor.h>
#include <Inventor/nodes/SoTexture2.h>
#include <Inventor/nodes/SoSeparator.h>
int main(int argc, char ** argv)
{
HWND mainwin = SoWin::init(argc, argv, argv[0]);
SoSeparator * root = new SoSeparator;
root->ref();
SoRotor * rotor = new SoRotor;
rotor->rotation.setValue(SbVec3f(0, 0, 1), 1.5707963f);
rotor->speed.setValue(0.05f);
SoTexture2 * texture = new SoTexture2;
texture->filename.setValue("elf.tga");
SoCube * cube = new SoCube;
root->addChild(rotor);
root->addChild(texture);
root->addChild(cube);
SoWinExaminerViewer * eviewer = new SoWinExaminerViewer(mainwin);
eviewer->setSceneGraph(root);
eviewer->setDecoration(FALSE);
eviewer->setTitle("a simple textured cube");
eviewer->show();
SoWin::show(mainwin);
SoWin::mainLoop();
delete eviewer;
root->unref();
return 0;
}
IV文件如下
#Inventor V2.1 ascii
Separator {
Rotor {
rotation 0 0 1 0
speed 0.05
}
Texture2 { filename "elf.tga" }
Cube { }
}
贴图纹理文件可以在此链接下载
http://download.csdn.net/detail/soprettyzz/2660647
运行结果如下