开发者

How to render Qt4 QPixmap to Ogre 3D Texture or Mesh? Please advise

开发者 https://www.devze.com 2023-02-27 09:46 出处:网络
First off, please forgive me if my question sounds primitive and stupid. I am mostly a C# .NET and database developer, but I am a n开发者_如何学Pythonewbie to Ogre3D, and my Qt4/C++ dev experience is

First off, please forgive me if my question sounds primitive and stupid. I am mostly a C# .NET and database developer, but I am a n开发者_如何学Pythonewbie to Ogre3D, and my Qt4/C++ dev experience is also rather limited...

I have code which renders a custom Qt4 widget (a subclass of QWidget) onto a QPixmap, and I have to display it on an Ogre3D surface.

I've been reading the latest Ogre3D book and searching for a QWidget-to-Ogre3D code sample for several days now, but couldn't find how to do that.

I assume that I need to somehow create a Texture (or maybe, a Mesh) manually from the QPixmap (probably, saved as a byte array with a "PNG" or "BMP" option), but I'm having trouble trying to figure out how to do that.

Could someone point me in the right direction, please?

Thank you very much in advance.


Here's what I currently have:

m_currentGraph->setFixedSize(QSize(WIDTH, HEIGHT));

QPainter painter(this);

painter.end();

QPixmap pixmap(WIDTH, HEIGHT);

m_currentGraph->render(&pixmap);

QByteArray bytes;

QBuffer buffer(&bytes);

buffer.open(QIODevice::WriteOnly);

pixmap.save(&buffer, "PNG"); // writes pixmap into bytes in PNG format

// How to render it onto Ogre3D ???


If you need access to the actual image data, you need to use QImage class rather than QPixmap. QImage provides you API to operate on pixels rather than with the image overall. So you can do either of the following:

1) Convert your pixmap to QImage calling QPixmap::toImage() which probably rather expensive operation (takes resources)

2) As QImage is QPaintDevice like QPixmap, you can change your code to render the widget on QImage rather than on QPixmap.

To get access to the actual bytes you can use QImage::bits() method.

Hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号