Laden...

GTKSharp2 + X11 für Linux: - Ich habe Problem mit glX / gl zum Einbetten ( Embed )

Erstellt von DeafMan1983 vor 3 Jahren Letzter Beitrag vor 3 Jahren 1.488 Views
D
DeafMan1983 Themenstarter:in
1 Beiträge seit 2020
vor 3 Jahren
GTKSharp2 + X11 für Linux: - Ich habe Problem mit glX / gl zum Einbetten ( Embed )

Hallo gnädige Leute,

Ich habe Problem wenn Gtk Sharp 2 absturzt

Datei GLXArea.cs

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Gdk;

namespace Gtk
{
    public class GLXArea : DrawingArea
    {
        private IntPtr x_display;
        private int x_screen_number;
        private int major, minor;
        private List<int> visualAttributes = new List<int>();
        private unsafe IntPtr* glx_fbconfig;
        private IntPtr x_window;
        private IntPtr glx_context;
        private IntPtr x_visual;

        private const string libgdk = "libgdk-x11-2.0.so.0";
        private const string libgl = "libGL.so.1";
        private const string libX11 = "libX11.so.6";


        // Gdk
        [DllImport(libgdk)]
        private static extern IntPtr gdk_x11_drawable_get_xdisplay(IntPtr gdk_display);

        [DllImport(libgdk)]
        private static extern IntPtr gdk_x11_drawable_get_xid(IntPtr gdk_window);


        // X11
        [DllImport(libX11)]
        private static extern int XDefaultScreen(IntPtr x11_display);

        [DllImport(libX11)]
        private static extern void XCloseDisplay(IntPtr x11_display);

        [DllImport(libX11)]
        private static extern void XFree(IntPtr data);

        [DllImport(libX11)]
        private unsafe static extern void XFree(IntPtr* datas);

        [DllImport(libX11)]
        private static extern void XClearWindow(IntPtr x11_display, IntPtr x11_window);

        [DllImport(libX11)]
        private static extern void XMapRaised(IntPtr x11_display, IntPtr x11_window);


        // GL
        [DllImport(libgl)]
        private static extern bool glXQueryVersion(IntPtr x11_display, out int major, out int minor);

        [DllImport(libgl)]
        private unsafe static extern IntPtr* glXChooseFBConfig(IntPtr x11_display, int x11_screen_number, int[] attriblists, out int fbount);

        [DllImport(libgl)]
        private static extern IntPtr glXGetVisualFromFBConfig(IntPtr x11_display, IntPtr glx_fbconfig);

        [DllImport(libgl)]
        private static extern IntPtr glXCreateNewContext(IntPtr x11_display, IntPtr glx_fbconfig, int render_type, IntPtr glx_context_share, bool direct);

        [DllImport(libgl)]
        private static extern bool glXIsDirect(IntPtr x11_display, IntPtr glx_context);

        [DllImport(libgl)]
        private static extern bool glXMakeCurrent(IntPtr x11_display, IntPtr x11_drawable, IntPtr glx_context);

        [DllImport(libgl)]
        private static extern void glXSwapBuffers(IntPtr x11_display, IntPtr x11_drawable);

        [DllImport(libgl)]
        private static extern IntPtr glXGetProcAddress([MarshalAs(UnmanagedType.LPTStr)] string proc_name);

        [DllImport(libgl)]
        private static extern void glXDestroyContext(IntPtr x11_display, IntPtr glx_context);

        private unsafe void PreparationFromXLib()
        {
            x_display = gdk_x11_drawable_get_xdisplay(GdkWindow.Handle);
            x_screen_number = XDefaultScreen(x_display);

            glXQueryVersion(x_display, out major, out minor);
            if (major <= 1 && minor <= 3)
            {
                Console.WriteLine("Error: GLX requieres 1.3 version.\n");
                XCloseDisplay(x_display);
            }

            glx_fbconfig = glXChooseFBConfig(x_display, x_screen_number, visualAttributes.ToArray(), out int fbcount);
            for (int i = 0; i < fbcount; ++i)
            {
                x_visual = glXGetVisualFromFBConfig(x_display, glx_fbconfig[i]);
            }

            XFree(glx_fbconfig);

            x_window = gdk_x11_drawable_get_xid(GdkWindow.Handle);
            for (int i = 0; i < fbcount; ++i)
            {
                glx_context = glXCreateNewContext(x_display, glx_fbconfig[i], 0, IntPtr.Zero, true);
            }

            XClearWindow(x_display, x_window);
            XMapRaised(x_display, x_window);
        }

        public GLXArea() : base(IntPtr.Zero)
        {
            PreparationFromXLib();
        }

        ~GLXArea()
        {
            glXDestroyContext(x_display, glx_context);
        }

        public IntPtr FunctionFromLibrary(string func_name)
        {
            return glXGetProcAddress(func_name);
        }

        public bool ISDirect
        {
            get
            {
                return glXIsDirect(x_display, glx_context);
            }
        }

        public bool MakeCurrent
        {
            get
            {
                return glXMakeCurrent(x_display, x_window, glx_context);
            }
        }

        protected override bool OnExposeEvent(EventExpose evnt)
        {
            // ... Ich werde noch arbeiten ...

            if (glXMakeCurrent(x_display, x_window, glx_context))
            {


                glXSwapBuffers(x_display, x_window);
            }

            return base.OnExposeEvent(evnt);
        }
    }
}

Datei MainWindow.cs

using System;
using System.Runtime.InteropServices;

namespace SpielTest
{
    public class MainWindow : Gtk.Window
    {
        private Gtk.VBox box;
        private Gtk.GLXArea area;

        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        private delegate void Viewport(int x, int y, int w, int h);
        private Viewport glViewport;

        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        private delegate void Clear(uint clear_mask);
        private Clear glClear;

        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        private delegate void ClearColor(float r, float g, float b, float a);
        private ClearColor glClearColor;

        public MainWindow() : base(Gtk.WindowType.Toplevel)
        {
            SetDefaultSize(400, 320);
            Title = "GTk 2 GLXArea Testversion";
            box = new Gtk.VBox(true, 0);
            Add(box);

            area = new Gtk.GLXArea();
            glViewport = (Viewport)Marshal.GetDelegateForFunctionPointer(
                area.FunctionFromLibrary("glViewport"),
                typeof(Viewport)
            );

            glClear = (Clear)Marshal.GetDelegateForFunctionPointer(
                area.FunctionFromLibrary("glClear"),
                typeof(Clear)
            );

            glClearColor = (ClearColor)Marshal.GetDelegateForFunctionPointer(
                area.FunctionFromLibrary("glClearColor"),
                typeof(ClearColor)
            );

            box.PackStart(area, true, true, 0);
            area.ExposeEvent += glx_area_expose_handler;
            area.Show();

            DeleteEvent += delegate
            {
                Destroy();
                Gtk.Application.Quit();
            };

            Show();
        }

        private void glx_area_expose_handler(object o, Gtk.ExposeEventArgs args)
        {
            area = (Gtk.GLXArea)o;
            glViewport(0, 0, area.Allocation.Width, area.Allocation.Height);
            glClear(0x4000);
            glClearColor(1.0f, 0.5f, 0.0f, 1.0f);
        }
    }
}

Datei Program.cs

using System;

namespace SpielTest
{
    class MainClass
    {
        static void Main(string[] args)
        {
            Gtk.Application.Init();
            new MainWindow().ShowAll();
            Gtk.Application.Run();
        }
    }
}

Achtet ihr darauf Ich nutze Gtk Sharp 2.12.4??

Und Ich wollte OpenGL Ansicht mit GtkSharp 2.x einbinden ohne GLArea weil GtkGLArea für GtkSharp 2.x schon gestorben ist. Und es existiert nicht mehr. Und warum habe ich 3 Codes gepostet weil ich komischerweise Siggev Fehlmeldung oder Segment Fault Fehlermeldung mit Mono 5.20.x / 6.6.x und ich habe versucht.

Ich bin am Boden verzweifelt, weil es keine Lösung mehr für GtkGLExt oder GtkGLArea nicht mehr im Internet gibt.

Und ich möchte dass ich mit XLib/X11 + libGL(X) im Gtk Sharp 2 Project einzubinden lasse. Ohne Hilfe von Erweiterung von ausgestorbenen Gtk Addons ( GtkGLArea oder GtkGLExt )

Es tut mir leid, dass mein Deutsch nicht gut tut, weil ich von frechen Leuten gemobbt wurde und ich schreibe manchmal schlecht. Bitte glaubt ihr mir ehrlich! Ich bin gehörlos und ich lasse nicht zu wenn jemand mich als Diskrimierung bezeichnet. Ich will mit euch respektieren. Danke!

Ich hoffe, dass ihr mich endlich versteht.

Hallo Ich bin untröstlich.