serinox's picture

F# issue using GameWindow

OK I'm writing a small F# program and am trying to use the GameWindow with the code found below ( a lot of it comes from the examples online). All I get is a black window. I can use the escape key to kill the window so I know it's doing something in the run loop. Any ideas one why it won't render anything? It doesn't give any error messages on the console until you kill the window and it says something about a "BadDrawable (invalid Pixmap or Window parameter)" I think thats just because I don't clean anything up yet right?

And if it makes any difference this has been run on Linux/mono in a virtual machine and Windows/.net under both systems it was tried from the F# interactive REPL with the same results.

type Test() = 
 
        let Window = new OpenTK.GameWindow()
 
        let RenderFrame (e:FrameEventArgs) = 
            Window.Context.MakeCurrent(Window.WindowInfo)
            GL.Clear(ClearBufferMask.ColorBufferBit ||| ClearBufferMask.DepthBufferBit)
            let mutable modelview = Matrix4.LookAt(Vector3.Zero, Vector3.UnitZ, Vector3.UnitY)
            GL.MatrixMode(MatrixMode.Modelview)
            GL.LoadMatrix(&modelview)
 
            GL.Begin(BeginMode.Triangles)
            GL.Color3(1.f, 1.f, 0.f); GL.Vertex3(-1.f, -1.f, 4.f)
            GL.Color3(1.f, 0.f, 0.f); GL.Vertex3(1.f, -1.f, 4.f)
            GL.Color3(0.2f, 0.9f, 1.f); GL.Vertex3(0.f, 1.f, 4.f)
            GL.End()
 
 
 
        let Resize e =
            GL.Viewport(Window.ClientRectangle.X, Window.ClientRectangle.Y, Window.ClientRectangle.Width, Window.ClientRectangle.Height)
            let mutable projection = Matrix4.CreatePerspectiveFieldOfView(float32 (Math.PI / 4.), float32 Window.Width / float32 Window.Height, 1.f, 64.f)
            GL.MatrixMode(MatrixMode.Projection)
            GL.LoadMatrix(&projection)
 
        let UpdateFrame e =
            if Window.Keyboard.[Key.Escape] then Window.Close()
 
        member this.run = 
                    Window.RenderFrame.Add RenderFrame
                    Window.Resize.Add Resize
                    Window.VSync <- VSyncMode.On
                    GL.ClearColor(0.1f, 0.2f, 0.5f, 0.0f)
                    GL.Enable(EnableCap.DepthTest)
                    Window.UpdateFrame.Add UpdateFrame
                    Window.Run(30.0)