本文整理汇总了C#中OpenTK.GameWindow.Exit方法的典型用法代码示例。如果您正苦于以下问题:C# GameWindow.Exit方法的具体用法?C# GameWindow.Exit怎么用?C# GameWindow.Exit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenTK.GameWindow
的用法示例。
在下文中一共展示了GameWindow.Exit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
private static void Main(string[] args)
{
var sprites = new List<Sprite>();
Window = new GameWindow(800, 600, GraphicsMode.Default, "Blunder Buzz");
Window.Load += (sender, e) => {
Window.VSync = VSyncMode.On;
sprites.Add(new Sprite(new Shader("Shaders/basicVertex.glsl", "Shaders/basicFragment.glsl")));
};
Window.UpdateFrame += (sender, e) => {
if (Window.Keyboard[Key.Escape]) {
Window.Exit();
}
foreach (var sprite in sprites) {
sprite.Update();
}
};
Window.RenderFrame += (sender, e) => {
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.ClearColor(Color.CornflowerBlue);
foreach (var sprite in sprites) {
sprite.Render();
}
Window.SwapBuffers();
};
Window.Run(DisplayDevice.Default.RefreshRate);
}
示例2: OpenExampleClick
protected void OpenExampleClick(object senderObj, EventArgs eArgs)
{
using (var game = new GameWindow())
{
game.Load += (sender, e) =>
{
// setup settings, load textures, sounds
game.VSync = VSyncMode.On;
};
game.Resize += (sender, e) =>
{
GL.Viewport(0, 0, game.Width, game.Height);
};
game.KeyDown += (sender, e) =>
{
if(e.Key == OpenTK.Input.Key.Escape)
{
game.Exit();
}
};
game.UpdateFrame += (sender, e) =>
{
// // add game logic, input handling
// if (game.Keyboard[OpenTK.Input.Key.Escape])
// {
// game.Exit();
// }
};
game.RenderFrame += (sender, e) =>
{
// render graphics
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
GL.Ortho(-1.0, 1.0, -1.0, 1.0, 0.0, 4.0);
GL.Begin(PrimitiveType.Triangles);
GL.Color3(Color.MidnightBlue);
GL.Vertex2(-1.0f, 1.0f);
GL.Color3(Color.SpringGreen);
GL.Vertex2(0.0f, -1.0f);
GL.Color3(Color.Ivory);
GL.Vertex2(1.0f, 1.0f);
GL.End();
game.SwapBuffers();
};
// Run the game at 60 updates per second
game.Run(60.0);
}
}
示例3: Main
public static void Main (string[] args)
{
Console.WriteLine ("Hello World!");
using (var game = new GameWindow ())
{
const int kVertsPerParticle = 6;
const int kParticleCountX = 500;
const int kParticleCountY = 320;
var solution = new MapPersistent (kVertsPerParticle, game.Width, game.Height);
var problem = new DynamicStreamingProblem (solution, kVertsPerParticle, kParticleCountX, kParticleCountY);
game.Load += (sender, e) =>
{
// setup settings, load textures, sounds
game.VSync = VSyncMode.On;
problem.Init();
};
game.Unload += (sender, e) =>
{
problem.Shutdown();
};
game.KeyDown += (object sender, KeyboardKeyEventArgs e) =>
{
if (e.Key == Key.Space)
{
game.Exit();
}
};
game.UpdateFrame += (sender, e) =>
{
// add game logic, input handling
// update shader uniforms
// update shader mesh
};
game.RenderFrame += (sender, e) =>
{
game.SwapBuffers();
};
game.Resize += (sender, e) =>
{
//GL.Viewport(0, 0, game.Width, game.Height);
solution.SetSize(game.Width, game.Height);
};
game.Run(60.0);
}
}
示例4: Main
static void Main(string[] args)
{
using (var game = new GameWindow())
{
game.Load += (sender, e) =>
{
// setup settings, load textures, sounds
game.VSync = VSyncMode.On;
};
game.Resize += (sender, e) =>
{
GL.Viewport(0, 0, game.Width, game.Height);
};
game.UpdateFrame += (sender, e) =>
{
// add game logic, input handling
if (game.Keyboard[Key.Escape])
{
game.Exit();
}
};
double rotation = 0;
game.RenderFrame += (sender, e) =>
{
rotation += 1;
rotation %= 360;
// render graphics
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
GL.Ortho(-1.0, 1.0, -1.0, 1.0, 0.0, 4.0);
GL.Rotate(rotation, 0, 0, 1);
GL.Begin(PrimitiveType.Triangles);
GL.Color3(Color.MidnightBlue);
GL.Vertex3(-1.0f, 1.0f,-1.0f);
GL.Color3(Color.SpringGreen);
GL.Vertex3(0.0f, -1.0f,-1.0f);
GL.Color3(Color.Ivory);
GL.Vertex3(1.0f, 1.0f,-1.0f);
GL.End();
game.SwapBuffers();
};
// Run the game at 60 updates per second
game.Run(60.0);
}
}
示例5: MyApplication
public MyApplication()
{
gameWindow = new GameWindow();
logic = new GameLogic();
Texture texPlayer = TextureLoader.FromBitmap(Resourcen.blueships1);
Texture texEnemy = TextureLoader.FromBitmap(Resourcen.redship4);
Texture texBullet = TextureLoader.FromBitmap(Resourcen.blueLaserRay);
visual = new Visual(texEnemy, texBullet, texPlayer);
sound = new Sound();
logic.OnShoot += (sender, args) => { sound.Shoot(); };
logic.OnEnemyDestroy += (sender, args) => { sound.DestroyEnemy(); };
logic.OnLost += (sender, args) => { sound.Lost(); gameWindow.Exit(); };
gameWindow.Load += GameWindow_Load;
gameWindow.Resize += GameWindow_Resize;
gameWindow.UpdateFrame += GameWindow_UpdateFrame;
gameWindow.RenderFrame += GameWindow_RenderFrame;
gameWindow.RenderFrame += (sender, e) => { gameWindow.SwapBuffers(); };
sound.Background();
timeSource.Start();
gameWindow.Run(60.0);
}
示例6: Main
//.........这里部分代码省略.........
GL.Enable(EnableCap.Blend); //Alpha-Kanäle aktivieren
GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
//GL.Disable(EnableCap.DepthTest);
BGColor = Color.FromArgb(0, 128, 128, 128); //Die Standardfensterfarbe //Nur zur Sicherheit
app.VSync = VSyncMode.On;
Sound.Play();
};
app.Resize += (sender, e) =>
{
GL.Viewport(0, 0, app.Width, app.Height);
};
app.UpdateFrame += (sender, e) =>
{
mousePos.X = app.Mouse.X; //Aktualisiere Maus-Koordinaten
mousePos.Y = Height - app.Mouse.Y - 1;
mouse = Mouse.GetState();
//if (app.Keyboard[Key.Escape])
//{
// app.Exit();
//}
switch (cron)
{
case (-1):
app.Exit();
break;
case 0:
//Console.WriteLine(mouse.GetType().ToString());
cron = pan_MenuEnd.clickCheck(mousePos.X, mousePos.Y, mouse, cron, globalClickLock);
cron = pan_MenuOpts.clickCheck(mousePos.X, mousePos.Y, mouse, cron, globalClickLock);
pan_MenuNew.clickCheck(mousePos.X, mousePos.Y, mouse, cron, globalClickLock);
break;
case 1:
cron = pan_OptsBack.clickCheck(mousePos.X, mousePos.Y, mouse, cron, globalClickLock);
if (!hsl_VolumeEffects.clickLock)
{
volumeMusic = hsl_VolumeMusic.clickCheck(mousePos.X, mousePos.Y, mouse, volumeMusic);
}
if (!hsl_VolumeMusic.clickLock)
{
volumeEffects = hsl_VolumeEffects.clickCheck(mousePos.X, mousePos.Y, mouse, volumeEffects);
}
break;
case 2:
config.writeConfig(volumeMusic.ToString(), volumeEffects.ToString());
cron = 0;
break;
}
globalClickLock = (mouse[MouseButton.Left]); //Überprüft, ob die Maustaste gehalten wird
};
app.RenderFrame += (sender, e) =>
{
示例7: Main
public static void Main()
{
System.Diagnostics.Process.GetCurrentProcess().ProcessorAffinity = (System.IntPtr) (System.Environment.ProcessorCount); //Assign the process to the last CPU-core of the System
Console.WriteLine("We have " + System.Environment.ProcessorCount + " CPU-Cores.");
Random rnd = new Random();
using (var game = new GameWindow())
{
game.Load += (sender, e) =>
{
// setup settings, load textures, sounds
FormWindow();
game.X = 32;
game.Y = 16;
game.VSync = VSyncMode.On;
game.Width = windowX;
game.Height = windowY;
game.WindowBorder = WindowBorder.Fixed; //Disables the resizable windowframe
GL.Enable(EnableCap.Blend); //These lines
GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); //enable transparency using alpha-channel
//////////////////////////////////////////////////////////////////////////////////////////////// Load all Background-Objects from the Folder
int i = 0;
foreach (string bmpFile in Directory.GetFiles((exePath + @"\gfx\backgrounds\tiles"), "*.bmp")) //get all background tiles and load them
{
Texture.bgTilesArray[i, 0] = MyImage.LoadTexture(bmpFile);
string framesCount = (bmpFile.Replace((exePath + @"\gfx\backgrounds\tiles\"), "").Substring(4, 2)); //get Animation FrameCount ( "<id><id><id>_<frameCount><frameCount>.bmp")
if (!int.TryParse(framesCount, out Texture.bgTilesArray[i, 1]))
Texture.bgTilesArray[i, 1] = 1;
i++;
}
foreach (string bmpFile in Directory.GetFiles((exePath + @"\gfx\backgrounds\tiles"), "*.png")) //get all background tiles and load them
{
Texture.bgTilesArray[i, 0] = MyImage.LoadTexture(bmpFile);
string framesCount = (bmpFile.Replace((exePath + @"\gfx\backgrounds\tiles\"), "").Substring(4, 2)); //get Animation FrameCount ( "<id><id><id>_<frameCount><frameCount>.bmp")
if (!int.TryParse(framesCount, out Texture.bgTilesArray[i, 1]))
Texture.bgTilesArray[i, 1] = 1;
i++;
}
////////////////////////////////////////////////////////////////////////////////////////////////
};
//string s = "---4";
//Console.WriteLine("3" + s[3]);
//Console.ReadKey();
Map karte = new Map(16);
game.Resize += (sender, e) =>
{
//sceneX = game.Height;
//sceneY = game.Width;
GL.Viewport(0, 0, windowX, windowY); //unZoomed
};
var mouse = Mouse.GetState();
game.UpdateFrame += (sender, e) =>
{
// add game logic, input handling
mouse = Mouse.GetState();
keyboard = Keyboard.GetState();
if (keyboard[Key.Escape])
{
game.Exit();
}
game.Title = (("FPS: " + (int)(game.RenderFrequency) +" ; "+ Math.Round(game.RenderTime*1000,2)+"ms/frame Zoom="+zoom));
Map.fpsLine.Insert(0,(int)game.RenderFrequency);
while (Map.fpsLine.Count > 230)
Map.fpsLine.RemoveAt(Map.fpsLine.Count - 1);
};
game.RenderFrame += (sender, e) =>
{
// render graphics
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
//GL.Scale(Map.temp, Map.temp, 0);
GL.MatrixMode(MatrixMode.Projection);
//GL.MatrixMode(MatrixMode.Modelview);
GL.LoadIdentity();
//GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
//Console.WriteLine("Cam (X:" + camX + " |Y:" + camY + ")");
GL.Viewport((int)(0), (int)(0), windowX, windowY);
GL.LineWidth(1.0f);
game.Width = windowX;
game.Height = windowY;
Vector2d mouseVector = new Vector2d(game.Mouse.X, game.Mouse.Y);
if (zoomed)
{
GL.Ortho((int)(-sceneX / 2), (int)(sceneX / 2), (int)(sceneY / 2), (int)(-sceneY / 2), -1000, 1000); //Render distant objects smaller
GL.MatrixMode(MatrixMode.Modelview);
//.........这里部分代码省略.........
示例8: RunScript
/// <summary>
/// This procedure contains the user code. Input parameters are provided as regular arguments,
/// Output parameters as ref arguments. You don't have to assign output parameters,
/// they will have a default value.
/// </summary>
private void RunScript(Mesh Profile, List<Mesh> x, bool y, ref object A)
{
if(y){
try{
using (var game = new GameWindow(Width, Height, GraphicsMode.Default))
{
game.Load += (sender, e) =>
{
OpenTK.Graphics.OpenGL.GL.ClearColor(Color.Gray);// 背景
OpenTK.Graphics.OpenGL.GL.Enable(OpenTK.Graphics.OpenGL.EnableCap.DepthTest);//线框模式
// OpenTK.Graphics.OpenGL.GL.Enable(OpenTK.Graphics.OpenGL.EnableCap.CullFace);//反面不可见
OpenTK.Graphics.OpenGL.GL.Light(OpenTK.Graphics.OpenGL.LightName.Light0,
OpenTK.Graphics.OpenGL.LightParameter.Ambient, LightAmbient);//设置系统灯光
OpenTK.Graphics.OpenGL.GL.Light(OpenTK.Graphics.OpenGL.LightName.Light0,
OpenTK.Graphics.OpenGL.LightParameter.Diffuse, LightDiffuse); // 设置漫射光
OpenTK.Graphics.OpenGL.GL.Light(OpenTK.Graphics.OpenGL.LightName.Light0,
OpenTK.Graphics.OpenGL.LightParameter.Position, LightPosition); // 设置光源位置
OpenTK.Graphics.OpenGL.GL.Enable(OpenTK.Graphics.OpenGL.EnableCap.Light0);//加载灯光
xl = 0;
};
game.Resize += (sender, e) =>
{
OpenTK.Graphics.OpenGL.GL.Viewport(0, 0, Width, Height);
OpenTK.Graphics.OpenGL.GL.MatrixMode(OpenTK.Graphics.OpenGL.MatrixMode.Projection);
OpenTK.Graphics.OpenGL.GL.LoadIdentity();
OpenTK.Graphics.OpenGL.GL.Ortho(-200.0, 200.0, -200.0, 200.0, 0.0, 1000.0);
};
game.UpdateFrame += (sender, e) =>
{
if (game.Keyboard[Key.Escape]){ game.Exit();}
};
game.RenderFrame += (sender, e) =>
{
OpenTK.Graphics.OpenGL.GL.Clear
(OpenTK.Graphics.OpenGL.ClearBufferMask.ColorBufferBit | OpenTK.Graphics.OpenGL.ClearBufferMask.DepthBufferBit);
OpenTK.Graphics.OpenGL.GL.MatrixMode(OpenTK.Graphics.OpenGL.MatrixMode.Modelview);
OpenTK.Graphics.OpenGL.GL.LoadIdentity();
Drawface2D(x[xl],4);
if(xl < x.Count){
Bitmap bitmap1 = new Bitmap(Width, Height);
int arrLen = Width * Height * 4;
Byte[] colorArr = new Byte[arrLen];
OpenTK.Graphics.OpenGL.GL.ReadPixels(0, 0, Width, Height, OpenTK.Graphics.OpenGL.PixelFormat.Rgba,
OpenTK.Graphics.OpenGL.PixelType.Byte, colorArr);
int sign = 0;
for(int i = Height - 1;i >= 0;i--){
for(int j = 0;j < Width;j++){
bitmap1.SetPixel(j, i, Color.FromArgb(colorArr[sign + 3] * 2, colorArr[sign] * 2, colorArr[sign + 1] * 2, colorArr[sign + 2] * 2));
// Print(colorArr[sign + 3].ToString() + "/" + colorArr[sign].ToString() + "/" + colorArr[sign + 1].ToString() + "/" + colorArr[sign + 2].ToString());
sign += 4;
}}
String str = @"D:\maps\temp" + xl.ToString() + ".jpg";
bitmap1.Save(str);
game.SwapBuffers();
}
xl++;
if(xl >= x.Count)game.Close();//xl = x.Count - 1;
};
game.Run(1);
}
}catch(Exception ex){Print(ex.ToString());}
}
}
示例9: Main
public static void Main()
{
using(var game = new GameWindow())
{
game.Load += (sender, e) =>
{
// Setup settings, load textures, sound etc.
game.VSync = VSyncMode.On;
game.Width = 1280;
game.Height = 720;
// Center window to desktop
game.Location = new Point( OpenTK.DisplayDevice.Default.Width/2 - game.Width/2,
OpenTK.DisplayDevice.Default.Height/2 - game.Height/2);
GL.ClearColor(0.4f, 0.4f, 0.4f, 1);
GraphicsManager.init_text_writer(game.ClientSize, game.ClientSize);
_skeletons.Add(new Skeleton());
};
game.Resize += (sender, e) =>
{
int offset = 0;
GL.Viewport(0 + offset, 0 + offset, game.Width + offset, game.Height + offset);
};
game.UpdateFrame += (sender, e) =>
{
// Add game logic, input handling
if(game.Keyboard[Key.Escape])
{
game.Exit();
}
if(game.Keyboard[Key.R])
{
reset();
Nearest.release_check();
}
if(game.Keyboard[Key.A] && _active_time < DateTime.Now.Ticks)
{
add_doll();
if(_active_time < DateTime.Now.Ticks + 2000000)
_active_time = DateTime.Now.Ticks + 2000000;
}
if(game.Keyboard[Key.P] && _active_time < DateTime.Now.Ticks)
{
_pause = !_pause;
if(_active_time < DateTime.Now.Ticks + 2000000)
_active_time = DateTime.Now.Ticks + 2000000;
}
if(game.Keyboard[Key.F] && _active_time < DateTime.Now.Ticks)
{
for(int i = 0; i < _skeletons.Count; ++i)
_skeletons[i].toggle_forces();
if(_active_time < DateTime.Now.Ticks + 2000000)
_active_time = DateTime.Now.Ticks + 2000000;
}
if(game.Keyboard[Key.B] && _active_time < DateTime.Now.Ticks)
{
for(int i = 0; i < _skeletons.Count; ++i)
_skeletons[i].toggle_bones();
if(_active_time < DateTime.Now.Ticks + 2000000)
_active_time = DateTime.Now.Ticks + 2000000;
}
if(game.Keyboard[Key.G] && _active_time < DateTime.Now.Ticks)
{
for(int i = 0; i < _skeletons.Count; ++i)
_skeletons[i].toggle_graphics();
if(_active_time < DateTime.Now.Ticks + 2000000)
_active_time = DateTime.Now.Ticks + 2000000;
}
if(game.Keyboard[Key.C] && _active_time < DateTime.Now.Ticks)
{
for(int i = 0; i < _skeletons.Count; ++i)
_skeletons[i].toggle_climbing_mode();
if(_active_time < DateTime.Now.Ticks + 2000000)
_active_time = DateTime.Now.Ticks + 2000000;
}
if(game.Keyboard[Key.M] && _active_time < DateTime.Now.Ticks)
{
for(int i = 0; i < _skeletons.Count; ++i)
_skeletons[i].toggle_christmas_mode();
_snow.toggle();
if(_active_time < DateTime.Now.Ticks + 2000000)
_active_time = DateTime.Now.Ticks + 2000000;
}
if(game.Mouse[MouseButton.Right] && _active_time < DateTime.Now.Ticks)
{
for(int i = 0; i < _skeletons.Count; ++i)
_skeletons[i].pin_point();
if(_active_time < DateTime.Now.Ticks + 2000000)
_active_time = DateTime.Now.Ticks + 2000000;
}
if(game.Mouse[MouseButton.Left])
{
// Finds the nearest ragdoll to mouse
Nearest.check_nearest(_skeletons, new Vector2D(game.Mouse.X, game.Mouse.Y));
//.........这里部分代码省略.........
示例10: Main
public void Main()
{
using (var game = new GameWindow())
{
game.Load += (sender, e) =>
{
// setup settings, load textures, sounds
game.VSync = VSyncMode.On;
};
game.Resize += (sender, e) =>
{
GL.Viewport(0, 0, game.Width, game.Height);
};
game.UpdateFrame += (sender, e) =>
{
// add game logic, input handling
if (game.Keyboard[Key.Escape])
{
game.Exit();
}
};
game.RenderFrame += (sender, e) =>
{
// render graphics
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
GL.Ortho(-1000.0, 1000.0, -1000.0, 1000.0, 0.0, 2000.0);
GL.Translate(x, y, 0); // position triangle according to our x variable
//GL.Color3(Color.MidnightBlue);
//GL.Vertex2(-1.0f, 1.0f);
//GL.Color3(Color.SpringGreen);
//GL.Vertex2(0.0f, -1.0f);
//GL.Color3(Color.Ivory);
//GL.Vertex2(1.0f, 1.0f);
framenr++;
System.Diagnostics.Trace.WriteLine("RenderFrame " + framenr.ToString());
DrawStars();
game.SwapBuffers();
};
// Run the game at 30 updates per second
game.Run(30.0);
}
}
示例11: Main
static void Main(string[] args)
{
Mesh monkey = new Mesh(null,null) ;
bool spaceHeld = false;
float rotation = 0;
using (var game = new GameWindow())
{
game.Load += (sender, e) =>
{
// setup settings, load textures, sounds
monkey = Mesh.LoadFromOBJFile(@"Content/Models/Monkey.obj");
game.VSync = VSyncMode.On;
};
game.Resize += (sender, e) =>
{
GL.Viewport(0, 0, game.Width, game.Height);
};
game.UpdateFrame += (sender, e) =>
{
// add game logic, input handling
spaceHeld = Keyboard.GetState().IsKeyDown(Key.Space);
if (Keyboard.GetState().IsKeyDown(Key.Right))
rotation += -0.1f;
if (Keyboard.GetState().IsKeyDown(Key.Left))
rotation += 0.1f;
if (game.Keyboard[Key.Escape])
{
game.Exit();
}
};
game.RenderFrame += (sender, e) =>
{
// render graphics
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
GL.Ortho(-1.0, 1.0, -1.0, 1.0, 0.0, 4.0);
Matrix4 translation = Matrix4.LookAt(new Vector3((float)Math.Cos(rotation),0,(float)Math.Sin(rotation)), Vector3.Zero, Vector3.UnitY);
Matrix4 scale = Matrix4.CreateScale(0.2f);
Matrix4 modelView = translation * scale;
GL.LoadMatrix(ref modelView);
GL.Begin(PrimitiveType.Triangles);
for(int t = 0; t < monkey.tris.Length; t += 3)
{
GL.Color3(spaceHeld ? Color.MidnightBlue : Color.OrangeRed);
GL.Vertex3(monkey.vertices[monkey.tris[t] - 1]);
GL.Color3(Color.SpringGreen);
GL.Vertex3(monkey.vertices[monkey.tris[t + 1] - 1]);
GL.Color3(Color.Ivory);
GL.Vertex3(monkey.vertices[monkey.tris[t + 2] - 1]);
}
GL.End();
game.SwapBuffers();
};
game.Run(60.0);
}
}
示例12: Main
static void Main(string[] args)
{
using (var game = new GameWindow())
{
game.Load += (sender, e) =>
{
game.VSync = VSyncMode.On;
};
game.Resize += (sender, e) =>
{
GL.Viewport(0, 0, game.Width, game.Height);
};
game.UpdateFrame += (sender, e) =>
{
if (game.Keyboard[Key.Escape])
{
game.Exit();
}
};
game.RenderFrame += (sender, e) =>
{
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
GL.Ortho(-1.0, 1.0, -1.0, 1.0, 0.0, 4.0);
GL.Begin(PrimitiveType.LineLoop);
GL.Color3(Color.Red);
GL.Vertex2(0.0f, -0.03f);
GL.Vertex2(0.02f, -0.03f);
GL.Vertex2(0.04f, 0.0f);
GL.Vertex2(0.01f, 0.04f);
GL.Vertex2(0.02f, 0.4f);
GL.Vertex2(0.6f, 0.9f);
GL.Vertex2(0.6f, 0.7f);
GL.Vertex2(0.2f, 0.35f);
GL.Vertex2(0.22f, 0.30f);
GL.Vertex2(0.6f, 0.6f);
GL.Vertex2(0.6f, 0.4f);
GL.Vertex2(0.3f, 0.15f);
GL.Vertex2(0.32f, 0.10f);
GL.Vertex2(0.6f, 0.3f);
GL.Vertex2(0.6f, 0.15f);
GL.Vertex2(0.3f, -0.07f);
GL.Vertex2(0.3f, -0.9f);
GL.Vertex2(0.28f, -0.9f);
GL.Vertex2(0.0f, -0.3f);
GL.Vertex2(-0.0f, -0.3f);
GL.Vertex2(-0.28f, -0.9f);
GL.Vertex2(-0.3f, -0.9f);
GL.Vertex2(-0.3f, -0.07f);
GL.Vertex2(-0.6f, 0.15f);
GL.Vertex2(-0.6f, 0.3f);
GL.Vertex2(-0.32f, 0.10f);
GL.Vertex2(-0.3f, 0.15f);
GL.Vertex2(-0.6f, 0.4f);
GL.Vertex2(-0.6f, 0.6f);
GL.Vertex2(-0.22f, 0.30f);
GL.Vertex2(-0.2f, 0.35f);
GL.Vertex2(-0.6f, 0.7f);
GL.Vertex2(-0.6f, 0.9f);
GL.Vertex2(-0.02f, 0.4f);
GL.Vertex2(-0.01f, 0.04f);
GL.Vertex2(-0.04f, 0.0f);
GL.Vertex2(-0.02f, -0.03f);
GL.Vertex2(-0.0f, -0.03f);
GL.End();
game.SwapBuffers();
};
game.Run(60.0);
}
}
示例13: Main
public static void Main (string[] args)
{
using (var game = new GameWindow ())
using (var ac = new AudioContext())
{
// var bag = new C5.TreeBag<IEffect> (new TimeToStartCutoffComparer ());
//// bag.Add (new SoundEffect{Id = 1, TimeToStart = 1.0f });
//// bag.Add (new SoundEffect{Id = 2, TimeToStart = 2.0f });
//// bag.Add (new SoundEffect{Id = 3, TimeToStart = 1.5f });
//// bag.Add (new SoundEffect{Id = 5, TimeToStart = 1.5f });
//// bag.Add (new SoundEffect{Id = 4, TimeToStart = 1.2f });
//
// foreach (IEffect effect in bag.RangeTo(new SoundEffect{TimeToStart=1.5f}))
// {
// Console.WriteLine ("Effect {0} - {1}", effect.Id, effect.TimeToStart);
// }
//var audio = new SoundMachine(new [] {ac});
//var scheduler = new EffectScheduler (new [] { audio }, 0f);
using (var fs = File.OpenRead ("01_Ghosts_I.flac"))
using (var wav = new WaveOverFlacStream(fs, WaveOverFlacStreamMode.Decode))
using (var ms = new MemoryStream())
{
wav.CopyTo(ms);
if (wav.StreamInfo == null)
{
throw new InvalidDataException ("FLAC: Missing wav stream info");
}
else
{
var sound_data = ms.ToArray();
int channels = wav.StreamInfo.ChannelsCount;
int bits_per_sample = wav.StreamInfo.BitsPerSample;
int sample_rate = wav.StreamInfo.SampleRate;
var sound_format =
channels == 1 && bits_per_sample == 8 ? ALFormat.Mono8 :
channels == 1 && bits_per_sample == 16 ? ALFormat.Mono16 :
channels == 2 && bits_per_sample == 8 ? ALFormat.Stereo8 :
channels == 2 && bits_per_sample == 16 ? ALFormat.Stereo16 :
(ALFormat)0; // unknown
Console.WriteLine ("Seconds : {0}",((wav.StreamInfo.TotalSampleCount / sample_rate) + ((wav.StreamInfo.TotalSampleCount % sample_rate)/(sample_rate))) );
int buffer = AL.GenBuffer ();
AL.BufferData(buffer, sound_format, sound_data, sound_data.Length, sample_rate);
ALError error_code = AL.GetError ();
if (error_code != ALError.NoError)
{
// respond to load error etc.
Console.WriteLine(error_code);
}
int source = AL.GenSource(); // gen 2 Source Handles
AL.Source( source, ALSourcei.Buffer, buffer ); // attach the buffer to a source
AL.SourcePlay(source); // start playback
AL.Source( source, ALSourceb.Looping, false ); // source loops infinitely
}
}
game.Load += (sender, e) =>
{
// setup settings, load textures, sounds
game.VSync = VSyncMode.On;
};
game.Unload += (sender, e) =>
{
};
game.KeyDown += (object sender, KeyboardKeyEventArgs e) =>
{
if (e.Key == Key.Space)
{
game.Exit();
}
};
game.UpdateFrame += (sender, e) =>
{
// add game logic, input handling
// update shader uniforms
// update shader mesh
};
game.RenderFrame += (sender, e) =>
{
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
game.SwapBuffers();
};
//.........这里部分代码省略.........
示例14: Main
static void Main() {
Console.WriteLine("Entering");
using (var game = new GameWindow(1920, 1080, new GraphicsMode(ColorFormat.Empty, 8, 0, 6), "Heart of Gold", GameWindowFlags.Default)) {
game.Icon = Icon.ExtractAssociatedIcon(Assembly.GetEntryAssembly().Location);
var size = 2048;
var zoom = 1.0;
game.Load += (sender, e) => { game.VSync = VSyncMode.On;
GL.PointSize(10);
};
game.MouseWheel += delegate (object sender, MouseWheelEventArgs args) {
if (args.Delta > 0)
zoom *= 1.1;
//zoom += args.Delta/10.0;
else
zoom /= 1.1;
//zoom += args.Delta/10.0;
if (zoom <= 0.1) zoom = 0.1;
var aspect = game.Width / (double)game.Height;
//GL.Viewport(0, 0, game.Width, game.Height);
//GL.Ortho(-xsize, xsize, ysize, -ysize, 0, 4.0);
};
game.Resize += (sender, e) =>
GL.Viewport(0, 0, game.Width, game.Height);
#region Heights
var matrix = new double[size, size];
var r = new Random();
#endregion
#region Color
Console.WriteLine("Initializing color...");
var cmatrix = new Color[size, size];
using (var b = (Bitmap)Image.FromFile(@"E:\Downloads\Untitled5.png")) {
for (var i = 0; i < size; i++) {
Console.Write($"\rOn column {i,4} of {size}");
for (var j = 0; j < size; j++) {
matrix[i, j] = ((double)b.GetPixel(i, j).A + 1);// / 8.0;
cmatrix[i, j] = Color.FromArgb(255, b.GetPixel(i, j));
}
}
}
Console.WriteLine();
#endregion
bool wDown = false,
aDown = false,
sDown = false,
dDown = false;
game.KeyDown += delegate(object sender, KeyboardKeyEventArgs args) {
switch (args.Key) {
case Key.W:
wDown = true;
break;
case Key.A:
aDown = true;
break;
case Key.S:
sDown = true;
break;
case Key.D:
dDown = true;
break;
}
};
Vector2 translate = Vector2.Zero;
game.KeyUp += delegate(object sender, KeyboardKeyEventArgs args) {
switch (args.Key) {
case Key.Escape:
game.Exit();
break;
case Key.R:
zoom = 1;
break;
case Key.W:
if (wDown)
translate += new Vector2(1f, 1f);
wDown = false;
break;
case Key.A:
if (aDown)
translate += new Vector2(1f, -1f);
aDown = false;
break;
case Key.S:
if (sDown)
translate += new Vector2(-1f, -1f);
sDown = false;
break;
case Key.D:
//.........这里部分代码省略.........
示例15: Main
static void Main()
{
int mouseX = 0;
int mouseY = 0;
Dictionary<BrickTypeEnum, int> brickTextures = new Dictionary<BrickTypeEnum,int>();
using (var w = new GameWindow(640, 480))
{
w.CursorVisible = false;
w.RenderFrame += (o, e) => {
GL.ClearColor(Color.Gray);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
CogitaGameEntities.CogitaGameInstance.Instance.Player.Camera.UseCamera();
//GL.ClientActiveTexture(TextureUnit.Texture0);
foreach (var bt in Enum.GetValues(typeof(BrickTypeEnum)))
{
GL.Enable(EnableCap.Texture2D);
GL.BindTexture(TextureTarget.Texture2D, brickTextures[(BrickTypeEnum)bt]);
//Debug.Assert(GL.GetError() == ErrorCode.NoError);
CogitaGameEntities.CogitaGameInstance.Instance.MapCursor.Draw((BrickTypeEnum)bt);
GL.BindTexture(TextureTarget.Texture2D,0);
//Debug.Assert(GL.GetError() == ErrorCode.NoError);
GL.Disable(EnableCap.Texture2D);
}
w.SwapBuffers();
};
w.UpdateFrame += (o, e) => {
CogitaGameEntities.CogitaGameInstance.Instance.MapCursor.Update();
CogitaTerrainObjects.EventPumps.UIThreadEventPump.Instance.DoWork();
CogitaGameEntities.CogitaGameInstance.Instance.DoPhysics(Math.Max(e.Time,0.01));
var gi = CogitaGameEntities.CogitaGameInstance.Instance;
var player = gi.Player;
ProcessKeyPresses(w, player);
if (w.Keyboard[OpenTK.Input.Key.Escape])
w.Exit();
var mState = OpenTK.Input.Mouse.GetState();
var mdx = mState.X - mouseX;
var mdy = mState.Y - mouseY;
mouseX = mState.X;
mouseY = mState.Y;
player.Pitch += ((double)mdy / 200.0);
player.Yaw += ((double)mdx / 200.0);
};
w.Load += (o, e) =>
{
foreach (var bt in Enum.GetValues(typeof(BrickTypeEnum)))
{
brickTextures[(BrickTypeEnum)bt] = Util.GenTexture(string.Format("../res/{0}.png",bt.ToString()));
}
};
w.Run();
}
}