Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. QPainter + QQuickFramebufferObject
Forum Updated to NodeBB v4.3 + New Features

QPainter + QQuickFramebufferObject

Scheduled Pinned Locked Moved Game Development
2 Posts 1 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tppo
    wrote on last edited by
    #1

    I asked allready here:
    https://forum.qt.io/topic/74083/qpainter-qquickframebufferobject
    but nobody answers me.

    Is it possible to use QPainter with QQuickFramebufferObject or only with QQuickPaintedItem??? I was set renderTarget flag of QQuickPaintedItem to QQuickPaintedItem::FramebufferObject but updates still work very slow :(

    Links:
    https://dangelog.wordpress.com/2013/02/10/using-fbos-instead-of-pbuffers-in-qt-5-2/
    http://doc.qt.io/qt-5/qtquick-scenegraph-textureinsgnode-example.html

    1 Reply Last reply
    0
    • T Offline
      T Offline
      Tppo
      wrote on last edited by Tppo
      #2

      Or is there a way to draw just over QQuickView?

      #include <QQuickView>
      #include <QOpenGLContext>
      #include <QOpenGLFramebufferObjectFormat>
      #include <QOpenGLPaintDevice>
      #include <QPainter>
      
      class MyView : public QQuickView {
      public:
          MyView() {
              setSurfaceType(QWindow::OpenGLSurface);
          }
      
      protected:
          bool event(QEvent *ev) {
              bool result = QQuickView::event(ev);
      
      // I don't know what type should be here
              if (ev->type() == QEvent::Expose /*?*/) {
                  QOpenGLContext context;
                  if (!context.create())
                      qFatal("Cannot create the requested OpenGL context!");
                  context.makeCurrent(this);
      
                  const QRect drawRect(0, 0, 400, 400);
                  const QSize drawRectSize = drawRect.size();
      
                  QOpenGLFramebufferObjectFormat fboFormat;
                  fboFormat.setSamples(16);
                  fboFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
      
                  QOpenGLFramebufferObject fbo(drawRectSize, fboFormat);
                  fbo.bind();
      
                  QOpenGLPaintDevice device(drawRectSize);
                  QPainter painter;
                  painter.begin(&device);
                  painter.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing);
      
                  painter.fillRect(drawRect, Qt::blue);
      
                  painter.end();
      
                  fbo.release();
              }
              return result;
          }
      };
      

      Does anyone know what's wrong here?

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved