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. Use QOpenGLFunctions_4_5_Core functions in an external file without declare a class
QtWS25 Last Chance

Use QOpenGLFunctions_4_5_Core functions in an external file without declare a class

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.1k 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.
  • A Offline
    A Offline
    aidoru
    wrote on last edited by aidoru
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0
      • A Offline
        A Offline
        aidoru
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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
          0

          • Login

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