fn create_context(
    events_loop: &glutin::EventsLoop,
    config: &Config,
) -> Result<Display, Box<dyn Error>> {
    // initialize window builder
    let mut window_builder = glutin::WindowBuilder::new();
    // check for window mode and set params
    match config.window_mode {
        WindowMode::Windowed => (),
        // TODO: if we add a fullscreen window mode
        // FullScreenWindow => (),
        WindowMode::FullScreen => {
            window_builder =
                window_builder.with_fullscreen(Some(events_loop.get_primary_monitor()));
            window_builder = window_builder.with_decorations(false);
        }
    }
    // set title, resolution & create glium context
    window_builder = window_builder.with_title(config.window_title.clone());
    window_builder =
        window_builder.with_dimensions((config.resolution.width, config.resolution.height).into());

    let context_builder = glutin::ContextBuilder::new()
        .with_depth_buffer(24)
        .with_vsync(config.vsync);

    let context = glium::Display::new(window_builder, context_builder, &events_loop);

    match context {
        Err(e) => {
            // TODO: print more user friendly output
            error!("OpenGL context creation failed! Detailed error:");
            error!("{}", e);

            Err(e.into())
        }
        Ok(context) => {
            // Print some information about the acquired OpenGL context
            info!("OpenGL context was successfully built");

            let glium::Version(api, major, minor) = *context.get_opengl_version();
            info!(
                "Version of context: {} {}.{}",
                if api == glium::Api::Gl {
                    "OpenGL"
                } else {
                    "OpenGL ES"
                },
                major,
                minor
            );

            let glium::Version(api, major, minor) = context.get_supported_glsl_version();
            info!(
                "Supported GLSL version: {} {}.{}",
                if api == glium::Api::Gl {
                    "GLSL"
                } else {
                    "GLSL ES"
                },
                major,
                minor
            );

            if let Some(mem) = context.get_free_video_memory().map(|mem| mem as u64) {
                let (mem, unit) = match () {
                    _ if mem < (1 << 12) => (mem, "B"),
                    _ if mem < (1 << 22) => (mem >> 10, "KB"),
                    _ if mem < (1 << 32) => (mem >> 20, "MB"),
                    _ => (mem >> 30, "GB"),
                };
                info!("Free GPU memory (estimated): {}{}", mem, unit);
            }

            Ok(context)
        }
    }
}
/// Creates the OpenGL context and prints useful information about the
/// success or failure of said action.
Creates the OpenGL context and prints useful information about the
success or failure of said action.
Creates the OpenGL context and prints useful information about the success or failure of said action .
fn create_context(
    events_loop: &glutin::EventsLoop,
    config: &Config,
) -> Result<Display, Box<dyn Error>> {
    // initialize window builder
    let mut window_builder = glutin::WindowBuilder::new();
    // check for window mode and set params
    match config.window_mode {
        WindowMode::Windowed => (),
        // TODO: if we add a fullscreen window mode
        // FullScreenWindow => (),
        WindowMode::FullScreen => {
            window_builder =
                window_builder.with_fullscreen(Some(events_loop.get_primary_monitor()));
            window_builder = window_builder.with_decorations(false);
        }
    }
    // set title, resolution & create glium context
    window_builder = window_builder.with_title(config.window_title.clone());
    window_builder =
        window_builder.with_dimensions((config.resolution.width, config.resolution.height).into());
    let context_builder = glutin::ContextBuilder::new()
        .with_depth_buffer(24)
        .with_vsync(config.vsync);
    let context = glium::Display::new(window_builder, context_builder, &events_loop);
    match context {
        Err(e) => {
            // TODO: print more user friendly output
            error!("OpenGL context creation failed! Detailed error:");
            error!("{}", e);
            Err(e.into())
        }
        Ok(context) => {
            // Print some information about the acquired OpenGL context
            info!("OpenGL context was successfully built");
            let glium::Version(api, major, minor) = *context.get_opengl_version();
            info!(
                "Version of context: {} {}.{}",
                if api == glium::Api::Gl {
                    "OpenGL"
                } else {
                    "OpenGL ES"
                },
                major,
                minor
            );
            let glium::Version(api, major, minor) = context.get_supported_glsl_version();
            info!(
                "Supported GLSL version: {} {}.{}",
                if api == glium::Api::Gl {
                    "GLSL"
                } else {
                    "GLSL ES"
                },
                major,
                minor
            );
            if let Some(mem) = context.get_free_video_memory().map(|mem| mem as u64) {
                let (mem, unit) = match () {
                    _ if mem < (1 << 12) => (mem, "B"),
                    _ if mem < (1 << 22) => (mem >> 10, "KB"),
                    _ if mem < (1 << 32) => (mem >> 20, "MB"),
                    _ => (mem >> 30, "GB"),
                };
                info!("Free GPU memory (estimated): {}{}", mem, unit);
            }
            Ok(context)
        }
    }
}
fn create_context ( events_loop : & glutin :: EventsLoop , config : & Config , ) -> Result < Display , Box < dyn Error > > { // initialize window builder let mut window_builder = glutin :: WindowBuilder :: new ( ) ; // check for window mode and set params match config . window_mode { WindowMode :: Windowed => ( ) , // TODO: if we add a fullscreen window mode // FullScreenWindow => (), WindowMode :: FullScreen => { window_builder = window_builder . with_fullscreen ( Some ( events_loop . get_primary_monitor ( ) ) ) ; window_builder = window_builder . with_decorations ( false ) ; } } // set title, resolution & create glium context window_builder = window_builder . with_title ( config . window_title . clone ( ) ) ; window_builder = window_builder . with_dimensions ( ( config . resolution . width , config . resolution . height ) . into ( ) ) ; let context_builder = glutin :: ContextBuilder :: new ( ) . with_depth_buffer ( 24 ) . with_vsync ( config . vsync ) ; let context = glium :: Display :: new ( window_builder , context_builder , & events_loop ) ; match context { Err ( e ) => { // TODO: print more user friendly output error ! ( " " ) ; error ! ( " " e ) ; Err ( e . into ( ) ) } Ok ( context ) => { // Print some information about the acquired OpenGL context info ! ( " " ) ; let glium :: Version ( api , major , minor ) = * context . get_opengl_version ( ) ; info ! ( " " if api glium Api Gl { " " } else { " " } major minor ) ; let glium :: Version ( api , major , minor ) = context . get_supported_glsl_version ( ) ; info ! ( " " if api glium Api Gl { " " } else { " " } major minor ) ; if let Some ( mem ) = context . get_free_video_memory ( ) . map ( | mem | mem as u64 ) { let ( mem , unit ) = match ( ) { _ if mem < ( 1 << 12 ) => ( mem , " " ) , _ if mem < ( 1 << 22 ) => ( mem >> 10 , " " ) , _ if mem < ( 1 << 32 ) => ( mem >> 20 , " " ) , _ => ( mem >> 30 , " " ) , } ; info ! ( " " mem unit ) ; } Ok ( context ) } } }
Creates the OpenGL context and prints useful information about the
success or failure of said action.
Creates the OpenGL context and prints useful information about the success or failure of said action .
events_loop
&glutin::EventsLoop
config
&Config