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 & raw OpenGL with glew not working
QtWS25 Last Chance

QT & raw OpenGL with glew not working

Scheduled Pinned Locked Moved Unsolved General and Desktop
openglglewqwindow
9 Posts 2 Posters 5.8k 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.
  • R Offline
    R Offline
    Row_Rebel
    wrote on 13 Dec 2015, 22:09 last edited by Row_Rebel
    #1

    It's been 2 days now that I'm trying to setup a working window where I can issue raw openGL commands with glew, but all I can see on screen is just a white empty window while my glClearColor is set to red

    So here's glwindow.h :

    #ifndef GLWINDOW_H
    #define GLWINDOW_H
    #include <QWindow>
    #include <QOpenGLContext>
    
    class GLWindow : public QWindow {
        QOpenGLContext* context;
    
        public:
        GLWindow(const QSurfaceFormat& format);
    
        void initGL();
        void resize(int w, int h);
    };
    #endif // GLWINDOW_H
    

    glwindow.cpp:

    #define GLEW_STATIC
    #include <glew.h>
    #include "glwindow.h"
    #include <QDebug>
    
    GLWindow::GLWindow(const QSurfaceFormat& format) : context(0) {
        
        setSurfaceType( OpenGLSurface );
        setFormat(format);
        create();
    
        context = new QOpenGLContext(this);
        context->setFormat(format);
        context->create();
    
        context->makeCurrent(this);
                glViewport(0,0,500,500);
                glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
                glClear(GL_COLOR_BUFFER_BIT);
        context->swapBuffers(this);
    }
    void GLWindow::resize(int w, int h) { }
    void GLWindow::initGL() { }
    

    main.cpp:

    #include <QGuiApplication>
    #include <glwindow.h>
    #include <QSurfaceFormat>
    int main(int argc, char *argv[])
    {
        QGuiApplication a(argc, argv);
        QSurfaceFormat format;
        format.setMajorVersion( 3 );
    
        #if !defined(Q_OS_MAC)
        format.setMinorVersion( 3 );
        #else
        format.setMinorVersion( 2 );
        #endif
        format.setDepthBufferSize( 24 );
        format.setSamples( 4 );
        format.setProfile( QSurfaceFormat::CoreProfile );
    
        GLWindow window(format);
        window.show();
        return a.exec();
    }
    

    Lastly here's the .pro file:

    QT       += core gui 
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    TARGET = Tentativo5
    TEMPLATE = app
    SOURCES += main.cpp\
        glwindow.cpp
    
    HEADERS  += \
        glwindow.h
    INCLUDEPATH += "C:/....../OpenGL/headers/GL"
    LIBS += "C:/......./OpenGL/lib/glew32s.lib"
    LIBS += opengl32.lib
    

    I'm pretty desperate at this point so feel free to ask anything about the setup, I'm really not suited to set all the mess that qt apparently need to have a working opengl window

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 13 Dec 2015, 22:46 last edited by
      #2

      Hi and welcome to devnet,

      With Qt 5 you don't need glew at all, you can use QOpenGLFunctions and derived class.

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

      R 1 Reply Last reply 13 Dec 2015, 22:59
      1
      • S SGaist
        13 Dec 2015, 22:46

        Hi and welcome to devnet,

        With Qt 5 you don't need glew at all, you can use QOpenGLFunctions and derived class.

        R Offline
        R Offline
        Row_Rebel
        wrote on 13 Dec 2015, 22:59 last edited by
        #3

        @SGaist
        Is there a step-bystep tutorial that explains them without too much magic?
        Maybe ending up with a simple openGL window up and running

        PS: Possibly without using QGLWidget since performance-wise seems not to be the best solution

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 13 Dec 2015, 23:08 last edited by
          #4

          The OpenGL window example might be a good starting point.

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

          R 1 Reply Last reply 13 Dec 2015, 23:15
          1
          • S SGaist
            13 Dec 2015, 23:08

            The OpenGL window example might be a good starting point.

            R Offline
            R Offline
            Row_Rebel
            wrote on 13 Dec 2015, 23:15 last edited by
            #5

            @SGaist
            Unfortunately I didn't understand many of the called functions in there like the need of exposeEvent or renderlater which was what I was referring before as "magic"

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 13 Dec 2015, 23:29 last edited by
              #6

              renderLater is used to trigger an update of the scene while exposeEvent will trigger it when the window exposure changed.

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

              R 1 Reply Last reply 13 Dec 2015, 23:46
              1
              • S SGaist
                13 Dec 2015, 23:29

                renderLater is used to trigger an update of the scene while exposeEvent will trigger it when the window exposure changed.

                R Offline
                R Offline
                Row_Rebel
                wrote on 13 Dec 2015, 23:46 last edited by Row_Rebel
                #7

                @SGaist
                Last question, I found a working example here: https://wiki.qt.io/Using-QOpenGLFunctions-and-QOpenGLContext
                which I blindly implemented and played a bit around till I finally rendered a triangle on screen, the problem is that as with QGLWidget, if I resize fast enough I start to see white flickering as shown in this screenshot: http://oi63.tinypic.com/11wgi9t.jpg
                what could be causing it?

                Fun thing is that I switched from qglwidget since I thought the performance impact could have caused it

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 13 Dec 2015, 23:48 last edited by
                  #8

                  I can't say from the top of my head. However, QGLWidget is old tech, you should move to the new QOpenGLWidget class directly.

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

                  R 1 Reply Last reply 14 Dec 2015, 01:37
                  1
                  • S SGaist
                    13 Dec 2015, 23:48

                    I can't say from the top of my head. However, QGLWidget is old tech, you should move to the new QOpenGLWidget class directly.

                    R Offline
                    R Offline
                    Row_Rebel
                    wrote on 14 Dec 2015, 01:37 last edited by
                    #9

                    @SGaist
                    Ok I guess i'll open a different question for this issue, thanks anyway for your help

                    1 Reply Last reply
                    0

                    8/9

                    13 Dec 2015, 23:48

                    • Login

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