// Released to the public domain. Use, modify and relicense at will. //#r "OpenTK.dll" open System open System.Drawing open System.Collections.Generic open OpenTK open OpenTK.Graphics open OpenTK.Graphics.OpenGL open OpenTK.Input type Game() = /// Creates a 800x600 window with the specified title. inherit GameWindow(800, 600, GraphicsMode.Default, "F# OpenTK Sample") do base.VSync <- VSyncMode.On /// Load resources here. /// Not used. override o.OnLoad e = base.OnLoad(e) GL.ClearColor(0.1f, 0.2f, 0.5f, 0.0f) GL.Enable(EnableCap.DepthTest) /// /// Called when your window is resized. Set your viewport here. It is also /// a good place to set up your projection matrix (which probably changes /// along when the aspect ratio of your window). /// /// Not used. override o.OnResize e = base.OnResize e GL.Viewport(base.ClientRectangle.X, base.ClientRectangle.Y, base.ClientRectangle.Width, base.ClientRectangle.Height) let mutable projection = Matrix4.CreatePerspectiveFieldOfView(float32 (Math.PI / 4.), float32 base.Width / float32 base.Height, 1.f, 64.f) GL.MatrixMode(MatrixMode.Projection) GL.LoadMatrix(&projection) /// /// Called when it is time to setup the next frame. Add you game logic here. /// /// Contains timing information for framerate independent logic. override o.OnUpdateFrame e = base.OnUpdateFrame e if base.Keyboard.[Key.Escape] then base.Close() /// /// Called when it is time to render the next frame. Add your rendering code here. /// /// Contains timing information. override o.OnRenderFrame(e) = base.OnRenderFrame e 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() base.SwapBuffers() /// /// The main entry point for the application. /// let game = new Game() do game.Run(30.)