aboutsummaryrefslogtreecommitdiff
path: root/samples/OpenGL/x11argb_opengl/x11argb_opengl.c
diff options
context:
space:
mode:
authorWolfgang Draxinger <Wolfgang.Draxinger@draxit.de>2012-01-05 21:01:19 +0100
committerWolfgang Draxinger <Wolfgang.Draxinger@draxit.de>2012-01-05 21:01:19 +0100
commit62462d2734a16c2b355216b98089f405f6a8163f (patch)
treeb8deee3a60f18d201aa35e4f62e1f4285c673e80 /samples/OpenGL/x11argb_opengl/x11argb_opengl.c
parentf50ddaa63c563cf2483e9c61d22086a05cfd2115 (diff)
downloadcodesamples-62462d2734a16c2b355216b98089f405f6a8163f.tar.gz
codesamples-62462d2734a16c2b355216b98089f405f6a8163f.tar.bz2
OpenGL 3 context creation
Diffstat (limited to 'samples/OpenGL/x11argb_opengl/x11argb_opengl.c')
-rw-r--r--samples/OpenGL/x11argb_opengl/x11argb_opengl.c68
1 files changed, 65 insertions, 3 deletions
diff --git a/samples/OpenGL/x11argb_opengl/x11argb_opengl.c b/samples/OpenGL/x11argb_opengl/x11argb_opengl.c
index f7f4c58..77565f0 100644
--- a/samples/OpenGL/x11argb_opengl/x11argb_opengl.c
+++ b/samples/OpenGL/x11argb_opengl/x11argb_opengl.c
@@ -69,6 +69,37 @@ GLX_DEPTH_SIZE, 16,
None
};
+static int isExtensionSupported(const char *extList, const char *extension)
+{
+
+ const char *start;
+ const char *where, *terminator;
+
+ /* Extension names should not have spaces. */
+ where = strchr(extension, ' ');
+ if ( where || *extension == '\0' )
+ return 0;
+
+ /* It takes a bit of care to be fool-proof about parsing the
+ OpenGL extensions string. Don't be fooled by sub-strings,
+ etc. */
+ for ( start = extList; ; ) {
+ where = strstr( start, extension );
+
+ if ( !where )
+ break;
+
+ terminator = where + strlen( extension );
+
+ if ( where == start || *(where - 1) == ' ' )
+ if ( *terminator == ' ' || *terminator == '\0' )
+ return 1;
+
+ start = terminator;
+ }
+ return 0;
+}
+
static Bool WaitForMapNotify(Display *d, XEvent *e, char *arg)
{
return d && e && arg && (e->type == MapNotify) && (e->xmap.window == *(Window*)arg);
@@ -222,9 +253,40 @@ static void createTheRenderContext()
fatalError("OpenGL not supported by X server\n");
}
- render_context = glXCreateNewContext(Xdisplay, fbconfig, GLX_RGBA_TYPE, 0, True);
- if (!render_context) {
- fatalError("Failed to create a GL context\n");
+#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
+ };
+
+ render_context = glXCreateContextAttribsARB( Xdisplay, fbconfig, 0, True, context_attribs );
+ fputs("glXCreateContextAttribsARB failed", stderr);
+ } else {
+ fputs("glXCreateContextAttribsARB could not be retrieved", stderr);
+ }
+ } else {
+ fputs("glXCreateContextAttribsARB not supported", stderr);
+ }
+
+ if(!render_context)
+ {
+#else
+ {
+#endif
+ render_context = glXCreateNewContext(Xdisplay, fbconfig, GLX_RGBA_TYPE, 0, True);
+ if (!render_context) {
+ fatalError("Failed to create a GL context\n");
+ }
}
if (!glXMakeContextCurrent(Xdisplay, glX_window_handle, glX_window_handle, render_context)) {