Hi! I want to draw a single item in QtQuick scene using raw OpenGL calls. It 's important for me to do raw OpenGL calls because I want to integrate to external library which will be drawing on my Item.
I have decided to take approach suggested in this stackoverflow question <http://stackoverflow.com/questions/27948211/comparison-of-two-approaches-to-rendering-raw-opengl-into-a-qml-ui-in-qt> . I have created a Qt Quick item deriving from QQuickFramebufferObject and exposed it to QML as Renderer (code is based on Qt example: Scene Graph - Rendering FBOs <http://doc.qt.io/qt-5/qtquick-scenegraph-textureinsgnode-example.html>): class FboInSGRenderer : public QQuickFramebufferObject { Q_OBJECTpublic: Renderer *createRenderer() const;}; source file: class LogoInFboRenderer : public QQuickFramebufferObject::Renderer { public: LogoInFboRenderer() { } void render() { int width = 1, height = 1; glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(0.0, 1.0, 0.0, 0.8); glBegin(GL_QUADS); glVertex2f(0, 0); glVertex2f(width, 0); glVertex2f(width, height); glVertex2f(0, height); glEnd(); glLineWidth(2.5); glColor4f(0.0, 0.0, 0.0, 1.0); glBegin(GL_LINES); glVertex2f(0, 0); glVertex2f(width, height); glVertex2f(width, 0); glVertex2f(0, height); glEnd(); update(); } QOpenGLFramebufferObject *createFramebufferObject(const QSize &size) { QOpenGLFramebufferObjectFormat format; format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); format.setSamples(4); return new QOpenGLFramebufferObject(size, format); }}; QQuickFramebufferObject::Renderer *FboInSGRenderer::createRenderer() const { return new LogoInFboRenderer();} In Qml I use it as follows: import QtQuick 2.4import SceneGraphRendering 1.0 Rectangle { width: 400 height: 400 color: "purple" Renderer { id: renderer anchors.fill: parent }} I was expecting to see that rendered "X" will fill entire scene, but instead I get the result I included in attachment. Other experiments seem to confirm that drew shape has always it's size (width/height) divided by 2. I also checked that size parameter in createFramebufferObject has correct value. Looking into docs led me to property textureFollowsItemSize <http://doc.qt.io/qt-5/qquickframebufferobject.html#textureFollowsItemSize-prop> in QQuickFramebufferObjectclass but it is by default set to true. Am I doing something wrong or should I consider this behavior as Qt bug? (I have also post this question on stackoverflow <http://stackoverflow.com/questions/28070778/issue-with-drawing-an-qml-item-with-raw-opengl-calls> ) Best regards, Paweł
_______________________________________________ Interest mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/interest
