QOpenGlWidget and GLEW 2.0



  • Hi,

    I know this is a very old topic, but I cannot seem to find a solution for this problem.
    I want to use GLEW 2.0 with QOpenGLWIdget as a window manager. I already did what most of the sites recommend: create a subclass of QOpenGLWidget, in initializeGL() first call makeCurrent() and then glewInit(). It works, the program can be compiled, I get no error messages and I can run my program. Now, as soon as I call an OpenGL function (like glClear) I get an error message:
    LNK2019 unresolved external symbol _imp_glClear referenced in function "public: init....)
    I don't understand this error. If I have a linker error, why does glewInit and glewExperimental work?

    I also did add a SurfaceFormat in my main:

    QSurfaceFormat format;
    format.setVersion(4, 5);
    format.setProfile(QSurfaceFormat::CoreProfile);
    format.setDepthBufferSize(24);
    QSurfaceFormat::setDefaultFormat(format);
    QApplication a(argc, argv);
    MainWindow mainWindow;
    mainWindow.show();
    return a.exec();
    

    Can anyone help me?
    Another question: does QOpenGLFunction contain native OpenGL API or OpenGL ES 2.0 (as I've read in some threads)?
    Thx!


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Because they are not in the same libraries.

    QOpenGLFunction provides the common subset of functions so check it to see if it have everything you need. Otherwise if you need functions only available in the 4.5 core profile, you can use the QOpenGLFunctions_4_5_Core class.



  • Thanks :)

    Hm, does this mean I need both libs: glew32 and glew32s? These are the only libraries that come with the include files.

    Oh, I didn't know there is a special class for 4.5 OpenGL.

    Thx


  • Lifetime Qt Champion

    AFAIK, the s means in this case static, so no you don't need both.

    AFAIK, there's one for each version of OpenGL.



  • Hi,

    thanks for the answer, I managed to compile and run the program with GLEW :)
    Now I am facing a new problem: black window while rendering points.

    My workflow so far:
    MyWidget
    ::initGL() create the connections for signals ans slots, start GLEW and timer
    ::timer calls myUpdate() when timeout is called
    ::myUpdate() computes some values and calls update()
    ::paintGL() clears the window and calls custom shader::draw() function which uses GLEW for native OpenGL API

    MyShader
    ::construct() uses QOpenGLShaderProgram to compile and link the shaders; QOpenGLShaderProgram::link() returns true
    ::draw() calls glUseProgram(QOpenGLShaderProgram::programID), glPointSize(100.f), glDrawArrays(GL_POINTS, 0, 1) and glUseProgram(0) in that order. The result is a black window. I even call makeCurrent() before calling this function but it does not help. I get no shader compile errors. Are QOpenGLShaderProgram and GLEW interfering with eachother?

    Thx for the help!



  • @SGaist If I subclass QOpenGLFunction_x_x, do I still need to call makeCurrent or pass the QOpenGLContext as an argument to my subclass?


  • Lifetime Qt Champion

    The QOpenGLFucntionXXX classes only provides your class with access to the OpenGL functions, it's still up to you to mange the context and friends properly.


Log in to reply