qt中ogre與QPainter混合

兩個想法,一是繪製內容託管給QT繪製,二是全部託管給Ogre的3D繪製

後者國外有人實現了,用的是ogreoverlay的方法,關鍵是用了qt與ogre兩者通用的一種像素格式A8R8G8B8,通過static_cast把ogre的紋理內容轉爲QImage,因此可以用QPainter來改變OverLay紋理

http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Ogre%20overlays%20using%20Qt

前者的實現要點:

當然關鍵還是溝通兩者的QImage::Format_ARGB32格式

(這個方法只能在opengl模式下用,directx下會報錯,因爲不允許鎖定RenderTarget,要用blitFromMemory,格式匹配有些麻煩,還沒實現)

Ogre::HardwarePixelBufferSharedPtr pixelBuffer = texture->getBuffer();
pixelBuffer->lock(Ogre::HardwareBuffer::HBL_NORMAL);
const Ogre::PixelBox& pixelBox = pixelBuffer->getCurrentLock();
Ogre::uint8* pDest = static_cast<Ogre::uint8*>(pixelBox.data);
ogreImage = QImage(pDest,texture->getWidth(),texture->getHeight(),QImage::Format_ARGB32);
painter.drawImage(0,0,ogreImage);
pixelBuffer->unlock();

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章