|
1.新建6个osg::Image- for(unsigned int i = 0; i < 6; i++)
- {
- image_data[i] = new unsigned char[512*512*3];
- cube_surface[i] = new osg::Image;
- cube_surface[i]->setImage(512,512,
- 1,GL_LINE_STRIP,GL_BGR,GL_UNSIGNED_BYTE,(BYTE*)image_data[i],
- osg::Image::AllocationMode::USE_NEW_DELETE);
- }
复制代码 2.初始化Skybox的cubemap- void SkyBox::setEnvironmentMap( unsigned int unit, osg::Image* posX, osg::Image* negX,
- osg::Image* posY, osg::Image* negY, osg::Image* posZ, osg::Image* negZ )
- {
- if ( posX && posY && posZ && negX && negY && negZ )
- {
- osg::ref_ptr<osg::TextureCubeMap> cubemap = new osg::TextureCubeMap;
- cubemap->setImage( osg::TextureCubeMap::POSITIVE_X, posX );
- cubemap->setImage( osg::TextureCubeMap::NEGATIVE_X, negX );
- cubemap->setImage( osg::TextureCubeMap::POSITIVE_Y, posY );
- cubemap->setImage( osg::TextureCubeMap::NEGATIVE_Y, negY );
- cubemap->setImage( osg::TextureCubeMap::POSITIVE_Z, posZ );
- cubemap->setImage( osg::TextureCubeMap::NEGATIVE_Z, negZ );
- cubemap->setWrap( osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE );
- cubemap->setWrap( osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE );
- cubemap->setWrap( osg::Texture::WRAP_R, osg::Texture::CLAMP_TO_EDGE );
- cubemap->setFilter( osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR );
- cubemap->setFilter( osg::Texture::MAG_FILTER, osg::Texture::LINEAR );
- cubemap->setResizeNonPowerOfTwoHint( false );
- getOrCreateStateSet()->setTextureAttributeAndModes( unit, cubemap.get() );
- }
- }
复制代码 3.在计时器函数OnTimer中,动态地改变每个osg::Image的数据- for (unsigned int f = 0; f < 6; f++)
- {
- m_camera.getCubeMap(&cube_image,f);
-
- memcpy(image_data[f],cube_image.pData,512*512*3);
- }
复制代码 可是,什么也没有显示,如下图:
是灰色的。我估计是新建时候的数据。
但是我调试发现memcpy()函数之后原始的Image确实改变了。
也就是说,cubemap没有及时更新。
那么,问题就是怎么让cubemap动态地更新图像。 |
|