pub fn initialize_offscreen_rendering() -> Result<impl OffscreenRenderContext, RenderInitError> {
    unsafe {
        // Try to select a pixel format
        let pixel_attributes        = vec![
            cgl::kCGLPFAAccelerated,
            cgl::kCGLPFAOpenGLProfile, 0x3200,
            cgl::kCGLPFAColorSize, 24,
            cgl::kCGLPFADepthSize, 16,
            0
        ];
        let mut pixel_format        = ptr::null_mut();
        let mut num_pixel_formats   = 0;
        let pixel_format_error      = cgl::CGLChoosePixelFormat(pixel_attributes.as_ptr(), &mut pixel_format, &mut num_pixel_formats);
        to_render_error(pixel_format_error)?;

        if pixel_format.is_null() {
            Err(RenderInitError::DisplayNotAvailable)?
        }

        // Try to create a context from the pixel format we selected
        let mut context     = ptr::null_mut();
        let context_error   = cgl::CGLCreateContext(pixel_format, ptr::null_mut(), &mut context);
        to_render_error(context_error)?;

        if context.is_null() {
            Err(RenderInitError::CouldNotCreateContext)?
        }

        // Try to set this as the current thread's context
        let set_context_error = cgl::CGLSetCurrentContext(context);
        if set_context_error != 0 {
            Err(RenderInitError::ContextDidNotStart)?
        }

        // Load as the GL functions
        gl::load_with(|name| get_proc_address(name));

        // Check for errors
        let error = gl::GetError();
        if error != gl::NO_ERROR { println!("gl::GetError {:x}", error); Err(RenderInitError::ContextDidNotStart)? }
        assert!(error == gl::NO_ERROR);

        // Result is a CGL offscreen context
        Ok(CglOffscreenRenderContext {
            _pixel_format:  pixel_format,
            context:        context
        })
    }
}
///
/// Performs on-startup initialisation steps for offscreen rendering
///
/// Only required if not using a toolkit renderer (eg, in an HTTP renderer or command-line tool). Will likely replace
/// the bindings for any GUI toolkit, so this is not appropriate for desktop-type apps.
///
/// This version is the CGL version for Mac OS X
///
Performs on-startup initialisation steps for offscreen rendering
Only required if not using a toolkit renderer . Will likely replace
the bindings for any GUI toolkit, so this is not appropriate for desktop-type apps.

This version is the CGL version for Mac OS X
Performs on - startup initialisation steps for offscreen rendering Only required if not using a toolkit renderer . Will likely replace the bindings for any GUI toolkit so this is not appropriate for desktop - type apps . This version is the CGL version for Mac OS X
pub fn initialize_offscreen_rendering() -> Result<impl OffscreenRenderContext, RenderInitError> {
    unsafe {
        // Try to select a pixel format
        let pixel_attributes        = vec![
            cgl::kCGLPFAAccelerated,
            cgl::kCGLPFAOpenGLProfile, 0x3200,
            cgl::kCGLPFAColorSize, 24,
            cgl::kCGLPFADepthSize, 16,
            0
        ];
        let mut pixel_format        = ptr::null_mut();
        let mut num_pixel_formats   = 0;
        let pixel_format_error      = cgl::CGLChoosePixelFormat(pixel_attributes.as_ptr(), &mut pixel_format, &mut num_pixel_formats);
        to_render_error(pixel_format_error)?;
        if pixel_format.is_null() {
            Err(RenderInitError::DisplayNotAvailable)?
        }
        // Try to create a context from the pixel format we selected
        let mut context     = ptr::null_mut();
        let context_error   = cgl::CGLCreateContext(pixel_format, ptr::null_mut(), &mut context);
        to_render_error(context_error)?;
        if context.is_null() {
            Err(RenderInitError::CouldNotCreateContext)?
        }
        // Try to set this as the current thread's context
        let set_context_error = cgl::CGLSetCurrentContext(context);
        if set_context_error != 0 {
            Err(RenderInitError::ContextDidNotStart)?
        }
        // Load as the GL functions
        gl::load_with(|name| get_proc_address(name));
        // Check for errors
        let error = gl::GetError();
        if error != gl::NO_ERROR { println!("gl::GetError {:x}", error); Err(RenderInitError::ContextDidNotStart)? }
        assert!(error == gl::NO_ERROR);
        // Result is a CGL offscreen context
        Ok(CglOffscreenRenderContext {
            _pixel_format:  pixel_format,
            context:        context
        })
    }
}
pub fn initialize_offscreen_rendering ( ) -> Result < impl OffscreenRenderContext , RenderInitError > { unsafe { // Try to select a pixel format let pixel_attributes = vec ! [ cgl kCGLPFAAccelerated cgl kCGLPFAOpenGLProfile 0x3200 cgl kCGLPFAColorSize 24 cgl kCGLPFADepthSize 16 0 ] ; let mut pixel_format = ptr :: null_mut ( ) ; let mut num_pixel_formats = 0 ; let pixel_format_error = cgl :: CGLChoosePixelFormat ( pixel_attributes . as_ptr ( ) , & mut pixel_format , & mut num_pixel_formats ) ; to_render_error ( pixel_format_error ) ? ; if pixel_format . is_null ( ) { Err ( RenderInitError :: DisplayNotAvailable ) ? } // Try to create a context from the pixel format we selected let mut context = ptr :: null_mut ( ) ; let context_error = cgl :: CGLCreateContext ( pixel_format , ptr :: null_mut ( ) , & mut context ) ; to_render_error ( context_error ) ? ; if context . is_null ( ) { Err ( RenderInitError :: CouldNotCreateContext ) ? } // Try to set this as the current thread's context let set_context_error = cgl :: CGLSetCurrentContext ( context ) ; if set_context_error != 0 { Err ( RenderInitError :: ContextDidNotStart ) ? } // Load as the GL functions gl :: load_with ( | name | get_proc_address ( name ) ) ; // Check for errors let error = gl :: GetError ( ) ; if error != gl :: NO_ERROR { println ! ( " " error ) ; Err ( RenderInitError :: ContextDidNotStart ) ? } assert ! ( error gl NO_ERROR ) ; // Result is a CGL offscreen context Ok ( CglOffscreenRenderContext { _pixel_format : pixel_format , context : context } ) } }
Performs on-startup initialisation steps for offscreen rendering
Only required if not using a toolkit renderer (eg, in an HTTP renderer or command-line tool).
Performs on - startup initialisation steps for offscreen rendering Only required if not using a toolkit renderer ( eg in an HTTP renderer or command - line tool ) .