Hello everyone I have tested with my own GLFW3 ( DeafMan1983.Interop.GLFW3 ( new version for Net 7.x )
I have add with TerraFX.Interop.Xlib for X11 as gui, like Button, panel, text and combobox for example. I decide my own. but XEvent forcies me if I can’t manipulate Event of X11 and it happens GLFW3 freezes.
Example: GLFWMain.cs
namespace GLFWTest;
using static DeafMan1983.ConvFunctions;
using DeafMan1983.Interop.GLFW3;
using static DeafMan1983.Interop.GLFW3.GLFW3;
using TerraFX.Interop.Xlib;
using static TerraFX.Interop.Xlib.Xlib;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
unsafe class GLFWMain
{
// Preparing GL functions
static delegate *unmanaged[Cdecl]<int, int, int, int, void> glViewport_t;
static delegate *unmanaged[Cdecl]<uint, void> glClear_t;
static delegate *unmanaged[Cdecl]<float, float, float, float, void> glClearColor_t;
static delegate *unmanaged[Cdecl]<uint, sbyte *> glGetString_t;
static void Viewport(int x, int y, int w, int h)
{
glViewport_t = (delegate *unmanaged[Cdecl]<int, int, int, int, void>)glfwGetProcAddress(SBytePointerWithString("glViewport"));
if (glViewport_t != null)
{
glViewport_t(x, y, w, h);
}
}
static void Clear(uint mask)
{
glClear_t = (delegate *unmanaged[Cdecl]<uint, void>)glfwGetProcAddress(SBytePointerWithString("glClear"));
if (glClear_t != null)
{
glClear_t(mask);
}
}
static void ClearColor(float r, float g, float b, float a)
{
glClearColor_t = (delegate *unmanaged[Cdecl]<float, float, float, float, void>)glfwGetProcAddress(SBytePointerWithString("glClearColor"));
if (glClearColor_t != null)
{
glClearColor_t(r, g, b, a);
}
}
static string GetString(uint name)
{
glGetString_t = (delegate *unmanaged[Cdecl]<uint, sbyte *>)glfwGetProcAddress(SBytePointerWithString("glGetString"));
return StringwithSBytePointer(glGetString_t(name));
}
static void Main(string[] args)
{
if (glfwInit() == 0)
{
glfwSetErrorCallback(&error_callback);
Environment.Exit(1);
}
glfwWindowHint((int)GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint((int)GLFW_CONTEXT_VERSION_MINOR, 6);
GLFWwindow *window = glfwCreateWindow(600, 400, SBytePointerWithString("Hello GLFW3 Window"), null, null);
if (window == null)
{
Console.Error.WriteLine("Error: Creating GLFW3 Window!");
Environment.Exit(1);
}
glfwSetKeyCallback(window, &key_callback);
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
Console.WriteLine("Renderer is {0}", GetString(0x1F01));
// Create GUI like Steam's VGUI
Display *display = (Display*)glfwGetX11Display();
int screen_number = XDefaultScreen(display);
Window root = (Window)glfwGetX11Window(window);
Window simple = XCreateSimpleWindow(display, root, 100, 100, 200, 200, 0, XBlackPixel(display, screen_number), XWhitePixel(display, screen_number));
XMapWindow(display, simple);
XSelectInput(display, simple, ButtonPressMask);
XEvent xev = new();
while (XNextEvent(display, &xev) != 0)
{
if (xev.type == ButtonPress)
{
if (xev.xbutton.button == Button1)
{
Console.WriteLine("Click me!");
}
}
}
while (glfwWindowShouldClose(window) == 0)
{
int width, height;
glfwGetFramebufferSize(window, &width, &height);
Viewport(0, 0, width, height);
Clear(0x00004000);
ClearColor(1.0f, 1.0f / 3, 0.0f, 1.0f);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwDestroyWindow(window);
glfwTerminate();
}
[UnmanagedCallersOnly(CallConvs = new[] {typeof(CallConvCdecl)})]
private static void error_callback(int error, sbyte *description)
{
string desc_str = StringwithSBytePointer(description);
Console.Error.WriteLine("Error: {0}", desc_str);
}
[UnmanagedCallersOnly(CallConvs = new[] {typeof(CallConvCdecl)})]
private static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, GLFW_TRUE);
}
}
But there packages from DeafMan1983 are my developed packages See in Nuget.org And SDL3 is still buggy for OpenGL 4.x
GLFW3 works fine 100 % That is surprised for me.
And I want know how do I embed X11 as GUI inside GLFW window. I want test for clicking like ButtonPress
and I want know if 2 events of GLFW3 and X11 and they conflict but How do I fix? If I want embed X11 inside GLFW. Thanks for helping