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. QOpenGLFunctions glGetString(GL_EXTENSIONS) is null
QtWS25 Last Chance

QOpenGLFunctions glGetString(GL_EXTENSIONS) is null

Scheduled Pinned Locked Moved Solved General and Desktop
qt5.5openglqopenglfunctioncontextglextensions
22 Posts 4 Posters 13.0k 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.
  • D Offline
    D Offline
    deleted451
    wrote on 23 Feb 2016, 20:57 last edited by deleted451
    #1

    Qt 5.5.1
    I want to see which extensions (GL_EXTENSIONS) supports my graphics card (GeForce 7000M), but it always is null.
    Here is the correct minimum code for this task.

    test.pro

    QT += opengl
    
    CONFIG += c++11
    
    TARGET = test
    CONFIG += console
    CONFIG -= app_bundle
    
    TEMPLATE = app
    
    SOURCES += main.cpp
    

    main.cpp

    #include <QtOpenGL>
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        QOffscreenSurface surf;
        surf.create();
        QOpenGLContext ctx;
        ctx.create();
        ctx.makeCurrent(&surf);
        std::string ext = QString::fromLatin1((const char*)ctx.functions()->glGetString(GL_EXTENSIONS)).replace(' ', "\n\t").toStdString();
        printf("OpenGL: %s %s %s\n\n\t%s\n", ctx.functions()->glGetString(GL_VENDOR), ctx.functions()->glGetString(GL_RENDERER), ctx.functions()->glGetString(GL_VERSION), ext.c_str());
        return 0;
    }
    

    stdout

    OpenGL: nouveau Gallium 0.4 on NV67 2.1 Mesa 11.1.2
    
            GL_ARB_multisample
            GL_EXT_abgr
            GL_EXT_bgra
            GL_EXT_blend_color
            GL_EXT_blend_minmax
            GL_EXT_blend_subtract
            GL_EXT_copy_texture
            GL_EXT_polygon_offset
            GL_EXT_subtexture
            GL_EXT_texture_object
            GL_EXT_vertex_array
            GL_EXT_compiled_vertex_array
            GL_EXT_texture
            GL_EXT_texture3D
            GL_IBM_rasterpos_clip
            GL_ARB_point_parameters
            GL_EXT_draw_range_elements
            GL_EXT_packed_pixels
            GL_EXT_point_parameters
            GL_EXT_rescale_normal
            GL_EXT_separate_specular_color
            GL_EXT_texture_edge_clamp
            GL_SGIS_generate_mipmap
            GL_SGIS_texture_border_clamp
            GL_SGIS_texture_edge_clamp
            GL_SGIS_texture_lod
            GL_ARB_multitexture
            GL_IBM_multimode_draw_arrays
            GL_IBM_texture_mirrored_repeat
            GL_ARB_texture_cube_map
            GL_ARB_texture_env_add
            GL_ARB_transpose_matrix
            GL_EXT_blend_func_separate
            GL_EXT_fog_coord
            GL_EXT_multi_draw_arrays
            GL_EXT_secondary_color
            GL_EXT_texture_env_add
            GL_EXT_texture_filter_anisotropic
            GL_EXT_texture_lod_bias
            GL_INGR_blend_func_separate
            GL_NV_blend_square
            GL_NV_light_max_exponent
            GL_NV_texgen_reflection
            GL_NV_texture_env_combine4
            GL_S3_s3tc
            GL_SUN_multi_draw_arrays
            GL_ARB_texture_border_clamp
            GL_ARB_texture_compression
            GL_EXT_framebuffer_object
            GL_EXT_texture_compression_s3tc
            GL_EXT_texture_env_combine
            GL_EXT_texture_env_dot3
            GL_MESA_window_pos
            GL_NV_packed_depth_stencil
            GL_NV_texture_rectangle
            GL_ARB_depth_texture
            GL_ARB_occlusion_query
            GL_ARB_shadow
            GL_ARB_texture_env_combine
            GL_ARB_texture_env_crossbar
            GL_ARB_texture_env_dot3
            GL_ARB_texture_mirrored_repeat
            GL_ARB_window_pos
            GL_EXT_stencil_two_side
            GL_EXT_texture_cube_map
            GL_NV_depth_clamp
            GL_NV_fog_distance
            GL_APPLE_packed_pixels
            GL_APPLE_vertex_array_object
            GL_ARB_draw_buffers
            GL_ARB_fragment_program
            GL_ARB_fragment_shader
            GL_ARB_shader_objects
            GL_ARB_vertex_program
            GL_ARB_vertex_shader
            GL_ATI_draw_buffers
            GL_ATI_texture_env_combine3
            GL_EXT_depth_bounds_test
            GL_EXT_shadow_funcs
            GL_EXT_stencil_wrap
            GL_MESA_pack_invert
            GL_NV_primitive_restart
            GL_ARB_depth_clamp
            GL_ARB_fragment_program_shadow
            GL_ARB_half_float_pixel
            GL_ARB_occlusion_query2
            GL_ARB_point_sprite
            GL_ARB_shading_language_100
            GL_ARB_sync
            GL_ARB_texture_non_power_of_two
            GL_ARB_vertex_buffer_object
            GL_ATI_blend_equation_separate
            GL_EXT_blend_equation_separate
            GL_OES_read_format
            GL_ARB_pixel_buffer_object
            GL_ARB_texture_rectangle
            GL_EXT_pixel_buffer_object
            GL_EXT_texture_compression_dxt1
            GL_EXT_texture_mirror_clamp
            GL_EXT_texture_rectangle
            GL_EXT_texture_sRGB
            GL_EXT_framebuffer_blit
            GL_EXT_packed_depth_stencil
            GL_ARB_vertex_array_object
            GL_ATI_separate_stencil
            GL_ATI_texture_mirror_once
            GL_EXT_gpu_program_parameters
            GL_EXT_texture_sRGB_decode
            GL_EXT_timer_query
            GL_OES_EGL_image
            GL_ARB_copy_buffer
            GL_ARB_half_float_vertex
            GL_ARB_map_buffer_range
            GL_ARB_texture_swizzle
            GL_ARB_vertex_array_bgra
            GL_EXT_texture_swizzle
            GL_EXT_vertex_array_bgra
            GL_NV_conditional_render
            GL_ARB_ES2_compatibility
            GL_ARB_debug_output
            GL_ARB_draw_elements_base_vertex
            GL_ARB_explicit_attrib_location
            GL_ARB_fragment_coord_conventions
            GL_ARB_provoking_vertex
            GL_ARB_sampler_objects
            GL_EXT_provoking_vertex
            GL_EXT_texture_snorm
            GL_MESA_texture_signed_rgba
            GL_ARB_get_program_binary
            GL_ARB_robustness
            GL_ARB_separate_shader_objects
            GL_ARB_timer_query
            GL_ANGLE_texture_compression_dxt3
            GL_ANGLE_texture_compression_dxt5
            GL_ARB_compressed_texture_pixel_storage
            GL_ARB_internalformat_query
            GL_ARB_map_buffer_alignment
            GL_ARB_texture_storage
            GL_AMD_shader_trinary_minmax
            GL_ARB_clear_buffer_object
            GL_ARB_explicit_uniform_location
            GL_ARB_invalidate_subdata
            GL_ARB_program_interface_query
            GL_ARB_vertex_attrib_binding
            GL_KHR_debug
            GL_ARB_buffer_storage
            GL_ARB_multi_bind
            GL_ARB_texture_mirror_clamp_to_edge
            GL_ARB_get_texture_sub_image
            GL_KHR_context_flush_control
    
    
    kshegunovK 1 Reply Last reply 23 Feb 2016, 21:04
    0
    • D deleted451
      23 Feb 2016, 20:57

      Qt 5.5.1
      I want to see which extensions (GL_EXTENSIONS) supports my graphics card (GeForce 7000M), but it always is null.
      Here is the correct minimum code for this task.

      test.pro

      QT += opengl
      
      CONFIG += c++11
      
      TARGET = test
      CONFIG += console
      CONFIG -= app_bundle
      
      TEMPLATE = app
      
      SOURCES += main.cpp
      

      main.cpp

      #include <QtOpenGL>
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          QOffscreenSurface surf;
          surf.create();
          QOpenGLContext ctx;
          ctx.create();
          ctx.makeCurrent(&surf);
          std::string ext = QString::fromLatin1((const char*)ctx.functions()->glGetString(GL_EXTENSIONS)).replace(' ', "\n\t").toStdString();
          printf("OpenGL: %s %s %s\n\n\t%s\n", ctx.functions()->glGetString(GL_VENDOR), ctx.functions()->glGetString(GL_RENDERER), ctx.functions()->glGetString(GL_VERSION), ext.c_str());
          return 0;
      }
      

      stdout

      OpenGL: nouveau Gallium 0.4 on NV67 2.1 Mesa 11.1.2
      
              GL_ARB_multisample
              GL_EXT_abgr
              GL_EXT_bgra
              GL_EXT_blend_color
              GL_EXT_blend_minmax
              GL_EXT_blend_subtract
              GL_EXT_copy_texture
              GL_EXT_polygon_offset
              GL_EXT_subtexture
              GL_EXT_texture_object
              GL_EXT_vertex_array
              GL_EXT_compiled_vertex_array
              GL_EXT_texture
              GL_EXT_texture3D
              GL_IBM_rasterpos_clip
              GL_ARB_point_parameters
              GL_EXT_draw_range_elements
              GL_EXT_packed_pixels
              GL_EXT_point_parameters
              GL_EXT_rescale_normal
              GL_EXT_separate_specular_color
              GL_EXT_texture_edge_clamp
              GL_SGIS_generate_mipmap
              GL_SGIS_texture_border_clamp
              GL_SGIS_texture_edge_clamp
              GL_SGIS_texture_lod
              GL_ARB_multitexture
              GL_IBM_multimode_draw_arrays
              GL_IBM_texture_mirrored_repeat
              GL_ARB_texture_cube_map
              GL_ARB_texture_env_add
              GL_ARB_transpose_matrix
              GL_EXT_blend_func_separate
              GL_EXT_fog_coord
              GL_EXT_multi_draw_arrays
              GL_EXT_secondary_color
              GL_EXT_texture_env_add
              GL_EXT_texture_filter_anisotropic
              GL_EXT_texture_lod_bias
              GL_INGR_blend_func_separate
              GL_NV_blend_square
              GL_NV_light_max_exponent
              GL_NV_texgen_reflection
              GL_NV_texture_env_combine4
              GL_S3_s3tc
              GL_SUN_multi_draw_arrays
              GL_ARB_texture_border_clamp
              GL_ARB_texture_compression
              GL_EXT_framebuffer_object
              GL_EXT_texture_compression_s3tc
              GL_EXT_texture_env_combine
              GL_EXT_texture_env_dot3
              GL_MESA_window_pos
              GL_NV_packed_depth_stencil
              GL_NV_texture_rectangle
              GL_ARB_depth_texture
              GL_ARB_occlusion_query
              GL_ARB_shadow
              GL_ARB_texture_env_combine
              GL_ARB_texture_env_crossbar
              GL_ARB_texture_env_dot3
              GL_ARB_texture_mirrored_repeat
              GL_ARB_window_pos
              GL_EXT_stencil_two_side
              GL_EXT_texture_cube_map
              GL_NV_depth_clamp
              GL_NV_fog_distance
              GL_APPLE_packed_pixels
              GL_APPLE_vertex_array_object
              GL_ARB_draw_buffers
              GL_ARB_fragment_program
              GL_ARB_fragment_shader
              GL_ARB_shader_objects
              GL_ARB_vertex_program
              GL_ARB_vertex_shader
              GL_ATI_draw_buffers
              GL_ATI_texture_env_combine3
              GL_EXT_depth_bounds_test
              GL_EXT_shadow_funcs
              GL_EXT_stencil_wrap
              GL_MESA_pack_invert
              GL_NV_primitive_restart
              GL_ARB_depth_clamp
              GL_ARB_fragment_program_shadow
              GL_ARB_half_float_pixel
              GL_ARB_occlusion_query2
              GL_ARB_point_sprite
              GL_ARB_shading_language_100
              GL_ARB_sync
              GL_ARB_texture_non_power_of_two
              GL_ARB_vertex_buffer_object
              GL_ATI_blend_equation_separate
              GL_EXT_blend_equation_separate
              GL_OES_read_format
              GL_ARB_pixel_buffer_object
              GL_ARB_texture_rectangle
              GL_EXT_pixel_buffer_object
              GL_EXT_texture_compression_dxt1
              GL_EXT_texture_mirror_clamp
              GL_EXT_texture_rectangle
              GL_EXT_texture_sRGB
              GL_EXT_framebuffer_blit
              GL_EXT_packed_depth_stencil
              GL_ARB_vertex_array_object
              GL_ATI_separate_stencil
              GL_ATI_texture_mirror_once
              GL_EXT_gpu_program_parameters
              GL_EXT_texture_sRGB_decode
              GL_EXT_timer_query
              GL_OES_EGL_image
              GL_ARB_copy_buffer
              GL_ARB_half_float_vertex
              GL_ARB_map_buffer_range
              GL_ARB_texture_swizzle
              GL_ARB_vertex_array_bgra
              GL_EXT_texture_swizzle
              GL_EXT_vertex_array_bgra
              GL_NV_conditional_render
              GL_ARB_ES2_compatibility
              GL_ARB_debug_output
              GL_ARB_draw_elements_base_vertex
              GL_ARB_explicit_attrib_location
              GL_ARB_fragment_coord_conventions
              GL_ARB_provoking_vertex
              GL_ARB_sampler_objects
              GL_EXT_provoking_vertex
              GL_EXT_texture_snorm
              GL_MESA_texture_signed_rgba
              GL_ARB_get_program_binary
              GL_ARB_robustness
              GL_ARB_separate_shader_objects
              GL_ARB_timer_query
              GL_ANGLE_texture_compression_dxt3
              GL_ANGLE_texture_compression_dxt5
              GL_ARB_compressed_texture_pixel_storage
              GL_ARB_internalformat_query
              GL_ARB_map_buffer_alignment
              GL_ARB_texture_storage
              GL_AMD_shader_trinary_minmax
              GL_ARB_clear_buffer_object
              GL_ARB_explicit_uniform_location
              GL_ARB_invalidate_subdata
              GL_ARB_program_interface_query
              GL_ARB_vertex_attrib_binding
              GL_KHR_debug
              GL_ARB_buffer_storage
              GL_ARB_multi_bind
              GL_ARB_texture_mirror_clamp_to_edge
              GL_ARB_get_texture_sub_image
              GL_KHR_context_flush_control
      
      
      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on 23 Feb 2016, 21:04 last edited by
      #2

      @Ilya-Indigo
      You're calling a non-static function as static. That's the problem. Create an object of type QOpenGLFunctions and then query your version and extensions.

      QOpenGLFunctions gl;
      const GLubyte * version = gl.glGetString(GL_VERSION);
      // ... and so on ...
      

      Kind regards.

      Read and abide by the Qt Code of Conduct

      D 1 Reply Last reply 23 Feb 2016, 21:24
      0
      • kshegunovK kshegunov
        23 Feb 2016, 21:04

        @Ilya-Indigo
        You're calling a non-static function as static. That's the problem. Create an object of type QOpenGLFunctions and then query your version and extensions.

        QOpenGLFunctions gl;
        const GLubyte * version = gl.glGetString(GL_VERSION);
        // ... and so on ...
        

        Kind regards.

        D Offline
        D Offline
        deleted451
        wrote on 23 Feb 2016, 21:24 last edited by
        #3

        @kshegunov

        #include <iostream>
        #include <stdio.h>
        #include <string.h>
        #include <GL/gl.h>
        #include <GL/glu.h>
        #include <GL/glext.h>
        #include <QtOpenGL/QtOpenGL>
        #include <QtOpenGL/QGL>
        #include <QtOpenGL/QGLFunctions>
        #include <QtGui/QOpenGLFunctions>
        int main()
        {
            QOpenGLFunctions gl;
            //gl.initializeOpenGLFunctions();
            const GLubyte* gl_version = gl.glGetString(GL_VERSION);
            const GLubyte* gl_extensions = gl.glGetString(GL_EXTENSIONS);
            printf("GL_VERSION:\n%s\n\nGL_EXTENSIONS:\n%s\n",gl_version,gl_extensions);
            return 0;
        }
        
        /tmp/test/test/main.cpp:-1: error: undefined reference to `QOpenGLFunctions::QOpenGLFunctions()'
        :-1: error: collect2: error: ld returned 1 exit status
        

        http://doc.qt.io/qt-5/qopenglfunctions.html#glGetString
        What's wrong now?
        QOpenGLFunctions seem included.

        kshegunovK 1 Reply Last reply 23 Feb 2016, 21:33
        0
        • D deleted451
          23 Feb 2016, 21:24

          @kshegunov

          #include <iostream>
          #include <stdio.h>
          #include <string.h>
          #include <GL/gl.h>
          #include <GL/glu.h>
          #include <GL/glext.h>
          #include <QtOpenGL/QtOpenGL>
          #include <QtOpenGL/QGL>
          #include <QtOpenGL/QGLFunctions>
          #include <QtGui/QOpenGLFunctions>
          int main()
          {
              QOpenGLFunctions gl;
              //gl.initializeOpenGLFunctions();
              const GLubyte* gl_version = gl.glGetString(GL_VERSION);
              const GLubyte* gl_extensions = gl.glGetString(GL_EXTENSIONS);
              printf("GL_VERSION:\n%s\n\nGL_EXTENSIONS:\n%s\n",gl_version,gl_extensions);
              return 0;
          }
          
          /tmp/test/test/main.cpp:-1: error: undefined reference to `QOpenGLFunctions::QOpenGLFunctions()'
          :-1: error: collect2: error: ld returned 1 exit status
          

          http://doc.qt.io/qt-5/qopenglfunctions.html#glGetString
          What's wrong now?
          QOpenGLFunctions seem included.

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on 23 Feb 2016, 21:33 last edited by
          #4

          @Ilya-Indigo
          Do you have QT += gui in your .pro file?

          Read and abide by the Qt Code of Conduct

          D 1 Reply Last reply 23 Feb 2016, 21:35
          0
          • kshegunovK kshegunov
            23 Feb 2016, 21:33

            @Ilya-Indigo
            Do you have QT += gui in your .pro file?

            D Offline
            D Offline
            deleted451
            wrote on 23 Feb 2016, 21:35 last edited by
            #5

            @kshegunov No.

            QT += core
            QT -= gui
            
            CONFIG += c++11
            
            TARGET = test
            CONFIG += console
            CONFIG -= app_bundle
            
            TEMPLATE = app
            
            SOURCES += main.cpp
            
            kshegunovK 1 Reply Last reply 23 Feb 2016, 21:37
            0
            • D deleted451
              23 Feb 2016, 21:35

              @kshegunov No.

              QT += core
              QT -= gui
              
              CONFIG += c++11
              
              TARGET = test
              CONFIG += console
              CONFIG -= app_bundle
              
              TEMPLATE = app
              
              SOURCES += main.cpp
              
              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on 23 Feb 2016, 21:37 last edited by kshegunov
              #6

              @Ilya-Indigo
              Then you should add it, so the linker doesn't complain. :)
              Substitute this:

              QT -= gui
              

              with

              QT += gui
              

              Additionally it seems you need a open gl context to resolve the functions (after calling initializeOpenGLFunctions()). You may need to create that as well.

              Read and abide by the Qt Code of Conduct

              D 2 Replies Last reply 23 Feb 2016, 22:03
              0
              • kshegunovK kshegunov
                23 Feb 2016, 21:37

                @Ilya-Indigo
                Then you should add it, so the linker doesn't complain. :)
                Substitute this:

                QT -= gui
                

                with

                QT += gui
                

                Additionally it seems you need a open gl context to resolve the functions (after calling initializeOpenGLFunctions()). You may need to create that as well.

                D Offline
                D Offline
                deleted451
                wrote on 23 Feb 2016, 22:03 last edited by deleted451
                #7

                @kshegunov Thank you, I do it

                QT += core
                QT += gui
                .........
                

                but if I'am use object stdout is empty, even constant in printf don't printed/

                int main()
                {
                    QOpenGLFunctions gl;
                    gl.initializeOpenGLFunctions();
                    const GLubyte* gl_version = gl.glGetString(GL_VERSION);
                    const GLubyte* gl_extensions = gl.glGetString(GL_EXTENSIONS);
                    printf("GL_VERSION:\n%s\n\nGL_EXTENSIONS:\n%s\n",gl_version,gl_extensions);
                    return 0;
                }
                

                stdout is empty and /tmp/test/build-test-Desktop-Release/test crashed (segmenation fail (core dumped))

                if i don't use object values is null

                int main()
                {
                    void initializeGL();
                    void initializeOpenGLFunctions();
                    const GLubyte* gl_version = glGetString(GL_VERSION);
                    const GLubyte* gl_extensions = glGetString(GL_EXTENSIONS);
                    printf("GL_VERSION:\n%s\n\nGL_EXTENSIONS:\n%s\n",gl_version,gl_extensions);
                    return 0;
                }
                
                GL_VERSION:
                (null)
                
                GL_EXTENSIONS:
                (null)
                
                1 Reply Last reply
                0
                • kshegunovK kshegunov
                  23 Feb 2016, 21:37

                  @Ilya-Indigo
                  Then you should add it, so the linker doesn't complain. :)
                  Substitute this:

                  QT -= gui
                  

                  with

                  QT += gui
                  

                  Additionally it seems you need a open gl context to resolve the functions (after calling initializeOpenGLFunctions()). You may need to create that as well.

                  D Offline
                  D Offline
                  deleted451
                  wrote on 24 Feb 2016, 00:10 last edited by
                  #8

                  @kshegunov
                  What is it "open gl context"?
                  How create it?
                  A lot of this is about where I read, but nowhere is an example of what it is and how to create it.

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    deleted451
                    wrote on 24 Feb 2016, 01:51 last edited by
                    #9
                    #include <iostream>
                    #include <stdio.h>
                    #include <string.h>
                    #include <Qt>
                    #include <QCoreApplication>
                    #include <QObject>
                    #include <GL/gl.h>
                    #include <GL/glu.h>
                    #include <GL/glext.h>
                    #include <QtOpenGL/QtOpenGL>
                    #include <QtOpenGL/QGL>
                    #include <QtOpenGL/QGLFunctions>
                    #include <QOpenGLFunctions>
                    #include <QOpenGLContext>
                    #include <QWidget>
                    #include <QOpenGLWidget>
                    int main()
                    {
                        QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL,true);
                        void initializeGL();
                        void initializeOpenGLFunctions();
                        const GLubyte* gl_version = glGetString(GL_VERSION);
                        const GLubyte* gl_extensions = glGetString(GL_EXTENSIONS);
                        printf("GL_VERSION: %s\nGL_EXTENSIONS: %s\n",gl_version,gl_extensions);
                    
                        QOpenGLContext qc;
                        QOpenGLFunctions* f=qc.shareContext()->functions();
                        const GLubyte* gl_version2 = f->glGetString(GL_VERSION);
                        const GLubyte* gl_extensions2 = f->glGetString(GL_EXTENSIONS);
                        printf("GL_VERSION from Context: %s\nGL_EXTENSIONS from Context: %s\n",gl_version2,gl_extensions2);
                    
                        return 0;
                    }
                    
                    GL_VERSION: (null)
                    GL_EXTENSIONS: (null)
                    Ошибка сегментирования (core dumped)
                    
                    kshegunovK 1 Reply Last reply 24 Feb 2016, 09:41
                    0
                    • D deleted451
                      24 Feb 2016, 01:51
                      #include <iostream>
                      #include <stdio.h>
                      #include <string.h>
                      #include <Qt>
                      #include <QCoreApplication>
                      #include <QObject>
                      #include <GL/gl.h>
                      #include <GL/glu.h>
                      #include <GL/glext.h>
                      #include <QtOpenGL/QtOpenGL>
                      #include <QtOpenGL/QGL>
                      #include <QtOpenGL/QGLFunctions>
                      #include <QOpenGLFunctions>
                      #include <QOpenGLContext>
                      #include <QWidget>
                      #include <QOpenGLWidget>
                      int main()
                      {
                          QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL,true);
                          void initializeGL();
                          void initializeOpenGLFunctions();
                          const GLubyte* gl_version = glGetString(GL_VERSION);
                          const GLubyte* gl_extensions = glGetString(GL_EXTENSIONS);
                          printf("GL_VERSION: %s\nGL_EXTENSIONS: %s\n",gl_version,gl_extensions);
                      
                          QOpenGLContext qc;
                          QOpenGLFunctions* f=qc.shareContext()->functions();
                          const GLubyte* gl_version2 = f->glGetString(GL_VERSION);
                          const GLubyte* gl_extensions2 = f->glGetString(GL_EXTENSIONS);
                          printf("GL_VERSION from Context: %s\nGL_EXTENSIONS from Context: %s\n",gl_version2,gl_extensions2);
                      
                          return 0;
                      }
                      
                      GL_VERSION: (null)
                      GL_EXTENSIONS: (null)
                      Ошибка сегментирования (core dumped)
                      
                      kshegunovK Offline
                      kshegunovK Offline
                      kshegunov
                      Moderators
                      wrote on 24 Feb 2016, 09:41 last edited by
                      #10

                      @Ilya-Indigo
                      Hello,
                      I'm not an expert on OpenGL, but you could try something like this:

                      int main(int argc, char ** argv)
                      {
                          QGuiApplication app(argc, argv);
                      
                          QOpenGLWindow window;
                          window.setSurfaceType(QSurface::OpenGLSurface);
                      
                          QSurfaceFormat format;
                          if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) {
                              format.setVersion(4, 3);
                              format.setProfile(QSurfaceFormat::CoreProfile);
                          }   
                          format.setDepthBufferSize(24);
                          format.setSamples(4);
                          format.setStencilBufferSize(8);
                      
                          window.setFormat(format);
                          window.create();
                      
                          QOpenGLContext context;
                          context.setFormat(format);
                          context.setScreen(QGuiApplication::primaryScreen());
                          context.create();
                      
                          QOpenGLFunctions * gl = context.functions();
                          const GLubyte* gl_version = gl->glGetString(GL_VERSION);
                          // ... and so on ...
                      }
                      

                      I hope this helps.
                      Kind regards.

                      Read and abide by the Qt Code of Conduct

                      D 1 Reply Last reply 24 Feb 2016, 11:59
                      0
                      • kshegunovK kshegunov
                        24 Feb 2016, 09:41

                        @Ilya-Indigo
                        Hello,
                        I'm not an expert on OpenGL, but you could try something like this:

                        int main(int argc, char ** argv)
                        {
                            QGuiApplication app(argc, argv);
                        
                            QOpenGLWindow window;
                            window.setSurfaceType(QSurface::OpenGLSurface);
                        
                            QSurfaceFormat format;
                            if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) {
                                format.setVersion(4, 3);
                                format.setProfile(QSurfaceFormat::CoreProfile);
                            }   
                            format.setDepthBufferSize(24);
                            format.setSamples(4);
                            format.setStencilBufferSize(8);
                        
                            window.setFormat(format);
                            window.create();
                        
                            QOpenGLContext context;
                            context.setFormat(format);
                            context.setScreen(QGuiApplication::primaryScreen());
                            context.create();
                        
                            QOpenGLFunctions * gl = context.functions();
                            const GLubyte* gl_version = gl->glGetString(GL_VERSION);
                            // ... and so on ...
                        }
                        

                        I hope this helps.
                        Kind regards.

                        D Offline
                        D Offline
                        deleted451
                        wrote on 24 Feb 2016, 11:59 last edited by deleted451
                        #11

                        @kshegunov Hello.

                        Unfortunately, still does not want to work.

                        QOpenGLFunctions created with non-current context
                        Ошибка сегментирования (core dumped)
                        
                        #include <iostream>
                        #include <stdio.h>
                        #include <string.h>
                        #include <Qt>
                        #include <QCoreApplication>
                        #include <QGuiApplication>
                        #include <QObject>
                        #include <GL/gl.h>
                        #include <GL/glu.h>
                        #include <GL/glext.h>
                        #include <QtOpenGL/QtOpenGL>
                        #include <QtOpenGL/QGL>
                        #include <QtOpenGL/QGLFunctions>
                        #include <QOpenGLFunctions>
                        #include <QOpenGLContext>
                        #include <QWidget>
                        #include <QOpenGLWidget>
                        int main(int argc, char ** argv)
                        {
                            /*QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL,true);
                            void initializeGL();
                            void initializeOpenGLFunctions();
                            const GLubyte* gl_version1 = glGetString(GL_VERSION);
                            const GLubyte* gl_extensions1 = glGetString(GL_EXTENSIONS);
                            printf("GL_VERSION: %s\nGL_EXTENSIONS: %s\n",gl_version1,gl_extensions1);*/
                        
                            QGuiApplication app(argc, argv);
                            QOpenGLWindow window;
                            window.setSurfaceType(QSurface::OpenGLSurface);
                            QSurfaceFormat format;
                            if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL)
                            {
                                format.setVersion(1,2);
                                format.setProfile(QSurfaceFormat::CoreProfile);
                            }
                            format.setDepthBufferSize(24);
                            format.setSamples(4);
                            format.setStencilBufferSize(8);
                            window.setFormat(format);
                            window.create();
                            QOpenGLContext context;
                            context.setFormat(format);
                            context.setScreen(QGuiApplication::primaryScreen());
                            context.create();
                            QOpenGLFunctions* gl = context.functions();
                            const GLubyte* gl_version2 = gl->glGetString(GL_VERSION);
                            const GLubyte* gl_extensions2 = gl->glGetString(GL_EXTENSIONS);
                            printf("GL_VERSION from Context: %s\nGL_EXTENSIONS from Context: %s\n",gl_version2,gl_extensions2);
                        
                            return 0;
                        }
                        
                        kshegunovK 1 Reply Last reply 24 Feb 2016, 18:29
                        0
                        • D deleted451
                          24 Feb 2016, 11:59

                          @kshegunov Hello.

                          Unfortunately, still does not want to work.

                          QOpenGLFunctions created with non-current context
                          Ошибка сегментирования (core dumped)
                          
                          #include <iostream>
                          #include <stdio.h>
                          #include <string.h>
                          #include <Qt>
                          #include <QCoreApplication>
                          #include <QGuiApplication>
                          #include <QObject>
                          #include <GL/gl.h>
                          #include <GL/glu.h>
                          #include <GL/glext.h>
                          #include <QtOpenGL/QtOpenGL>
                          #include <QtOpenGL/QGL>
                          #include <QtOpenGL/QGLFunctions>
                          #include <QOpenGLFunctions>
                          #include <QOpenGLContext>
                          #include <QWidget>
                          #include <QOpenGLWidget>
                          int main(int argc, char ** argv)
                          {
                              /*QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL,true);
                              void initializeGL();
                              void initializeOpenGLFunctions();
                              const GLubyte* gl_version1 = glGetString(GL_VERSION);
                              const GLubyte* gl_extensions1 = glGetString(GL_EXTENSIONS);
                              printf("GL_VERSION: %s\nGL_EXTENSIONS: %s\n",gl_version1,gl_extensions1);*/
                          
                              QGuiApplication app(argc, argv);
                              QOpenGLWindow window;
                              window.setSurfaceType(QSurface::OpenGLSurface);
                              QSurfaceFormat format;
                              if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL)
                              {
                                  format.setVersion(1,2);
                                  format.setProfile(QSurfaceFormat::CoreProfile);
                              }
                              format.setDepthBufferSize(24);
                              format.setSamples(4);
                              format.setStencilBufferSize(8);
                              window.setFormat(format);
                              window.create();
                              QOpenGLContext context;
                              context.setFormat(format);
                              context.setScreen(QGuiApplication::primaryScreen());
                              context.create();
                              QOpenGLFunctions* gl = context.functions();
                              const GLubyte* gl_version2 = gl->glGetString(GL_VERSION);
                              const GLubyte* gl_extensions2 = gl->glGetString(GL_EXTENSIONS);
                              printf("GL_VERSION from Context: %s\nGL_EXTENSIONS from Context: %s\n",gl_version2,gl_extensions2);
                          
                              return 0;
                          }
                          
                          kshegunovK Offline
                          kshegunovK Offline
                          kshegunov
                          Moderators
                          wrote on 24 Feb 2016, 18:29 last edited by
                          #12

                          @Ilya-Indigo
                          Hm, try calling QOpenGLContext::makeCurrent then. From your last code:

                          // ...
                          context.create();
                          context.makeCurrent(&window);  //< Try inserting this line after creating the context and before retrieving the functions.
                          QOpenGLFunctions* gl = context.functions();
                          // ...
                          

                          Read and abide by the Qt Code of Conduct

                          D 1 Reply Last reply 24 Feb 2016, 22:51
                          1
                          • Chris KawaC Offline
                            Chris KawaC Offline
                            Chris Kawa
                            Lifetime Qt Champion
                            wrote on 24 Feb 2016, 19:32 last edited by Chris Kawa
                            #13

                            All you need is an application object, surface and a context. Here's a minimal example:

                            #include <QApplication>
                            #include <QOffscreenSurface>
                            #include <QOpenGLContext>
                            #include <QOpenGLFunctions>
                            #include <QDebug>
                            
                            int main(int argc, char *argv[])
                            {
                                QApplication a(argc, argv);
                            
                                QOffscreenSurface surf;
                                surf.create();
                            
                                QOpenGLContext ctx;
                                ctx.create();
                                ctx.makeCurrent(&surf);
                            
                                qDebug () << (const char*)ctx.functions()->glGetString(GL_VERSION);
                                qDebug () << (const char*)ctx.functions()->glGetString(GL_EXTENSIONS);
                            }
                            
                            1 Reply Last reply
                            3
                            • kshegunovK kshegunov
                              24 Feb 2016, 18:29

                              @Ilya-Indigo
                              Hm, try calling QOpenGLContext::makeCurrent then. From your last code:

                              // ...
                              context.create();
                              context.makeCurrent(&window);  //< Try inserting this line after creating the context and before retrieving the functions.
                              QOpenGLFunctions* gl = context.functions();
                              // ...
                              
                              D Offline
                              D Offline
                              deleted451
                              wrote on 24 Feb 2016, 22:51 last edited by
                              #14

                              @kshegunov
                              Thank you very much for all your help! :-)
                              After adding this line, the code worked.
                              Although it is not the best, but it is working. :-)

                              @Chris-Kawa
                              Thank you for working and best example, this is what I needed. :-)

                              test.pro

                              QT += opengl
                              
                              CONFIG += c++11
                              
                              TARGET = test
                              CONFIG += console
                              CONFIG -= app_bundle
                              
                              TEMPLATE = app
                              
                              SOURCES += main.cpp
                              

                              main.cpp

                              #include <QtOpenGL>
                              
                              int main(int argc, char *argv[])
                              {
                                  QApplication a(argc, argv);
                              
                                  QOffscreenSurface surf;
                                  surf.create();
                              
                                  QOpenGLContext ctx;
                                  ctx.create();
                                  ctx.makeCurrent(&surf);
                              
                                  const GLubyte* extensions = ctx.functions()->glGetString(GL_EXTENSIONS);
                                  std::string ext = "\t";
                                  int l = strlen((char*)extensions);
                              
                                  for (int i=0;i<l;i++)
                                  {
                                      if (extensions[i] != ' ')
                                          ext += extensions[i];
                                      else
                                          ext += "\n\t";
                                  }
                              
                                  printf("OpenGL: %s %s %s\n\n%s\n", ctx.functions()->glGetString(GL_VENDOR), ctx.functions()->glGetString(GL_RENDERER), ctx.functions()->glGetString(GL_VERSION), ext.c_str());
                              
                                  return 0;
                              }
                              

                              I wonder whether it was possible somehow to replace the spaces (in my code ' ' -> "\n\t", but would be satisfied with a simple ' ' -> '\n') at the line breaks more optimally than I did?
                              replace()/find() doing a little bit more, and with replace_if I did not understand.

                              1 Reply Last reply
                              0
                              • Chris KawaC Offline
                                Chris KawaC Offline
                                Chris Kawa
                                Lifetime Qt Champion
                                wrote on 25 Feb 2016, 00:03 last edited by
                                #15

                                Well, since you're using Qt anyway why not go all the way:

                                QString exts = QString::fromLatin1((const char*)ctx.functions()->glGetString(GL_EXTENSIONS)).replace(" ", "\n\t");
                                

                                or, if you prefer a list instead of one string:

                                QStringList exts = QString::fromLatin1((const char*)ctx.functions()->glGetString(GL_EXTENSIONS)).split(' ');
                                
                                D 1 Reply Last reply 25 Feb 2016, 15:15
                                0
                                • Chris KawaC Chris Kawa
                                  25 Feb 2016, 00:03

                                  Well, since you're using Qt anyway why not go all the way:

                                  QString exts = QString::fromLatin1((const char*)ctx.functions()->glGetString(GL_EXTENSIONS)).replace(" ", "\n\t");
                                  

                                  or, if you prefer a list instead of one string:

                                  QStringList exts = QString::fromLatin1((const char*)ctx.functions()->glGetString(GL_EXTENSIONS)).split(' ');
                                  
                                  D Offline
                                  D Offline
                                  deleted451
                                  wrote on 25 Feb 2016, 15:15 last edited by deleted451
                                  #16

                                  @Chris-Kawa said:

                                  Well, since you're using Qt anyway why not go all the way:

                                  I'm still starting to learn Qt and still do not know about all of its features.

                                  QString exts = QString::fromLatin1((const char*)ctx.functions()->glGetString(GL_EXTENSIONS)).replace(" ", "\n\t");
                                  

                                  Oh great, what you need.

                                  const char* ext = QString::fromLatin1((const char*)ctx.functions()->glGetString(GL_EXTENSIONS)).replace(' ', "\n\t").toStdString().c_str();
                                  
                                  or, if you prefer a list instead of one string:
                                  ```cpp
                                  QStringList exts = QString::fromLatin1((const char*)ctx.functions()->glGetString(GL_EXTENSIONS)).split(' ');
                                  

                                  It reminded me explode(' ') / foreach() in PHP or split(' ').join('\n\t') in JS.
                                  In PHP foreach through the easiest process, but there is no native JS recursive replacement, this had to be split into an array.
                                  But in Qt would like to do is normal, especially if there is native support this. :-)
                                  Although it is not surprised that there is Qt and foreach(), which works the same way as in PHP. :-)

                                  1 Reply Last reply
                                  0
                                  • Chris KawaC Offline
                                    Chris KawaC Offline
                                    Chris Kawa
                                    Lifetime Qt Champion
                                    wrote on 25 Feb 2016, 15:44 last edited by
                                    #17

                                    @Ilya-Indigo said:

                                    const char* ext = QString::fromLatin1((const char*)ctx.functions()->glGetString(GL_EXTENSIONS)).replace(' ', "\n\t").toStdString().c_str();

                                    Don't do that! The string generated by toStdString is a temporary destroyed at the end of this line. The resulting pointer ext points to garbage memory this way!

                                    Do it like this:

                                    QByteArray ext = QString::fromLatin1((const char*)ctx.functions()->glGetString(GL_EXTENSIONS)).replace(' ', "\n\t").toUtf8();
                                    
                                    someFunctionthatExpectsConstCharStar(ext.constData());
                                    

                                    or, if you want std::string, like this:

                                    std::string ext = QString::fromLatin1((const char*)ctx.functions()->glGetString(GL_EXTENSIONS)).replace(' ', "\n\t").toStdString();
                                    
                                    someFunctionthatExpectsConstCharStar(ext.c_str());
                                    

                                    you can store that pointer (almost always bad idea), as long as the original string lives:

                                    std::string ext = QString::fromLatin1((const char*)ctx.functions()->glGetString(GL_EXTENSIONS)).replace(' ', "\n\t").toStdString();
                                    const char* ext_c_str = ext.c_str();
                                    someFunctionthatExpectsConstCharStar(ext_c_str);
                                    

                                    but don't ever store a pointer to a temporary like you did.

                                    1 Reply Last reply
                                    1
                                    • D Offline
                                      D Offline
                                      deleted451
                                      wrote on 25 Feb 2016, 16:16 last edited by deleted451
                                      #18

                                      @Chris-Kawa
                                      Thank you for your comment and clarification. :-)
                                      If I correctly understood and grasped the essence, the "const char *" should be used only in the case of constant declarations.

                                      const char* var_name = "Constant string";
                                      

                                      And if it is not constant, and any expression, it is better to use std :: string?

                                      std::string var_name = a+b+c.some_string_method() ... etc ... ;
                                      
                                      1 Reply Last reply
                                      0
                                      • Chris KawaC Offline
                                        Chris KawaC Offline
                                        Chris Kawa
                                        Lifetime Qt Champion
                                        wrote on 25 Feb 2016, 18:04 last edited by
                                        #19

                                        It's not that general. It's better to understand what's the difference.

                                        std:string, QString, CString and any other kind of library strings are containers. They store data and manage its lifetime. They are responsible for it. The data goes away when the object goes away. Because they do this bookkeeping they are a little heavier to initialize and destroy.
                                        Pointer is just a finger pointing to a place in memory. It carries no notion of ownership or lifetime. The data it points to has no ties to it. It doesn't go away when data goes away. The data doesn't go away when the pointer does. Because of this pointers are ultra-light but also a lot more dangerous.

                                        Pointers to characters are generally good for api-boundary situations. When you have a container type string it usually gives you a raw pointer to its internal data so you can "look" at it from some functions.

                                        A rule of thumb is that you should avoid conversions between container types whenever possible, as they allocate memory, copy stuff around and are generally heavy. If you're using STL stick to std::string. If you're using Qt stick to QString.

                                        Pointers are good and cheap when used for their purpose - pointing at things. They should not be used to manage lifetimes.
                                        For example const char* foo = "bar bazz"; just points at some static data in memory. The data is not going away so its safe to keep this pointer around too. On the other hand const char* foo = someFuncThatGivesMeAPointer()is more vague. Who is responsible for that memory? should you call delete foo at some point or is the memory managed by someone? If it is then when is it released and can you keep the foo pointer and use without worrying that someone releases the memory from under it?

                                        Qt uses a lot of pointers, but it has strict policies about the lifetimes of stuff it gives you pointers to. These are not, however, rules enforced by a compiler, only a general programmer-documentation contract.

                                        D 1 Reply Last reply 25 Feb 2016, 18:27
                                        1
                                        • Chris KawaC Chris Kawa
                                          25 Feb 2016, 18:04

                                          It's not that general. It's better to understand what's the difference.

                                          std:string, QString, CString and any other kind of library strings are containers. They store data and manage its lifetime. They are responsible for it. The data goes away when the object goes away. Because they do this bookkeeping they are a little heavier to initialize and destroy.
                                          Pointer is just a finger pointing to a place in memory. It carries no notion of ownership or lifetime. The data it points to has no ties to it. It doesn't go away when data goes away. The data doesn't go away when the pointer does. Because of this pointers are ultra-light but also a lot more dangerous.

                                          Pointers to characters are generally good for api-boundary situations. When you have a container type string it usually gives you a raw pointer to its internal data so you can "look" at it from some functions.

                                          A rule of thumb is that you should avoid conversions between container types whenever possible, as they allocate memory, copy stuff around and are generally heavy. If you're using STL stick to std::string. If you're using Qt stick to QString.

                                          Pointers are good and cheap when used for their purpose - pointing at things. They should not be used to manage lifetimes.
                                          For example const char* foo = "bar bazz"; just points at some static data in memory. The data is not going away so its safe to keep this pointer around too. On the other hand const char* foo = someFuncThatGivesMeAPointer()is more vague. Who is responsible for that memory? should you call delete foo at some point or is the memory managed by someone? If it is then when is it released and can you keep the foo pointer and use without worrying that someone releases the memory from under it?

                                          Qt uses a lot of pointers, but it has strict policies about the lifetimes of stuff it gives you pointers to. These are not, however, rules enforced by a compiler, only a general programmer-documentation contract.

                                          D Offline
                                          D Offline
                                          deleted451
                                          wrote on 25 Feb 2016, 18:27 last edited by
                                          #20

                                          @Chris-Kawa
                                          Thanks for your reply. I am now much clearer.

                                          1 Reply Last reply
                                          0

                                          1/22

                                          23 Feb 2016, 20:57

                                          • Login

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