예제 #1
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)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            GraphicsDevice.Clear(Color.CornflowerBlue);

            SpriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, null, null, CurrentCamera.GetViewMatrix());

            foreach (IDrawer drawer in Drawers)
            {
                drawer.DrawAll(SpriteBatch);
            }

            SpriteBatch.DrawString(SpriteFont, Cursor.ScreenPosition.ToString(), Vector2.Zero, Color.Orange);
            SpriteBatch.End();

            SpriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, SamplerState.PointClamp);
            SpriteDrawer.Draw(SpriteBatch, Cursor.Sprite);
            SpriteBatch.End();

            sw.Stop();
            _deltaTimeDraw = (float)sw.Elapsed.TotalSeconds;

            base.Draw(gameTime);
        }
        private void Draw()
        {
            if (!renderTargetDrawn)
            {
                renderTexture.Use();
                renderTexture.Clear(Color4.Gray);
                vab.Bind();
                vao.Bind();
                pipeline.Bind();
                worldMatrix.Matrix = renderTexture.WorldMatrix;
                worldMatrix.Set(pipeline);
                vab.DrawDirect(3);
                var imageData = renderTexture.Framebuffer.Read(800, 600);
                var image     = Image.LoadPixelData <Rgba32>(imageData, 800, 600);
                image.Save("Screenshot.png");
                renderTargetDrawn = true;
                var sprite = SpriteDrawer.Draw(renderTexture, 0f, 0f);
                spriteRenderer.SetRenderItems(new SpriteRenderItem[] { sprite });
                spriteRenderer.RenderToData((data, count, tex) =>
                {
                    spriteDisplayList.SetVertices(data);
                    spriteDisplayList.SetIndices(SpriteRenderer.GetIndices(1));
                    resourceSet.Texture = tex;
                });
            }

            defaultFramebuffer.Bind();
            normal.Set();

            rotation += 0.001f;
            spriteDisplayList.Draw(resourceSet);
        }
예제 #3
0
 public void Draw()
 {
     if (texture.Height != 0)
     {
         float recoilX = 0, recoilY = 0;
         recoilX = (float)Math.Cos(parent.rotation + rotaOffset) * Math.Max(currentShootCD - 5, 0);
         recoilY = (float)Math.Sin(parent.rotation + rotaOffset) * Math.Max(currentShootCD - 5, 0);
         SpriteDrawer.Draw(texture,
                           parent.pos + new Vector2((float)Math.Cos(parent.rotation + posOffsetDirection) * posOffsetDistance - recoilX, (float)Math.Sin(parent.rotation + posOffsetDirection) * posOffsetDistance - recoilY),
                           Vector2.One,
                           Color.White,
                           new Vector2(((float)texture.Width) / 2, ((float)texture.Height) / 2),
                           parent.rotation - (float)Math.PI / 2);
     }
 }
예제 #4
0
        public void Run()
        {
            PlainCoreSettings.GlfwSearchPath = Path.GetFullPath("../../../../../Native/");
            var window = new RenderWindow();

            var rs       = new TextureResourceSet(window);
            var t        = Texture.FromFile("Example.png");
            var renderer = new SpriteRenderer();
            var dl       = DynamicDisplayList <VertexPositionColorTexture> .Create(renderer);

            var sprites     = new List <SpriteRenderItem>();
            var description = FontGenerator.GenerateFont("OpenSans-Regular.ttf", 40);
            var font        = new Font(description);

            sprites.Add(SpriteDrawer.Draw(t, Color4.White, 0f, 0f));
            sprites.Add(SpriteDrawer.Draw(t, Color4.White, 100f, 100f));
            sprites.Add(SpriteDrawer.Draw(t, Color4.White, 200f, 200f));
            sprites.Add(SpriteDrawer.Draw(t, Color4.White, 400f, 400f));
            var glyphs = font.DrawString("ASDF", 500f, 400f);

            sprites.AddRange(glyphs);
            var indices = SpriteRenderer.GetIndices(sprites.Count);

            renderer.SetRenderItems(sprites.ToArray());

            while (window.IsOpen)
            {
                window.Clear(Color4.Black);

                window.PollEvents();

                renderer.RenderToData((vertices, count, tex) =>
                {
                    dl.SetVertices(vertices);
                    dl.SetIndices(indices, count);
                    rs.Texture = tex;
                    dl.Draw(rs, count);
                });

                window.Display();
            }

            dl.Dispose();
            font.Dispose();
            renderer.Dispose();
            window.Dispose();
        }
예제 #5
0
        /// <summary>
        /// Generate the sprites for drawing a string.
        /// </summary>
        /// <param name="text">The text to draw</param>
        /// <param name="color">The color of the text</param>
        /// <param name="x">Position x</param>
        /// <param name="y">Position y</param>
        /// <param name="scale">Scale of the text (default 1)</param>
        /// <returns>A list of sprites</returns>
        public SpriteRenderItem[] DrawString(string text, Color4 color, float x, float y, int layer = 0, float scale = 1f)
        {
            SpriteRenderItem[] renderItems = new SpriteRenderItem[text.Length];

            float currentX = x;

            for (int i = 0; i < text.Length; i++)
            {
                char character = text[i];
                var  glyph     = description.GetGlyph(character);
                var  fx        = 1f / texture.Width;
                var  fy        = 1f / texture.Height;
                var  x1        = fx * (float)glyph.BitmapPosition.X;
                var  y1        = fy * (float)glyph.BitmapPosition.Y;
                var  x2        = x1 + (fx * (float)glyph.GlyphSize.W);
                var  y2        = y1 + (fy * (float)glyph.GlyphSize.H);
                renderItems[i] = SpriteDrawer.Draw(texture, color, currentX, y, glyph.GlyphSize.W * scale, glyph.GlyphSize.H * scale, x1, y1, x2, y2, layer);
                currentX      += glyph.GlyphSize.W * scale;
            }

            return(renderItems);
        }
예제 #6
0
파일: Bullet.cs 프로젝트: vjoensen/A6k
 override public void Draw()
 {
     SpriteDrawer.Draw(texture, pos, Vector2.One * textureScale, Color.Azure, new Vector2(((float)texture.Width) / 2, ((float)texture.Height) / 2), rotation - (float)Math.PI / 2);
 }