0

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 newbie 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 ???

4

1 回答 1

0

如果需要访问实际的图像数据,则需要使用 QImage 类而不是 QPixmap。QImage 为您提供 API 来操作像素而不是整体图像。因此,您可以执行以下任一操作:

1)将您的像素图转换为调用 QPixmap::toImage() 的 QImage 可能相当昂贵的操作(占用资源)

2) 由于 QImage 是 QPaintDevice,类似于 QPixmap,您可以更改代码以在 QImage 而不是 QPixmap 上呈现小部件。

要访问实际字节,您可以使用 QImage::bits() 方法。

希望这可以帮助。

于 2011-04-21T15:00:02.777 回答