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. OpenGL questions

OpenGL questions

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 891 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.
  • QT-static-prgmQ Offline
    QT-static-prgmQ Offline
    QT-static-prgm
    wrote on last edited by
    #1

    Hi,

    i'm working on an OpenGL project and i was already finished with most of the OpenGL things, but i noticed that my old libraries (glew, glfw,..) were very limited about the Window itself.
    So i switched to Qt, since i already worked a lot of times with this library. So my aim is to port my old project over to a new one with Qt.
    Here is my old project: https://git.rwth-aachen.de/carstenf/OpenGL/tree/master/MshViewer

    If you wanna test it, you can get a finished build here: https://git.rwth-aachen.de/carstenf/OpenGL/tree/master/Release

    My Qt project is located in the same repository here: https://git.rwth-aachen.de/carstenf/OpenGL/tree/master/MeshViewerQt

    Is there any tutorial about how to use OpenGL with Qt the best way?? Since it looks very different from the OpenGL i used before.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi! I assume we're talking about a GUI using QWidgets. In this case it's pretty simple: You create a custom widget that inherits from QOpenGLWidget and QOpenGLFunctions, and you need to override a handful of functions. You can then add instances of your custom widget to mainwindow etc.

      mywidget.h

      #ifndef MYWIDGET_H
      #define MYWIDGET_H
      
      #include <QOpenGLWidget>
      #include <QOpenGLFunctions>
      
      class MyWidget: public QOpenGLWidget, protected QOpenGLFunctions
      {
          Q_OBJECT
      public:
          explicit MyWidget(QWidget *parent = nullptr);
      
      protected:
          void initializeGL() override;
          void resizeGL(int w, int h) override;
          void paintGL() override;
      };
      
      #endif // MYWIDGET_H
      

      mywidget.cpp

      #include "mywidget.h"
      
      MyWidget::MyWidget(QWidget *parent)
          : QOpenGLWidget(parent)
      {
      }
      
      void MyWidget::initializeGL()
      {
          initializeOpenGLFunctions();
          glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
      }
      
      void MyWidget::resizeGL(int w, int h)
      {
          Q_UNUSED(w)
          Q_UNUSED(h)
      }
      
      void MyWidget::paintGL()
      {
          glClear(GL_COLOR_BUFFER_BIT);
      }
      

      In your .pro file don't forget to add opengl:

      QT       += core gui opengl
      

      Placed on a QMainWindow together with a layout and a QPushButton the result looks like this:

      Q 1 Reply Last reply
      1
      • ? A Former User

        Hi! I assume we're talking about a GUI using QWidgets. In this case it's pretty simple: You create a custom widget that inherits from QOpenGLWidget and QOpenGLFunctions, and you need to override a handful of functions. You can then add instances of your custom widget to mainwindow etc.

        mywidget.h

        #ifndef MYWIDGET_H
        #define MYWIDGET_H
        
        #include <QOpenGLWidget>
        #include <QOpenGLFunctions>
        
        class MyWidget: public QOpenGLWidget, protected QOpenGLFunctions
        {
            Q_OBJECT
        public:
            explicit MyWidget(QWidget *parent = nullptr);
        
        protected:
            void initializeGL() override;
            void resizeGL(int w, int h) override;
            void paintGL() override;
        };
        
        #endif // MYWIDGET_H
        

        mywidget.cpp

        #include "mywidget.h"
        
        MyWidget::MyWidget(QWidget *parent)
            : QOpenGLWidget(parent)
        {
        }
        
        void MyWidget::initializeGL()
        {
            initializeOpenGLFunctions();
            glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
        }
        
        void MyWidget::resizeGL(int w, int h)
        {
            Q_UNUSED(w)
            Q_UNUSED(h)
        }
        
        void MyWidget::paintGL()
        {
            glClear(GL_COLOR_BUFFER_BIT);
        }
        

        In your .pro file don't forget to add opengl:

        QT       += core gui opengl
        

        Placed on a QMainWindow together with a layout and a QPushButton the result looks like this:

        Q Offline
        Q Offline
        Q139
        wrote on last edited by
        #3

        Also gltriangle example can help.

        1 Reply Last reply
        0
        • QT-static-prgmQ Offline
          QT-static-prgmQ Offline
          QT-static-prgm
          wrote on last edited by
          #4

          Thank you :D i found this tutorial: http://www.trentreed.net/blog/qt5-opengl-part-2-3d-rendering/
          Currently i'm reading one chapter after the other and implement it for my widget instead of window. Looks similar for me.

          I used this tutorial first: http://www.opengl-tutorial.org/beginners-tutorials/tutorial-1-opening-a-window/ and the steps seam to be the same, but Qt has different function names, but for me it's easier to have one powerful library that can do everything instead of multiple different libraries (glew, glfw, glut, glm,...).

          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