简体   繁体   English

GTK#和OpenTK库

[英]GTK# & OpenTK libraries

How to join this two things? 如何加入这两件事? How to create a widget (or any canvas) to draw in it from another thread? 如何创建一个小部件(或任何画布)以从另一个线程绘制它?

You can edit one of the examples in the OpenTk source download here to have a GTK# window and a OpenTK Gamewindow in the same application. 您可以在此处的OpenTk源代码下载中编辑示例之一,以在同一应用程序中具有GTK#窗口和OpenTK Gamewindow。

Download OpenTK source here: http://sourceforge.net/projects/opentk/files/latest/download 在此处下载OpenTK源: http : //sourceforge.net/projects/opentk/files/latest/download

First, make sure that the examples work by building and running the examples. 首先,通过构建和运行示例来确保示例可以正常工作。 Try the OpenTK multithreading one specifically, it should give you two windows with spinning cubes. 专门尝试使用OpenTK多线程,它应该为您提供两个带有旋转多维数据集的窗口。

Now, edit the example to spawn a gtk# window instead of a second openTK gamewindow. 现在,编辑示例以生成gtk#窗口,而不是第二个openTK游戏窗口。

Open the file opentk/Source/Examples/OpenTK/Test/Multithreading.cs 打开文件opentk / Source / Examples / OpenTK / Test / Multithreading.cs

You will need to make a function to create a gtk window, like so 您将需要创建一个函数来创建gtk窗口,如下所示

static void gtkWindow() {
    Application.Init ();
    var gtkform = new Gtk.Window("test");
    var btn = new Gtk.Button("flip");
    btn.Clicked += HandleBtnClicked;
    gtkform.Add(btn);
    gtkform.ShowAll();
    Application.Run();
}

Now edit the main loop to launch this window, like so: 现在编辑主循环以启动此窗口,如下所示:

// launch threads
for (int i = 0; i < ThreadCount; i++)
{
    if (i == 0) {
        Thread t = new Thread(RunGame);
        t.IsBackground = true;
        t.Priority = ThreadPriority.BelowNormal;
        t.Start();
        threads.Add(t);
    } else {
        Thread t = new Thread(gtkWindow);
        t.IsBackground = true;
        t.Priority = ThreadPriority.BelowNormal;
        t.Start();
        threads.Add(t);
    }
}

You will now have a Gtk# window and OpenTK game windows in the same application. 现在,您将在同一应用程序中拥有一个Gtk#窗口和OpenTK游戏窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM