Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 1.51 KB | None | 0 0
  1. let sdlsys = match sdl2::init() {
  2.             Ok(s) => s,
  3.             Err(e) => return Err(format!("Could not initialize SDL. {}", e))
  4.         };
  5.  
  6.         let videosys: sdl2::VideoSubsystem = match sdlsys.video() {
  7.             Ok(s) => s,
  8.             Err(e) => return Err(format!("Could not initialize video. {}", e))
  9.         };
  10.  
  11.         let windowsys: Window = match videosys.window(title, w, h).position_centered().opengl().build() {
  12.             Ok(s) => s,
  13.             Err(e) => return Err(format!("Could not create window. {}", e))
  14.         };
  15.  
  16.         let attr = videosys.gl_attr();
  17.         attr.set_context_profile(GLProfile::Core);
  18.         attr.set_context_version(3, 3);
  19.         attr.set_double_buffer(true);
  20.         attr.set_context_flags().debug().set();
  21.  
  22.         let context = match windowsys.gl_create_context() {
  23.             Ok(s) => s,
  24.             Err(e) => return Err(format!("Could not create OpenGL context. {}", e))
  25.         };
  26.         windowsys.gl_make_current(&context);
  27.  
  28.         gl::load_with(|s| videosys.gl_get_proc_address(s) as *const _);
  29.  
  30.         let evt = match sdlsys.event_pump() {
  31.             Ok(s) => s,
  32.             Err(e) => return Err(format!("Could not create Event handler. {}", e))
  33.         };
  34.  
  35.         unsafe {
  36.             println!("GL_VERSION: {}", CStr::from_ptr(gl::GetString(gl::VERSION) as *const i8).to_string_lossy().into_owned());
  37.             println!("GL_VENDOR: {}", CStr::from_ptr(gl::GetString(gl::VENDOR) as *const i8).to_string_lossy().into_owned());
  38.             println!("GL_RENDERER: {}", CStr::from_ptr(gl::GetString(gl::RENDERER) as *const i8).to_string_lossy().into_owned());
  39.         }
  40.  
  41.         Ok(Display {
  42.             _window: windowsys,
  43.             _evt: evt,
  44.             width: w,
  45.             height: h
  46.         })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement