SHARE
TWEET

Untitled

a guest Jul 21st, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module ElmEye
  2. open Veldrid
  3. open Veldrid.StartupUtilities
  4.  
  5. let CreateApp windowWidth windowHeight name =
  6.     let windowCI = WindowCreateInfo(
  7.                           X = 400,
  8.                           Y =400,
  9.                           WindowWidth = windowWidth,
  10.                           WindowHeight = windowHeight,
  11.                           WindowTitle = name
  12.                           )
  13.     let window = VeldridStartup.CreateWindow(windowCI)
  14.     window.add_Closed (fun () -> exit 0  |>ignore )
  15.     window.Resizable <- true
  16.     window.BorderVisible <-true
  17.     window
  18.  
  19. open System.Diagnostics
  20. open System.Numerics
  21. open ImGuiNET
  22.  
  23. [<EntryPoint>]
  24. let main argv =
  25.     let window = CreateApp 640 480 "ElmEye"
  26.     let gdo = GraphicsDeviceOptions()
  27.     let gd = VeldridStartup.CreateGraphicsDevice(window)
  28.    
  29.     let gui = new ImGuiRenderer(gd, (gd.MainSwapchain.Framebuffer.OutputDescription),window.Width, window.Height)
  30.     let sw = Stopwatch.StartNew()
  31.     let mutable lastFrame = sw.ElapsedMilliseconds
  32.    
  33.     window.add_Resized ( fun ()-> gd.ResizeMainWindow(uint32 window.Width,uint32 window.Height)
  34.                                   gui.WindowResized(window.Width, window.Height)
  35.                                   )
  36.    
  37.     while window.Exists do
  38.         let cl = gd.ResourceFactory.CreateCommandList()
  39.         let events = window.PumpEvents()
  40.        
  41.         gui.Update( float32(sw.ElapsedMilliseconds - lastFrame) ,events)
  42.        
  43.  
  44.         //If the font is too small
  45.         //ImGui.SetWindowFontScale (float32 1.8)
  46.        
  47.         //Use these commands to create an anchor-style panel
  48.         ImGui.SetNextWindowSize(Vector2(float32 (window.Width/2), float32 window.Height))
  49.         ImGui.SetNextWindowPos( Vector2(float32 0,float32 0), ImGuiCond.Always)
  50.         ImGui.Begin("main", ImGuiWindowFlags.NoMove
  51.                         ||| ImGuiWindowFlags.NoCollapse
  52.                         ||| ImGuiWindowFlags.NoTitleBar
  53.                         ||| ImGuiWindowFlags.NoResize)|>ignore
  54.         ImGui.Text "Hello Veldrid"
  55.         ImGui.End()
  56.        
  57.         //the actual Veldrid drawing part
  58.         cl.Begin()
  59.         cl.SetFramebuffer(gd.MainSwapchain.Framebuffer)
  60.  
  61.         //A simple interaction to show you how to capture mouse events in GUI vs your game
  62.         if ImGui.GetIO().WantCaptureMouse then
  63.             cl.ClearColorTarget(uint32 0 , RgbaFloat.Black)
  64.         else
  65.             cl.ClearColorTarget(uint32 0 , RgbaFloat.CornflowerBlue)
  66.         gui.Render (gd, cl)
  67.         cl.End()
  68.  
  69.         gd.SubmitCommands cl
  70.         gd.SwapBuffers()
  71.     printfn "%A" argv
  72.     0 // return an integer exit code
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top