简体   繁体   English

如何在X窗口中指定OpenGL版本?

[英]How to specify OpenGL version in X window?

My question is how to specify OpenGL version in X window system and in addition remove those deprecated functions. 我的问题是如何在X窗口系统中指定OpenGL版本,另外删除那些已弃用的函数。 My GL version is 4.3. 我的GL版本是4.3。 I know how to do that using SDL or glut. 我知道如何使用SDL或过剩来做到这一点。

First you must know how to create a OpenGL context using bare X11 / Xlib first. 首先,您必须首先了解如何使用裸X11 / Xlib创建OpenGL上下文。 Have a look at this code https://github.com/datenwolf/codesamples/blob/master/samples/OpenGL/x11argb_opengl/x11argb_opengl.c 看看这段代码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. 选择使用GLX_CONTEXT_FLAGS核心和/或转发兼容配置文件,这将禁用已弃用的功能。

Creating a GLX context for version 3/4 without the compatibility profile detects use of deprecated functions at runtime. 在没有兼容性配置文件的情况下为版本3/4创建GLX上下文会检测在运行时使用已弃用的函数。

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 . 如果希望编译器检测旧函数,则需要从http://www.opengl.org/registry/#apispecs下载glcorearb.h(以前称为gl3.h)的副本。 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. 调整源代码以确保#include这而不是旧的gl.h,并将-D__gl_h_添加到构建标志以阻止其他头(例如glx.h)导入旧API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM