Ogre 中将Texture转成本地任意格式图片
来源:互联网 发布:淘宝客双十一怎么赚钱 编辑:程序博客网 时间:2024/06/05 17:26
bool _saveTextureToLocal(Ogre::TexturePtr texPtr, const Ogre::String& fileName)
{
Ogre::HardwarePixelBufferSharedPtr tmpTexBuf = texPtr->getBuffer();
int width = texPtr->getWidth();
int height= texPtr->getHeight();
char* tmpBuf = new char[width*height*4];
Ogre::PixelBox tmpBox(width,
height,
texPtr->getDepth(),
texPtr->getFormat(),
tmpBuf);
tmpTexBuf->blitToMemory(tmpBox);
TexturePtr tmpTexPtr = TextureManager::getSingleton().createManual ( fileName, "General",
TEX_TYPE_2D, texPtr->getWidth(), texPtr->getHeight(), 1, 0, PF_A8B8G8R8 );
tmpTexPtr->load();
HRESULT hr;
IDirect3DSurface9 *pDstSurface = 0;
Ogre::D3D9Texture *d3dTex = reinterpret_cast< D3D9Texture * >(tmpTexPtr.get());
RECT dstRC = {0, 0, d3dTex->getWidth(), d3dTex->getHeight()};
if( FAILED( hr = d3dTex->getNormTexture()->GetSurfaceLevel(0, &pDstSurface) ) )
{
return false;
}
size_t rowWidth;
if (PixelUtil::isCompressed(tmpBox.format))
{
// D3D wants the width of one row of cells in bytes
if (tmpBox.format == PF_DXT1)
{
// 64 bits (8 bytes) per 4x4 block
rowWidth = (tmpBox.rowPitch / 4) * 8;
}
else
{
// 128 bits (16 bytes) per 4x4 block
rowWidth = (tmpBox.rowPitch / 4) * 16;
}
}
else
{
rowWidth = tmpBox.rowPitch * PixelUtil::getNumElemBytes(tmpBox.format);
}
if( FAILED( hr = D3DXLoadSurfaceFromMemory(
pDstSurface, NULL, &dstRC, tmpBox.data,
Ogre::D3D9Mappings::_getPF( tmpBox.format),
rowWidth, 0,
&dstRC, D3DX_FILTER_TRIANGLE | D3DX_FILTER_DITHER, 0)) )
{
SAFE_RELEASE(pDstSurface);
return false;
}
Ogre::HardwarePixelBufferSharedPtr tmpDesTexBuf = tmpTexPtr->getBuffer();
char* tmpDesBuf = new char[width*height*4];
Ogre::PixelBox tmpDesBox(width,
height,
tmpTexPtr->getDepth(),
tmpTexPtr->getFormat(),
tmpDesBuf);
tmpDesTexBuf->blitToMemory(tmpDesBox);
Ogre::Image image;
image.loadDynamicImage((Ogre::uchar*)tmpDesBox.data, tmpDesBox.getWidth(), tmpDesBox.getHeight(), tmpDesBox.format);
image.save(fileName);
delete [] tmpDesBuf;
delete [] tmpBuf;
tmpTexPtr.setNull();
return true;
}
- Ogre 中将Texture转成本地任意格式图片
- 图片怎样转成pdf格式
- lua中将表转成json格式的字符串
- Ogre Texture-based Shadows
- Ogre:render to texture
- Ogre:render to texture
- android 中将bitmap保存为本地图片
- JS中将毫秒转换成任意日期格式
- base64解码后转成图片到本地
- Symbian下 把任意 格式的字符串 转成Unicode
- C#中任意类型数据转成JSON格式数据输出
- C#中任意类型数据转成JSON格式数据输出
- C#中任意类型数据转成JSON格式数据输出
- C#中任意类型数据转成JSON格式
- 任意格式文件转成字符串,传输之后,还原为原文件格式
- Unity之讲Texture图片转换成Sprite格式
- Ogre中的render to texture.
- Java将网络地址对应的图片转成本地的图片
- Excel批量修改超链接
- 一个简单std::cout 引出的学习
- Goodbye to CSS Hack
- vs2005 TreeView控件 根节点点击文字即展开
- 基础学习--表的存储参数(三)
- Ogre 中将Texture转成本地任意格式图片
- native2ascii 的用法
- 让系统 idle 时更省电_采用平台相关 idle 函数以降低平均功耗的一个实践
- MFC中基于对话框程序快捷键的实现
- 增加linux的swap空间
- 读书笔记--VC6.0高级调试技巧
- 【小阅读^大脑袋】0402 NO.348
- vc++文件目录的删除
- __initdata 的奇怪影响