anchor.diff:          use reader = new StreamReader(stream)
           reader.ReadToEnd()
   
  -    /// Loads the shader sourcecode from the text file.
  -    let LoadTextFile (textFileName : string) = 
  +    /// Load the shader sourcecode from the text file.
  +    static member LoadTextFile (textFileName : string) = 
           if Regex(@"^(([a-zA-Z]:\\)|([a-zA-Z]://)|(//)).*").IsMatch(textFileName) then
               File.ReadAllText(textFileName)
           else
               File.ReadAllText(Path.Combine(__SOURCE_DIRECTORY__, textFileName))
   
  -
  -    let OpenGL (openGLVersion : Version.OpenGLVersion) 
  -                (renderContextType : RenderContextType)
  -                width height bitDepth 
  -                (parameters : obj) =
  +    /// Create an OpenGL instance of named version, otherwise throw an exception. 
  +    /// https://github.com/mattdesl/lwjgl-basics/wiki/GLSL-Versions
  +    static member OpenGL (openGLVersion : Version.OpenGLVersion) 
  +                         (renderContextType : RenderContextType)
  +                         width height bitDepth 
  +                         (parameters : obj) =
           let gl = OpenGL()
           if not (gl.Create(openGLVersion, 
                             renderContextType, 
  -                          width, height, 32, 
  +                          width, height, bitDepth, 
                             parameters)) then
               failwith (sprintf "Base.glCreate SharpGL.Version.OpenGLVersion %A" openGLVersion)       
           gl
   
  -
  -
  -
  -
  -
  -
  -
  -module Main = 
  -
  -
  -    // https://github.com/mattdesl/lwjgl-basics/wiki/GLSL-Versions
  +    /// Called after the window and OpenGL are initialized. Called exactly once, before the main loop.
  +    static member Init (gl : OpenGL ref) 
  +             (shaderProgram : ShaderProgram) 
  +             (attributeLocations : Dictionary<uint32, string>) 
  +             vertexShaderCode 
  +             fragmentShaderCode =
  +        shaderProgram.Bind(!gl)
  +        attributeLocations.AsEnumerable()
  +        |> Seq.iter (fun x -> shaderProgram.BindAttributeLocation(!gl, x.Key, x.Value))
  +    
  +        let vertexShader gl shaderSource = 
  +            let shader =  Shaders.VertexShader()
  +            shader.CreateInContext(!gl)
  +            shader.SetSource(shaderSource)
  +            shader.Compile()
  +            if not (shader.CompileStatus.HasValue) then 
  +                failwith (sprintf "failed with source:\n %s" shaderSource)
  +            if not (shader.CompileStatus.Value) then
  +                failwith (sprintf "failed with source:\n%s\ninfoLog:\n%s" shaderSource shader.InfoLog)
  +            shader
  +
  +        let fragmentShader gl shaderSource = 
  +            let shader =  Shaders.FragmentShader()
  +            shader.CreateInContext(!gl)
  +            shader.SetSource(shaderSource)
  +            shader.Compile()
  +            if not (shader.CompileStatus.HasValue) then 
  +                failwith (sprintf "failed with source:\n %s" shaderSource)
  +            if not (shader.CompileStatus.Value) then
  +                failwith (sprintf "failed with source:\n%s\ninfoLog:\n%s" shaderSource shader.InfoLog)
  +            shader
  +
  +        let pixelVertexShader = vertexShader gl vertexShaderCode
  +        let pixelFragmentShader = fragmentShader gl fragmentShaderCode
  +
  +        pixelVertexShader.IsEnabled <- true
  +        pixelFragmentShader.IsEnabled <- true
  +    
  +        (!gl).AttachShader (shaderProgram.ShaderProgramObject, pixelVertexShader.ShaderObject)
  +        (!gl).AttachShader (shaderProgram.ShaderProgramObject, pixelFragmentShader.ShaderObject)
  +        (!gl).LinkProgram (shaderProgram.ShaderProgramObject)
  +        (!gl).DetachShader (shaderProgram.ShaderProgramObject, pixelVertexShader.ShaderObject)
  +        (!gl).DetachShader (shaderProgram.ShaderProgramObject, pixelFragmentShader.ShaderObject)
  +
  +        pixelVertexShader, pixelFragmentShader
  +
  +
  +module Globals = 
  + 
       let vertexShaderCode =
           """
   #version 140
  
positive.code: open GlmNet
  
  
  /// Extending SharpGL.Shaders.ShaderProgram
  module Base =
      
      /// Loads the shader sourcecode from the named manifest resource.
      let LoadManifestResource (textFileName : string) =
      
          let executingAssembly = Assembly.GetExecutingAssembly()
          let pathToDots = textFileName.Replace("\\", ".")
          let location = String.Format("{0}.{1}", executingAssembly.GetName().Name, pathToDots)
  
negative.code:         let mutable openGlCtrl =  w.FindName("openGlCtrl") :?> SharpGL.WPF.OpenGLControl
          
          openGlCtrl.InitializeComponent()
          openGlCtrl.OpenGL.Create(Version.OpenGLVersion.OpenGL3_1, RenderContextType.FBO, 800, 600, 32, (box [||]))
          |> printfn "openGlCtrl.OpenGL.Create %b"
  
          openGlCtrl.OpenGLVersion <- Version.OpenGLVersion.OpenGL3_1
          Arrange (ref openGlCtrl.OpenGL)
  
          openGlCtrl.DrawFPS <- true
          //openGlCtrl.Foreground <- Media.Brushes.White
          openGlCtrl.OpenGLDraw.Add (fun x -> Display (ref x.OpenGL))
  //        openGlCtrl.Resized.Add (fun x -> Display (ref x.OpenGL))
  
  //        [| 
  //            fun _ -> () 
  //            fun _ -> openGlCtrl.OpenGLDraw.Add (fun x -> Display (ref x.OpenGL)) 
  //            fun _ -> openGlCtrl.OpenGLInitialized.Add (fun x -> Display (ref x.OpenGL))         
  //            fun _ -> openGlCtrl.RenderContextType <- RenderContextType.FBO
  //            fun _ -> openGlCtrl.Resized.Add (fun x -> Display (ref x.OpenGL))                    
  //            fun _ -> openGlCtrl.Visibility <- Visibility.Visible            
  //        |]
  //        |> Array.iteri (fun i f -> f (); printfn "%d" i)
  
          w.Title <- sprintf "%s - OpenGL %A" w.Title openGlCtrl.OpenGLVersion
          w
  