-
I have the following code: open Silk.NET.Windowing
open Silk.NET.Maths
open Silk.NET.OpenGL
open SkiaSharp
let mutable options = WindowOptions.Default
options.Size <- Vector2D<int>(800, 600)
options.Title <- "Testing"
let mutable window = Window.Create(options)
Glfw.GlfwWindowing.IsViewGlfw(window) |> printfn "%A"
window.Initialize()
let glContext = window.GLContext
let glContextHandle = glContext.Handle
let grglInterface = GRGlInterface.CreateAngle(fun name -> window.CreateOpenGL().Context.GetProcAddress(name))
//let grglInterface = GRGlInterface.CreateAngle(fun _ -> glContextHandle)
let grContext = GRContext.CreateGl(grglInterface)
let skImageInfo = SKImageInfo(800, 600)
let surface = SKSurface.Create(grContext, false, skImageInfo)
let canvas = surface.Canvas
canvas.Clear(SKColors.Cyan)
canvas.Flush()
[<EntryPoint>]
let main argv =
window.Run()
0
The Nuget dependencies are simply Silk.NET (2.9.0) and SkiaSharp (2.80.3). I'm on macOS at the moment and have not tried this on Windows yet. Any thoughts? As may be obvious, I know little about OpenGL. I just want to get a setup where I am able to use SkiaSharp to completely handle all drawing inside a GLFW window, using GLFW only for windowing and events. Thanks ahead of time! Update 1Modifying (i.e., fixing) the way I was creating the GRGlInterface has seemed to remove the crashes. Now the issue seems to be the way I am creating the SKSurface, so I'm working on that.
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
From a Silk.NET standpoint I'd expect an issue beeing that you call Window.Run, which will in a loop call on render and then swap, which will in turn make the screen black. |
Beta Was this translation helpful? Give feedback.
-
You can create a |
Beta Was this translation helpful? Give feedback.
-
I am no longer using Silk.NET with SkiaSharp and am instead using my own GLFW bindings with SkiaSharp. Here's what a solution looks like, which mirrors what one would need for using SkiaSharp with any GLFW-based windowing library. open System
open SkiaSharp
open Windowing.Utilities
open Windowing.GLFW.Native.OpenGL
open Windowing.GLFW.Native.Helpers
open Windowing.GLFW.Native.Initialization
open Windowing.GLFW.Native.Context
open Windowing.GLFW.Native.Window
let initialWidth, initialHeight = 500, 500
let mutable framebufferWidth, framebufferHeight = initialWidth, initialHeight
//**********************************************************************
//***** Load the GLFW DLL and initialize GLFW **************************
//**********************************************************************
loadGLFWDLL()
glfwInit()
|> Convert.ToBoolean
|> printfn "Initialized?: %A"
//**********************************************************************
//***** Set window hints ***********************************************
//**********************************************************************
do
match getOSPlatform() with
| MacOS ->
// See https://www.glfw.org/faq.html#41---how-do-i-create-an-opengl-30-context
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3)
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2)
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE)
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE)
| Windows -> ()
| Linux -> ()
| Unsupported osString -> raise (UnsupportedOS osString)
glfwWindowHint(GLFW_SAMPLES, 0)
glfwWindowHint(GLFW_STENCIL_BITS, 1)
glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE)
glfwWindowHint(GLFW_FOCUSED, GLFW_FALSE)
glfwWindowHint(GLFW_MAXIMIZED, GLFW_FALSE)
glfwWindowHint(GLFW_VISIBLE, GLFW_TRUE)
//**********************************************************************
//***** Create the window **********************************************
//**********************************************************************
printfn "Creating window..."
let window = glfwCreateWindow(initialWidth, initialHeight, "Test Window", NULL_MONITOR, NULL_WINDOW)
printfn "Window: %A" window
glfwMakeContextCurrent(window)
//**********************************************************************
//***** Create a Skia surface and draw to its canvas *******************
//**********************************************************************
let grGlInterface = GRGlInterface.Create(glfwGetProcAddress)
if not (grGlInterface.Validate()) then
raise (System.Exception("Invalid GRGlInterface"))
let grContext = GRContext.CreateGl(grGlInterface)
let grGlFramebufferInfo = new GRGlFramebufferInfo(0u, uint32(GL_RGBA8))
let draw(window, width, height) =
glfwPollEvents()
grContext.ResetContext()
let grBackendRenderTarget = new GRBackendRenderTarget(width, height, 1, 0, grGlFramebufferInfo)
let surface = SKSurface.Create(grContext, grBackendRenderTarget, GRSurfaceOrigin.BottomLeft, SKColorType.Rgba8888)
let canvas = surface.Canvas
canvas.Clear(SKColors.Cyan)
let red = new SKPaint(Color = SKColor(200uy, 100uy, 200uy, 255uy))
canvas.DrawCircle(float32(width)/2.0f, float32(height)/2.0f, 100.0f, red)
canvas.Flush()
glfwSwapBuffers(window)
red.Dispose()
surface.Dispose()
grBackendRenderTarget.Dispose()
//**********************************************************************
//***** Setup a callback for when the window is resized ****************
//**********************************************************************
let resizeCallback (window, newWidth: int, newHeight: int) =
draw(window, newWidth, newHeight)
let resizeCallbackFun = GLFWframebuffersizefun(fun window width height -> resizeCallback(window, width, height))
glfwSetFramebufferSizeCallback(window, resizeCallbackFun)
|> ignore
//**********************************************************************
//***** Window loop ****************************************************
//**********************************************************************
while glfwWindowShouldClose window <> 1 do
glfwGetFramebufferSize(window, &framebufferWidth, &framebufferHeight)
draw(window, framebufferWidth, framebufferHeight)
//**********************************************************************
//***** Destroy the window and terminate GLFW **************************
//**********************************************************************
glfwDestroyWindow(window)
glfwTerminate()
|
Beta Was this translation helpful? Give feedback.
I am no longer using Silk.NET with SkiaSharp and am instead using my own GLFW bindings with SkiaSharp. Here's what a solution looks like, which mirrors what one would need for using SkiaSharp with any GLFW-based windowing library.