Skip to content

Instantly share code, notes, and snippets.

@tk3
Created January 16, 2021 11:18
Show Gist options
  • Save tk3/a7abd69eb62387f14e6090cd7e7e1c4d to your computer and use it in GitHub Desktop.
Save tk3/a7abd69eb62387f14e6090cd7e7e1c4d to your computer and use it in GitHub Desktop.
Lesson 01 Hello SDL
open FSharp.SDL2
open System
open System.Runtime.InteropServices
[<EntryPoint>]
let main argv =
if SDL.Init(SDL.INIT_VIDEO) < 0 then
printfn"SDL could not initialize! SDL_Error: %s\n" (SDL.GetError())
Environment.Exit 1
let screenWidth = 640
let screenHeight = 480
let window = SDL.CreateWindow("SDL Tutorial", SDL.WINDOWPOS_CENTERED, SDL.WINDOWPOS_CENTERED, screenWidth, screenHeight, SDL.WindowFlags.WINDOW_SHOWN)
let screenSurfacePtr = SDL.GetWindowSurface(window)
let screenSurface: SDL.Surface = Marshal.PtrToStructure(screenSurfacePtr, typeof<SDL.Surface>) :?> SDL.Surface
let mapRgb = SDL.MapRGB(screenSurface.format, 0xffuy, 0xffuy, 0xffuy)
SDL.FillRect(screenSurfacePtr, IntPtr.Zero, mapRgb) |> ignore
SDL.UpdateWindowSurface(screenSurfacePtr) |> ignore
SDL.Delay(2000u)
SDL.DestroyWindow(window)
SDL.Quit()
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment