-1

How to join this two things? How to create a widget (or any canvas) to draw in it from another thread?

itun
  • 3,439
  • 12
  • 51
  • 75
  • It depends on what you're trying to accomplish. You could just render stuff in OpenTK, pass the window pointer to GTK# and have it do it's rendering. There are many ways to put these two libraries together, but multithreading will be pretty difficult since you'll have to stall the OpenGL context to render with GTK#. – Robert Rouhani Dec 31 '11 at 06:52
  • @Robert Rouhani Show me at least one way please. – itun Dec 31 '11 at 20:20

1 Answers1

2

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.

Download OpenTK source here: 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.

Now, edit the example to spawn a gtk# window instead of a second openTK gamewindow.

Open the file opentk/Source/Examples/OpenTK/Test/Multithreading.cs

You will need to make a function to create a gtk window, like so

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.

Doug Blank
  • 2,031
  • 18
  • 36
Dan McNamara
  • 301
  • 1
  • 7