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. Custom OpenGL rendering in a QWidget
QtWS25 Last Chance

Custom OpenGL rendering in a QWidget

Scheduled Pinned Locked Moved Unsolved Game Development
qwidgetopenglglew glfw to qtvulkangraphics
3 Posts 3 Posters 1.2k 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.
  • J Offline
    J Offline
    julienchz
    wrote on 22 Nov 2023, 14:27 last edited by
    #1

    I want to render OpenGL in a QWidget but I don't want to use Qt's built-in tools like QOpenGLWidget because :

    • I want to have a graphics API abstraction (vulkan, directX) to render in a QWidget
    • I want to use a minimum of Qt only in a QWidget because the rendering methods must belong to an external library that does not use Qt (possible use of frameworks other than Qt later).

    For the moment I'm just trying to get a working example with OpenGL (with glew and OpenGL functions), but I can't see how to render cleanly in a QWidget.

    class RenderWidget : public QWidget
    {
        Q_OBJECT
    
    public:
    
        /** Constructors **/
    
        explicit RenderWidget(QWidget* parent = nullptr);
        ~RenderWidget();
    
    protected:
    
        /** Methods **/
    
        virtual void initialize();
        virtual void paint();
        virtual void resize(int width, int height);
    
        void paintEvent(QPaintEvent *event) override;
        void resizeEvent(QResizeEvent *event) override;
    
    private:
        GLuint vertexBuffer;  // Un exemple de tampon de vertex
        GLuint program;       // Un exemple de programme de shader
    };
    
    

    At the moment, calling glewInit() in the RenderWidget constructor fails, I've certainly misdeclared my OpenGL context (I used QSurfaceFormat from main).

    I've seen topics saying that you shouldn't call OpenGL rendering functions directly from QWidget's paintEvent().

    Do you have any ideas on how to do this properly? Do you have any examples of custom OpenGL (or other API) integration in Qt?

    Thanks.

    J 1 Reply Last reply 24 Jan 2024, 06:29
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 22 Nov 2023, 20:05 last edited by
      #2

      Hi,

      You should rather take a look at QWindow.

      That said, Qt already provides integration for many of the modern graphics API such as Direct3D or Vulkan. You might want to explore the scene graph documentation and the corresponding classes. Engines such as Ogre3D have integration that might of interest.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • J julienchz
        22 Nov 2023, 14:27

        I want to render OpenGL in a QWidget but I don't want to use Qt's built-in tools like QOpenGLWidget because :

        • I want to have a graphics API abstraction (vulkan, directX) to render in a QWidget
        • I want to use a minimum of Qt only in a QWidget because the rendering methods must belong to an external library that does not use Qt (possible use of frameworks other than Qt later).

        For the moment I'm just trying to get a working example with OpenGL (with glew and OpenGL functions), but I can't see how to render cleanly in a QWidget.

        class RenderWidget : public QWidget
        {
            Q_OBJECT
        
        public:
        
            /** Constructors **/
        
            explicit RenderWidget(QWidget* parent = nullptr);
            ~RenderWidget();
        
        protected:
        
            /** Methods **/
        
            virtual void initialize();
            virtual void paint();
            virtual void resize(int width, int height);
        
            void paintEvent(QPaintEvent *event) override;
            void resizeEvent(QResizeEvent *event) override;
        
        private:
            GLuint vertexBuffer;  // Un exemple de tampon de vertex
            GLuint program;       // Un exemple de programme de shader
        };
        
        

        At the moment, calling glewInit() in the RenderWidget constructor fails, I've certainly misdeclared my OpenGL context (I used QSurfaceFormat from main).

        I've seen topics saying that you shouldn't call OpenGL rendering functions directly from QWidget's paintEvent().

        Do you have any ideas on how to do this properly? Do you have any examples of custom OpenGL (or other API) integration in Qt?

        Thanks.

        J Offline
        J Offline
        johngod
        wrote on 24 Jan 2024, 06:29 last edited by
        #3

        @julienchz
        Hi
        I have created some opengl tutorials check here: https://bitbucket.org/joaodeusmorgado/opengltutorials/src/master/
        I am using QOpenGLWidget, but I use mostly raw opengl, you could easily create a abstract render class, and then reuse it to QOpenGLWidget, or any other frame work of your choice render class.
        Hope it helps

        1 Reply Last reply
        1

        • Login

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