dotnet / Silk.NET

The high-speed OpenGL, OpenCL, OpenAL, OpenXR, GLFW, SDL, Vulkan, Assimp, WebGPU, and DirectX bindings library your mother warned you about.
https://dotnet.github.io/Silk.NET
MIT License
4.13k stars 397 forks source link

virtualbox 3d accel support #246

Closed devel0 closed 4 years ago

devel0 commented 4 years ago

Summary of feature

Trying to run hello quad on virtualbox win guest in linux host with 3d accel enabled I got Unhandled exception. Silk.NET.GLFW.GlfwException: VersionUnavailable: WGL: Failed to create OpenGL context

Comments

Trying to run the gears example of glfw in virtualbox it works without any problem. I tried to replace glfw3.dll generated file into silknet example but nothing changes, full error follow:

Unhandled exception. Silk.NET.GLFW.GlfwException: VersionUnavailable: WGL: Failed to create OpenGL context
   at Silk.NET.GLFW.Glfw.<>c.<.cctor>b__137_0(ErrorCode errorCode, String description) in Z:\Silk.NET\src\Windowing\Silk.NET.GLFW\Glfw.cs:line 51
   at Silk.NET.Windowing.Desktop.GlfwWindow.Initialize() in Z:\Silk.NET\src\Windowing\Silk.NET.Windowing.Desktop\GlfwWindow.cs:line 569
   at Silk.NET.Windowing.Common.WindowExtensions.Run(IView view) in Z:\Silk.NET\src\Windowing\Silk.NET.Windowing.Common\WindowExtensions.cs:line 46
   at Tutorial.Program.Main(String[] args) in Z:\Silk.NET\examples\CSharp\Tutorial 1.2 - Hello quad\Program.cs:line 73

Attached XML containing details of graphic card as seen from inside virtualbox generted with glview

glview-SVGA3D; build_ RELEASE; .XML.txt

Perksey commented 4 years ago

The examples won't work on your machine as the data you provided indicates that the Mesa implementation on your system only supports OpenGL 2.1. Our samples are built around OpenGL 3.3

If you would like to try Silk out in this environment, you'll need to use Silk.NET.OpenGL.Legacy (and the old fixed-function pipeline, which was deprecated in OpenGL 3) and modify the GraphicsAPI in your WindowOptions.

Thanks!

devel0 commented 1 year ago

Found a way to make it work in Virtualbox OpenGL 3.3 using mesa software driver from here ; it's not hardware accelerated but enough for crossplatform tests I needed.

[DllImport("kernel32")]
public static extern IntPtr LoadLibrary(string path);

void InitGL()
{
  var opts = WindowOptions.Default;
  opts.IsVisible = false;

  // if need to use mesa driver ( ie. windows guest on virtualbox )
  // download driver from https://fdossena.com/?p=mesa/index.frag)
  // and set OPENGL_LIBRARY_PATH to the folder containing Opengl32.dll

  var mesa_lib_path = Environment.GetEnvironmentVariable("OPENGL_LIBRARY_PATH", EnvironmentVariableTarget.User);
  if (mesa_lib_path is not null)
  {
      var lib_pathfilename = Path.Combine(mesa_lib_path, "opengl32.dll");
      if (File.Exists(lib_pathfilename))
      {
          LoadLibrary(lib_pathfilename);
      }
  }

  glContext = Silk.NET.Windowing.Window.Create(opts);
  glContext.Initialize();

  // https://github.com/Ultz/Silk.NET/issues/66
  glContext.IsVisible = false;

  GL = GL.GetApi(glContext);
  // ...
}