Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QT 5 mixed opengl and qml problem

QT 5 mixed opengl and qml problem

Scheduled Pinned Locked Moved General and Desktop
3 Posts 1 Posters 3.1k 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.
  • M Offline
    M Offline
    matteli
    wrote on 18 Nov 2012, 20:46 last edited by
    #1

    Hi all,

    i want to mix opengl and QML stuff. I used qt 5 beta 2.
    I make a minimalist programm for show you the problem :

    main.ccp
    @
    #include <QGuiApplication>
    #include "back.h"
    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    Back b;
    b.setSource(QUrl("ui.qml"));
    b.show();

    return a.exec&#40;&#41;;
    

    }
    @

    back.h

    @
    #ifndef BACK_H
    #define BACK_H
    #include <QtQuick>
    #include <QtOpenGL>
    #include <QTimer>

    class Back : public QQuickView
    {
    Q_OBJECT
    public:
    ~Back();
    Back();
    public slots :
    void paint();
    };

    #endif // BACK_H
    @

    back.ccp

    @#include "back.h"

    Back::Back()
    {
    setClearBeforeRendering(false);
    connect(this, SIGNAL(beforeRendering()), this, SLOT(paint()), Qt::DirectConnection);
    QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(update()), Qt::DirectConnection);
    timer->start(3000);
    }

    Back::~Back()
    {
    }

    void Back::paint()
    {
    glViewport(0, 0, 150, 150);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, 150, 150,0,0,10);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glColor3ub(255, 0, 0);
    glBegin(GL_QUADS);
        glVertex2i(0, 0);
        glVertex2i(100, 0);
        glVertex2i(100, 100);
        glVertex2i(0, 100);
    glEnd();
    

    }
    @

    ui.qml

    @
    import QtQuick 2.0

    Item {
    width : 150
    height : 150

    Rectangle {
         x : 50
         y : 50
         width: 100
         height: 100
         color: "green"
    }
    

    }
    @

    The first picture is correct :
    I have a red square with a green square with offset and a black background.
    "Picture 1":http://imageshack.us/photo/my-images/854/14898400.png

    After 3 seconds, the second is uncorrect :
    I have only the green square with withe background
    "Picture 2":http://imageshack.us/photo/my-images/690/56801100.png

    Is someone know what i make wrong ?

    Thank you

    matteli

    1 Reply Last reply
    0
    • M Offline
      M Offline
      matteli
      wrote on 19 Nov 2012, 13:11 last edited by
      #2

      Ok i inspect the problem and change a little my program.
      My new minimalist program.

      main.ccp
      @#include <QGuiApplication>
      #include "back.h"

      int main(int argc, char *argv[])
      {
      QApplication a(argc, argv);
      Back b;
      b.setSource(QUrl("ui.qml"));
      b.show();

      return a.exec&#40;&#41;;
      

      }
      @

      back.h
      @#ifndef BACK_H
      #define BACK_H
      #include <QtQuick>
      #include <QtOpenGL>
      #include <QTimer>
      #include <QColor>

      class Back : public QQuickView
      {
      Q_OBJECT
      public:
      ~Back();
      Back();
      public slots :
      void paint();
      private :
      bool mColor;
      };

      #endif // BACK_H
      @

      back.ccp
      @
      #include "back.h"

      Back::Back()
      {
      setClearBeforeRendering(false);
      connect(this, SIGNAL(beforeRendering()), this, SLOT(paint()), Qt::DirectConnection);
      QTimer *timer = new QTimer(this);
      connect(timer, SIGNAL(timeout()), this, SLOT(update()), Qt::DirectConnection);
      timer->start(1000);
      mColor = true;
      }

      Back::~Back()
      {
      }

      void Back::paint()
      {
      glViewport(0, 0, 300, 300);

      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      glOrtho(0.0f, 300.0f, 300.0f,0.0f,0.0f,1.0f);
      glMatrixMode(GL_MODELVIEW);
      glLoadIdentity();
      
      glDisable(GL_DEPTH_TEST);
      
      glClearColor(0.0f, 1.0f, 1.0f, 1.0f);
      glClear(GL_COLOR_BUFFER_BIT);
      
      
      mColor=!mColor;
      if (mColor) glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
      else glColor4f(1.0f, 1.0f, 0.0f,1.0f);
      glBegin(GL_QUADS);
          glVertex2f(100.0f, 100.0f);
          glVertex2f(200.0f, 100.0f);
          glVertex2f(200.0f, 200.0f);
          glVertex2f(100.0f, 200.0f);
      glEnd();
      

      }
      @

      ui.qml
      @
      import QtQuick 2.0

      Item {
      width : 300
      height : 300

      Rectangle {
           x : 0
           y : 0
           width: 50
           height: 50
           color: "purple"
      }
      

      }
      @

      The result is good for the 1st picture
      "Picture 1":http://imageshack.us/photo/my-images/694/picture11psi.png/

      After 1 second, the 2nd picture is not good (black square)
      "Picture 2":http://imageshack.us/photo/my-images/72/picture12mr.png/

      Now i change only the qml file (x and y) :
      @
      import QtQuick 2.0

      Item {
      width : 300
      height : 300

      Rectangle {
           x : 50
           y : 50
           width: 50
           height: 50
           color: "purple"
      }
      

      }
      @

      1st picture good
      "picture 1":http://imageshack.us/photo/my-images/571/picture21t.png/

      2nd picture bad : square in black and with an offset.
      "picture 2":http://imageshack.us/photo/my-images/820/picture22dh.png/

      Do you think it's a bug af QT 5 ?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        matteli
        wrote on 20 Nov 2012, 21:05 last edited by
        #3

        In my example, i mixed old rendering opengl stuff with qquick item which used VBO i presume. I think, it's not a good idea to mixed that. So now i used VBO for my rendering and it's work.

        1 Reply Last reply
        0

        1/3

        18 Nov 2012, 20:46

        • Login

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