Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Use QOpenGLFunctions_4_5_Core functions in an external file without declare a class

    General and Desktop
    2
    4
    928
    Loading More Posts
    • 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.
    • A
      aidoru last edited by aidoru

      Hello,
      I would like to know if is it possibile to use OpenGL functions outside my glWidget class.
      For example if I have an external header file like this:

      //shader.hpp
      #ifndef SHADER_HPP
      #define SHADER_HPP
      
      #include <QOpenGLWidget>
      #include <QOpenGLFunctions>
      #include <QOpenGLFunctions_4_5_Core> 
      
      
      GLuint MyShaders(const char * vertex_file_path, const char * fragment_file_path);
      
      #endif
      
      

      why I can`t use in cpp that:

      
      #include "shader.hpp"
      
      GLuint MyShaders(const char * vertex_file_path, const char * fragment_file_path){
      
      	// Create the shaders
      	GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
      	GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
              .........................
              ......................
      
      

      Visual Studio told me that glCreateShader identifier not found.

      Thank you

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        QOpenGLFunctions_4_5_Core is a class not just a bunch of function to use. You have to inherit from it to use the functions it provides.

        Note, I haven't used them outside QOpenGLWidget/Window.

        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 Reply Quote 0
        • A
          aidoru last edited by

          So I can only create/use my "MyShaders" function inside glwidget class?

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            Your function must be integrated in a class that derives from QOpenGLFunctions_4_5_Core. Don't forget to handle the context properly.

            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 Reply Quote 0
            • First post
              Last post