diff options
author | Pierre Krieger <pierre.krieger1708@gmail.com> | 2014-08-07 18:03:56 +0200 |
---|---|---|
committer | Pierre Krieger <pierre.krieger1708@gmail.com> | 2014-08-07 18:03:56 +0200 |
commit | d3e3590b84502c0d18228d40d2676cea2247bd02 (patch) | |
tree | 9285e751e5a4194011ce656455d2def50756f226 /src | |
parent | 76ebf39bcdec733bd11950ea8478c665878460a6 (diff) | |
download | glutin-d3e3590b84502c0d18228d40d2676cea2247bd02.tar.gz glutin-d3e3590b84502c0d18228d40d2676cea2247bd02.zip |
Fix glXCreateContextAttrib always null
Diffstat (limited to 'src')
-rw-r--r-- | src/x11/mod.rs | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/src/x11/mod.rs b/src/x11/mod.rs index d2619c9..9103ea2 100644 --- a/src/x11/mod.rs +++ b/src/x11/mod.rs @@ -141,19 +141,33 @@ impl Window { // getting the pointer to glXCreateContextAttribs let create_context_attribs = unsafe { - let mut addr = unsafe { ffi::glXGetProcAddress(b"glXCreateContextAttribs".as_ptr() - as *const u8) } as *const (); - - if addr.is_null() { - addr = unsafe { ffi::glXGetProcAddress(b"glXCreateContextAttribsARB".as_ptr() + // creating the dummy context + let dummy_context = + ffi::glXCreateContext(display, &visual_infos, ptr::null(), 1); + ffi::glXMakeCurrent(display, window, dummy_context); + + // getting the pointer + let fn_ptr = { + let mut addr = unsafe { ffi::glXGetProcAddress(b"glXCreateContextAttribs".as_ptr() as *const u8) } as *const (); - } - - addr.to_option().map(|addr| { - let addr: extern "system" fn(*mut ffi::Display, ffi::GLXFBConfig, ffi::GLXContext, - ffi::Bool, *const libc::c_int) -> ffi::GLXContext = unsafe { mem::transmute(addr) }; - addr - }) + + if addr.is_null() { + addr = unsafe { ffi::glXGetProcAddress(b"glXCreateContextAttribsARB".as_ptr() + as *const u8) } as *const (); + } + + addr.to_option().map(|addr| { + let addr: extern "system" fn(*mut ffi::Display, ffi::GLXFBConfig, ffi::GLXContext, + ffi::Bool, *const libc::c_int) -> ffi::GLXContext = mem::transmute(addr); + addr + }) + }; + + // cleaning up + ffi::glXMakeCurrent(ptr::mut_null(), 0, ptr::null()); + ffi::glXDestroyContext(display, dummy_context); + + fn_ptr }; // creating IM |