Example #1
0
 public void Draw(Scene ActiveScene)
 {
     _RenderTarget.BeginDraw();
     _RenderTarget.Clear(_ClearColor);
     ActiveScene.Draw(this);
     _RenderTarget.EndDraw();
 }
Example #2
0
 public void DrawLogo()
 {
     RenderTarget2D.Clear(_blackScreen);
     _textColorAnimation.AnimationStart(300, ref _mapObjectsColors[11]);
     RenderTarget2D.DrawText("Battle City v0.1",
                             _logoBrushTextFormat, _logoTextRect, _mapObjectsColors[14]);
     RenderTarget2D.DrawText("Press any button to start a game",
                             _statusTextFormat, _statusTextRect, _mapObjectsColors[11]);
 }
Example #3
0
        } // NextColor

        #endregion

        #region Render All Object to Picker

        /// <summary>
        /// Render the object using a constant shasder to picker texture.
        /// Each object will be render using a unique color.
        /// </summary>
        private void RenderObjectsToPickerTexture(Matrix viewMatrix, Matrix projectionMatrix, Viewport viewport)
        {
            this.viewMatrix       = viewMatrix;
            this.projectionMatrix = projectionMatrix;

            byte  red = 0, green = 0, blue = 0;
            Color colorMaterial;

            // Start rendering onto the picker map
            pickerTexture.EnableRenderTarget();

            // Set Render States.
            EngineManager.Device.BlendState        = BlendState.NonPremultiplied;
            EngineManager.Device.RasterizerState   = RasterizerState.CullCounterClockwise;
            EngineManager.Device.DepthStencilState = DepthStencilState.Default;

            EngineManager.Device.Viewport = viewport;

            // Clear render target
            pickerTexture.Clear(Color.Black);

            constantShader.Resource.CurrentTechnique = constantShader.Resource.Techniques["ConstantsRGB"];

            // Render every object, one at a time
            foreach (GameObject obj in GameObject.GameObjects)
            {
                // Select the next color
                NextColor(ref red, ref green, ref blue);
                colorMaterial = new Color(red, green, blue);
                // Editor elements or not visible game objects should not be picked.
                if (obj.Layer != Layer.GetLayerByNumber(30) && obj.Layer != Layer.GetLayerByNumber(31) && Layer.IsVisible(obj.Layer.Mask) && obj.Active)
                {
                    RenderObjectToPicker(obj, colorMaterial);
                }
            }
            // Render icons
            LineManager.Begin2D(PrimitiveType.TriangleList);
            foreach (GameObject obj in GameObject.GameObjects)
            {
                // Select the next color
                NextColor(ref red, ref green, ref blue);
                colorMaterial = new Color(red, green, blue);
                // Editor elements or not visible game objects should not be picked.
                if (obj.Layer != Layer.GetLayerByNumber(30) && obj.Layer != Layer.GetLayerByNumber(31) && Layer.IsVisible(obj.Layer.Mask) && obj.Active)
                {
                    RenderIconToPicker(obj, colorMaterial);
                }
            }
            LineManager.End();

            // Activate the frame buffer again.
            pickerTexture.DisableRenderTarget();
        } // RenderObjectsToPickerTexture
Example #4
0
        public void DisplayName(string name)
        {
            var brush      = new SolidColorBrush(renderTarget, Color4.White);
            var layoutRect = new SharpDX.RectangleF(0, (float)bounds.Height / 2f, bounds.Width, 100f);

            renderTarget.BeginDraw();
            renderTarget.Clear(Color4.Black);
            renderTarget.DrawRectangle(new SharpDX.RectangleF(0, 0, bounds.Width, bounds.Height), brush, 10f);

            renderTarget.DrawText(name, textFormat, layoutRect, solidColorBrush);
            renderTarget.EndDraw();

            brush.Dispose();
        }
Example #5
0
 /// <summary>
 /// 渲染控件绘制的事件。
 /// </summary>
 private void renderPanel_Paint(object sender, PaintEventArgs e)
 {
     devices.BeginDraw();
     renderTarget.Clear(this.backgroundColor);
     if (this.hasGame)
     {
         renderTarget.Transform = renderPanel.RenderTargetTansform;
         // 绘制背景图片。
         if (ShowBackground)
         {
             float scale = renderPanel.JigsawScale;
             this.renderTarget.DrawBitmap(this.background,
                                          new RectangleF(0, 0, imageSize.Width * scale, imageSize.Height * scale),
                                          BackgroundAlpha, BitmapInterpolationMode.Linear);
         }
         // 渲染拼图碎片。
         renderer.Render(pieces);
         // 绘制选择框。
         if (isSelecting)
         {
             renderTarget.DrawRectangle(selectRect, selectionRectBrush, 1f, selectionRectStyle);
         }
     }
     devices.EndDraw();
 }
Example #6
0
        /// <summary>
        /// Renders the scene to the given render target.
        /// Clears the scene, then draws all shapes
        /// </summary>
        /// <param name="renderTarget">The render target.</param>
        private void RenderScene(RenderTarget renderTarget)
        {
            Cursor c = null;

            if (renderMode != RenderModes.HwndRenderTarget)
            {
                c      = Cursor;
                Cursor = Cursors.WaitCursor;
            }
            renderTarget.BeginDraw();
            renderTarget.Clear(BackColorF);

            for (int i = 0; i < drawingShapes.Count; i++)
            {
                DrawingShape shape = drawingShapes[i];
                //tag with shape index for debugging
                renderTarget.Tags = new Tags((ulong)i, 0);
                shape.Draw(renderTarget);
            }
            Tags      tags;
            ErrorCode errorCode;

            if (!renderTarget.TryEndDraw(out tags, out errorCode))
            {
                Debug.WriteLine(String.Format("Failed EndDraw. Error: {0}, tag1: {1}, tag2: {2}, shape[{1}]: {3}",
                                              errorCode, tags.Tag1, tags.Tag2,
                                              (int)tags.Tag1 < drawingShapes.Count ? drawingShapes[(int)tags.Tag1].ToString() : "<none>"));
            }
            if (renderMode != RenderModes.HwndRenderTarget)
            {
                Cursor = c;
            }
        }
Example #7
0
        private void Draw()
        {
            while (true)
            {
                if (token.IsCancellationRequested)
                {
                    return;
                }
                lock (Locker)
                {
                    //if (Disposed)
                    //    return;
                    rt.BeginDraw();
                    rt.Clear();

                    if (Redraw)
                    {
                        Elements.Draw(rt);
                        Redraw = false;
                    }
                    else
                    {
                        Elements.DrawChangedLayers(rt);
                    }

                    rt.EndDraw();
                }
                Thread.Sleep(UpdateInterval);
            }
        }
Example #8
0
        private void Render()
        {
            frameAccumulator += FrameDelta;
            frameCount++;
            if (frameAccumulator >= 1.0f)
            {
                FramesPerSecond  = frameCount / frameAccumulator;
                frameAccumulator = 0.0f;
                frameCount       = 0;
            }

            BeginDraw();

            Device.Rasterizer.SetViewports(new Viewport(0, 0, form.Width, form.Height));
            Device.OutputMerger.SetTargets(BackBufferView);
            RenderTarget.BeginDraw();
            RenderTarget.Clear(SceneColorBrush.Color);

            Draw(clock);

            RenderTarget.EndDraw();
            swapChain.Present(0, PresentFlags.None);

            EndDraw();
        }
        protected override void BeginRender()
        {
            base.BeginRender();

            _renderTarget2D.BeginDraw();
            _renderTarget2D.Clear(Color.Orange);
        }
Example #10
0
        protected override void OnPaint(WindowHandle window)
        {
            SizeF targetSize = RenderTarget.GetSize();

            RenderTarget.SetTransform();
            RenderTarget.Clear(Color.White);
            RenderTarget.FillRectangle(RenderTarget.GetSize(), _gridPatternBrush);
            RenderTarget.SetTransform(Matrix3x2.CreateScale(Math.Min(targetSize.Width / 840.0f, targetSize.Height / 700.0f) * 1.4f));

            RenderTarget.FillGeometry(_sunGeometry, _radialGradientBrush);
            _sceneBrush.SetColor(Color.Black);
            RenderTarget.DrawGeometry(_sunGeometry, _sceneBrush);

            _sceneBrush.SetColor(Color.OliveDrab);
            RenderTarget.FillGeometry(_leftMountainGeometry, _sceneBrush);
            _sceneBrush.SetColor(Color.Black);
            RenderTarget.DrawGeometry(_leftMountainGeometry, _sceneBrush);

            _sceneBrush.SetColor(Color.LightSkyBlue);
            RenderTarget.FillGeometry(_riverGeometry, _sceneBrush);
            _sceneBrush.SetColor(Color.Black);
            RenderTarget.DrawGeometry(_riverGeometry, _sceneBrush);

            _sceneBrush.SetColor(Color.YellowGreen);
            RenderTarget.FillGeometry(_rightMountainGeometry, _sceneBrush);
            _sceneBrush.SetColor(Color.Black);
            RenderTarget.DrawGeometry(_rightMountainGeometry, _sceneBrush);
        }
        private BitmapRenderTarget RenderIntermediate(
            SharpDX.Direct2D1.RenderTarget target,
            BitmapImpl bitmap,
            TileBrushCalculator calc)
        {
            var result = new BitmapRenderTarget(
                target,
                CompatibleRenderTargetOptions.None,
                calc.IntermediateSize.ToSharpDX());

            using (var context = new RenderTarget(result).CreateDrawingContext(null))
            {
                var dpi  = new Vector(target.DotsPerInch.Width, target.DotsPerInch.Height);
                var rect = new Rect(bitmap.PixelSize.ToSizeWithDpi(dpi));

                context.Clear(Colors.Transparent);
                context.PushClip(calc.IntermediateClip);
                context.Transform = calc.IntermediateTransform;

                context.DrawBitmap(RefCountable.CreateUnownedNotClonable(bitmap), 1, rect, rect, _bitmapInterpolationMode);
                context.PopClip();
            }

            return(result);
        }
Example #12
0
        public override void Render(RenderTarget target)
        {
            target.Clear(new RawColor4(1.0f, 1.0f, 1.0f, 1.0f));
            var brush = _rnd.Next(3) switch
            {
                0 => ResourceCache["RedBrush"] as Brush,
                1 => ResourceCache["GreenBrush"] as Brush,
                2 => ResourceCache["BlueBrush"] as Brush,
                _ => null
            };

            target.DrawRectangle(new RawRectangleF(_x, _y, _x + W, _y + H), brush);

            _x += _dx;
            _y += _dy;
            if (_x >= ActualWidth - W || _x <= 0)
            {
                _dx = -_dx;
            }

            if (_y >= ActualHeight - H || _y <= 0)
            {
                _dy = -_dy;
            }
        }
    }
Example #13
0
        private BrushImpl CreateBrushImpl(IBrush brush, Size destinationSize)
        {
            var       solid = brush as ISolidColorBrush;
            var       linearGradientBrush = brush as ILinearGradientBrush;
            var       radialGradientBrush = brush as IRadialGradientBrush;
            var       imageBrush          = brush as IImageBrush;
            var       visualBrush         = brush as IVisualBrush;
            BrushImpl impl = null;

            if (solid != null)
            {
                impl = new SolidColorBrushImpl(solid, opacityOverride);
            }
            else if (linearGradientBrush != null)
            {
                impl = new LinearGradientBrushImpl(linearGradientBrush, destinationSize);
            }
            else if (radialGradientBrush != null)
            {
                impl = new RadialGradientBrushImpl(radialGradientBrush, destinationSize);
            }
            else if (imageBrush != null)
            {
                impl = new ImageBrushImpl(imageBrush, (BitmapImpl)imageBrush.Source.PlatformImpl, destinationSize);
            }
            else if (visualBrush != null)
            {
                if (_visualBrushRenderer != null)
                {
                    var intermediateSize = _visualBrushRenderer.GetRenderTargetSize(visualBrush);

                    if (intermediateSize.Width >= 1 && intermediateSize.Height >= 1)
                    {
                        using (var intermediate = new Cairo.ImageSurface(Cairo.Format.ARGB32, (int)intermediateSize.Width, (int)intermediateSize.Height))
                        {
                            using (var ctx = new RenderTarget(intermediate).CreateDrawingContext(_visualBrushRenderer))
                            {
                                ctx.Clear(Colors.Transparent);
                                _visualBrushRenderer.RenderVisualBrush(ctx, visualBrush);
                            }

                            return(new ImageBrushImpl(
                                       visualBrush,
                                       new RenderTargetBitmapImpl(intermediate),
                                       destinationSize));
                        }
                    }
                }
                else
                {
                    throw new NotSupportedException("No IVisualBrushRenderer was supplied to DrawingContextImpl.");
                }
            }
            else
            {
                impl = new SolidColorBrushImpl(null, opacityOverride);
            }

            return(impl);
        }
Example #14
0
        private void RenderBuffers()
        {
            if (_indexBuffer == null || _vertexBuffer == null)
            {
                return;
            }
            var context = _tileTexture2D.Device.ImmediateContext;

            _renderTarget2D.BeginDraw();
            _renderTarget2D.Clear(SharpDX.Color.Red);

            context.InputAssembler.InputLayout       = _inputLayout;
            context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_vertexBuffer, 16 + 16 + 12, 0));
            context.InputAssembler.SetIndexBuffer(_indexBuffer, Format.R16_UInt, 0);
            context.VertexShader.Set(_vertexShader);
            context.Rasterizer.SetViewport(new Viewport(0, 0, 256, 256));
            context.PixelShader.Set(_pixelShader);
            context.OutputMerger.SetTargets(_renderTargetView);
            context.OutputMerger.ResetTargets();
            // int indexBufferTriangleCount = _indexBuffer.Description.SizeInBytes / _indexBuffer.Description.StructureByteStride / 3;
            context.DrawIndexed(_triangleCount, 0, 0);

            _renderTarget2D.EndDraw();
        }
Example #15
0
        protected override void Draw()
        {
            RenderTarget.BeginDraw();
            RenderTarget.Transform = Matrix3x2.Identity;
            Random random = new Random();

            RenderTarget.Clear(new Color4(0.5f, 0.5f, 0.5f, 0.0f));
            RenderTarget.AntialiasMode = AntialiasMode.Aliased;
            StrokeStyleProperties properties = new StrokeStyleProperties();

            properties.LineJoin = LineJoin.MiterOrBevel;
            StrokeStyle strokeStyle = new StrokeStyle(RenderTarget.Factory, properties);

            foreach (DirectPath path in paths)
            {
                if (path.Geometry != null && path.Brush != null)
                {
                    if (path is DirectPathScatter)
                    {
                        (path as DirectPathScatter).RenderScatterGeometry(RenderTarget);
                    }
                    else
                    {
                        if (path.QuickStrokeDash != QuickStrokeDash.None)
                        {
                            RenderTarget.DrawGeometry(path.Geometry, path.Brush, (float)path.StrokeThickness, strokeStyle);
                        }
                    }
                }
            }
            RenderTarget.EndDraw();
            graphicsDeviceService10.CopyTextureAcross();
            graphicsDeviceService10.Device.Flush();
        }
Example #16
0
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            if (RenderTarget.IsDisposed)
            {
                return;
            }
            drawCount++;
            if (drawCount == 10000)
            {
                GC.Collect();
                drawCount = 0;
            }
            //Thread.Sleep(45);
            // Begin rendering
            RenderTarget.BeginDraw();
            RenderTarget.Clear(colorBack);

            layerBack.Draw();
            layerParticle.Draw();
            layerClock.Draw();

            // End drawing
            RenderTarget.EndDraw();

            //Left = (int)(Location.X + (Width - ClientSize.Width) / 2f);
            //Right = Left + ClientSize.Width;
            //Top = (int)(Location.Y + (Height - ClientSize.Height) - 8f);
            //Bottom = Top + ClientSize.Height;

            this.Invalidate();
        }
Example #17
0
        public void Draw()
        {
            lock (_drawLock)
            {
                if (_ui == null || d2dRenderTarget == null || !_ui.ready)
                {
                    return;
                }
                d2dRenderTarget.BeginDraw();
                d2dRenderTarget.Clear(Color.Gray);

                if (_ui.gameStarted)
                {
                    int stride = UI.GameWidth * 4;
                    gameBitmap.CopyFromMemory(_ui.rawBitmap, stride);

                    d2dRenderTarget.DrawBitmap(gameBitmap, clientArea, 1f,
                                               _ui._filterMode == UI.FilterMode.Linear
                            ? BitmapInterpolationMode.Linear
                            : BitmapInterpolationMode.NearestNeighbor);
                }

                d2dRenderTarget.EndDraw();
                swapChain.Present(0, PresentFlags.None);
            }
        }
Example #18
0
        public override void Render(RenderTarget target)
        {
            target.Clear(new RawColor4(1.0f, 1.0f, 1.0f, 1.0f));
            Brush brush = null;

            switch (rnd.Next(3))
            {
            case 0:
                brush = resCache["RedBrush"] as Brush;
                break;

            case 1:
                brush = resCache["GreenBrush"] as Brush;
                break;

            case 2:
                brush = resCache["BlueBrush"] as Brush;
                break;
            }

            target.DrawRectangle(new RawRectangleF(x, y, x + w, y + h), brush);

            x = x + dx;
            y = y + dy;
            if (x >= ActualWidth - w || x <= 0)
            {
                dx = -dx;
            }

            if (y >= ActualHeight - h || y <= 0)
            {
                dy = -dy;
            }
        }
Example #19
0
        public void DrawFromCamera(Camera camera, RenderTarget renderTarget)
        {
            //GlowingPass( camera );
            ShadowMappingPass(camera);

            camera.SetCurrentView();

            renderTarget.Clear();
            renderTarget.Bind();
            DeviceContext.OutputMerger.BlendState = mainBlend;

            SetViewport(camera.GetViewport());

            LightManager.Instance.Update(View.Current);

            if (!turnOffSceneRendering)
            {
                //ProjectorManager.Instance.Bind();
                scene_.Render();
                //ProjectorManager.Instance.UnBind();
            }

            //renderTarget.DepthStencil.SetDepthComparison( Comparison.Greater );
            // On vérifie si la camera possède une skybox
            if (camera.Skybox != null)
            {
                // Dans ce cas, on affiche la skybox
                // On l'affiche en dernier pour éviter d'effectuer les test du Stencil buffer inutilement
                camera.Skybox.Render();
            }
            // if (Isglowing){
            // GlowingManager.Instance.DrawQuadOnTop();
            // }
        }
        private void OnRenderCallback()
        {
            d2dRenderTarget.BeginDraw();

            d2dRenderTarget.Clear(Color.Black);

            d2dRenderTarget.SaveDrawingState(drawingStateBlock);

            d2dRenderTarget.Transform = this.transformation;

            //    renderPolygon(this.leftEyebrow);
            //    renderPolygon(this.leftEye);
            //    renderPolygon(this.leftPupil);
            //    renderPolygon(this.rightEyebrow);
            //    renderPolygon(this.rightEye);
            //    renderPolygon(this.rightPupil);
            //    renderPolygon(this.mouth);
            //    renderPolygon(this.nose);

            //renderPolygon(this.facePoints);
            renderPoints(facePoints);

            d2dRenderTarget.RestoreDrawingState(drawingStateBlock);

            if (this.showDebugInfo)
            {
                renderDebugInfo();
            }

            d2dRenderTarget.EndDraw();

            swapChain.Present(0, PresentFlags.None);

            framesPerSecond.Frame();
        }
        } // GetParameters

        #endregion

        #region Render

        /// <summary>
        /// Generate ambient occlusion texture.
        /// </summary>
        public RenderTarget Render(RenderTarget depthTexture, RenderTarget normalTexture, RayMarchingAmbientOcclusion rmao, float fieldOfView)
        {
            try
            {
                // I decided to work with Color format for a number of reasons.
                // First, this format is very used so chances are that I can reuse it latter in another shader.
                // Second, GPUs tend to work faster in non-floating point render targets.
                // Third, I can blur it with linear sampling.
                // The main disadvantage is that I am wasting three channels.
                // A single 8 bit channel render target is not available in XNA 4.0 and I have two options for 16 bits render targets.
                // First, the compressed 4 channels formats, the compression is visible and the results are not satisfactory.
                // Last we have the half single format, it is a good option but I prefer to have linear sampling.
                RenderTarget ambientOcclusionTexture = RenderTarget.Fetch(depthTexture.Size, SurfaceFormat.HalfSingle,
                                                                          DepthFormat.None, RenderTarget.AntialiasingType.NoAntialiasing);

                // Set shader atributes
                SetNormalTexture(normalTexture);
                SetDepthTexture(depthTexture);
                SetNumberSteps(rmao.NumberSteps);
                SetNumberRays(rmao.NumberRays);
                SetNumberDirections(rmao.NumberDirections);
                SetContrast(rmao.Contrast);
                SetLineAttenuation(rmao.LineAttenuation);
                SetRadius(rmao.Radius);
                SetHalfPixel(new Vector2(-0.5f / (ambientOcclusionTexture.Width / 2), 0.5f / (ambientOcclusionTexture.Height / 2)));
                Vector2 focalLen = new Vector2
                {
                    X = 1.0f / (float)Math.Tan(fieldOfView * (3.1416f / 180) * 0.5f) * (float)ambientOcclusionTexture.Height / (float)ambientOcclusionTexture.Width,
                    Y = 1.0f / (float)Math.Tan(fieldOfView * (3.1416f / 180) * 0.5f)
                };
                SetFocalLength(focalLen);

                // Set Render States.
                EngineManager.Device.BlendState        = BlendState.Opaque;
                EngineManager.Device.DepthStencilState = DepthStencilState.None;
                EngineManager.Device.RasterizerState   = RasterizerState.CullCounterClockwise;
                EngineManager.Device.SamplerStates[3]  = SamplerState.PointWrap;

                Resource.CurrentTechnique = Resource.Techniques["SSAO"];
                Resource.CurrentTechnique.Passes[0].Apply();

                // Render
                ambientOcclusionTexture.EnableRenderTarget();
                ambientOcclusionTexture.Clear(Color.White);
                Resource.CurrentTechnique.Passes[0].Apply();
                RenderScreenPlane();
                ambientOcclusionTexture.DisableRenderTarget();

                RenderTarget bluredAmbientOcclusionTexture = RenderTarget.Fetch(depthTexture.Size, SurfaceFormat.HalfSingle,
                                                                                DepthFormat.None, RenderTarget.AntialiasingType.NoAntialiasing);
                BilateralBlurShader.Instance.Filter(ambientOcclusionTexture, bluredAmbientOcclusionTexture, depthTexture);
                RenderTarget.Release(ambientOcclusionTexture);
                return(bluredAmbientOcclusionTexture);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException("Ray Marching Ambient Occlusion Shader: Unable to render.", e);
            }
        } // Render
Example #22
0
 internal void NextFrame()
 {
     drawer.BeginDraw();
     drawer.Clear(Color.Black);
     sight.Draw();
     drawer.EndDraw();
     swapChain.Present(0, PresentFlags.None);
 }
Example #23
0
 public override void Render(RenderTarget target)
 {
     target.Clear(new RawColor4(1.0f, 1.0f, 1.0f, 1.0f));
     for (int i = 0; i < drawables.Count; i++)
     {
         this.drawables[i].Draw(target);
     }
 }
Example #24
0
 protected virtual void Render(RenderTarget renderer)
 {
     renderer.Clear(Color.Black);
     foreach (GameObject obj in GameObjects)
     {
         renderer.Draw(obj);
     }
 }
Example #25
0
 public void Run()
 {
     RenderTarget.BeginDraw();
     if (window.BackgroundColor.A > 0)
     {
         RenderTarget.Clear(new Color4(window.BackgroundColor.PackedArgb));
     }
 }
Example #26
0
        unsafe void OnRenderModel()
        {
            if (mRenderer == null)
            {
                return;
            }

            mTarget.Clear();
            mTarget.Apply();

            var ctx = WorldFrame.Instance.GraphicsContext;
            var vp  = ctx.Viewport;

            ctx.Context.Rasterizer.SetViewport(new Viewport(0, 0, ImgWidth, ImgHeight, 0.0f, 1.0f));

            ctx.Context.VertexShader.SetConstantBuffer(0, mMatrixBuffer.Native);
            mRenderer.RenderPortrait();

            mTarget.Remove();
            ctx.Context.Rasterizer.SetViewport(vp);

            ctx.Context.ResolveSubresource(mTarget.Texture, 0, mResolveTexture, 0, Format.B8G8R8A8_UNorm);
            ctx.Context.CopyResource(mResolveTexture, mMapTexture);

            var box  = ctx.Context.MapSubresource(mMapTexture, 0, MapMode.Read, MapFlags.None);
            var bmp  = new Bitmap(ImgWidth, ImgHeight, PixelFormat.Format32bppArgb);
            var bmpd = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly,
                                    PixelFormat.Format32bppArgb);
            byte *ptrDst = (byte *)bmpd.Scan0.ToPointer();
            byte *ptrSrc = (byte *)box.DataPointer.ToPointer();

            for (var i = 0; i < bmp.Height; ++i)
            {
                UnsafeNativeMethods.CopyMemory(ptrDst + i * bmp.Width * 4, ptrSrc + i * box.RowPitch, bmp.Width * 4);
            }

            bmp.UnlockBits(bmpd);
            ctx.Context.UnmapSubresource(mMapTexture, 0);

            //Cache thumbnail
            if (mThumbnailCaptureFrame > 0 && --mThumbnailCaptureFrame == 0)
            {
                renderTimer.Stop();

                Bitmap thumbnail = new Bitmap(ImgWidth, ImgHeight);
                using (var g = System.Drawing.Graphics.FromImage(thumbnail))
                {
                    g.Clear(Color.Black);
                    g.DrawImage(bmp, new PointF(0, 0));
                }

                ThumbnailCache.Cache(mRenderer.Model.FileName, thumbnail);
                if (mModels.Count > 0) //More models so render next
                {
                    LoadModel();
                }
            }
        }
        public override void Draw(RenderTarget renderTarget, ResourceFactory rf)
        {
            renderTarget.Clear(Color.White);

            var step = _steps[_currentStepIndex];

            foreach (var circle in step.GetCircles())
            {
                var brush = rf.GetSolidColorBrush(circle.Item2);
                renderTarget.FillEllipse(new Ellipse(circle.Item1, circle.Item3, circle.Item3), brush);
            }

            foreach (var segment in step.GetSegments())
            {
                var brush = rf.GetSolidColorBrush(segment.Item3);
                renderTarget.DrawLine(segment.Item1, segment.Item2, brush, segment.Item4);
            }

            foreach (var poly in step.GetPolygons())
            {
                var brush = rf.GetSolidColorBrush(poly.Color);
                renderTarget.FillGeometry(poly.GetGeometry(renderTarget.Factory), brush);
            }

            var points = step.GetPoints().ToList();

            foreach (var point in points)
            {
                var brush = rf.GetSolidColorBrush(point.Item2);
                renderTarget.FillEllipse(new Ellipse(point.Item1, point.Item3, point.Item3), brush);
            }

            var font = rf.GetFont("Arial", 16);
            var rect = new RectangleF(0, 0, renderTarget.Size.Width, 30);

            var text1 = string.Format("Initially: {0} point(s)", _steps.First().GetPoints().Count());

            font.TextAlignment = TextAlignment.Leading;
            renderTarget.DrawText(text1, font, rect, rf.GetSolidColorBrush(Color.Black));

            var text2 = string.Format("Step {0}: {1} point(s)", _currentStepIndex, points.Count(p => p.Item2 == Color.Black));

            font.TextAlignment = TextAlignment.Center;
            renderTarget.DrawText(text2, font, rect, rf.GetSolidColorBrush(Color.Black));

            var text3 = "";

            if (_visualizationFinished)
            {
                text3 = string.Format("Step {0}: {1} point(s)", _steps.Count - 1, _steps.Last().GetPoints().Count(p => p.Item2 == Color.Black));
            }
            else if (IsPaused)
            {
                text3 = string.Format("Paused; computed {0} step(s) so far", _steps.Count - 1);
            }
            font.TextAlignment = TextAlignment.Trailing;
            renderTarget.DrawText(text3, font, rect, rf.GetSolidColorBrush(Color.Black));
        }
Example #28
0
    public void Compose(RenderTarget renderTarget, FrameworkElement fe)
    {
        renderTarget.BeginDraw();
        Do your rendering here
        renderTarget.Clear(new Color(0, 0, 0, 0));

        Render(renderTarget, fe, fe);
        renderTarget.EndDraw();
    }
Example #29
0
        protected override void Render()
        {
            RenderTarget.Clear(new Color(15, 87, 83));

            foreach (var p in points)
            {
                RenderTarget.FillEllipse(p, redBrush);
            }
        }
 public override void Draw(RenderTarget target, RenderStates states)
 {
     target.Clear(Color.Black);
     target.Draw(_backgroundSprite);
     foreach (var w in Widgets)
     {
         target.Draw(w);
     }
 }
Example #31
0
        private void RenderInternal(RenderTarget target)
        {
            target.Clear(Color.Black);

            Render(target);
            debugTerminal.Render(target);

            target.Display();
        }
Example #32
0
 public static void Draw(RenderTarget surface)
 {
     if (EntityToFollow != null)
     {
         surface.SetView (new View(EntityToFollow.GetPosition (), surface.GetView ().Size));
     }
     surface.Clear (BackgroundColor);
     foreach (Entity e in Entities)
         e._Draw (surface);
 }
Example #33
0
        public static void Draw(RenderTarget RT)
        {
            if (States.Count > 0)
                States.Peek().Draw(Screen);
            Screen.Display();

            RT.Clear(Color.Transparent);
            RT.Draw(Screen);
            if (Program.Debug)
                RT.Draw(FPSLabel);
        }
Example #34
0
 public void Render(TimeSpan delta, RenderTarget target, UISceneManager ui)
 {
     target.Clear(Colors.White);
     particles.Render(particleTexture, particle);
     bg.Texture = particleTexture.Texture;
     bg.Color = new Color(150, 150, 150, 150);
     target.Draw(bg);
     ui.CurrentScene = scene;
 }
Example #35
0
        public void Render(RenderTarget gfx)
        {
            {
                var binWidth = (uint) Math.Pow(2, (int) Math.Ceiling(Math.Log(this.simView.Width, 2)));
                var binHeight = (uint) Math.Pow(2, (int) Math.Ceiling(Math.Log(this.simView.Height, 2)));

                if (binWidth != this.simTex.Size.X || binHeight != this.simTex.Size.Y) {
                    this.simTex = new RenderTexture(binWidth, binHeight);
                }
            }

            this.sim.Update();

            {
                this.simTex.Clear(this.BgColor);

                this.simView.Render(this.simTex);

                this.simTex.Display();
            }

            gfx.Clear(this.BgColor);

            {
                var simSprite = new Sprite(this.simTex.Texture);

                var posX = (int) (gfx.Size.X / 2 - (this.simView.LocalCursorPos.X + this.CellSize / 2) * this.Zoom);
                var posY = (int) (gfx.Size.Y / 2 - (this.simView.LocalCursorPos.Y + this.CellSize / 2) * this.Zoom);
                simSprite.Position = new Vector2f(posX, posY);

                if (Math.Abs(this.Zoom - 1f) > .1f) {
                    simSprite.Scale = new Vector2f(this.Zoom, this.Zoom);
                }

                gfx.Draw(simSprite);
            }

            if (this.showHelp) {
                this.helpOverlay.Render(gfx);
            } else {
                this.helpLastSimState = this.sim.IsRunning;

                {
                    this.menuBg.Size = new Vector2f(gfx.Size.X, 20);
                    gfx.Draw(this.menuBg);
                }
                gfx.Draw(this.helpText);
            }

            {
                this.simStateText.DisplayedString = String.Format("[ {0} ]", (this.sim.IsRunning ? "RUNNING" : "PAUSED"));
                var x = (int) (gfx.Size.X - this.simStateText.GetLocalBounds().Width) / 2;
                this.simStateText.Position = new Vector2f(x, 2);
                gfx.Draw(this.simStateText);
            }

            {
                this.fpsText.DisplayedString = String.Format(
                    "FPS: {0:F1}",
                    this.wnd.FPSGauge.FPS);
                var x = gfx.Size.X - this.fpsText.GetLocalBounds().Width - 5;
                this.fpsText.Position = new Vector2f(x, 2);
                gfx.Draw(this.fpsText);
            }
        }
        public override void Draw(RenderTarget target, RenderStates states)
        {
            target.Clear(Color.Black);

            target.SetView(_view);

            _game._mouseLight.SetPosition(target.MapPixelToCoords(InputHandler.MousePosition));
            _game.Map.Draw(target, states);
            if (_fpsToggle)
                _msFLabel.Draw(target, states);
        }
Example #37
0
		private static void RenderBegin(RenderTarget renderTarget)
		{
			renderTarget.BeginDraw();
			renderTarget.Transform = Matrix3x2.Identity;
			renderTarget.Clear(new Color4(1.0f, 1.0f, 1.0f));
		}
Example #38
0
        /// <summary>
        /// Renders the scene to the given render target.
        /// Clears the scene, then draws all shapes
        /// </summary>
        /// <param name="renderTarget">The render target.</param>
        private void RenderScene(RenderTarget renderTarget)
        {
            Cursor c = null;
            if (renderMode != RenderModes.HwndRenderTarget)
            {
                c = Cursor;
                Cursor = Cursors.WaitCursor;
            }
            renderTarget.BeginDraw();
            renderTarget.Clear(BackColorF);

            for (int i = 0; i < drawingShapes.Count; i++)
            {
                DrawingShape shape = drawingShapes[i];
                //tag with shape index for debugging
                renderTarget.Tags = new Tags((ulong)i, 0);
                shape.Draw(renderTarget);
            }
            Tags tags;
            ErrorCode errorCode;
            if (!renderTarget.TryEndDraw(out tags, out errorCode))
            {
                Debug.WriteLine(String.Format("Failed EndDraw. Error: {0}, tag1: {1}, tag2: {2}, shape[{1}]: {3}",
                    errorCode, tags.Tag1, tags.Tag2,
                    (int)tags.Tag1 < drawingShapes.Count ? drawingShapes[(int)tags.Tag1].ToString() : "<none>"));
            }
            if (renderMode != RenderModes.HwndRenderTarget)
                Cursor = c;
        }
Example #39
0
        public void Draw(RenderTarget t)
        {
            t.Clear(new Color(65, 64, 60));

            btnAddRoom.Draw(t, cursorMode == CursorMode.AddRoom);
            btnAddDoor.Draw(t, cursorMode == CursorMode.AddDoor);
            //btnLoad.Draw(t, false);
            btnLoadBase.Draw(t, false);
            btnLoadFloor.Draw(t, false);
            btnOptions.Draw(t, false);

            if (BaseTex != null)
                btnToggleBase.Draw(t, drawBase);
            if (FloorTex != null)
                btnToggleFloor.Draw(t, drawFloor);

            if (BaseTex != null || FloorTex != null)
                btnMoveBG.Draw(t, cursorMode == CursorMode.PlaceBGCursor || cursorMode == CursorMode.PlacedBGCursor);

            btnMoveGibs.Draw(t, cursorMode == CursorMode.PlaceGibsCursor || cursorMode == CursorMode.PlacedGibsCursor);

            placeRoomCloaking.Draw(t, false);
            placeRoomDoors.Draw(t, false);
            placeRoomDrones.Draw(t, false);
            placeRoomEngines.Draw(t, false);
            placeRoomMedbay.Draw(t, false);
            placeRoomOxygen.Draw(t, false);
            placeRoomPilot.Draw(t, false);
            placeRoomSensors.Draw(t, false);
            placeRoomShields.Draw(t, false);
            placeRoomTeleporter.Draw(t, false);
            placeRoomWeapons.Draw(t, false);
            if (BaseTex != null && drawBase)
            {
                BaseTex.Position = bgOffset + (new Vector2f(Game.ship.LayoutData.X_OFFSET, Game.ship.LayoutData.Y_OFFSET) * 35);
                BaseTex.Draw(t, RenderStates.Default);
            }
            if (FloorTex != null && drawFloor)
            {
                FloorTex.Position = bgOffset + (new Vector2f(Game.ship.LayoutData.X_OFFSET, Game.ship.LayoutData.Y_OFFSET) * 35);
                FloorTex.Draw(t, RenderStates.Default);
            }

            // Draw grid
            foreach (FTLRoom room in ShipRooms)
                t.Draw(room.drawer);
            foreach (FTLDoor door in ShipDoors)
                t.Draw(door.drawer);

            for (int currentY = 1; currentY < 600; currentY += 35)
            {
                verts[0].Position = new Vector2f(0, currentY);
                verts[1].Position = new Vector2f(GUIStartX, currentY);
                t.Draw(verts, PrimitiveType.Lines);
            }
            for (int currentX = 0; currentX < GUIStartX; currentX += 35)
            {
                verts[0].Position = new Vector2f(currentX, 0);
                verts[1].Position = new Vector2f(currentX, 600);
                t.Draw(verts, PrimitiveType.Lines);
            }

            if (ship != null)
                foreach (RoomFunc rf in ship.rooms.Values)
                {
                    if (rf == null || rf.location == null)
                        continue;
                    Sprite temp = new Sprite(rf.image);
                    temp.Position = new Vector2f((rf.location.position.X + (((float)rf.location.size.X - 1) / 2)) * 35, (rf.location.position.Y + (((float)rf.location.size.Y - 1) / 2)) * 35);
                    temp.Position += (new Vector2f(Game.ship.LayoutData.X_OFFSET, Game.ship.LayoutData.Y_OFFSET) * 35);
                    t.Draw(temp);
                    temp.Dispose();
                }

            ViewOffsetter.Draw(t, rs);

            if (cursorMode == CursorMode.AddDoor)
            {
                RectangleShape curDoor;
                if (DoorHorizontal)
                {
                    curDoor = new RectangleShape(new Vector2f(19, 4));
                    curDoor.Position = new Vector2f((SFML.Window.Mouse.GetPosition(Program.app).X / 35) * 35 + 7, (SFML.Window.Mouse.GetPosition(Program.app).Y / 35) * 35 - 2);

                }
                else
                {
                    curDoor = new RectangleShape(new Vector2f(4, 19));
                    curDoor.Position = new Vector2f((SFML.Window.Mouse.GetPosition(Program.app).X / 35) * 35 - 2, (SFML.Window.Mouse.GetPosition(Program.app).Y / 35) * 35 + 7);
                }
                curDoor.FillColor = new Color(255, 150, 50);
                curDoor.OutlineColor = new Color(0, 0, 0);
                curDoor.OutlineThickness = 1;
                t.Draw(curDoor);
                curDoor.Dispose();

            }

            if (cursorMode == CursorMode.AddRoom)
            {
                RectangleShape currentroom = new RectangleShape(new Vector2f(35, 35));
                currentroom.Position = new Vector2f((SFML.Window.Mouse.GetPosition(Program.app).X / 35) * 35, (SFML.Window.Mouse.GetPosition(Program.app).Y / 35) * 35);
                currentroom.FillColor = new Color(0, 0, 0);
                t.Draw(currentroom);
                currentroom = new RectangleShape(new Vector2f(31, 31));
                currentroom.Position = new Vector2f((SFML.Window.Mouse.GetPosition(Program.app).X / 35) * 35 + 2, (SFML.Window.Mouse.GetPosition(Program.app).Y / 35) * 35 + 2);
                currentroom.FillColor = new Color(230, 226, 219);
                t.Draw(currentroom);
                currentroom.Dispose();

            }

            Sprite roomSpr = null;
            switch (setRoom)
            {
                case RoomID.None:
                    break;
                case RoomID.cloaking:
                    roomSpr = new Sprite(placeRoomCloaking.button);
                    break;
                case RoomID.doors:
                    roomSpr = new Sprite(placeRoomDoors.button);
                    break;
                case RoomID.drones:
                    roomSpr = new Sprite(placeRoomDrones.button);
                    break;
                case RoomID.engines:
                    roomSpr = new Sprite(placeRoomEngines.button);
                    break;
                case RoomID.medbay:
                    roomSpr = new Sprite(placeRoomMedbay.button);
                    break;
                case RoomID.oxygen:
                    roomSpr = new Sprite(placeRoomOxygen.button);
                    break;
                case RoomID.pilot:
                    roomSpr = new Sprite(placeRoomPilot.button);
                    break;
                case RoomID.sensors:
                    roomSpr = new Sprite(placeRoomSensors.button);
                    break;
                case RoomID.shields:
                    roomSpr = new Sprite(placeRoomShields.button);
                    break;
                case RoomID.teleporter:
                    roomSpr = new Sprite(placeRoomTeleporter.button);
                    break;
                case RoomID.weapons:
                    roomSpr = new Sprite(placeRoomWeapons.button);
                    break;
                default:
                    break;
            }
            if (roomSpr != null)
            {
                roomSpr.Position = new Vector2f(Mouse.GetPosition(Program.app).X, Mouse.GetPosition(Program.app).Y);
                t.Draw(roomSpr);
                roomSpr.Dispose();
            }
        }
Example #40
0
File: Game.cs Project: tilpner/hp
        public void Render(RenderTarget app) {
            if (!initalized) Init(app);
            app.Clear(Color.Transparent);

            world = CalcView(app);

            app.SetView(world);
            level.Draw(app, RenderStates.Default);
            foreach (GameObject o in objects) o.Draw(this, app, RenderStates.Default);
            player.Draw(app, RenderStates.Default);

            app.SetView(gui);
            infoText.Draw(app, RenderStates.Default);

            app.SetView(world);

            frames.Tick();
			InfoText = $"FPS: {frames.CurrentRate}, PSS: {physics.CurrentRate}";
        }
Example #41
0
        public void Render(RenderTarget target)
        {
            // Fill background depending on render mode
            if (NoteManager.RenderFancy)
                target.FillRectangle(GFXResources.BackgroundGradient, new RectangleF(PointF.Empty, target.Size));
            else
                target.Clear(Color.Black);

            // Render notes and keyboard display
            lock (NoteManager.Notes)
            {
                if (NoteManager.RenderFancy)
                    NoteRenderers[1].Render(target, NoteManager.Notes, Keyboard);
                else
                    NoteRenderers[0].Render(target, NoteManager.Notes, Keyboard);
            }
            lock (Keyboard.KeyPressed)
            {
                if (NoteManager.RenderFancy)
                    KeyRenderers[1].Render(target, Keyboard.KeyPressed);
                else
                    KeyRenderers[0].Render(target, Keyboard.KeyPressed);
            }

            // Draw time progress bar
            if (sequence?.GetLength() > 0)
            {
                float percentComplete = 1f * sequencer.Position / sequence.GetLength();
                target.FillRectangle(GFXResources.DefaultBrushes[5],
                    new RectangleF(GFXResources.ProgressBarBounds.X, GFXResources.ProgressBarBounds.Y, GFXResources.ProgressBarBounds.Width * percentComplete, GFXResources.ProgressBarBounds.Height));
                target.DrawRectangle(GFXResources.DefaultBrushes[2], GFXResources.ProgressBarBounds, .8f);
            }

            // Render debug information
            string[] debug;
            string usage = Application.ProductName + " " + Application.ProductVersion + " (c) " + Application.CompanyName;
            if (ShowDebug)
            {
                debug = new[]
                {
                    usage,
                    "      file: " + MIDIFile,
                    "note_count: " + NoteManager.Notes.Count,
                    "  frames/s: " + (Kazedan.Elapsed == 0 ? "NaN" : 1000 / Kazedan.Elapsed + "") +" fps",
                    "  renderer: " + (NoteManager.RenderFancy ? "fancy" : NoteManager.UserEnabledFancy ? "forced-fast" : "fast"),
                    "  seq_tick: " + (sequence == null ? "? / ?" : sequencer.Position + " / " + sequence.GetLength()),
                    "     delay: " + Delay+"ms",
                    "       kbd: " + GFXResources.NoteCount + " key(s) +" + GFXResources.NoteOffset + " offset",
                    "   stopped: " + Stopped
                };

            }
            else
            {
                debug = new[] { usage };
            }
            string debugText = debug.Aggregate("", (current, ss) => current + ss + '\n');
            target.DrawText(debugText, GFXResources.DebugFormat, GFXResources.DebugRectangle, GFXResources.DefaultBrushes[0], DrawTextOptions.None,
                MeasuringMethod.Natural);

            // Render large title text
            if (Loading == 0)
                target.DrawText("INITIALIZING MIDI DEVICES", GFXResources.HugeFormat, GFXResources.FullRectangle, GFXResources.DefaultBrushes[0], DrawTextOptions.None, MeasuringMethod.Natural);
            else if (Loading > 0 && Loading < 100)
                target.DrawText("LOADING " + Loading + "%", GFXResources.HugeFormat, GFXResources.FullRectangle, GFXResources.DefaultBrushes[0], DrawTextOptions.None, MeasuringMethod.Natural);
        }
Example #42
0
        public void Paint(RenderTarget target)
        {
            target.BeginDraw();
            target.Transform = Matrix3x2.Identity;
            if (Fancy)
                target.FillRectangle(BackgroundGradient, new RectangleF(PointF.Empty, target.Size));
            else
                target.Clear(Color.Black);
            #region draw_notes
            lock (notes)
            {
                foreach (Note n in notes)
                {
                    float wheelOffset = (Keyboard.Pitchwheel[n.Channel] - 8192) / 8192f * 2 * KeyWidth;
                    float bottom = n.Position + n.Length;
                    float left = n.Key * KeyWidth + (bottom >= KeyboardY ? wheelOffset : 0);
                    if (Fancy)
                    {
                        NoteRoundRect.Left = left;
                        NoteRoundRect.Top = n.Position;
                        NoteRoundRect.Right = left + KeyWidth;
                        NoteRoundRect.Bottom = bottom;

                        float alpha = n.Velocity / 127f * (Keyboard.ChannelVolume[n.Channel] / 127f);
                        alpha *= alpha;
                        var gradientBrush = ChannelGradientBrushes[n.Channel];
                        gradientBrush.Opacity = alpha;
                        GradientPoint.X = NoteRoundRect.Left;
                        gradientBrush.StartPoint = GradientPoint;
                        GradientPoint.X = NoteRoundRect.Right;
                        gradientBrush.EndPoint = GradientPoint;
                        target.FillRoundedRectangle(ChannelGradientBrushes[n.Channel], NoteRoundRect);
                    }
                    else
                    {
                        NoteRect.X = left;
                        NoteRect.Y = n.Position;
                        NoteRect.Width = KeyWidth;
                        NoteRect.Height = n.Length;
                        target.FillRectangle(ChannelBrushes[n.Channel], NoteRect);
                    }
                }
            }
            #endregion

            Keyboard.Render(target);

            // Draw time progress bar
            if (sequence?.GetLength() > 0)
            {
                float percentComplete = 1f*sequencer.Position/sequence.GetLength();
                target.FillRectangle(DefaultBrushes[5],
                    new RectangleF(ProgressBarBounds.X, ProgressBarBounds.Y, ProgressBarBounds.Width*percentComplete, ProgressBarBounds.Height));
                target.DrawRectangle(DefaultBrushes[2], ProgressBarBounds, .8f);
            }


            string[] debug =
            {
                "      file: " + MIDIFile,
                "note_count: " + notes.Count,
                "  renderer: " + (Fancy ? "fancy" : UserFancy ? "forced-fast" : "fast"),
                "      note: " + (sequence == null ? "? / ?" : sequencer.Position + " / " + sequence.GetLength()),
                "     delay: " + Delay
            };
            string debugText = debug.Aggregate("", (current, ss) => current + ss + '\n');
            target.DrawText(debugText, DebugFormat, DebugRectangle, DefaultBrushes[0], DrawTextOptions.None, MeasuringMethod.Natural);

            if (Loading == 0)
                target.DrawText("INITIALIZING MIDI DEVICES", HugeFormat, FullRectangle, DefaultBrushes[0], DrawTextOptions.None, MeasuringMethod.Natural);
            else if (Loading > 0)
                target.DrawText("LOADING " + Loading + "%", HugeFormat, FullRectangle, DefaultBrushes[0], DrawTextOptions.None, MeasuringMethod.Natural);
            target.EndDraw();
        }