本文整理汇总了C#中OpenTK.GameWindow.Close方法的典型用法代码示例。如果您正苦于以下问题:C# GameWindow.Close方法的具体用法?C# GameWindow.Close怎么用?C# GameWindow.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenTK.GameWindow
的用法示例。
在下文中一共展示了GameWindow.Close方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MyApplication
private MyApplication()
{
//setup
gameWindow = new GameWindow(700, 700);
gameWindow.KeyDown += (s, arg) => gameWindow.Close();
gameWindow.Resize += (s, arg) => GL.Viewport(0, 0, gameWindow.Width, gameWindow.Height);
gameWindow.RenderFrame += GameWindow_RenderFrame;
gameWindow.RenderFrame += (s, arg) => gameWindow.SwapBuffers();
//animation using a single SpriteSheet
explosion = new SpriteSheetAnimation(new SpriteSheet(TextureLoader.FromBitmap(Resourcen.explosion), 5), 0, 24, 1);
//animation using a bitmap for each frame
alienShip = new AnimationTextures(.5f);
//art from http://millionthvector.blogspot.de/p/free-sprites.html
alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10001));
alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10002));
alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10003));
alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10004));
alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10005));
alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10006));
alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10007));
alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10008));
alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10009));
alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10010));
alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10011));
alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10012));
alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10013));
alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10014));
alienShip.AddFrame(TextureLoader.FromBitmap(Resourcen.alien10015));
//for transparency in textures
GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
//start game time
timeSource.Start();
}
示例2: MyApplication
private MyApplication()
{
gameWindow = new GameWindow();
//gameWindow.WindowState = WindowState.Fullscreen;
gameWindow.MouseMove += GameWindow_MouseMove;
gameWindow.MouseWheel += GameWindow_MouseWheel;
gameWindow.KeyDown += (s, arg) => gameWindow.Close();
gameWindow.Resize += (s, arg) => GL.Viewport(0, 0, gameWindow.Width, gameWindow.Height);
gameWindow.RenderFrame += (s, arg) => visual.Render();
gameWindow.RenderFrame += (s, arg) => gameWindow.SwapBuffers();
visual = new MainVisual();
}
示例3: TestClear
public void TestClear()
{
var pixel = new Pixel();
_window = new GameWindow();
_window.RenderFrame += (caller, args) =>
{
GL.ReadBuffer(ReadBufferMode.Front);
GL.ClearColor(0.4f, 0.2f, 1.0f, 1.0f);
GL.Clear(ClearBufferMask.ColorBufferBit);
_window.SwapBuffers();
pixel.ReadBuffer(0, 0);
_window.Close();
};
_window.Run();
Assert.AreEqual(new Pixel(0.4f, 0.2f, 1.0f), pixel);
}
示例4: Main
static void Main(string[] args)
{
bool isRunning = true;
Task.Factory.StartNew(() =>
{
var win = new GameWindow(800, 600);
win.RenderFrame += new EventHandler<FrameEventArgs>((o, e) =>
{
if (UIThreadQueue.Instance.Any())
{
var a = UIThreadQueue.Instance.Dequeue();
a(win);
}
});
win.UpdateFrame += new EventHandler<FrameEventArgs>((o, e) =>
{
if (!isRunning)
win.Close();
});
win.Closed += (o, e) => { isRunning = false; };
win.Run();
});
var map = Pycraft.Commanders.MapCommander.CreateMap();
Commanders.MapCommander.SetBlock(map, 0, 0, 0, 0);
var mapCursor = Commanders.MapCursorCommander.CreateMapCursorForMap(map, 0, 0, 0);
while (isRunning)
{
Drawing.Clear();
Commanders.MapCursorCommander.DrawCursor(mapCursor);
Drawing.SwapBuffers();
};
}
示例5: TestDrawQuad
public void TestDrawQuad()
{
var pixel = new Pixel();
_window = new GameWindow {Width = 200, Height = 200};
_window.RenderFrame += (caller, args) =>
{
GL.ReadBuffer(ReadBufferMode.Front);
GL.Clear(ClearBufferMask.ColorBufferBit);
GL.Begin(PrimitiveType.Quads);
{
GL.Color3(1.0f, 1.0f, 1.0f);
GL.Vertex2(0.0f, 0.0f);
GL.Vertex2(-1.0f, 0.0f);
GL.Vertex2(-1.0f, -1.0f);
GL.Vertex2(0.0f, -1.0f);
}
GL.End();
_window.SwapBuffers();
pixel.ReadBuffer(0, 0);
_window.Close();
};
_window.Run();
Assert.AreEqual(new Pixel(1.0f, 1.0f, 1.0f), pixel);
}
示例6: TestDrawTexture
public void TestDrawTexture()
{
var pixels = new[] { new Pixel(), new Pixel(), new Pixel(), new Pixel() };
_window = new GameWindow { Width = 200, Height = 200 };
_window.RenderFrame += (caller, args) =>
{
GL.Viewport(0, 0, 200, 200);
GL.ReadBuffer(ReadBufferMode.Front);
GL.Enable(EnableCap.Texture2D);
int textureId = GL.GenTexture();
GL.BindTexture(TextureTarget.Texture2D, textureId);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
var bitmap = new Bitmap(@"..\..\Images\testtexture.png");
var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
ImageLockMode.ReadOnly,
System.Drawing.Imaging.PixelFormat.Format32bppArgb);
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height,
0, PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);
bitmap.UnlockBits(data);
GL.Clear(ClearBufferMask.ColorBufferBit);
GL.Begin(PrimitiveType.Quads);
{
GL.TexCoord2(0.0f, 0.0f);
GL.Vertex2(-1.0f, -1.0f);
GL.TexCoord2(1.0f, 0.0f);
GL.Vertex2(1.0f, -1.0f);
GL.TexCoord2(1.0f, 1.0f);
GL.Vertex2(1.0f, 1.0f);
GL.TexCoord2(0.0f, 1.0f);
GL.Vertex2(-1.0f, 1.0f);
}
GL.End();
_window.SwapBuffers();
pixels[0].ReadBuffer(99, 99);
pixels[1].ReadBuffer(99, 100);
pixels[2].ReadBuffer(100, 100);
pixels[3].ReadBuffer(100, 99);
_window.Close();
};
_window.Run();
Assert.AreEqual(new Pixel(1.0f, 0.0f, 0.0f), pixels[0]);
Assert.AreEqual(new Pixel(0.0f, 1.0f, 0.0f), pixels[1]);
Assert.AreEqual(new Pixel(0.0f, 0.0f, 1.0f), pixels[2]);
Assert.AreEqual(new Pixel(0.0f, 0.0f, 0.0f), pixels[3]);
}
示例7: TestSetModelViewMatrix
public void TestSetModelViewMatrix()
{
var pixels = new[] { new Pixel(), new Pixel(), new Pixel(), new Pixel() };
_window = new GameWindow { Width = 200, Height = 200 };
_window.RenderFrame += (caller, args) =>
{
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
GL.Ortho(0.0, 2.0, 0.0, 2.0, 0.0, 4.0);
GL.Viewport(0, 0, 200, 200);
GL.MatrixMode(MatrixMode.Modelview);
GL.ReadBuffer(ReadBufferMode.Front);
GL.Clear(ClearBufferMask.ColorBufferBit);
GL.Color3(1.0f, 1.0f, 1.0f);
DrawQuad();
GL.PushMatrix();
GL.Translate(0.0f, 1.0f, 0.0f);
GL.Color3(1.0f, 0.0f, 0.0f);
DrawQuad();
GL.PopMatrix();
GL.PushMatrix();
GL.Translate(1.0f, 1.0f, 0.0f);
GL.Color3(0.0f, 1.0f, 0.0f);
DrawQuad();
GL.PopMatrix();
GL.PushMatrix();
GL.Translate(1.0f, 0.0f, 0.0f);
GL.Color3(0.0f, 0.0f, 1.0f);
DrawQuad();
GL.PopMatrix();
_window.SwapBuffers();
pixels[0].ReadBuffer(99, 99);
pixels[1].ReadBuffer(99, 100);
pixels[2].ReadBuffer(100, 100);
pixels[3].ReadBuffer(100, 99);
_window.Close();
};
_window.Run();
Assert.AreEqual(new Pixel(1.0f, 1.0f, 1.0f), pixels[0]);
Assert.AreEqual(new Pixel(1.0f, 0.0f, 0.0f), pixels[1]);
Assert.AreEqual(new Pixel(0.0f, 1.0f, 0.0f), pixels[2]);
Assert.AreEqual(new Pixel(0.0f, 0.0f, 1.0f), pixels[3]);
}
示例8: TestOrtho
public void TestOrtho()
{
var pixels = new[] {new Pixel(), new Pixel(), new Pixel(), new Pixel()};
_window = new GameWindow {Width = 200, Height = 200};
_window.RenderFrame += (caller, args) =>
{
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
GL.Ortho(0.0, 2.0, 0.0, 2.0, 0.0, 4.0);
GL.Viewport(0, 0, 200, 200);
GL.MatrixMode(MatrixMode.Modelview);
GL.ReadBuffer(ReadBufferMode.Front);
GL.Clear(ClearBufferMask.ColorBufferBit);
GL.Begin(PrimitiveType.Quads);
{
GL.Color3(1.0f, 1.0f, 1.0f);
GL.Vertex2(0.0f, 0.0f);
GL.Vertex2(1.0f, 0.0f);
GL.Vertex2(1.0f, 1.0f);
GL.Vertex2(0.0f, 1.0f);
}
GL.End();
_window.SwapBuffers();
pixels[0].ReadBuffer(99, 99);
pixels[1].ReadBuffer(99, 100);
pixels[2].ReadBuffer(100, 100);
pixels[3].ReadBuffer(100, 99);
_window.Close();
};
_window.Run();
Assert.AreEqual(new Pixel(1.0f, 1.0f, 1.0f), pixels[0]);
Assert.AreEqual(new Pixel(0.0f, 0.0f, 0.0f), pixels[1]);
Assert.AreEqual(new Pixel(0.0f, 0.0f, 0.0f), pixels[2]);
Assert.AreEqual(new Pixel(0.0f, 0.0f, 0.0f), pixels[3]);
}
示例9: SetupViewport
private static unsafe void SetupViewport()
{
int width = 800;
int height = 600;
GameWindow window = new GameWindow(width, height, OpenTK.Graphics.GraphicsMode.Default, "Mandelbrot", GameWindowFlags.Default);
int tex;
byte[] buffer = new byte[width * height * 4];
OpenTK.Graphics.IGraphicsContextInternal ctx = (OpenTK.Graphics.IGraphicsContextInternal)OpenTK.Graphics.GraphicsContext.CurrentContext;
IntPtr contextHandle = ctx.Context.Handle;
var mandelbrot = new MandelbrotCalculator(maxRecursionCount: 200, imageWidth: width, imageHeight: height);
mandelbrot.Initialize();
GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);
GL.GenTextures(1, out tex);
GL.BindTexture(TextureTarget.Texture2D, tex);
mandelbrot.GetNextImageFrame();
mandelbrot.ReadResultBuffer(buffer);
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, width, height, 0, PixelFormat.Bgra, PixelType.UnsignedByte, buffer);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
bool isButtonPressed = false;
bool changed = true;
window.Mouse.ButtonDown += (s, e) => isButtonPressed = true;
window.Keyboard.KeyDown += (s, e) =>
{
if (e.Key == OpenTK.Input.Key.Escape)
{
window.Close();
}
};
window.Mouse.ButtonUp += (s, e) => isButtonPressed = false;
window.Mouse.Move += (s, e) =>
{
if (isButtonPressed)
{
mandelbrot.CenterX -= e.XDelta / (double)mandelbrot.ImageWidth * mandelbrot.Width;
mandelbrot.CenterY += e.YDelta / (double)mandelbrot.ImageHeight * mandelbrot.Height;
changed = true;
}
};
window.Mouse.WheelChanged += (s, e) =>
{
mandelbrot.Width /= Math.Pow(2, e.DeltaPrecise);
mandelbrot.Height /= Math.Pow(2, e.DeltaPrecise);
changed = true;
};
window.UpdateFrame += (s, e) =>
{
if (changed)
{
window.Title = string.Format("Mandelbrot: {0} + {1}i", mandelbrot.CenterX, mandelbrot.CenterY);
mandelbrot.GetNextImageFrame();
mandelbrot.ReadResultBuffer(buffer);
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, width, height, 0, PixelFormat.Bgra, PixelType.UnsignedByte, buffer);
}
changed = false;
};
window.RenderFrame += (sender, e) =>
{
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
DrawImage(tex, mandelbrot.ImageWidth, mandelbrot.ImageHeight);
window.SwapBuffers();
};
window.VSync = VSyncMode.Off;
window.Run(0);
}