diff options
| author | Tomaka17 <pierre.krieger1708@gmail.com> | 2014-08-02 11:03:09 +0200 | 
|---|---|---|
| committer | Tomaka17 <pierre.krieger1708@gmail.com> | 2014-08-02 11:03:09 +0200 | 
| commit | 8c074af9fca98d2b01036658377a2a66a8dd56b7 (patch) | |
| tree | c3db1917d5dd997fea69d8415a96df5d2842ae7f /src | |
| parent | 13c73cce5edde5b2eab3c0a1ef01a34eadf2949b (diff) | |
| download | glutin-8c074af9fca98d2b01036658377a2a66a8dd56b7.tar.gz glutin-8c074af9fca98d2b01036658377a2a66a8dd56b7.zip | |
Add support for specific OpenGL version for Win32
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib.rs | 11 | ||||
| -rw-r--r-- | src/win32/ffi.rs | 11 | ||||
| -rw-r--r-- | src/win32/init.rs | 16 | 
3 files changed, 34 insertions, 4 deletions
| @@ -29,6 +29,7 @@ pub struct WindowBuilder {      dimensions: (uint, uint),      title: String,      monitor: Option<winimpl::MonitorID>, +    gl_version: Option<(uint, uint)>,  }  impl WindowBuilder { @@ -38,6 +39,7 @@ impl WindowBuilder {              dimensions: (1024, 768),              title: String::new(),              monitor: None, +            gl_version: None,          }      } @@ -57,6 +59,15 @@ impl WindowBuilder {          self      } +    /// Requests to use a specific OpenGL version. +    /// +    /// Version is a (major, minor) pair. For example to request OpenGL 3.3 +    ///  you would pass `(3, 3)`. +    pub fn with_gl_version(mut self, version: (uint, uint)) -> WindowBuilder { +        self.gl_version = Some(version); +        self +    } +      /// Builds the window.      ///       /// Error should be very rare and only occur in case of permission denied, incompatible system, diff --git a/src/win32/ffi.rs b/src/win32/ffi.rs index a217e20..73ade51 100644 --- a/src/win32/ffi.rs +++ b/src/win32/ffi.rs @@ -365,6 +365,17 @@ pub static VK_NONAME: WPARAM = 0xFC;  pub static VK_PA1: WPARAM = 0xFD;  pub static VK_OEM_CLEAR: WPARAM = 0xFE; +// ? +pub static WGL_CONTEXT_DEBUG_BIT_ARB: libc::c_int = 0x00000001; +pub static WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB: libc::c_int = 0x00000002; +pub static WGL_CONTEXT_MAJOR_VERSION_ARB: libc::c_int = 0x2091; +pub static WGL_CONTEXT_MINOR_VERSION_ARB: libc::c_int = 0x2092; +pub static WGL_CONTEXT_LAYER_PLANE_ARB: libc::c_int = 0x2093; +pub static WGL_CONTEXT_FLAGS_ARB: libc::c_int = 0x2094; +pub static WGL_CONTEXT_PROFILE_MASK_ARB: libc::c_int = 0x9126; +pub static WGL_CONTEXT_CORE_PROFILE_BIT_ARB: libc::c_int = 0x00000001; +pub static WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB: libc::c_int = 0x00000002; +  // messages  pub static WM_LBUTTONDOWN: UINT = 0x0201;  pub static WM_LBUTTONUP: UINT = 0x0202; diff --git a/src/win32/init.rs b/src/win32/init.rs index c4d31da..09df5b0 100644 --- a/src/win32/init.rs +++ b/src/win32/init.rs @@ -250,14 +250,22 @@ pub fn new_window(builder: WindowBuilder) -> Result<Window, String> {          let context = {              use libc; -            let attributes: [libc::c_int, ..1] = [ -                0 -            ]; +            let mut attributes = Vec::new(); + +            if builder.gl_version.is_some() { +                let version = builder.gl_version.as_ref().unwrap(); +                attributes.push(ffi::WGL_CONTEXT_MAJOR_VERSION_ARB); +                attributes.push(version.val0() as libc::c_int); +                attributes.push(ffi::WGL_CONTEXT_MINOR_VERSION_ARB); +                attributes.push(version.val1() as libc::c_int); +            } + +            attributes.push(0);              let ctxt = unsafe {                  match create_context_attribs {                      None => ffi::wglCreateContext(hdc), -                    Some(ptr) => ptr(hdc, ptr::mut_null(), attributes.as_ptr()) +                    Some(ptr) => ptr(hdc, ptr::mut_null(), attributes.as_slice().as_ptr())                  }              }; | 
