如何将 Qt4 QPixmap 渲染为 Ogre 3D 纹理或网格?请指教
首先,如果我的问题听起来很原始和愚蠢,请原谅我。 我主要是 C# .NET 和数据库开发人员,但我是 Ogre3D 的新手,而且我的 Qt4/C++ 开发经验也相当有限...
我有代码将自定义 Qt4 小部件(QWidget 的子类)渲染到QPixmap,我必须将它显示在 Ogre3D 表面上。
我几天来一直在阅读最新的 Ogre3D 书籍并搜索 QWidget-to-Ogre3D 代码示例,但找不到如何做到这一点。
我假设我需要以某种方式从 QPixmap 手动创建一个纹理(或者可能是一个网格)(可能保存为带有“PNG”或“BMP”选项的字节数组),但我在尝试计算时遇到了麻烦知道如何做到这一点。
有人能给我指出正确的方向吗?
预先非常感谢您。
这是我目前拥有的:
m_currentGraph->setFixedSize(QSize(WIDTH, HEIGHT));
QPainter画家(this);
画家.end();
QPixmap pixmap(WIDTH, HEIGHT);
m_currentGraph->render(&pixmap);
QByteArray 字节;
QBuffer 缓冲区(&字节);
buffer.open(QIODevice::WriteOnly);
pixmap.save(&buffer, "PNG"); // 将像素图写入 PNG 格式的字节
// 如何将其渲染到 Ogre3D 上???
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 ???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您需要访问实际的图像数据,您需要使用 QImage 类而不是 QPixmap。 QImage 为您提供了对像素进行操作的 API,而不是对整个图像进行操作。因此,您可以执行以下任一操作:
1)调用 QPixmap::toImage() 将像素图转换为 QImage,这可能相当昂贵的操作(占用资源)
2)由于 QImage 是像 QPixmap 一样的 QPaintDevice,您可以更改代码来渲染小部件在 QImage 而不是 QPixmap 上。
要访问实际字节,您可以使用 QImage::bits() 方法。
希望这有帮助。
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.