当前位置: 首页>>代码示例>>C#>>正文


C# GameWindow.SwapBuffers方法代码示例

本文整理汇总了C#中OpenTK.GameWindow.SwapBuffers方法的典型用法代码示例。如果您正苦于以下问题:C# GameWindow.SwapBuffers方法的具体用法?C# GameWindow.SwapBuffers怎么用?C# GameWindow.SwapBuffers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OpenTK.GameWindow的用法示例。


在下文中一共展示了GameWindow.SwapBuffers方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnRenderFrame

        public override void OnRenderFrame(OpenTK.FrameEventArgs e, GameWindow window)
        {
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            GL.Ortho(0, 1280, 0,720,0,1);
            GL.Disable(EnableCap.DepthTest);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            GL.ClearColor(0.2f , 0.2f, 0.2f, 0);
            GL.Clear(ClearBufferMask.ColorBufferBit);

            for (int y=0;y<720;y++)
            {
                for (int x = 0; x < 1280; x++)
                {
                    var c = (int) (Math.Floor(Math.Sin(x/35d)*128 + Math.Sin(y/28d)*32f + Math.Sin((x + y)/16d)*64));
                    c = mod(c, 256);
                    var r = cols[0, c] % 256;
                    var g = cols[1, c] % 256;
                    var b = cols[2, c] % 256;
                    GL.Color3(r/256, g/256, b/256);
                    GL.Begin(BeginMode.Points);
                        GL.Vertex2(x, y);
                    GL.End();
                }

            }
            window.SwapBuffers();
        }
开发者ID:samerai,项目名称:FastIntroFramework,代码行数:29,代码来源:Plasma.cs

示例2: 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();
        }
开发者ID:danielscherzer,项目名称:Framework,代码行数:34,代码来源:Program.cs

示例3: 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);
        }
开发者ID:Herbstein,项目名称:BlunderBuzz,代码行数:35,代码来源:Program.cs

示例4: Main

		static void Main ()
		{
			// OpenGL 창
			GameWindow window = new GameWindow ();
			
			// 창이 처음 생성됐을 때 
			window.Load += ( sender, e ) =>
			{
				
			};
			// 업데이트 프레임(연산처리, 입력처리 등)
			window.UpdateFrame += ( sender, e ) =>
			{
				
			};
			// 렌더링 프레임(화면 표시)
			window.RenderFrame += ( sender, e ) =>
			{
				// 화면 초기화 설정
				//> 화면 색상은 검정색(R: 0, G: 0, B: 0, A: 255)
				GL.ClearColor ( 0, 0, 0, 1 );
				//> 깊이 버퍼는 1(쓸 수 있는 깊이)
				GL.ClearDepth ( 1 );
				//> 스텐실 버퍼는 0
				GL.ClearStencil ( 0 );
				// 화면 초기화(색상 버퍼, 깊이 버퍼, 스텐실 버퍼에 처리)
				GL.Clear ( ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit );

				// OpenGL 1.0 삼각형 그리기 시작
				// OpenGL 3.2부터 Deprecated, OpenGL ES 2.0부터 Deprecated
				GL.Begin ( PrimitiveType.Triangles );

				// 삼각형의 세 꼭지점 설정
				// OpenGL 3.2부터 Deprecated, OpenGL ES 2.0부터 Deprecated
				GL.Vertex2 ( +0.0, +0.5 );
				GL.Vertex2 ( +0.5, -0.5 );
				GL.Vertex2 ( -0.5, -0.5 );

				// 삼각형 색상은 마젠타(R: 255, G: 0, B: 255)
				// OpenGL 3.2부터 Deprecated, OpenGL ES 2.0부터 Deprecated
				GL.Color3 ( 1.0f, 0, 1.0f );

				// OpenGL 1.0 삼각형 그리기 끝
				// OpenGL 3.2부터 Deprecated, OpenGL ES 2.0부터 Deprecated
				GL.End ();
				// 버퍼에 출력
				GL.Flush ();

				// 백 버퍼와 화면 버퍼 교환
				window.SwapBuffers ();
			};
			// 창이 종료될 때
			window.Closing += ( sender, e ) =>
			{
				
			};

			// 창을 띄우고 창이 종료될 때까지 메시지 펌프 및 무한 루프 처리
			window.Run ();
		}
开发者ID:GROWrepo,项目名称:OpenGL.Study,代码行数:60,代码来源:Program.cs

示例5: 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);
			}
		}
开发者ID:tgsstdio,项目名称:BirdNest.QuickFont,代码行数:57,代码来源:Program.cs

示例6: MyApplication

 private MyApplication()
 {
     gameWindow = new GameWindow(800, 800);
     //gameWindow.WindowState = WindowState.Fullscreen;
     gameWindow.KeyDown += GameWindow_KeyDown;
     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();
 }
开发者ID:danielscherzer,项目名称:Framework,代码行数:10,代码来源:Program.cs

示例7: 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);
            }
        }
开发者ID:piokra,项目名称:crispy-octo-garbanzo,代码行数:53,代码来源:Program.cs

示例8: MyApplication

        public MyApplication()
        {
            shootCoolDown.OnPeriodElapsed += (s, t) => shootCoolDown.Stop();

            gameWindow = new GameWindow();
            gameWindow.WindowState = WindowState.Fullscreen;
            CreateEnemies();
            gameWindow.Resize += (sender, e) => GL.Viewport(0, 0, gameWindow.Width, gameWindow.Height);
            gameWindow.UpdateFrame += GameWindow_UpdateFrame;
            gameWindow.RenderFrame += GameWindow_RenderFrame;
            gameWindow.RenderFrame += (sender, e) => gameWindow.SwapBuffers();
            timeSource.Start();
            gameWindow.Run(60.0);
        }
开发者ID:danielscherzer,项目名称:Framework,代码行数:14,代码来源:Program.cs

示例9: HandleFrame

        protected override void HandleFrame(GameWindow window)
        {
            GL.ClearColor (Color4.Black);
            GL.Clear (ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.Enable (EnableCap.Blend);
            GL.BlendFunc (BlendingFactorSrc.SrcAlpha, BlendingFactorDest.One);
            GL.BlendEquation (BlendEquationMode.FuncAdd);

            SetCamera (window);
            PrepareState ();
            GL.DrawArraysInstanced (BeginMode.TriangleFan, 0, 4, PARTICLES_COUNT);

            window.SwapBuffers ();
        }
开发者ID:smalld,项目名称:particle_system,代码行数:14,代码来源:System1.cs

示例10: 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);
 }
开发者ID:Ziretech,项目名称:Ubiq,代码行数:16,代码来源:GLTest.cs

示例11: Main

        public static void Main(string[] args)
        {
            using (var game = new GameWindow(1024, 768))
            {
                // Load event - fired once before entering the mainLoop
                game.Load += (object sender, EventArgs e) =>
                {
                    game.Title = "OpenGL in C#";                    // Set the window title;
                    GL.Enable(EnableCap.Blend);                     // Enable OpenGL alpha blending
                    GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); // Set the default blending calculation
                };

                // Resize event - fires when the window changes size
                // Using it to reset the Viewport on resize
                game.Resize += (object sender, EventArgs e) =>
                {
                    GL.Viewport(0, 0, game.Width, game.Height);     // Set the OpenGL ViewPort(the area that it will draw to)
                };

                // Called once every N frames set by the Run method
                game.RenderFrame += (object sender, FrameEventArgs e) =>
                {
                    GL.ClearColor(Color.CornflowerBlue);            // Sets the default color of the color buffer
                    GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); // Clears individual buffers, fills the color buffer with the set clearColor

                    GL.MatrixMode(MatrixMode.Projection);           // Tells OpenGL that we will use the Projection Matrix
                    GL.LoadIdentity();                              // Replaces the selected matrix with a Identity matrix
                    GL.Ortho(-1.5, 1.5, -1.5, 1.5, 0.0, 4.0);       // Create an Orthographic matrix(parallel view with no depth(3rd dimension)

                    GL.Begin(PrimitiveType.Polygon);                // Tells OpenGL that we want to draw Verticies with the given mode, this case Polygon(deprecated, dont use it in real applications)
                    GL.Color3(Color.Blue);                          // Tells OpenGL that the Vertex Colors after this call will be Blue
                    GL.Vertex2(-1, 1);                              // Sets a Vertex at the set position
                    GL.Color3(Color.Red);
                    GL.Vertex2(1, 1);
                    GL.Color3(Color.Yellow);
                    GL.Vertex2(1, -1);
                    GL.Color3(Color.White);
                    GL.Vertex2(-1, -1);

                    GL.End();                                       // Tells OpenGL that we are done passing our data.

                    game.SwapBuffers();                             // Swaps the back buffer with the front buffer. We draw on the back buffer while the front buffer is on the screen.
                };

                game.Run();                                         // Starts the mainLoop and fires onetime events
            }
        }
开发者ID:Inspix,项目名称:Learning-OpenGL,代码行数:47,代码来源:Program.cs

示例12: 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);
 }
开发者ID:Ziretech,项目名称:Ubiq,代码行数:24,代码来源:GLTest.cs

示例13: Main


//.........这里部分代码省略.........
                    {
                        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));
                        if(_ragdoll_release_time < DateTime.Now.Ticks + 2000000)
                            _ragdoll_release_time = DateTime.Now.Ticks + 2000000;

                        // Adds a mouse drag force.
                        for(int i = 0; i < _skeletons.Count; ++i)
                            _skeletons[i].mouse_force(new Vector2D(game.Mouse.X, game.Mouse.Y));
                    }
                    else
                    {
                        // Makes it possible to drag around another ragdoll
                        if(_ragdoll_release_time < DateTime.Now.Ticks)
                            Nearest.release_check();

                        for(int i = 0; i < _skeletons.Count; ++i)
                            _skeletons[i].release_point_lock();
                    }

                    // Update skeleton
                    if(!_pause)
                    {
                        for(int i = 0; i < _skeletons.Count; ++i)
                            _skeletons[i].update(1.0/10.0);
                        _snow.update(1.0/10.0);
                    }
                };

                game.RenderFrame += (sender, e) =>
                {
                    // Render graphics
                    GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                    GL.MatrixMode(MatrixMode.Projection);
                    GL.LoadIdentity();
                    GL.Ortho(0, game.Width, game.Height, 0, -1, 1);

                    // Render ragdolls
                    for(int i = 0; i < _skeletons.Count; ++i)
                            _skeletons[i].draw(new Vector2D(game.Mouse.X, game.Mouse.Y));

                    // Render snow
                    _snow.draw();

                    // Some user friendly info
                    if(_fps_timer < DateTime.Now.Ticks)
                    {
                        _fps_timer = DateTime.Now.Ticks + 800000;
                        _fps = Math.Round(game.RenderFrequency, 2);
                    }

                    // Render help text
                    draw_info();

                    game.SwapBuffers();
                };

                // Run the game at 60 updates per second
                game.Run(60.0);
            }
        }
开发者ID:ThatHg,项目名称:ragdollphysics,代码行数:101,代码来源:Program.cs

示例14: Main

        public static void Main(int resX, int resY)
        {

            Graphics.Sprite sprite = new Graphics.Sprite();
            Graphics.Mesh mesh = new Graphics.Mesh();
            using (var game = new GameWindow())
            {
                game.VSync = VSyncMode.On;
                game.Width = resX;
                game.Height = resY;
                
                game.Load += (sender, e) =>
                {
                    Console.WriteLine("Using OpenGL version: " + GL.GetString(StringName.Version));

                    
                    Graphics.TextureManager.LoadTexture("F:/DestWa/Pictures/artkleiner.png", "art");

                    // setup settings, load textures, sounds


                    sprite = new Graphics.Sprite("art", Vector3.Zero, Vector3.Zero, Vector3.One);
                    sprite.scale = new Vector3(1280, 720, 1);
                    sprite.position.X = 10;


                    mesh = Graphics.Mesh.CreateMeshFromOBJ("C:/Users/DestWa/Desktop/man.obj");
                    mesh.scale = new Vector3(1, 1, 1);
                    mesh.position.Z = 100;

                    GL.ClearColor(Color.Cornsilk);
                };

                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);

                    Graphics.Renderer.DrawSprite(sprite);
                    //mesh.rotation.X += 0.01f;
                    //mesh.rotation.Y += 0.01f;

                    Graphics.Renderer.activeCamera.location.Z -= 0.1f;
                    Graphics.Renderer.DrawMesh(mesh);

                    game.SwapBuffers();
                };

                // Run the game at 60 updates per second
                game.Run(60.0);
            }
        }
开发者ID:7216,项目名称:TWCEngine,代码行数:66,代码来源:TWCEngine.cs


注:本文中的OpenTK.GameWindow.SwapBuffers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。