Skip to content

Problem with System.PlatformNotSupportedException #510

@DeafMan1983

Description

@DeafMan1983

Hello @HurricanKai , junger Deutscher 👍 Ich weiß schon dass du jüngster Programmierer. Ich bin auch Deutscher :D

Sorry I contact with @HurricanKai on German Language.
I would like to show about GtkSharp 3 with GLFW3 via glfwGetX11Window()

I made code below:

using System;
using System.Runtime.InteropServices;
using Silk.NET.Maths;
using Silk.NET.OpenGL;
using Silk.NET.Windowing;

namespace GLFWOnGtk3
{
    unsafe class Program
    {
        private const string libgdk = "gdk-3";
        private const string libglfw = "glfw.so.3";
        
        [DllImport(libgdk)]
        private static extern IntPtr gdk_x11_display_get_xdisplay(IntPtr gdk_display);

        [DllImport(libgdk)]
        private static extern IntPtr gdk_x11_window_foreign_new_for_display(IntPtr gdk_display, IntPtr x_window);

        [DllImport((libglfw))]
        private static extern IntPtr glfwGetX11Window(nint glfw_window);

        private static IWindow glfw_win;
        private static GL gl;
        
        static void Main(string[] args)
        {
            Gtk.Application.Init();

            Gdk.Display gd = Gdk.Display.Default;
            
            var opts = WindowOptions.Default;
            opts.Size = new Vector2D<int>(200, 200);
            Window.PrioritizeGlfw();
            glfw_win = Window.Create(opts);
            glfw_win.Initialize();
            glfw_win.Render += OnRender;
            glfw_win.Closing += OnClose;
            glfw_win.Run();

            IntPtr x_window = glfwGetX11Window(glfw_win.Handle);
            Gdk.Window gw = new Gdk.Window(gdk_x11_window_foreign_new_for_display(gd.Handle, x_window));
            
            Gtk.Window gtk_window = new Gtk.Window(Gtk.WindowType.Toplevel);
            gtk_window.Realized += delegate {
                gtk_window.Window = gw;
            };

            gtk_window.HasWindow = true;
            gtk_window.Realize();

            bool running = true;
            while (running)
            {
                if (Gdk.Events.Pending())
                {
                    Gtk.Application.RunIteration();
                }
            }
        }

        private static void OnRender(double obj)
        {
            gl = GL.GetApi(glfw_win);
            
            gl.Clear(ClearBufferMask.ColorBufferBit);
            gl.ClearColor(1.0f, 1.0f /3, 0f, 1.0f);
        }
        
        private static void OnClose()
        {
            Gtk.Application.Quit();
        }
    }
}

After compilation was successfully.
I try to open with dotnet run
It throws exception:

Unhandled exception. System.PlatformNotSupportedException: Couldn't find a suitable window platform. https://docs.ultz.co.uk/silk.net/windowing/troubleshooting.html
   at Silk.NET.Windowing.Window.Create(WindowOptions options)
   at GLFWOnGtk3.Program.Main(String[] args) in /home/jens/RiderProjects/TestForGLFW/GLFWOnGtk3/Program.cs:line 35

Is it better then System.Runtime... DLLImport - I need use NativeApi, correctly?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions