How to specify OpenGL version in window X?

My question is how to specify the version of OpenGL in the X-window system and, in addition, remove these obsolete features. My version of GL is 4.3. I know how to do this using SDL or glut.

+3
source share
2 answers

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

To do 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 

Choosing to use basic and / or advanced compatible GLX_CONTEXT_FLAGS profiles that disable legacy features.

+6
source

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

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 . Modify the source code to make sure you # include it instead of the old gl.h and add -D__gl_h_ to your build flags to stop other headers (like glx.h) from importing the old API.

0
source

Source: https://habr.com/ru/post/1259673/


All Articles