Use QOpenGLFunctions_4_5_Core functions in an external file without declare a class



  • 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


  • Lifetime Qt Champion

    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.



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


  • Lifetime Qt Champion

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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.