|
在网上搜过很多资料,照这样子写,就是Repeat不了,始终只贴了一个纹理。请教一下高手,我错在哪了?谢谢!
代码:
//-----头文件------//
#include <osg/Node>
#include <osg/Group>
#include <osg/Geode>
#include <osg/Geometry>
#include <osg/Texture2D>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osgViewer/Viewer>
#include <osg/TexEnv>
#include <osg/TexGen>
#include <osg/StateSet>
#include <osgViewer/ViewerEventHandlers>
#include <osgGA/StateSetManipulator>
#include <osg/PositionAttitudeTransform>
#include <osgGA/TrackballManipulator>
#include <osg/ImageStream>
……
osg::Geode* geode = new osg::Geode;//创建几何节点
//画一个可体贴纹理的几何方块,并加到几何节点上(三个坐标是我个人理解,我觉得OSG做得很奇怪)
geode->addDrawable(osg::createTexturedQuadGeometry(osg::Vec3(0.0f,0.0f,0.0f), //左下角点
osg::Vec3(230.0f,0.0f,0.0f), //右下角点
osg::Vec3(0.0f,0.0f,130.0f)));//坐上角点
osg::Texture2D* PICT = new osg::Texture2D; //创建二维纹理对象
osg::Image* pure = osgDB::readImageFile("negx.gif") ;//读图片
osg::ImageStream* ImStr = dynamic_cast<osg::ImageStream*>(pure);//设置动态
if (ImStr) ImStr->play();//如果图片有动态,则播放
PICT->setImage(pure);//将图片pure设为纹理
//设置为重复,我三个方向都设了,没用,它就是不重复
PICT->setWrap(osg::Texture::WRAP_S,osg::Texture::REPEAT);
PICT->setWrap(osg::Texture::WRAP_T,osg::Texture::REPEAT);
PICT->setWrap(osg::Texture::WRAP_R,osg::Texture::REPEAT);
//设置纹理去黑边
PICT->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE);
PICT->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE);
osg::StateSet* state1= new osg::StateSet();//创建渲染状态
state1->setTextureAttributeAndModes(0,PICT,osg::StateAttribute::ON);//将纹理PICT加入到状态中
geode->setStateSet(state1);//将状态state1设为几何节点的状态
……
[ 本帖最后由 sdd548 于 2009-7-6 16:28 编辑 ] |
|