Run() public method

Enters the game loop of the GameWindow using the maximum update rate.
public Run ( ) : void
return void
Esempio n. 1
3
        public static void Main()
        {
            // Create static (global) window instance
            Window = new OpenTK.GameWindow();

            // Hook up the initialize callback
            Window.Load += new EventHandler<EventArgs>(Initialize);
            // Hook up the update callback
            Window.UpdateFrame += new EventHandler<FrameEventArgs>(Update);
            // Hook up the render callback
            Window.RenderFrame += new EventHandler<FrameEventArgs>(Render);
            // Hook up the shutdown callback
            Window.Unload += new EventHandler<EventArgs>(Shutdown);

            // Set window title and size
            Window.Title = "Game Name";
            Window.ClientSize = new Size(30*8, 30*6);
            Window.VSync = VSyncMode.On;
            // Run the game at 60 frames per second. This method will NOT return
            // until the window is closed.
            Window.Run(60.0f);

            // If we made it down here the window was closed. Call the windows
            // Dispose method to free any resources that the window might hold
            Window.Dispose();

            #if DEBUG
            Console.WriteLine("\nFinished executing, press any key to exit...");
            Console.ReadKey();
            #endif
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            var win = new OpenTK.GameWindow (200, 200, GraphicsMode.Default, "", OpenTK.GameWindowFlags.Default);

            var form1 = new Form ();
            form1.Size = new Size(400, 1000);
            PropertyGrid propertyGrid1 = new PropertyGrid ();
            propertyGrid1.CommandsVisibleIfAvailable = true;
            propertyGrid1.Location = new Point (10, 20);
            propertyGrid1.TabIndex = 1;
            propertyGrid1.Text = "Property Grid";
            propertyGrid1.Dock = DockStyle.Fill;
            propertyGrid1.Font = new Font("URW Gothic L", 10.25f, GraphicsUnit.Point);
            propertyGrid1.CategoryForeColor = SystemColors.ControlLight;
            propertyGrid1.ViewForeColor = SystemColors.ControlText;
            propertyGrid1.ViewBackColor = SystemColors.Control;
            propertyGrid1.LineColor = SystemColors.ControlLight;
            form1.Controls.Add (propertyGrid1);
            form1.Show ();

            win.RenderFrame += (sender, aaa) => { Application.DoEvents (); };

            using(var system = (new System6.System6()).GetInstance (win))
            {
                //system.PropertyChanged += (sender, e) => propertyGrid1.Refresh();
                propertyGrid1.SelectedObject = system;
                win.Run ();
            }
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
		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 ();
		}
Esempio n. 5
0
        public static void Main()
        {
            //create static(global) window instance
            Window = new OpenTK.GameWindow();

            //hook up the initialize callback
            Window.Load += new EventHandler<EventArgs>(Initialize);
            //hook up the update callback
            Window.UpdateFrame += new EventHandler<FrameEventArgs>(Update);
            //hook up render callback
            Window.RenderFrame += new EventHandler<FrameEventArgs>(Render);
            //hook up shutdown callback
            Window.Unload += new EventHandler<EventArgs>(Shutdown);
            Window.VSync = VSyncMode.On;

            //set window title and size
            Window.Title = "Game Name";
            Window.ClientSize = new Size(800, 600);
            //run game at 60fps. will not return until window is closed
            Window.Run(60.0f);

            Window.Dispose();
            #if DEBUG
            Console.ReadLine();
            #endif
        }
Esempio n. 6
0
		static void Main ()
		{
			// OpenGL 창
			GameWindow window = new GameWindow ();

			float [] vertices = new float []
			{
				+0.0f, +0.5f,
				+0.5f, -0.5f,
				-0.5f, -0.5f,
			};

			// 창이 처음 생성됐을 때 
			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 3.2부터 Deprecated, OpenGL ES 2.0부터 Deprecated
				GL.VertexPointer<float> ( 2, VertexPointerType.Float, 0, vertices );
				GL.EnableClientState ( ArrayCap.VertexArray );

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

				GL.DrawArrays ( PrimitiveType.Triangles, 0, 3 );

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

			};

			// 창을 띄우고 창이 종료될 때까지 메시지 펌프 및 무한 루프 처리
			window.Run ();
		}
Esempio n. 7
0
        static void Main(string[] args)
        {
            GameWindow window = new GameWindow(800, 600, new OpenTK.Graphics.GraphicsMode(32, 8, 0, 8));

            Game game = new Game(window);

            window.Run(1.0 / 60.0);
        }
Esempio n. 8
0
 void LaunchGameWindow()
 {
     hidden = new GameWindow(320, 240, GraphicsMode.Default, "OpenTK | Hidden input window");
     hidden.Load += hidden_Load;
     hidden.Unload += hidden_Unload;
     hidden.RenderFrame += hidden_RenderFrame;
     hidden.Run(60.0, 0.0);
 }
Esempio n. 9
0
 static void Main(string[] args)
 {
     window = new GameWindow(800, 600, GraphicsMode.Default, "Cube");
     window.RenderFrame += Window_RenderFrame;
     window.KeyDown += Window_KeyDown;
     GL.Enable(EnableCap.DepthTest);
     window.Run();
 }
Esempio n. 10
0
		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);
			}
		}
Esempio n. 11
0
        public Game()
        {
            _win = new GameWindow();
            _win.Load += (s, e) => { Load(s, e); };
            _win.UpdateFrame += (s, e) => { Update(s, e); };
            _win.Resize += (s, e) => { Resize(s, e); };
            _win.RenderFrame += (s, e) => { Render(s, e); };

            _win.Run(60.0);
        }
Esempio n. 12
0
 private void Form1_Load(object sender, EventArgs e)
 {
     game = new GameWindow(800, 600, GraphicsMode.Default, "Primitive Draw");
     game.Load += Game_Load;
     game.Resize += Game_Resize;
     game.RenderFrame += Game_RenderFrame;
     game.UpdateFrame += Game_UpdateFrame;
     game.KeyDown += Game_KeyDown;
     game.Run();
 }
Esempio n. 13
0
 private static void Main()
 {
     using (window = new GameWindow(1024, 600, GraphicsMode.Default, "PhysicsEngine"))
     {
         CreateRectangles();
         window.Resize += Resize;
         window.UpdateFrame += Update;
         window.RenderFrame += Draw;
         window.Run();
     }
 }
Esempio n. 14
0
 private static void Main()
 {
     using (window = new GameWindow(1024, 600, GraphicsMode.Default, "PhysicsEngine"))
     {
         window.Load += Initialize;
         window.Resize += Resize;
         window.UpdateFrame += Update;
         window.RenderFrame += Draw;
         window.Run();
     }
 }
Esempio n. 15
0
        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);
            }
        }
Esempio n. 16
0
        public void Run()
        {
            Instance = this;

            Window = new GameWindow();

            Window.Load += Window_Load;
            Window.Resize += Window_Resize;
            Window.UpdateFrame += Window_UpdateFrame;
            Window.RenderFrame += Window_RenderFrame;

            Window.Run();
        }
Esempio n. 17
0
        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);
        }
Esempio n. 18
0
		private static void InitWindow(){
			Window = new GameWindow ();
			Window.Title = Reference.getFullName();

			//Add event handlers
			Window.Load += (sender, e) =>  {
				Console.WriteLine("Load");	
			};
			Window.Load += new EventHandler<EventArgs> (OnLoad);
			Window.RenderFrame += new EventHandler<FrameEventArgs>(OnRenderFrame);
			Window.UpdateFrame += new EventHandler<FrameEventArgs>(OnUpdateFrame);
			Window.Resize += new EventHandler<EventArgs> (OnWindowResize);
			//Create the window
			Window.Run(Reference.UPDATES_PER_SECOND, Reference.FRAMES_PER_SECOND);//Starts a game loop.s;
		}
Esempio n. 19
0
 public MyApplication()
 {
     gameWindow = new GameWindow(800, 800);
     string basePath = "../../media/";
     levelFileNamePrefix = basePath + "level";
     visual = new Visual();
     gameWindow.Load += GameWindow_Load;
     gameWindow.Resize += GameWindow_Resize;
     gameWindow.KeyDown += GameWindow_KeyDown;
     gameWindow.UpdateFrame += GameWindow_UpdateFrame;
     gameWindow.RenderFrame += GameWindow_RenderFrame;
     gameWindow.RenderFrame += (sender, e) => { gameWindow.SwapBuffers(); };
     LoadLevel();
     gameWindow.Run(60.0);
 }
Esempio n. 20
0
 static void Main(string[] args)
 {
     Window = new OpenTK.GameWindow();
     Window.Title = "Items";
     Window.Load += new EventHandler<EventArgs>(Initialize);
     Window.UpdateFrame += new EventHandler<FrameEventArgs>(Update);
     Window.RenderFrame += new EventHandler<FrameEventArgs>(Render);
     Window.Unload += new EventHandler<EventArgs>(Shutdown);
     Window.Run(60.0);
     Window.Dispose();
     #if DEBUG
     Console.WriteLine("\nFinished executing, press any key to exit...");
     Console.ReadKey();
     #endif
 }
Esempio n. 21
0
 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);
 }
Esempio n. 22
0
        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
            }
        }
Esempio n. 23
0
        public WindowsRender(GameWindow game)
        {
            this.Game = game;
            //step = 0.5;
            time = 0.0f;

            //Camera = new Camera();
            Shelf = new Board();

            Game.Load += Game_Load;
            Game.Resize += Game_Resize;
            Game.UpdateFrame += Game_UpdateFrame;
            Game.RenderFrame += Game_RenderFrame;
            Game.KeyPress += Game_KeyPress;

            game.Run(1 / 60.0);
        }
Esempio n. 24
0
        public static void Main()
        {
            DisplayDevice device = DisplayDevice.Default;
            window = new GameWindow(device.Width, device.Height, GraphicsMode.Default, "ColorGuesser", GameWindowFlags.Fullscreen, device );

            string glVersion = GL.GetString(StringName.Version);
            string shaderLanguageVersion = GL.GetString(StringName.ShadingLanguageVersion);
            Debug.WriteLine(glVersion);
            Debug.WriteLine(shaderLanguageVersion);

            // adds event handlers to events of the game window, will be executed by the window when the events happen
            window.Load += onWindowLoad;
            window.Resize += onWindowResize;
            window.UpdateFrame += onWindowUpdateFrame;
            window.RenderFrame += onWindowRenderFrame;
            // start!
            window.Run(60);
        }
        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();

            };
        }
Esempio n. 26
0
        static void Main(string[] Args)
        {
            //loads audio files
            GeneralAudio.LoadSound("data/audio/hmn.wav", "Include4eto - Hindered No More");
            GeneralAudio.LoadSound("data/audio/layla.wav", "Eric Clapton - Layla");
            GeneralAudio.LoadSound("data/audio/exp/1.wav", "1");
            GeneralAudio.LoadSound("data/audio/exp/2.wav", "2");
            GeneralAudio.LoadSound("data/audio/exp/3.wav", "3");
            GeneralAudio.LoadSound("data/audio/exp/4.wav", "4");
            GeneralAudio.LoadSound("data/audio/exp/5.wav", "5");
            GeneralAudio.LoadSound("data/audio/exp/6.wav", "6");
            GeneralAudio.LoadSound("data/audio/exp/7.wav", "7");
            GeneralAudio.LoadSound("data/audio/exp.wav", "8");
            BackgroundMusic.AddSongs("Include4eto - Hindered No More", "Eric Clapton - Layla");

            var window = new GameWindow();
            window.BackgroundColor = Color.Wheat;
            Camera.Zoom = -50m;
            Camera.ControlMode = Camera.Mode.Smooth;

            BackgroundMusic.LinkToWindow(window);
            //window.Menu = new MainMenu(window);

            //if (!Settings.Default.CredentialsVerified)
            //{
                //var betaVer = new BetaVerification(window);
            //}
            //else
            {
                window.Menu = new MainMenu(window);
                if (Settings.Default.MusicStatus)
                    BackgroundMusic.StartPlayback();
            }

            if (Settings.Default.unlockStatus == null || Settings.Default.itemsShot == null)
                Game.Game.DeleteProgress();

            window.GameMenu = new IngameMenu(window);
            Game.Game.MainWindow = window;
            Game.Game.InitializeGame();

            window.Run(30);
        }
Esempio n. 27
0
		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 );



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

			};

			// 창을 띄우고 창이 종료될 때까지 메시지 펌프 및 무한 루프 처리
			window.Run ();
		}
Esempio n. 28
0
        public static void Main(string[] args) {
            //create new window
            Window = new MainGameWindow();
            Axiis = new Grid();
            TheGame = new CameraExample();
            TheGame.Resize(Window.Width, Window.Height);
            Window.Load += new EventHandler<EventArgs>(Initialize);
            Window.UpdateFrame += new EventHandler<FrameEventArgs>(Update);
            Window.RenderFrame += new EventHandler<FrameEventArgs>(Render);
            Window.Unload += new EventHandler<EventArgs>(Shutdown);

            Window.Title = "Game Name";
            Window.ClientSize = new System.Drawing.Size(800, 600);
            Window.VSync = VSyncMode.On;
            //run 60fps
            Window.Run(60.0f);

            //Dispose at end
            Window.Dispose();
        }
Esempio n. 29
0
 public static void Initialize(int width, int height)
 {
     Scenes = new Dictionary<string, SceneBase>();
     #if PC
     window = new GameWindow(width, height);
     cgContext = Context.Create();
     window.RenderFrame += (a, b) =>
     {
         curScene.Render(b.Time);
     };
     window.UpdateFrame += (a, b) =>
     {
         curScene.Update(b.Time);
     };
     window.Run(30, 30);
     #elif PSM
     graphics = new GraphicsContext(
         width, height, PixelFormat.Rgba, PixelFormat.Depth24, MultiSampleMode.Msaa2x);
     #endif
 }
Esempio n. 30
0
        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);
        }
Esempio n. 31
0
        private void Task1Btn_Click(object sender, RoutedEventArgs e)
        {
            double baseSpeed = 1, speedUp = 1.2, slowness = 0.95, maxSpeed = 40;
            double xOffset = 0, yOffset = 0, xSpeed = 0, ySpeed = 0;

            using (var visualWindow = new VisualWindow())
            {
                visualWindow.Load += (s, args) =>
                {
                    visualWindow.Width = visualWindow.Height = 400;
                    visualWindow.VSync = VSyncMode.On;
                };
                visualWindow.Resize += (s, args) =>
                {
                    GL.Viewport(0, 0, visualWindow.Width, visualWindow.Height);
                };
                visualWindow.UpdateFrame += (s, args) =>
                {
                    var keyboardState = OpenTK.Input.Keyboard.GetState();

                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.Escape))
                    {
                        visualWindow.Exit();
                    }

                    GL.MatrixMode(MatrixMode.Modelview);

                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.Up) || keyboardState.IsKeyDown(OpenTK.Input.Key.W))
                    {
                        ySpeed = baseSpeed + ySpeed * (ySpeed > 0 ? speedUp : 0);
                    }
                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.Down) || keyboardState.IsKeyDown(OpenTK.Input.Key.S))
                    {
                        ySpeed = -baseSpeed + ySpeed * (ySpeed < 0 ? speedUp : 0);
                    }
                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.Left) || keyboardState.IsKeyDown(OpenTK.Input.Key.A))
                    {
                        xSpeed = -baseSpeed + xSpeed * (xSpeed < 0 ? speedUp : 0);
                    }
                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.Right) || keyboardState.IsKeyDown(OpenTK.Input.Key.D))
                    {
                        xSpeed = baseSpeed + xSpeed * (xSpeed > 0 ? speedUp : 0);
                    }

                    // Max speed controll
                    xSpeed = Math.Abs(xSpeed) < maxSpeed ? xSpeed : maxSpeed * (xSpeed < 0 ? -1 : 1);
                    ySpeed = Math.Abs(ySpeed) < maxSpeed ? ySpeed : maxSpeed * (ySpeed < 0 ? -1 : 1);

                    // Small speed aprox to 0
                    if (Math.Abs(xSpeed) < 1)
                    {
                        xSpeed = 0;
                    }
                    if (Math.Abs(ySpeed) < 1)
                    {
                        ySpeed = 0;
                    }

                    // Auto slow speed
                    xSpeed *= slowness;
                    ySpeed *= slowness;

                    xOffset += xSpeed;
                    yOffset += ySpeed;
                };
                visualWindow.RenderFrame += (s, args) =>
                {
                    float left  = -1000,
                          right = 1000,
                          down  = -1000,
                          up    = 1000;

                    GL.ClearColor(255, 255, 255, 255);
                    GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                    GL.MatrixMode(MatrixMode.Projection);
                    GL.LoadIdentity();
                    GL.Ortho(left, right, down, up, 0, 100);


                    GL.Begin(BeginMode.Lines);
                    GL.Vertex2(left, 0);
                    GL.Vertex2(right, 0);
                    GL.Vertex2(0, up);
                    GL.Vertex2(0, down);
                    GL.End();

                    GL.PushMatrix();
                    GL.Translate(xOffset, yOffset, 0);

                    GL.Begin(BeginMode.Quads);

                    GL.Color3(1.0, 1.0, 1.0);
                    GL.Vertex2(250, 450);
                    GL.Color3(0.0, 0.0, 1.0);
                    GL.Vertex2(250, 150);
                    GL.Color3(0.0, 1.0, 0.0);
                    GL.Vertex2(550, 150);
                    GL.Color3(1.0, 0.0, 0.0);
                    GL.Vertex2(550, 450);

                    GL.End();

                    GL.PopMatrix();

                    visualWindow.SwapBuffers();
                };

                visualWindow.Run(60.0);
            }
        }
        private void Task1Btn_Click(object sender, RoutedEventArgs e)
        {
            double xOffset = 0, yOffset = 0, zOffset = 0,
                   scale = 1, xRotate = 0, yRotate = 0, zRotate = 0;
            bool perspectiveMode = false;
            int  teaPotMode      = 1;

            using (var visualWindow = new VisualWindow())
            {
                visualWindow.Load += (s, args) =>
                {
                    visualWindow.Width = visualWindow.Height = 400;
                    visualWindow.VSync = VSyncMode.On;
                };
                visualWindow.Resize += (s, args) =>
                {
                    GL.Viewport(0, 0, visualWindow.Width, visualWindow.Height);
                };
                visualWindow.UpdateFrame += (s, args) =>
                {
                    var keyboardState = OpenTK.Input.Keyboard.GetState();

                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.Escape))
                    {
                        visualWindow.Exit();
                    }


                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.Up))
                    {
                        yOffset += 10;
                    }
                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.Down))
                    {
                        yOffset -= 10;
                    }
                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.Right))
                    {
                        xOffset += 10;
                    }
                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.Left))
                    {
                        xOffset -= 10;
                    }

                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.Plus))
                    {
                        scale += 0.1;
                    }
                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.Minus))
                    {
                        scale -= 0.1;
                    }


                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.Home))
                    {
                        xRotate -= 5;
                    }
                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.End))
                    {
                        yRotate -= 5;
                    }
                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.Delete))
                    {
                        zRotate -= 5;
                    }


                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.PageUp))
                    {
                        xRotate += 5;
                        yRotate += 5;
                        zRotate += 5;
                    }
                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.PageDown))
                    {
                        xRotate -= 5;
                        yRotate -= 5;
                        zRotate -= 5;
                    }


                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.P))
                    {
                        perspectiveMode = true;
                    }
                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.O))
                    {
                        perspectiveMode = false;
                    }

                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.F1))
                    {
                        teaPotMode = 1;
                    }
                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.F2))
                    {
                        teaPotMode = 2;
                    }
                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.F3))
                    {
                        teaPotMode = 3;
                    }
                };
                visualWindow.RenderFrame += (s, args) =>
                {
                    float left    = -1000,
                          right   = 1000,
                          down    = -1000,
                          up      = 1000,
                          forward = -1000,
                          back    = 1000;

                    float width  = right - left,
                          height = up - down,
                          depth  = back - forward;

                    GL.ClearColor(255, 255, 255, 255);
                    GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                    GL.MatrixMode(MatrixMode.Projection);
                    GL.LoadIdentity();

                    if (perspectiveMode)
                    {
                        // GLU Perspective
                        Matrix4 perspectiveMatrix = Matrix4.CreatePerspectiveFieldOfView(
                            MathHelper.PiOver2,
                            width / height,
                            0.1f,
                            depth);
                        GL.LoadMatrix(ref perspectiveMatrix);
                        // GLU Look at
                        GL.Translate(0, 0, forward);
                    }
                    else
                    {
                        GL.Ortho(left, right, down, up, forward, back);
                    }

                    // Draw Axis
                    GL.Color3(255d, 0d, 0d);
                    GL.Begin(BeginMode.Lines);
                    GL.Vertex3(left, 0, 0);
                    GL.Vertex3(right, 0, 0);
                    GL.Vertex3(0, up, 0);
                    GL.Vertex3(0, down, 0);
                    GL.Vertex3(0, 0, forward);
                    GL.Vertex3(0, 0, back);
                    GL.End();

                    // Translations
                    GL.Translate(xOffset, yOffset, zOffset);
                    GL.Scale(scale, scale, scale);
                    GL.Rotate(xRotate, 1, 0, 0);
                    GL.Rotate(yRotate, 0, 1, 0);
                    GL.Rotate(zRotate, 0, 0, 1);


                    // Drawing
                    GL.Color3(0d, 0d, 0d);
                    switch (teaPotMode)
                    {
                    case 1:
                        Teapot.DrawWireTeapot(500);
                        break;

                    case 2:
                        Teapot.DrawSolidTeapot(500);
                        break;

                    case 3:
                        Teapot.DrawPointTeapot(500);
                        break;
                    }

                    visualWindow.SwapBuffers();
                };

                visualWindow.Run(60.0);
            }
        }
        public void Start(string path = "")
        {
            // Configuration
            double xOffset = 0, yOffset = 0, zOffset = 0,
                   xRotate = 0, yRotate = 0, zRotate = 0,
                   scale = 1,
                   moveSpeed = 3, rotateSpeed = 3, scaleSpeed = 0.05;
            bool perspectiveMode = false, drawAxis = false;

            _drawPolygon = false;

            // Visual window init
            _visualWindow       = new VisualWindow();
            _visualWindow.Load += (s, args) =>
            {
                _visualWindow.Width = _visualWindow.Height = 400;
                _visualWindow.VSync = VSyncMode.On;

                if (string.IsNullOrEmpty(path))
                {
                    LoadDefaultScene();
                }
                else
                {
                    LoadFile(path);
                }
            };
            _visualWindow.Resize += (s, args) =>
            {
                GL.Viewport(0, 0, _visualWindow.Width, _visualWindow.Height);
            };
            _visualWindow.FileDrop += (s, args) =>
            {
                LoadFile(args.FileName);
            };
            _visualWindow.UpdateFrame += (s, args) =>
            {
                var keyboardState = Keyboard.GetState();

                if (keyboardState.IsKeyDown(Key.Escape))
                {
                    _visualWindow.Exit();
                }


                if (keyboardState.IsKeyDown(Key.Up))
                {
                    yOffset += moveSpeed;
                }
                if (keyboardState.IsKeyDown(Key.Down))
                {
                    yOffset -= moveSpeed;
                }
                if (keyboardState.IsKeyDown(Key.Right))
                {
                    xOffset += moveSpeed;
                }
                if (keyboardState.IsKeyDown(Key.Left))
                {
                    xOffset -= moveSpeed;
                }

                if (keyboardState.IsKeyDown(Key.Plus))
                {
                    scale += scaleSpeed;
                }
                if (keyboardState.IsKeyDown(Key.Minus))
                {
                    scale -= scaleSpeed;
                }

                if (keyboardState.IsKeyDown(Key.Home))
                {
                    xRotate -= rotateSpeed;
                }
                if (keyboardState.IsKeyDown(Key.End))
                {
                    yRotate -= rotateSpeed;
                }
                if (keyboardState.IsKeyDown(Key.Delete))
                {
                    zRotate -= rotateSpeed;
                }


                if (keyboardState.IsKeyDown(Key.PageUp))
                {
                    xRotate += rotateSpeed;
                    yRotate += rotateSpeed;
                    zRotate += rotateSpeed;
                }
                if (keyboardState.IsKeyDown(Key.PageDown))
                {
                    xRotate -= rotateSpeed;
                    yRotate -= rotateSpeed;
                    zRotate -= rotateSpeed;
                }

                if (keyboardState.IsKeyDown(Key.BackSpace))
                {
                    xOffset = 0; yOffset = 0; zOffset = 0;
                    xRotate = 0; yRotate = 0; zRotate = 0;
                    scale   = 1;
                }

                if (keyboardState.IsKeyDown(Key.P))
                {
                    perspectiveMode = true;
                }
                if (keyboardState.IsKeyDown(Key.O))
                {
                    perspectiveMode = false;
                }
                if (keyboardState.IsKeyDown(Key.Z))
                {
                    drawAxis = true;
                }
                if (keyboardState.IsKeyDown(Key.Z) && keyboardState.IsKeyDown(Key.ShiftLeft))
                {
                    drawAxis = false;
                }
                if (keyboardState.IsKeyDown(Key.L))
                {
                    _drawPolygon = true;
                }
                if (keyboardState.IsKeyDown(Key.L) && keyboardState.IsKeyDown(Key.ShiftLeft))
                {
                    _drawPolygon = false;
                }
            };
            _visualWindow.RenderFrame += (s, args) =>
            {
                float width  = _loadedScene.WorldRight - _loadedScene.WorldLeft,
                      height = _loadedScene.WorldTop - _loadedScene.WorldBottom,
                      depth  = _loadedScene.WorldForward - _loadedScene.WorldBack;

                float halfX = (_loadedScene.WorldRight + _loadedScene.WorldLeft) / 2,
                      halfY = (_loadedScene.WorldTop + _loadedScene.WorldBottom) / 2,
                      halfZ = (_loadedScene.WorldBack + _loadedScene.WorldForward) / 2;


                GL.ClearColor(255, 255, 255, 255);
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                GL.MatrixMode(MatrixMode.Projection);
                GL.LoadIdentity();

                if (perspectiveMode)
                {
                    // GLU Perspective
                    Matrix4 perspectiveMatrix = Matrix4.CreatePerspectiveFieldOfView(
                        MathHelper.DegreesToRadians(90),
                        width / height,
                        0.1f,
                        depth * 2);
                    GL.LoadMatrix(ref perspectiveMatrix);
                    // Look at
                    GL.Translate(-halfX, -halfY, -halfZ);
                }
                else
                {
                    GL.Ortho(_loadedScene.WorldLeft, _loadedScene.WorldRight,
                             _loadedScene.WorldBottom, _loadedScene.WorldTop,
                             _loadedScene.WorldForward, _loadedScene.WorldBack);
                }
                GL.Translate(0, 0, -depth);


                // Draw Axis
                if (drawAxis)
                {
                    GL.Color3(0f, 255f, 0f);
                    GL.Begin(BeginMode.Lines);
                    GL.Vertex3(-width, halfY, halfZ);
                    GL.Vertex3(width * 2, halfY, halfZ);
                    GL.Vertex3(halfX, -height, halfZ);
                    GL.Vertex3(halfX, height * 2, halfZ);
                    GL.Vertex3(halfX, halfY, -depth);
                    GL.Vertex3(halfX, halfY, depth);
                    GL.End();
                }

                // Translations
                GL.Translate(xOffset, yOffset, zOffset);
                GL.Translate(halfX, halfY, halfZ);
                GL.Rotate(xRotate, 1, 0, 0);
                GL.Rotate(yRotate, 0, 1, 0);
                GL.Rotate(zRotate, 0, 0, 1);
                GL.Scale(scale, scale, scale);
                GL.Translate(-halfX, -halfY, -halfZ);

                // Draw
                GL.Color3(255f, 0, 0);
                foreach (Parallelepiped parallelepiped in _loadedScene.Parallelepipeds)
                {
                    DrawParallelepiped(parallelepiped.FirstCoordinates, parallelepiped.SecondCoordinates);
                }


                _visualWindow.SwapBuffers();
            };

            _visualWindow.Run(60.0);
        }
Esempio n. 34
0
        static void Main(string[] args)
        {
            Game.ClientSize = new Size(1280, 720);

            //load textures
            TextureManager.LoadTexture("face", "./Assets/face.tif");
            TextureManager.LoadTexture("face_alpha", "./Assets/face_alpha.tif");

            //create state system
            System.AddState("splash", new SplashScreenState(System));
            System.AddState("title_menu", new TitleScreenState());
            System.AddState("sprite_test", new DrawSpriteState(TextureManager));
            System.AddState("test_sprite_class", new TestSpriteClassState(TextureManager));

            //set init state
            System.ChangeState("test_sprite_class");

            //set up events
            Game.Load += (sender, e) =>
            {
                Game.VSync = VSyncMode.On;
            };
            Setup2D(Game.Width, Game.Height);

            Game.Resize += (sender, e) =>
            {
                GL.Viewport(0, 0, Game.Width, Game.Height);
                Setup2D(Game.Width, Game.Height);
            };

            Game.UpdateFrame += (sender, e) =>
            {
                // add game logic, input handling
                if (Game.Keyboard[Key.Escape])
                {
                    Game.Exit();
                }
                if (Game.Keyboard[Key.AltRight] && Game.Keyboard[Key.Enter])
                {
                    if (Game.WindowState == WindowState.Normal)
                    {
                        Game.WindowState = WindowState.Fullscreen;
                    }
                    else
                    {
                        Game.WindowState = WindowState.Normal;
                    }
                }

                System.Update(e.Time);
            };

            Game.RenderFrame += (sender, e) =>
            {
                System.Render();
                Game.SwapBuffers();
            };

            // Run the game at 60 updates per second
            Game.Run(60.0);
            Game.Dispose();
        }
        private void Task3Btn_Click(object sender, RoutedEventArgs e)
        {
            using (var visualWindow = new VisualWindow())
            {
                visualWindow.Load += (s, args) =>
                {
                    visualWindow.VSync = VSyncMode.On;
                };
                visualWindow.Resize += (s, args) =>
                {
                    GL.Viewport(0, 0, visualWindow.Width, visualWindow.Height);
                };
                visualWindow.UpdateFrame += (s, args) =>
                {
                };
                visualWindow.RenderFrame += (s, args) =>
                {
                    float left  = 0,
                          right = 300,
                          down  = 0,
                          up    = 100;


                    GL.ClearColor(255, 255, 255, 255);
                    GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                    GL.MatrixMode(MatrixMode.Projection);
                    GL.LoadIdentity();
                    GL.Ortho(left, right, down, up, 0, 100);

                    // T
                    GL.Begin(PrimitiveType.LineLoop);

                    GL.Color3(Color.DarkBlue);
                    GL.Vertex2(10, 80);
                    GL.Vertex2(90, 80);
                    GL.Vertex2(90, 70);
                    GL.Vertex2(55, 70);
                    GL.Vertex2(55, 20);
                    GL.Vertex2(45, 20);
                    GL.Vertex2(45, 70);
                    GL.Vertex2(10, 70);

                    GL.End();

                    // S
                    GL.Begin(PrimitiveType.LineLoop);

                    GL.Color3(Color.DarkBlue);
                    GL.Vertex2(190, 80);
                    GL.Vertex2(110, 80);
                    GL.Vertex2(110, 45);
                    GL.Vertex2(180, 45);
                    GL.Vertex2(180, 30);
                    GL.Vertex2(110, 30);
                    GL.Vertex2(110, 20);
                    GL.Vertex2(190, 20);
                    GL.Vertex2(190, 55);
                    GL.Vertex2(120, 55);
                    GL.Vertex2(120, 70);
                    GL.Vertex2(190, 70);

                    GL.End();

                    // I
                    GL.Begin(PrimitiveType.LineLoop);

                    GL.Color3(Color.DarkBlue);
                    GL.Vertex2(235, 80);
                    GL.Vertex2(265, 80);
                    GL.Vertex2(265, 70);
                    GL.Vertex2(255, 70);
                    GL.Vertex2(255, 30);
                    GL.Vertex2(265, 30);
                    GL.Vertex2(265, 20);
                    GL.Vertex2(235, 20);
                    GL.Vertex2(235, 30);
                    GL.Vertex2(245, 30);
                    GL.Vertex2(245, 70);
                    GL.Vertex2(235, 70);

                    GL.End();

                    visualWindow.SwapBuffers();
                };

                visualWindow.Run(60.0);
            }
        }
        private void Task4Btn_Click(object sender, RoutedEventArgs e)
        {
            using (var visualWindow = new VisualWindow())
            {
                visualWindow.Load += (s, args) =>
                {
                    visualWindow.Width  = 600;
                    visualWindow.Height = 200;
                    visualWindow.VSync  = VSyncMode.On;
                };
                visualWindow.Resize += (s, args) =>
                {
                    GL.Viewport(0, 0, visualWindow.Width, visualWindow.Height);
                };
                visualWindow.UpdateFrame += (s, args) =>
                {
                };
                visualWindow.RenderFrame += (s, args) =>
                {
                    float left  = 0,
                          right = 300,
                          down  = 0,
                          up    = 100;

                    GL.ClearColor(255, 255, 255, 255);
                    GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                    GL.MatrixMode(MatrixMode.Projection);
                    GL.LoadIdentity();
                    GL.Ortho(left, right, down, up, 0, 100);

                    // T
                    DrawSplines(new List <Point>()
                    {
                        new Point(20, 70),
                        new Point(18, 70),
                        new Point(10, 75),
                        new Point(10, 85),
                        new Point(18, 90),
                        new Point(20, 90)
                    });
                    DrawLine(20, 90, 80, 90);
                    DrawSplines(new List <Point>()
                    {
                        new Point(80, 70),
                        new Point(82, 70),
                        new Point(90, 75),
                        new Point(90, 85),
                        new Point(82, 90),
                        new Point(80, 90)
                    });
                    DrawLine(20, 70, 40, 70);
                    DrawLine(60, 70, 80, 70);
                    DrawLine(40, 70, 40, 20);
                    DrawLine(60, 70, 60, 20);
                    DrawSplines(new List <Point>()
                    {
                        new Point(40, 20),
                        new Point(40, 18),
                        new Point(45, 10),
                        new Point(55, 10),
                        new Point(60, 18),
                        new Point(60, 20)
                    });

                    // S
                    DrawSplines(new List <Point>()
                    {
                        new Point(180, 90),
                        new Point(182, 90),
                        new Point(190, 85),
                        new Point(190, 75),
                        new Point(182, 70),
                        new Point(180, 70)
                    });
                    DrawLine(180, 70, 140, 70);
                    DrawLine(180, 90, 140, 90);
                    DrawSplines(new List <Point>()
                    {
                        new Point(140, 70),
                        new Point(138, 70),
                        new Point(130, 67),
                        new Point(130, 63),
                        new Point(138, 60),
                        new Point(140, 60),
                    });
                    DrawSplines(new List <Point>()
                    {
                        new Point(140, 90),
                        new Point(138, 90),
                        new Point(120, 85),
                        new Point(110, 70),
                        new Point(110, 60),
                        new Point(120, 45),
                        new Point(138, 40),
                        new Point(140, 40),
                    });
                    DrawLine(140, 40, 160, 40);
                    DrawLine(140, 60, 160, 60);
                    DrawSplines(new List <Point>()
                    {
                        new Point(120, 10),
                        new Point(118, 10),
                        new Point(110, 15),
                        new Point(110, 25),
                        new Point(118, 30),
                        new Point(120, 30)
                    });
                    DrawLine(120, 10, 160, 10);
                    DrawLine(120, 30, 160, 30);
                    DrawSplines(new List <Point>()
                    {
                        new Point(160, 30),
                        new Point(162, 30),
                        new Point(170, 33),
                        new Point(170, 37),
                        new Point(162, 40),
                        new Point(160, 40)
                    });
                    DrawSplines(new List <Point>()
                    {
                        new Point(160, 10),
                        new Point(162, 10),
                        new Point(180, 15),
                        new Point(190, 30),
                        new Point(190, 40),
                        new Point(180, 55),
                        new Point(162, 60),
                        new Point(160, 60),
                    });

                    // I
                    DrawSplines(new List <Point>()
                    {
                        new Point(220, 70),
                        new Point(218, 70),
                        new Point(210, 75),
                        new Point(210, 85),
                        new Point(218, 90),
                        new Point(220, 90)
                    });
                    DrawLine(220, 90, 280, 90);
                    DrawSplines(new List <Point>()
                    {
                        new Point(280, 70),
                        new Point(282, 70),
                        new Point(290, 75),
                        new Point(290, 85),
                        new Point(282, 90),
                        new Point(280, 90)
                    });
                    DrawLine(260, 70, 280, 70);
                    DrawLine(220, 70, 240, 70);

                    DrawLine(240, 70, 240, 30);
                    DrawLine(260, 70, 260, 30);

                    DrawLine(260, 30, 280, 30);
                    DrawLine(220, 30, 240, 30);

                    DrawSplines(new List <Point>()
                    {
                        new Point(220, 30),
                        new Point(218, 30),
                        new Point(210, 25),
                        new Point(210, 15),
                        new Point(218, 10),
                        new Point(220, 10)
                    });
                    DrawLine(220, 10, 280, 10);
                    DrawSplines(new List <Point>()
                    {
                        new Point(280, 30),
                        new Point(282, 30),
                        new Point(290, 25),
                        new Point(290, 15),
                        new Point(282, 10),
                        new Point(280, 10)
                    });

                    visualWindow.SwapBuffers();
                };

                visualWindow.Run(60.0);
            }
        }
Esempio n. 37
0
 internal void Run(double updateRate)
 {
     window.Run(updateRate);
 }
Esempio n. 38
0
        private void Task2Btn_Click(object sender, RoutedEventArgs e)
        {
            using (var visualWindow = new VisualWindow())
            {
                double angle = 0, selfAngle = 0, xOffset = 0, yOffset = 0, scale = 1;
                visualWindow.Load += (s, args) =>
                {
                    visualWindow.Width  = 600;
                    visualWindow.Height = 200;
                    visualWindow.VSync  = VSyncMode.On;
                };
                visualWindow.Resize += (s, args) =>
                {
                    GL.Viewport(0, 0, visualWindow.Width, visualWindow.Height);
                };
                visualWindow.UpdateFrame += (s, args) =>
                {
                    var keyboardState = OpenTK.Input.Keyboard.GetState();

                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.Escape))
                    {
                        visualWindow.Exit();
                    }

                    GL.MatrixMode(MatrixMode.Modelview);

                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.Up))
                    {
                        yOffset += 10;
                    }
                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.Down))
                    {
                        yOffset -= 10;
                    }
                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.Left))
                    {
                        xOffset -= 10;
                    }
                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.Right))
                    {
                        xOffset += 10;
                    }

                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.Plus))
                    {
                        scale += 0.1;
                    }
                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.Minus))
                    {
                        scale -= 0.1;
                    }

                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.Home))
                    {
                        angle += 5;
                    }
                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.End))
                    {
                        angle -= 5;
                    }

                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.Q))
                    {
                        selfAngle += 3;
                    }

                    if (keyboardState.IsKeyDown(OpenTK.Input.Key.E))
                    {
                        selfAngle -= 3;
                    }
                };
                visualWindow.RenderFrame += (s, args) =>
                {
                    float left  = 0,
                          right = 300,
                          down  = 0,
                          up    = 100;

                    GL.ClearColor(255, 255, 255, 255);
                    GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                    GL.MatrixMode(MatrixMode.Projection);
                    GL.LoadIdentity();
                    GL.Ortho(left, right, down, up, 0, 100);

                    // Translations
                    GL.Translate(xOffset, yOffset, 0);
                    GL.Translate(150, 50, 0);
                    GL.Scale(scale, scale, 0);
                    GL.Rotate(angle, 0, 0, 1);
                    GL.Translate(-150, -50, 0);


                    GL.Color3(255.0, 0, 0);

                    // T
                    GL.PushMatrix();
                    GL.Translate(50, 50, 0);
                    GL.Rotate(selfAngle, 0, 0, 1);
                    GL.Translate(-50, -50, 0);

                    GL.Begin(BeginMode.LineLoop);
                    GL.Vertex2(10, 80);
                    GL.Vertex2(90, 80);
                    GL.Vertex2(90, 70);
                    GL.Vertex2(55, 70);
                    GL.Vertex2(55, 20);
                    GL.Vertex2(45, 20);
                    GL.Vertex2(45, 70);
                    GL.Vertex2(10, 70);
                    GL.End();

                    GL.PopMatrix();


                    // S
                    GL.PushMatrix();
                    GL.Translate(150, 50, 0);
                    GL.Rotate(-selfAngle, 0, 0, 1);
                    GL.Translate(-150, -50, 0);

                    GL.Begin(BeginMode.LineLoop);
                    GL.Vertex2(190, 80);
                    GL.Vertex2(110, 80);
                    GL.Vertex2(110, 45);
                    GL.Vertex2(180, 45);
                    GL.Vertex2(180, 30);
                    GL.Vertex2(110, 30);
                    GL.Vertex2(110, 20);
                    GL.Vertex2(190, 20);
                    GL.Vertex2(190, 55);
                    GL.Vertex2(120, 55);
                    GL.Vertex2(120, 70);
                    GL.Vertex2(190, 70);
                    GL.End();

                    GL.PopMatrix();

                    // I
                    GL.PushMatrix();
                    GL.Translate(250, 50, 0);
                    GL.Rotate(selfAngle, 0, 0, 1);
                    GL.Translate(-250, -50, 0);

                    GL.Begin(BeginMode.LineLoop);
                    GL.Vertex2(265, 80);
                    GL.Vertex2(265, 70);
                    GL.Vertex2(255, 70);
                    GL.Vertex2(255, 30);
                    GL.Vertex2(265, 30);
                    GL.Vertex2(265, 20);
                    GL.Vertex2(235, 20);
                    GL.Vertex2(235, 30);
                    GL.Vertex2(245, 30);
                    GL.Vertex2(245, 70);
                    GL.Vertex2(235, 70);
                    GL.Vertex2(235, 80);
                    GL.End();

                    GL.PopMatrix();

                    visualWindow.SwapBuffers();
                };

                visualWindow.Run(60.0);
            }
        }