2011-01-18 11:40:49 +00:00
|
|
|
// This code was written for the OpenTK library and has been released
|
|
|
|
// to the Public Domain.
|
|
|
|
// It is provided "as is" without express or implied warranty of any kind.
|
2009-11-03 09:58:39 +00:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Text;
|
|
|
|
using System.Threading;
|
|
|
|
|
|
|
|
namespace Examples.Tests
|
|
|
|
{
|
|
|
|
[Example("Multithreading Test", ExampleCategory.OpenTK, "Test")]
|
|
|
|
class Multithreading
|
|
|
|
{
|
|
|
|
public static void Main()
|
|
|
|
{
|
2009-11-09 19:14:14 +00:00
|
|
|
const int ThreadCount = 2;
|
2009-11-03 09:58:39 +00:00
|
|
|
List<Thread> threads = new List<Thread>();
|
|
|
|
|
|
|
|
// launch threads
|
|
|
|
for (int i = 0; i < ThreadCount; i++)
|
|
|
|
{
|
2009-11-09 19:14:14 +00:00
|
|
|
Thread t = new Thread(RunGame);
|
2009-11-03 09:58:39 +00:00
|
|
|
t.IsBackground = true;
|
|
|
|
t.Priority = ThreadPriority.BelowNormal;
|
|
|
|
t.Start();
|
|
|
|
threads.Add(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
// wait for exit
|
|
|
|
foreach (Thread t in threads)
|
|
|
|
{
|
|
|
|
t.Join();
|
|
|
|
}
|
|
|
|
}
|
2009-11-09 19:14:14 +00:00
|
|
|
|
|
|
|
static void RunGame()
|
|
|
|
{
|
|
|
|
using (Tutorial.T03_Immediate_Mode_Cube game = new Examples.Tutorial.T03_Immediate_Mode_Cube())
|
|
|
|
{
|
|
|
|
Utilities.SetWindowTitle(game);
|
|
|
|
game.Keyboard.KeyUp += delegate(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
|
|
|
|
{
|
2010-02-03 19:04:42 +00:00
|
|
|
if (e.Key == OpenTK.Input.Key.F11)
|
2009-11-09 19:14:14 +00:00
|
|
|
{
|
|
|
|
if (game.WindowState == OpenTK.WindowState.Fullscreen)
|
|
|
|
game.WindowState = OpenTK.WindowState.Normal;
|
|
|
|
else
|
|
|
|
game.WindowState = OpenTK.WindowState.Fullscreen;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
game.Run(30.0);
|
|
|
|
}
|
|
|
|
}
|
2009-11-03 09:58:39 +00:00
|
|
|
}
|
|
|
|
}
|