コード例 #1
0
        protected override void OnRenderFrame(FrameEventArgs args)
        {
            _frameCounter += args.Time;


            base.OnRenderFrame(args);

            Matrix4 vp = _camera.View * _projection;

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            _shader.Use();
            _shader.UploadMatrix("viewproj", ref vp);
            _shader.UploadColor("color", Color4.White);

            Matrix4 m = _plane.Model;

            _shader.UploadMatrix("model", ref m);
            _plane.Draw();

            m = debugDraw.Model;
            _shader.UploadMatrix("model", ref m);
            debugDraw.Draw();

            _fontRenderer.DrawText(_frameTimeText, new Vector2(0.0f, 0.0f), 22.0f);
            _fontRenderer.EndRender();

            SwapBuffers();

            if (_frameCounter >= 1.0f)
            {
                _frameTimeText = $"Frame Time: {args.Time * 1000.0f}ms";
                _frameCounter  = 0.0f;
            }
        }
コード例 #2
0
ファイル: DemoCamera.cs プロジェクト: asiftastos/HabiCS
        protected override void OnRenderFrame(FrameEventArgs args)
        {
            base.OnRenderFrame(args);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            Matrix4 vp = (_debugCam ? _debugView : _camera.View) * _projection;

            shader.Use();
            shader.UploadMatrix("viewproj", ref vp);
            shader.UploadMatrix("model", ref _model);
            shader.UploadColor("color", Color4.White);
            GL.BindVertexArray(vao);
            GL.DrawArrays(PrimitiveType.Triangles, 0, 36);
            GL.BindVertexArray(0);

            if (_debugCam)
            {
                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
                shader.Use();
                shader.UploadMatrix("viewproj", ref vp);
                shader.UploadMatrix("model", ref _debugModel);
                shader.UploadColor("color", Color4.White);
                GL.BindVertexArray(_debugVao);
                GL.BindBuffer(BufferTarget.ArrayBuffer, _debugVbo);
                GL.DrawArrays(PrimitiveType.Triangles, 0, 36);

                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
                GL.LineWidth(4.0f);
                GL.BindVertexArray(_debugCamCoordsVao);
                GL.BindBuffer(BufferTarget.ArrayBuffer, _debugCamCoords);
                float[] v =
                {
                    0.0f,                               0.0f,                0.0f, 0.0f, 0.0f, 1.0f,
                    _camera.Forward.X,   _camera.Forward.Y,   _camera.Forward.Z,   0.0f, 0.0f, 1.0f,
                    0.0f,                               0.0f,                0.0f, 1.0f, 0.0f, 0.0f,
                    _camera.Up.X,        _camera.Up.Y,        _camera.Up.Z,        1.0f, 0.0f, 0.0f,
                    0.0f,                               0.0f,                0.0f, 0.0f, 1.0f, 0.0f,
                    _camera.Right.X,     _camera.Right.Y,     _camera.Right.Z,     0.0f, 1.0f, 0.0f,
                    0.0f,                               0.0f,                0.0f, 1.0f, 1.0f, 0.0f,
                    _camera.Direction.X, _camera.Direction.Y, _camera.Direction.Z, 1.0f, 1.0f, 0.0f
                };
                GL.BufferSubData(BufferTarget.ArrayBuffer, (IntPtr)(0), 48 * sizeof(float), v);
                GL.DrawArrays(PrimitiveType.Lines, 0, 8);
                GL.BindVertexArray(0);
                GL.LineWidth(1.0f);
            }

            fontRenderer.DrawText($"Cam pos: {_camera.Position}", new Vector2(0.0f, 20.0f), 32.0f);
            fontRenderer.EndRender();


            SwapBuffers();
        }
コード例 #3
0
ファイル: EndScreen.cs プロジェクト: CodeEdelmann/HideOut
        public override void Draw(GraphicsDevice gd)
        {
            gd.Clear(Color.White);

            //This block of code is a necessary ritual for the FOVs.  Just leave it be.
            gd.BlendState        = BlendState.Opaque;
            gd.DepthStencilState = DepthStencilState.Default;
            gd.SamplerStates[0]  = SamplerState.LinearWrap;
            Matrix projection      = Matrix.CreateOrthographicOffCenter(0, gd.Viewport.Width, gd.Viewport.Height, 0, 0, 1);
            Matrix halfPixelOffset = Matrix.CreateTranslation(-0.5f, -0.5f, 0);

            basicEffect.World              = Matrix.Identity;
            basicEffect.View               = Matrix.Identity;
            basicEffect.Projection         = halfPixelOffset * projection;
            basicEffect.VertexColorEnabled = true;
            gd.RasterizerState             = RasterizerState.CullNone;

            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearWrap, null, null);
            spriteBatch.Draw(bgTexture, new Rectangle(0, 0, HideOutGame.SCREEN_WIDTH, HideOutGame.SCREEN_HEIGHT), new Rectangle(0, 0, HideOutGame.SCREEN_WIDTH, HideOutGame.SCREEN_WIDTH), Color.Green);

            fontRenderer.DrawText(spriteBatch, HideOutGame.SCREEN_WIDTH / 2 - 50, 25, "Credits");

            fontRenderer.DrawText(spriteBatch, 100, 100, "Art Assets:");
            fontRenderer.DrawText(spriteBatch, 100, 150, "Faye Huynh");

            fontRenderer.DrawText(spriteBatch, 100, 250, "Sound Effects:");
            fontRenderer.DrawText(spriteBatch, 100, 300, "http://www.newgrounds.com/audio/listen/568885,");
            fontRenderer.DrawText(spriteBatch, 100, 350, "http://www.newgrounds.com/audio/listen/135985");

            spriteBatch.End();
        }
コード例 #4
0
 public Size2 DrawText(string text, int height, Vector2 position, Color color, FontDrawFlags align = FontDrawFlags.Left)
 {
     return(fontRenderer.DrawText(text, "Verdana", height, position, color, align));
 }
コード例 #5
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            // Clear the graphics
            GraphicsDevice.Clear(Color.White);

            // Draw the base class
            base.Draw(gameTime);

            // Draw the background
            _SpriteBatch.Begin();
            _SpriteBatch.Draw(_Background, new Rectangle(0, 0, ScreenWidth, ScreenHeight), Color.White);
            _SpriteBatch.End();

            // Draw the bird
            _Bird.Draw(_SpriteBatch);

            // Draw the pipes
            foreach (Pipe pipe in _Pipes)
            {
                pipe.Draw(_SpriteBatch);
            }

            // Draw the floors
            foreach (Floor floor in _Floors)
            {
                floor.Draw(_SpriteBatch);
            }


            // Check the game state
            switch (_GameState)
            {
            case GameState.Ready:
            {
                // Draw the ready cover
                _SpriteBatch.Begin();
                _SpriteBatch.Draw(_ReadyCover, new Rectangle(0, 0, ScreenWidth, ScreenHeight), Color.White);
                _SpriteBatch.End();

                // Draw the tips
                _TipsFontRenderer.DrawText(_SpriteBatch, 10, ScreenHeight - 50, "Press [Space] to start...", Color.Black);
            }
            break;


            case GameState.Start:
            {
                // Draw the score
                _ScoreFontWidth = _ScoreFontRenderer.DrawText(_SpriteBatch, ScreenWidth / 2 - _ScoreFontWidth / 2, 80, _Score.ToString(), Color.White);
            }
            break;


            case GameState.GameOver:
            {
                // Draw the game over cover
                _SpriteBatch.Begin();
                _SpriteBatch.Draw(_GameoverCover, new Rectangle(0, 0, ScreenWidth, ScreenHeight), Color.White);
                _SpriteBatch.End();
                _ScoreFontWidth = _ScoreFontRenderer.DrawText(_SpriteBatch, 300 - _ScoreFontWidth, 250, _Score.ToString(), Color.White);

                // Draw the tips
                _TipsFontRenderer.DrawText(_SpriteBatch, 10, ScreenHeight - 50, "Press [Enter] to get ready...", Color.Black);
            }
            break;
            }
        }
コード例 #6
0
        public override void Draw(GraphicsDevice gd)
        {
            gd.Clear(Color.White);

            //This block of code is a necessary ritual for the FOVs.  Just leave it be.
            gd.BlendState        = BlendState.Opaque;
            gd.DepthStencilState = DepthStencilState.Default;
            gd.SamplerStates[0]  = SamplerState.LinearWrap;
            Matrix projection      = Matrix.CreateOrthographicOffCenter(0, gd.Viewport.Width, gd.Viewport.Height, 0, 0, 1);
            Matrix halfPixelOffset = Matrix.CreateTranslation(-0.5f, -0.5f, 0);

            basicEffect.World              = Matrix.Identity;
            basicEffect.View               = Matrix.Identity;
            basicEffect.Projection         = halfPixelOffset * projection;
            basicEffect.VertexColorEnabled = true;
            gd.RasterizerState             = RasterizerState.CullNone;

            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearWrap, null, null);
            spriteBatch.Draw(bgTexture, new Rectangle(0, 0, HideOutGame.SCREEN_WIDTH, HideOutGame.SCREEN_HEIGHT), new Rectangle(0, 0, HideOutGame.SCREEN_WIDTH, HideOutGame.SCREEN_WIDTH), Color.Green);

            bool draw_ng = true, draw_lg = true, draw_ex = true;

            //spriteBatch.Draw(exposition, new Rectangle(20, 20, 199, 172), Color.White);

            spriteBatch.Draw(logo, new Rectangle(240, 30, (int)(643 * .8), (int)(414 * .8)), Color.White);

            //draw player and police
            int len = NPCController.textures[Direction.Right].Count;

            spriteBatch.Draw(NPCController.textures[Direction.Right][police1.directionIndex % len], police1.worldRectangle, Color.White);
            spriteBatch.Draw(NPCController.textures[Direction.Right][police2.directionIndex % len], police2.worldRectangle, Color.White);

            int       numTextures  = PlayerController.textures[player.direction].Count;
            Texture2D spriteToDraw = PlayerController.textures[player.direction][player.directionIndices[player.direction] % numTextures];

            spriteBatch.Draw(spriteToDraw, player.worldRectangle, Color.White);


            switch (index)
            {
            case 0:
                fontRenderer.DrawText(spriteBatch, HideOutGame.SCREEN_WIDTH / 2 - 70, HideOutGame.SCREEN_HEIGHT / 2 + 80, "> Continue");
                draw_ng = false;
                break;

            case 1:
                fontRenderer.DrawText(spriteBatch, HideOutGame.SCREEN_WIDTH / 2 - 70, HideOutGame.SCREEN_HEIGHT / 2 + 130, "> New Game");
                draw_lg = false;
                break;

            case 2:
                fontRenderer.DrawText(spriteBatch, HideOutGame.SCREEN_WIDTH / 2 - 70, HideOutGame.SCREEN_HEIGHT / 2 + 180, "> Exit");
                draw_ex = false;
                break;
            }

            if (draw_ng)
            {
                fontRenderer.DrawText(spriteBatch, HideOutGame.SCREEN_WIDTH / 2 - 50, HideOutGame.SCREEN_HEIGHT / 2 + 80, "Continue");
            }
            if (draw_lg)
            {
                fontRenderer.DrawText(spriteBatch, HideOutGame.SCREEN_WIDTH / 2 - 50, HideOutGame.SCREEN_HEIGHT / 2 + 130, "New Game");
            }
            if (draw_ex)
            {
                fontRenderer.DrawText(spriteBatch, HideOutGame.SCREEN_WIDTH / 2 - 50, HideOutGame.SCREEN_HEIGHT / 2 + 180, "Exit");
            }

            spriteBatch.End();
        }
コード例 #7
0
 public static void DrawText(this SpriteBatch batch, FontRenderer fontRenderer, string text, Rectangle borders, Color color)
 {
     fontRenderer.DrawText(batch, text, borders, color);
 }
コード例 #8
0
        // displayString("Game Over", xPos, yPos - offset, sb, backgroundColor);

        private void displayString(String text, int xx, int yy, SpriteBatch sb)
        {
            fontRenderer.DrawText(sb, xx, yy, text);
        }