How to specify OpenGL version in X window?

浪尽此生 提交于 2019-12-10 18:58:35

问题


My question is how to specify OpenGL version in X window system and in addition remove those deprecated functions. My GL version is 4.3. I know how to do that using SDL or glut.


回答1:


First you must know how to create a OpenGL context using bare X11 / Xlib first. Have a look at this code https://github.com/datenwolf/codesamples/blob/master/samples/OpenGL/x11argb_opengl/x11argb_opengl.c

To make this actually select a modern version profile this code block is used

#if USE_GLX_CREATE_CONTEXT_ATTRIB
    #define GLX_CONTEXT_MAJOR_VERSION_ARB       0x2091
    #define GLX_CONTEXT_MINOR_VERSION_ARB       0x2092
    render_context = NULL;
    if( isExtensionSupported( glXQueryExtensionsString(Xdisplay, DefaultScreen(Xdisplay)), "GLX_ARB_create_context" ) ) {
        typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
        glXCreateContextAttribsARBProc glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
        if( glXCreateContextAttribsARB ) {
            int context_attribs[] =
            {
                GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
                GLX_CONTEXT_MINOR_VERSION_ARB, 0,
                //GLX_CONTEXT_FLAGS_ARB        , GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
                None
            };

            int (*oldHandler)(Display*, XErrorEvent*) = XSetErrorHandler(&ctxErrorHandler);

            render_context = glXCreateContextAttribsARB( Xdisplay, fbconfig, 0, True, context_attribs );

            XSync( Xdisplay, False );
            XSetErrorHandler( oldHandler );

            fputs("glXCreateContextAttribsARB failed", stderr);
        } else {
            fputs("glXCreateContextAttribsARB could not be retrieved", stderr);
        }
    } else {
            fputs("glXCreateContextAttribsARB not supported", stderr);
    }

    if(!render_context)
    {
#else

Using the GLX_CONTEXT_FLAGS core and / or forward compatible profiles are selected, which disable deprecated functionality.




回答2:


Creating a GLX context for version 3/4 without the compatibility profile detects use of deprecated functions at runtime.

If you want the compiler to detect old functions, you need to download a copy of glcorearb.h (formerly gl3.h) from http://www.opengl.org/registry/#apispecs. Tweak the source code to make sure you #include this instead of the old gl.h, and add -D__gl_h_ to your build flags to stop other headers (eg glx.h) from importing the old API.



来源:https://stackoverflow.com/questions/17606752/how-to-specify-opengl-version-in-x-window

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!