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


C# OpenTK.GameWindow类代码示例

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


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

示例1: Main

        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
        }
开发者ID:Mszauer,项目名称:TileBasedGames,代码行数:31,代码来源:Program.cs

示例2: HandleInput

        public override bool HandleInput(GameWindow window)
        {
            m_Initialized = window.Mouse[MouseButton.Left];

            var mousepos = 2 * new Vector2 (window.Mouse.X, window.Mouse.Y);
            mousepos.Y = -mousepos.Y;

            if (!m_Initialized)
            {
                m_OldMousePos = mousepos;
                return false;
            }

            var deltaPos = mousepos - m_OldMousePos;
            var deltaAngles = deltaPos / 400;

            var temp = Position;
            temp.Normalize();
            temp = Vector3.Cross(temp, Vector3.UnitZ);
            temp.Normalize();

            var rotationH = Quaternion.FromAxisAngle (temp, deltaAngles.Y);
            var rotationV = Quaternion.FromAxisAngle (Vector3.UnitZ, deltaAngles.X);
            Position = Vector3.Transform(Position, Matrix4.Rotate(rotationH) * Matrix4.Rotate(rotationV));

            RTstack.ValueStack[0] = Matrix4.LookAt (Position, Target, UpDirection);

            m_OldMousePos = mousepos;
            return true;
        }
开发者ID:smalld,项目名称:particle_system,代码行数:30,代码来源:OrbitManipulator.cs

示例3: 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

示例4: MouseTrackBall

        public MouseTrackBall(GameWindow gm)
        {
            gm.Mouse.WheelChanged += (s,e) =>{

                distance+=e.Delta*zSpeed;
            };

            gm.Mouse.ButtonDown += (s, e) => {
                if(e.Button != OpenTK.Input.MouseButton.Middle && e.Button != OpenTK.Input.MouseButton.Right)
                    return;
                isDown = true;
                lastX = e.X;
                lastY = e.Y;
            //	Console.WriteLine(string.Format("Mouse Left Click on ({0},{1}):",lastX,lastY));
            };

            gm.Mouse.ButtonUp += (s, e) => {
                if(e.Button != OpenTK.Input.MouseButton.Middle && e.Button != OpenTK.Input.MouseButton.Right)
                return;
                isDown = false;
            };

            gm.Mouse.Move += (s,e) => {
                if(!isDown) return;
                move(e);
            //	gm.SwapBuffers();
            };
        }
开发者ID:paolo-slepoi,项目名称:OpenGLTkVerletDemo,代码行数:28,代码来源:MouseTrackBall.cs

示例5: Run

        public void Run()
        {
            _gameWindow = new GameWindow(1280, 720);

            try
            {
                _gameWindow.Title = "CubeHack";
                _gameWindow.VSync = VSyncMode.On;

                /* This sequence seems necessary to bring the window to the front reliably. */
                _gameWindow.WindowState = WindowState.Maximized;
                _gameWindow.WindowState = WindowState.Minimized;
                _gameWindow.Visible = true;
                _gameWindow.WindowState = WindowState.Maximized;

                _gameWindow.KeyDown += OnKeyDown;
                _gameWindow.KeyPress += OnKeyPress;
                _gameWindow.KeyUp += OnKeyUp;

                _gameLoop.RenderFrame += RenderFrame;
                try
                {
                    _gameLoop.Run(_gameWindow);
                }
                finally
                {
                    _gameLoop.RenderFrame -= RenderFrame;
                }
            }
            finally
            {
                _gameWindow.Dispose();
                _gameWindow = null;
            }
        }
开发者ID:AndiAngerer,项目名称:cubehack,代码行数:35,代码来源:GameApp.cs

示例6: Camera

        public Camera(GameWindow window, Vector3 position, Vector3 up)
        {
            Window = window;
            Position = position;
            Up = up;

            MouseDelta = new Point();

            Window.Resize += (sender, e) =>
            {
                Cursor.Position = ScreenCenter;
                Cursor.Hide();

                GL.Viewport(Window.ClientRectangle.X, Window.ClientRectangle.Y, Window.ClientRectangle.Width, Window.ClientRectangle.Height);

                Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 4, Window.Width / (float)Window.Height, 1f, Fog);
                GL.MatrixMode(MatrixMode.Projection);
                GL.LoadMatrix(ref projection);
            };

            Window.UpdateFrame += (sender, e) =>
            {
                MouseDelta = new Point(Window.Mouse.X - WindowCenter.X, Window.Mouse.Y - WindowCenter.Y);
                Point p = Cursor.Position;
                p.X -= MouseDelta.X;
                p.Y -= MouseDelta.Y;
                Cursor.Position = p;
                Facing += MouseDelta.X / (1000 - (float)(HorizontalSensitivity * 100));
                Pitch -= MouseDelta.Y / (1000 - (float)(VerticalSensitivity * 100));
                if (Pitch < -1.5f) Pitch = -1.5f;
                if (Pitch > 1.5f) Pitch = 1.5f;
                Vector3 lookatPoint = new Vector3((float)Math.Cos(Facing), (float)Math.Tan(Pitch), (float)Math.Sin(Facing));
                CameraMatrix = Matrix4.LookAt(Position, Position + lookatPoint, Up);
            };
        }
开发者ID:jonnyli1125,项目名称:FirstPerson,代码行数:35,代码来源:Camera.cs

示例7: WhenRendered

        public static Reaction<Reaction<FrameEventArgs>> WhenRendered(this Reaction<FrameEventArgs> reaction, 
			GameWindow window)
        {
            return reaction.ToEvent<FrameEventArgs> (
                handler => window.RenderFrame += handler,
                handler => window.RenderFrame -= handler);
        }
开发者ID:johtela,项目名称:Compose3D,代码行数:7,代码来源:WindowReactions.cs

示例8: Game

        public Game()
        {
            state = new BootState(this);

            window = new GameWindow(960, 540);
            window.Load += Window_Load;
            window.RenderFrame += Window_RenderFrame;
            window.UpdateFrame += Window_UpdateFrame;
            window.Closing += Window_Closing;
            window.Closed += Window_Closed;
            window.Resize += Window_Resize;
            window.FocusedChanged += Window_FocusedChanged;

            Console.WriteLine("OpenGL: {0}", GL.GetString(StringName.Version));

            keyHandler = new KeyHandler(window);

            Canvas = new SceneCanvas(keyHandler);
            shaderManager = new ShaderManager();

            shader = new StaticShader();
            shaderManager.Add(shader);

            fontShader = new FontShader();

            fontManager = new FontManager(fontShader);
            fontShader.Compile();
            font = FontParser.ParseFNT(@"Fonts/Verdana.fnt");
            fontManager.Add(font);

            lastMousePosition = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
        }
开发者ID:KodoRyu,项目名称:gameplayground,代码行数:32,代码来源:Game.cs

示例9: Initialize

        public static void Initialize(GameWindow gameWindow)
        {
            window = gameWindow;
            keysPressedLast = new List<Key>();
            keysPressed = new List<Key>();
            mousePressedLast = new List<MouseButton>();
            mousePressed = new List<MouseButton>();
            window.Keyboard.KeyDown += Keyboard_KeyDown;
            window.Keyboard.KeyUp += Keyboard_KeyUp;
            window.Mouse.ButtonDown += Mouse_ButtonDown;
            window.Mouse.ButtonUp += Mouse_ButtonUp;

            #region Create dot texture
            {
                int id = GL.GenTexture();
                GL.BindTexture(TextureTarget.Texture2D, id);

                Bitmap bmp = new Bitmap(1, 1);
                bmp.SetPixel(0, 0, Color.White);
                BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, 1, 1), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba,
                    1, 1, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra,
                    PixelType.UnsignedByte, bmpData.Scan0);

                dot = new Texture2D("dot", id, 1, 1);

                bmp.UnlockBits(bmpData);

                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMinFilter.Linear);
            }
            #endregion
        }
开发者ID:siltutorials,项目名称:TKPlatformer,代码行数:34,代码来源:My.cs

示例10: Enable

 public void Enable(GameWindow window)
 {
     if (Behavior == null) throw new InvalidOperationException("Can not enable Camera while the Behavior is not set.");
     window.UpdateFrame += UpdateFrame;
     window.Mouse.Move += MouseMove;
     window.Mouse.WheelChanged += MouseWheelChanged;
 }
开发者ID:olegbom,项目名称:ObjectTK,代码行数:7,代码来源:Camera.cs

示例11: OpenGLInputObservable

        public OpenGLInputObservable(GameWindow window)
        {
            gameWindow = window;

            IObservable<IInput> downEvents =
                from evt in Observable.FromEventPattern<KeyboardKeyEventArgs>(window, "KeyDown")
                let keyInput = GLKeyInput.FromArgs(evt.EventArgs, false)
                where keyInput != null
                select keyInput;

            IObservable<IInput> upEvents =
                from evt in Observable.FromEventPattern<KeyboardKeyEventArgs>(window, "KeyUp")
                let keyInput = GLKeyInput.FromArgs(evt.EventArgs, true)
                where keyInput != null
                select keyInput;

            IObservable<IInput> mouseMoveEvents =
                from evt in Observable.FromEventPattern<MouseMoveEventArgs>(window, "MouseMove")
                from mouseInput in GLMouseInput.FromArgs(evt.EventArgs, gameWindow.Width, gameWindow.Height)
                select mouseInput;

            IObservable<IInput> mouseDownEvents =
                from evt in Observable.FromEventPattern<MouseButtonEventArgs>(window, "MouseDown")
                select GLMouseClickInput.FromArgs(evt.EventArgs, false);

            IObservable<IInput> mouseUpEvents =
                from evt in Observable.FromEventPattern<MouseButtonEventArgs>(window, "MouseUp")
                select GLMouseClickInput.FromArgs(evt.EventArgs, true);

            InputEvents = downEvents.Merge(upEvents).Merge(mouseMoveEvents).Merge(mouseDownEvents).Merge(mouseUpEvents);

            window.MouseMove += (sender, e) => Cursor.Position = new Point(window.Width / 2, window.Height / 2); // keep mouse centered (bc fps)
        }
开发者ID:domisterwoozy,项目名称:LabBox,代码行数:33,代码来源:OpenGLInputObservable.cs

示例12: Render

 public override void Render(GameWindow window)
 {
     foreach (var item in m_Passes)
     {
         item.Render(window);
     }
 }
开发者ID:smalld,项目名称:particle_system,代码行数:7,代码来源:RenderPass.cs

示例13: Think

        /// <summary>
        /// Update input, including getting mouse deltas/etc.
        /// </summary>
        public static void Think(GameWindow window, FrameEventArgs e)
        {
            current = Mouse.GetState();

            window.CursorVisible = !LockMouse;

            if (current != previous && window.Focused)
            {
                // Mouse state has changed
                deltaX = current.X - previous.X;
                deltaY = current.Y - previous.Y;
                deltaZ = current.Wheel - previous.Wheel;

                if (LockMouse)
                {
                    Mouse.SetPosition(window.X + window.Width / 2, window.Y + window.Height / 2);
                }
            }
            else
            {
                deltaX = 0;
                deltaY = 0;
                deltaZ = 0;
            }
            previous = current;
        }
开发者ID:Foohy,项目名称:OlegEngine,代码行数:29,代码来源:Input.cs

示例14: Render

        public byte[] Render(IEnumerable<FeatureCollection> featureCollections)
        {
            lock (_syncRoot)
            {
                // There needs to be a gamewindow even though we don't write to screen. It is created but not used explicitly in our code.
                using (var gameWindow = new GameWindow(_pixelWidth, _pixelHeight))
                {
                    if (!GL.GetString(StringName.Extensions).Contains("GL_EXT_framebuffer_object"))
                    {
                        throw new NotSupportedException(
                            "GL_EXT_framebuffer_object extension is required. Please update your drivers.");
                    }

                    FrameBufferObjectHelper.StartFrameBufferObject(_pixelWidth, _pixelHeight);

                    OpenTK.Graphics.ES20.GL.ClearColor(Color4.White);
                    OpenTK.Graphics.ES20.GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                    Set2DViewport(_pixelWidth, _pixelHeight);

                    GL.PushMatrix();
                    GL.Scale(_pixelWidth/_extentWidth, _pixelHeight/_extentHeight, 1);
                    GL.Translate(-_extentMinX, -_extentMinY, 0);

                    PolygonRenderer(featureCollections);
                    var byteArray = GraphicsContextToBitmapConverter.ToBitmap(_pixelWidth, _pixelHeight);

                    GL.PopMatrix();

                    FrameBufferObjectHelper.StopFrameBufferObject();

                    return byteArray;
                }
            }
        }
开发者ID:nothingisnecessary,项目名称:BruTile,代码行数:35,代码来源:GeoJSONToOpenTKRenderer.cs

示例15: 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


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