使用 OpenGL 将图像渲染到子类 QDeclarativeItem 中
我正在尝试使用 OpenGL ES 2.0 执行多个图像操作,并将输出显示到子类 QDeclarativeItem 中,然后该子类将在我的 QML GUI 中使用。 我通读了这里找到的答案: http://developer.qt.nokia.com/forums /viewthread/4109 并通过覆盖 QDeclarativeItem 的 Paint() 方法成功地在我的 QML GUI 中绘制了一个红到蓝的矩形:
void GLDeclarativeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->beginNativePainting();
glBegin(GL_QUADS);
glColor3ub(0,0,255);
glVertex2d(0, 0);
glVertex2d(0, height());
glColor3ub(255,0,0);
glVertex2d(width(), height());
glVertex2d(width(), 0);
glEnd();
painter->endNativePainting();
}
但是,我想要实现的是绘制将在我的自定义 QGLWidget 中处理的图像上述 QDeclarativeItem 的内容(而不是红到蓝色的内容)。
在我的自定义 QGLWidget 中,我使用:
void GLWidget::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
用于绘图,效果很好。但是,我找不到 GLWidget 和 GLDeclarativeItem 中的绘图之间的转换。到目前为止我尝试过的所有事情都只是给了我一个没有任何内容的矩形。 感谢您的帮助!
I am trying to perform several image manipulations using OpenGL ES 2.0 and display the output into a subclassed QDeclarativeItem which will then be used within my QML GUI.
I read through the answers found here: http://developer.qt.nokia.com/forums/viewthread/4109
and succeeded in drawing a red-to-blue colored rectangle within my QML GUI by overriding the paint() methode of the QDeclarativeItem:
void GLDeclarativeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->beginNativePainting();
glBegin(GL_QUADS);
glColor3ub(0,0,255);
glVertex2d(0, 0);
glVertex2d(0, height());
glColor3ub(255,0,0);
glVertex2d(width(), height());
glVertex2d(width(), 0);
glEnd();
painter->endNativePainting();
}
However, what I am trying to achieve is to draw the image which will be handled within my custom QGLWidget as the content of the above described QDeclarativeItem (instead of the red-to-blue colored content).
Within my custom QGLWidget I am using:
void GLWidget::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
for drawing, which worked fine. However, I can not find the conversion between the drawing within my GLWidget and my GLDeclarativeItem. All the things I have tried so far just gave me a rectangle without any content at all.
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我做了类似的事情,但解决方式不同:我使用了覆盖。
我只是将 OpenGL 渲染放在它自己的小部件中,该小部件放置在 QDeclarativeView 之上。
虽然您无法在 OpenGL 渲染之上进行绘制,但效果很好。如果您确实需要,可以堆叠另一个具有半透明背景的 QML 视图。
祝你好运。
I did a similar thing, but solved differently: I used an overlay.
I simply put the OpenGL rendering in its own widget which is placed on top of the QDeclarativeView.
This works quite well, although you cannot draw ontop of the OpenGL rendering. If you should really need to, stack over another QML view with a translucent background.
Good luck.