Created
January 20, 2014 10:45
-
-
Save sbarski/8518136 to your computer and use it in GitHub Desktop.
F# and OpenTK together This sample is adopted from the C# example in http://www.opentk.com/doc/chapter/0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 g() as this = | |
inherit GameWindow(800, 600, GraphicsMode.Default, "http://www.opentk.com/doc/chapter/0") | |
do this.Resize.Add(fun e -> GL.Viewport(0, 0, this.Width, this.Height)) | |
do this.Load.Add(fun e -> this.VSync <- VSyncMode.On) | |
do this.UpdateFrame.Add(fun e -> if this.Keyboard.[Key.Escape] then this.Exit()) | |
do this.RenderFrame.Add(this._RenderFrameEvent) | |
member this._RenderFrameEvent e = | |
GL.Clear(ClearBufferMask.ColorBufferBit ||| ClearBufferMask.DepthBufferBit) | |
GL.MatrixMode(MatrixMode.Projection) | |
GL.LoadIdentity() | |
GL.Ortho(-1.0, 1.0, -1.0, 1.0, 0.0, 4.0) | |
GL.Begin(PrimitiveType.Triangles) | |
GL.Color3(Color.MidnightBlue); | |
GL.Vertex2(-1.0f, 1.0f); | |
GL.Color3(Color.SpringGreen); | |
GL.Vertex2(0.0f, -1.0f); | |
GL.Color3(Color.Ivory); | |
GL.Vertex2(1.0f, 1.0f); | |
GL.End(); | |
this.SwapBuffers() | |
/// <summary> | |
/// The main entry point for the application. | |
/// </summary> | |
let game = new g() | |
do game.Run(60.0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment