Beispiel #1
0
        protected override void DrawText(Object dev, String text, String text2 = null, int alpha = 0)
        {
            Device device = (Device)dev;

            if (_font == null)
            {
                _font = new SlimDX.Direct3D9.Font(device, new System.Drawing.Font("Lucida Console", 10.0f));
            }

            if (screenHeight == 0 | screenWidth == 0)
            {
                using (Surface backBuffer = device.GetBackBuffer(0, 0))
                {
                    screenWidth  = backBuffer.Description.Width;
                    screenHeight = backBuffer.Description.Height;
                }
            }

            _font.DrawString(null,
                             text,
                             new Rectangle(0, 0, screenWidth, screenHeight),
                             DrawTextFormat.Top | DrawTextFormat.Right,
                             System.Drawing.Color.Red);


            if (alpha > 0)
            {
                Color c = Color.FromArgb(alpha, System.Drawing.Color.Red);
                _font.DrawString(null,
                                 text2,
                                 new Rectangle(0, 15, screenWidth, screenHeight - 15),
                                 DrawTextFormat.Top | DrawTextFormat.Right,
                                 c);
            }
        }
Beispiel #2
0
        public void OnMainLoop(object sender, EventArgs e)
        {
            _sprite.Begin(Dx9.SpriteFlags.AlphaBlend);

            _font.DrawString(_sprite, "Hello World", 0, 0, SD.Color.White);
            _sprite.Draw(_circleTexture, Vector3.Zero, _mousePosition, new Color4(SD.Color.White));

            _sprite.End();

            using (Dx9.Sprite s = new Dx9.Sprite(_control.Device))
            {
                s.Begin(Dx9.SpriteFlags.AlphaBlend);

                s.Draw(_texture, Vector3.Zero, Vector3.Zero, new Color4(SD.Color.White));

                UpdateCamera();

                s.End();
            }

            _shipSprite.Begin(Dx9.SpriteFlags.AlphaBlend);

            Matrix matrix = Matrix.Transformation2D(new Vector2(0, 0), 0.0f, new Vector2(1f, 1f),
                                                    new Vector2(_shipVector3.X + 100f, _shipVector3.Y + 100f), _rotation, new Vector2(0f, 0f));

            _shipSprite.Transform = matrix;

            _shipSprite.Draw(_shipTexture, Vector3.Zero, _shipVector3, SD.Color.White);

            UpdateCamera();
            _shipSprite.End();
        }
Beispiel #3
0
        public override Result Render()
        {
            Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
            if (Device.BeginScene().IsSuccess&& MainWindow != null)
            {
                if (_hmRenderer != null)
                {
                    _hmRenderer.Render();
                }

                var rs = new[] {
                    new Rectangle(10, 10, 0, 0),
                    new Rectangle(10, 30, 0, 0),
                    new Rectangle(10, 50, 0, 0),
                    new Rectangle(10, 70, 0, 0)
                };

                Font.DrawString(null, String.Format("Arrows: Move camera"), rs[0], DrawTextFormat.Left | DrawTextFormat.Top | DrawTextFormat.NoClip, Color.White);
                Font.DrawString(null, String.Format("WASD: Move selection"), rs[1], DrawTextFormat.Left | DrawTextFormat.Top | DrawTextFormat.NoClip, Color.White);
                Font.DrawString(null, String.Format("+/-: Raise/Lower terrain"), rs[2], DrawTextFormat.Left | DrawTextFormat.Top | DrawTextFormat.NoClip, Color.White);
                Font.DrawString(null, String.Format("Space: Smooth terrain"), rs[3], DrawTextFormat.Left | DrawTextFormat.Top | DrawTextFormat.NoClip, Color.White);
                Device.EndScene();
                Device.Present();
            }
            return(ResultCode.Success);
        }
Beispiel #4
0
 public void Print(int x, int y, string text, Color color)
 {
     if (_font != null)
     {
         _font.DrawString(null, text, x, y, color);
     }
 }
Beispiel #5
0
        public virtual void Render()
        {
            try
            {
                if (deviceLost)
                {
                    ReinitializeRenderer();
                    return;
                }
                if (isInitialized && !isRendering && (swapChain != null))
                {
                    isRendering = true;
                    using (Surface surface = swapChain.GetBackBuffer(0))
                    {
                        Device.SetRenderTarget(0, surface);
                    }

                    Light light = this.Device.GetLight(0);
                    light.Direction = camera.Direction;
                    Device.SetLight(0, light);

                    Device.SetTransform(TransformState.View, camera.View);
                    Device.SetTransform(TransformState.Projection, camera.Projection);

                    Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Background, 1.0f, 0);
                    Device.BeginScene();

                    foreach (var pair in renderObjects)
                    {
                        pair.Value.Render();
                    }

                    if (mouseDown != MouseButtons.None)
                    {
                        DrawCursor();
                        DrawAxes();

                        string camStr = "(" + camera.target.X.ToString("0.##") + ", " + camera.target.Y.ToString("0.##") + ", " + camera.target.Z.ToString("0.##") + ")";
                        TextFont.DrawString(null, camStr, renderRect, DrawTextFormat.Right | DrawTextFormat.Top, TextColor);
                    }

                    Device.EndScene();
                    swapChain.Present(Present.None, renderRect, renderRect, renderControl.Handle);

                    isRendering = false;
                }
            }
            catch
            {
                isInitialized = false;
                isRendering   = false;
                ReinitializeRenderer();
                isInitialized = true;
                if (!deviceLost)
                {
                    Render();
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="text"></param>
        /// <param name="position"></param>
        /// <param name="color"></param>
        public void Draw(string text, BomberStuff.Core.Drawing.PointF position, System.Drawing.Color color)
        {
            int            x      = (int)(position.X * Form.ClientSize.Width);
            int            y      = (int)(position.Y * Form.ClientSize.Height);
            Rectangle      rect   = new Rectangle(x - 1, y - 1, 2, 2);
            DrawTextFormat format = DrawTextFormat.Center | DrawTextFormat.VerticalCenter | DrawTextFormat.NoClip;

            d3dFont.DrawString(Sprite, text, rect, format, color);
        }
Beispiel #7
0
        public Vec2 AddTextWithHeight(Vec2 pos, string text, Color color, int height, DrawTextFormat format)
        {
            SlimDX.Direct3D9.Font font      = this.GetFont(height);
            Rectangle             rectangle = font.MeasureString(this.textSprite, text, format);

            rectangle.X += pos.X;
            rectangle.Y += pos.Y;
            font.DrawString(this.textSprite, text, rectangle, format, color);
            return(new Vec2(rectangle.Width, rectangle.Height));
        }
Beispiel #8
0
        private void DrawText(string text)
        {
            int       numberOfLines = text.Split('\n').Length;
            int       bgHeight      = TEXT_SIZE * numberOfLines;
            Rectangle rcTextField   = new Rectangle(RENDER_OFFSET_LEFT, 0, SkinContext.BackBufferWidth - RENDER_OFFSET_LEFT, bgHeight);

            _fontSprite.Begin(SpriteFlags.AlphaBlend);
            _font.DrawString(_fontSprite, text, rcTextField, DrawTextFormat.Left, Color.Red);
            _fontSprite.End();
        }
Beispiel #9
0
        public void Write(string text)
        {
            if (dirty)
            {
                CreateFont();
            }

            device.DrawPrimitives(PrimitiveType.LineList, 0, 1);
            font.DrawString(sprite, text, Location.X, Location.Y, ForegroundColor);
        }
Beispiel #10
0
 public static void x()
 {
     using (SlimDX.Direct3D9.Font font = new SlimDX.Direct3D9.Font(device, new System.Drawing.Font("Times New Roman", 16.0f)))
     {
         if (_lastFrame != null)
         {
             font.DrawString(null, String.Format("{0:N1} fps", (1000.0 / (DateTime.Now - _lastFrame.Value).TotalMilliseconds)), 100, 100, System.Drawing.Color.Red);
         }
         _lastFrame = DateTime.Now;
     }
 }
Beispiel #11
0
        public void DrawString(Vector2 position, string text, Color color, float emSize)
        {
            Matrix matScale = Matrix.Scaling(emSize / 30.0f, emSize / 30.0f, 1);
            var    sprite   = FontManager.Sprite;

            var oldTransform = sprite.Transform;

            sprite.Transform = matScale * Matrix.Translation(position.X, position.Y, 0);

            mBaseFont.DrawString(sprite, text, 0, 0, color);

            sprite.Transform = oldTransform;
        }
        public void DrawString(int x, int y, Color4 color, SlimDX.Direct3D9.DrawTextFormat format, string text, SlimDX.Direct3D9.Font MenuFont)
        {
            Rectangle fontPos = new Rectangle();

            fontPos.X      = x;
            fontPos.Y      = y;
            fontPos.Width  = x + 120;
            fontPos.Height = y + 16;

            if (MenuFont != null)
            {
                MenuFont.DrawString(null, text, fontPos, format, color);
            }
        }
Beispiel #13
0
        public Vec2 AddTextWithHeightAndOutline(Vec2 pos, string text, Color color, Color outLine, int height, DrawTextFormat format, int outlineOsset = 1)
        {
            SlimDX.Direct3D9.Font font      = this.GetFont(height);
            Rectangle             rectangle = font.MeasureString(this.textSprite, text, format);

            rectangle.X += pos.X;
            rectangle.Y += pos.Y;

            rectangle.X -= 1 * outlineOsset;
            rectangle.Y -= 1 * outlineOsset;
            font.DrawString(this.textSprite, text, rectangle, format, outLine);
            rectangle.Y += 2 * outlineOsset;
            font.DrawString(this.textSprite, text, rectangle, format, outLine);
            rectangle.X += 2 * outlineOsset;
            font.DrawString(this.textSprite, text, rectangle, format, outLine);
            rectangle.Y -= 2 * outlineOsset;
            font.DrawString(this.textSprite, text, rectangle, format, outLine);

            rectangle.X -= 1 * outlineOsset;
            rectangle.Y += 1 * outlineOsset;
            font.DrawString(this.textSprite, text, rectangle, format, color);
            return(new Vec2(rectangle.Width, rectangle.Height));
        }
Beispiel #14
0
        private void AddLine(string text)
        {
            Rectangle stringSizeRect = new Rectangle();

            DisplayFontBold.MeasureString(null, text, DrawTextFormat.Center, ref stringSizeRect);

            DisplayFontNormal.DrawString(null, text, TextShadowRect, DrawTextFormat.Left | DrawTextFormat.Top, (int)ShadowColor);
            DisplayFontNormal.DrawString(null, text, TextRect, DrawTextFormat.Left | DrawTextFormat.Top, (int)TextColor);

            TextRect.Y       += FontSizeRect.Height;
            TextShadowRect.Y += FontSizeRect.Height;

            if (stringSizeRect.Width > Width)
            {
                Width = stringSizeRect.Width;
                Panel.ExpandDock(this);
            }

            if (TextRect.Y > Height)
            {
                Height = TextRect.Y;
                Panel.ExpandDock(this);
            }
        }
Beispiel #15
0
        public override Result Render()
        {
            Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);

            if (Device.BeginScene().IsSuccess&& MainWindow != null)
            {
                var r = MainWindow.ClientRectangle;

                Font.DrawString(null, "Hello World!", r, DrawTextFormat.Center | DrawTextFormat.NoClip | DrawTextFormat.VerticalCenter, Color.White);

                Device.EndScene();
                Device.Present();
            }
            return(ResultCode.Success);
        }
Beispiel #16
0
        /// <summary> Draws text. </summary>
        /// <param name="text">      The text. </param>
        /// <param name="x">         The x coordinate. </param>
        /// <param name="y">         The y coordinate. </param>
        /// <param name="color">     The color. </param>
        /// <param name="emSize">    (optional) size of the em. </param>
        /// <param name="fontStyle"> (optional) the font style. </param>
        public static void DrawText(string text, int x, int y, Color color, float emSize = 12f, FontStyle fontStyle = FontStyle.Regular)
        {
            if (_fontSprite == null)
            {
                _fontSprite = new Sprite(Device);
            }

            _fontSprite.Begin(SpriteFlags.AlphaBlend);
            using (Font font = new Font(Device, new System.Drawing.Font(FontFamily.GenericMonospace, emSize, fontStyle)))
            {
                Rectangle stringRect = font.MeasureString(_fontSprite, text, DrawTextFormat.Left);
                Rectangle rect       = new Rectangle(x, y, stringRect.Width + 1, stringRect.Height + 1);

                font.DrawString(_fontSprite, text, rect, DrawTextFormat.Left, color.ToArgb());
                _fontSprite.End();
            }
        }
Beispiel #17
0
        public override bool Render()
        {
            switch (State)
            {
            case ButtonState.OffNone:
                Texture = _offNoneTexture;
                break;

            case ButtonState.OffFocus:
                Texture = _offFocusTexture;
                break;

            case ButtonState.OffHover:
                Texture = _offHoverTexture;
                break;

            case ButtonState.OffDown:
                Texture = _offDownTexture;
                break;

            case ButtonState.OnNone:
                Texture = _onNoneTexture;
                break;

            case ButtonState.OnFocus:
                Texture = _onFocusTexture;
                break;

            case ButtonState.OnHover:
                Texture = _onHoverTexture;
                break;

            case ButtonState.OnDown:
                Texture = _onDownTexture;
                break;

            default:
                throw new Exception("Invalid switch statement value.");
            }
            var result = base.Render();

            _font.DrawString(null, Caption, Location.X + 10, Location.Y + 10, Color);

            return(result);
        }
Beispiel #18
0
        public void OnRender(float framesPerSecond)
        {
            if (_isEnabled == false)
            {
                return;
            }

            fontSprite.Begin(SlimDX.Direct3D9.SpriteFlags.AlphaBlend);

            if (fps != framesPerSecond)
            {
                fps        = framesPerSecond;
                textString = string.Format("FPS: {0}\n{1}", fps.ToString("0.00", culture), _text);
            }
            font.DrawString(fontSprite, textString, 0, 0, color);

            fontSprite.End();
        }
Beispiel #19
0
        public override Result Render()
        {
            Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
            if (Device.BeginScene().IsSuccess&& MainWindow != null)
            {
                if (_hmRenderer != null)
                {
                    _hmRenderer.Render();
                }

                Font.DrawString(null, String.Format("Size: {0} \t(UP/DOWN Arrow)", _size), new Rectangle(110, 10, 0, 0), DrawTextFormat.Left | DrawTextFormat.Top | DrawTextFormat.NoClip, Color.White);
                Font.DrawString(null, String.Format("Persistence: {0} \t(Left/Right Arrow)", _amplitude), new Rectangle(110, 30, 0, 0), DrawTextFormat.Left | DrawTextFormat.Top | DrawTextFormat.NoClip, Color.White);
                Font.DrawString(null, String.Format("Redraw: (SPACE)"), new Rectangle(110, 50, 0, 0), DrawTextFormat.Left | DrawTextFormat.Top | DrawTextFormat.NoClip, Color.White);
                Device.EndScene();
                Device.Present();
            }
            return(ResultCode.Success);
        }
Beispiel #20
0
        public override Result Render()
        {
            Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);

            if (Device.BeginScene().IsSuccess&& MainWindow != null)
            {
                if (_hmRenderer != null)
                {
                    _hmRenderer.Render();
                }

                var r = MainWindow.ClientRectangle;

                Font.DrawString(null, "Space: Change Image", r, DrawTextFormat.Left | DrawTextFormat.NoClip | DrawTextFormat.Top, Color.White);

                Device.EndScene();
                Device.Present();
            }
            return(ResultCode.Success);
        }
Beispiel #21
0
        private void DxThread()
        {
            const int y = 10;
            const int x = 10;

            while (true)
            {
                _device.Clear(ClearFlags.Target, Color.FromArgb(0, 0, 0, 0), 1.0f, 0);
                _device.SetRenderState(RenderState.ZEnable, false);
                _device.SetRenderState(RenderState.Lighting, false);
                _device.SetRenderState(RenderState.CullMode, 1);
                _device.SetTransform(0, Matrix.OrthoOffCenterLH(0, Width, Height, 0, 0, 1));
                _device.BeginScene();

                _font.DrawString(null, "STRING", x, y, Color.Aqua);

                _device.EndScene();
                _device.Present();
                Thread.Sleep(16);
            }
        }
 internal void DrawString2D(string Text, int X, int Y, System.Drawing.Color Color)
 {
     _font.DrawString(null, Text, X, Y, (SlimDX.Color4)Color);
 }
Beispiel #23
0
        /// <summary>
        /// Hook for IDirect3DDevice9.EndScene
        /// </summary>
        /// <param name="devicePtr">Pointer to the IDirect3DDevice9 instance. Note: object member functions always pass "this" as the first parameter.</param>
        /// <returns>The HRESULT of the original EndScene</returns>
        /// <remarks>Remember that this is called many times a second by the Direct3D application - be mindful of memory and performance!</remarks>
        int EndSceneHook(IntPtr devicePtr)
        {
            using (Device device = Device.FromPointer(devicePtr))
            {
                // If you need to capture at a particular frame rate, add logic here decide whether or not to skip the frame
                try
                {
                    #region Screenshot Request
                    // Is there a screenshot request? If so lets grab the backbuffer
                    lock (_lockRenderTarget)
                    {
                        if (Request != null)
                        {
                            _lastRequestTime = DateTime.Now;
                            DateTime start = DateTime.Now;
                            try
                            {
                                // First ensure we have a Surface to the render target data into
                                if (_renderTarget == null)
                                {
                                    // Create offscreen surface to use as copy of render target data
                                    using (SwapChain sc = device.GetSwapChain(0))
                                    {
                                        _renderTarget = Surface.CreateOffscreenPlain(device, sc.PresentParameters.BackBufferWidth, sc.PresentParameters.BackBufferHeight, sc.PresentParameters.BackBufferFormat, Pool.SystemMemory);
                                    }
                                }

                                #region Prepare lines for overlay
                                if (this.Request.RegionToCapture.Width == 0)
                                {
                                    _lineVectors = new SlimDX.Vector2[] {
                                        new SlimDX.Vector2(0, 0),
                                        new SlimDX.Vector2(_renderTarget.Description.Width - 1, _renderTarget.Description.Height - 1),
                                        new SlimDX.Vector2(0, _renderTarget.Description.Height - 1),
                                        new SlimDX.Vector2(_renderTarget.Description.Width - 1, 0),
                                        new SlimDX.Vector2(0, 0),
                                        new SlimDX.Vector2(0, _renderTarget.Description.Height - 1),
                                        new SlimDX.Vector2(_renderTarget.Description.Width - 1, _renderTarget.Description.Height - 1),
                                        new SlimDX.Vector2(_renderTarget.Description.Width - 1, 0),
                                    };
                                }
                                else
                                {
                                    _lineVectors = new SlimDX.Vector2[] {
                                        new SlimDX.Vector2(this.Request.RegionToCapture.X, this.Request.RegionToCapture.Y),
                                        new SlimDX.Vector2(this.Request.RegionToCapture.Right, this.Request.RegionToCapture.Bottom),
                                        new SlimDX.Vector2(this.Request.RegionToCapture.X, this.Request.RegionToCapture.Bottom),
                                        new SlimDX.Vector2(this.Request.RegionToCapture.Right, this.Request.RegionToCapture.Y),
                                        new SlimDX.Vector2(this.Request.RegionToCapture.X, this.Request.RegionToCapture.Y),
                                        new SlimDX.Vector2(this.Request.RegionToCapture.X, this.Request.RegionToCapture.Bottom),
                                        new SlimDX.Vector2(this.Request.RegionToCapture.Right, this.Request.RegionToCapture.Bottom),
                                        new SlimDX.Vector2(this.Request.RegionToCapture.Right, this.Request.RegionToCapture.Y),
                                    };
                                }
                                #endregion

                                using (Surface backBuffer = device.GetBackBuffer(0, 0))
                                {
                                    // Create a super fast copy of the back buffer on our Surface
                                    device.GetRenderTargetData(backBuffer, _renderTarget);

                                    // We have the back buffer data and can now work on copying it to a bitmap
                                    ProcessRequest();
                                }
                            }
                            finally
                            {
                                // We have completed the request - mark it as null so we do not continue to try to capture the same request
                                // Note: If you are after high frame rates, consider implementing buffers here to capture more frequently
                                //         and send back to the host application as needed. The IPC overhead significantly slows down
                                //         the whole process if sending frame by frame.
                                Request = null;
                            }
                            DateTime end = DateTime.Now;
                            this.DebugMessage("EndSceneHook: Capture time: " + (end - start).ToString());
                            _lastScreenshotTime = (end - start);
                        }
                    }
                    #endregion

                    #region Example: Draw Overlay (after screenshot so we don't capture overlay as well)

                    if (this.ShowOverlay)
                    {
                        #region Draw fading lines based on last screencapture request
                        if (_lastRequestTime != null && _lineVectors != null)
                        {
                            TimeSpan timeSinceRequest = DateTime.Now - _lastRequestTime.Value;
                            if (timeSinceRequest.TotalMilliseconds < 1000.0)
                            {
                                using (Line line = new Line(device))
                                {
                                    _lineAlpha     = (float)((1000.0 - timeSinceRequest.TotalMilliseconds) / 1000.0); // This is our fade out
                                    line.Antialias = true;
                                    line.Width     = 1.0f;
                                    line.Begin();
                                    line.Draw(_lineVectors, new SlimDX.Color4(_lineAlpha, 0.5f, 0.5f, 1.0f));
                                    line.End();
                                }
                            }
                            else
                            {
                                _lineVectors = null;
                            }
                        }
                        #endregion

                        #region Draw frame rate
                        using (SlimDX.Direct3D9.Font font = new SlimDX.Direct3D9.Font(device, new System.Drawing.Font("Times New Roman", 16.0f)))
                        {
                            if (_lastFrame != null)
                            {
                                font.DrawString(null, String.Format("{0:N1} fps", (1000.0 / (DateTime.Now - _lastFrame.Value).TotalMilliseconds)), 100, 100, System.Drawing.Color.Red);
                            }
                            _lastFrame = DateTime.Now;
                        }
                        #endregion
                    }

                    #endregion
                }
                catch (Exception e)
                {
                    // If there is an error we do not want to crash the hooked application, so swallow the exception
                    this.DebugMessage("EndSceneHook: Exeception: " + e.GetType().FullName + ": " + e.Message);
                }

                // EasyHook has already repatched the original EndScene - so calling EndScene against the SlimDX device will call the original
                // EndScene and bypass this hook. EasyHook will automatically reinstall the hook after this hook function exits.
                return(device.EndScene().Code);
            }
        }
Beispiel #24
0
        public void Render()
        {
            lock (m_csLock)
            {
                countElapsed++;
                if (countElapsed == 50)
                {
                    elapsed = (DateTime.Now.Ticks - elapsed);
                    TimeSpan elapsedSpan = new TimeSpan(elapsed);
                    fps          = (float)50f / ((float)elapsedSpan.TotalSeconds);
                    fps          = (int)fps;
                    elapsed      = DateTime.Now.Ticks;
                    countElapsed = 0;
                }

                m_Device.SetRenderTarget(0, m_RenderTarget);
                m_Device.Clear(ClearFlags.Target, Color.Blue, 1.0f, 0);
                Surface _backbuffer = m_Device.GetBackBuffer(0, 0);

                m_Device.BeginScene();

                float w = _backbuffer.Description.Width;
                float h = _backbuffer.Description.Height;

                //Surface tex = m_tex.GetSurfaceLevel(0);
                //m_Device.StretchRectangle(leftImage, tex, TextureFilter.Linear);
                //tex.Dispose();

                m_Device.SetRenderTarget(0, m_RenderTarget);

                float a = 2.0f * h / w;

                float aspectRatioValue = 640.0f / 800.0f;

                //Vertex[] lverts = { new Vertex(0, 0, 1, 0.5f, -1, -a), new Vertex(w / 2, 0, 1, 0.5f, 1, -a), new Vertex(0, h, 1, 0.5f, -1, a), new Vertex(w / 2, h, 1, 0.5f, 1, a) };
                //Vertex[] rverts = { new Vertex(w / 2, 0, 1, 0.5f, -1, -a), new Vertex(w, 0, 1, 0.5f, 1, -a), new Vertex(w / 2, h, 1, 0.5f, -1, a), new Vertex(w, h, 1, 0.5f, 1, a) };
                float z = 1.0f;

                Vertex[] lverts = { new Vertex(0, 0, z, 0.5f, 0, 0), new Vertex(w / 2, 0, z, 0.5f, 1, 0), new Vertex(0, h, z, 0.5f, 0, 1), new Vertex(w / 2, h, z, 0.5f, 1, 1) };
                Vertex[] rverts = { new Vertex(w / 2, 0, z, 0.5f, 0, 0), new Vertex(w, 0, z, 0.5f, 1, 0), new Vertex(w / 2, h, z, 0.5f, 0, 1), new Vertex(w, h, z, 0.5f, 1, 1) };
                //Vertex[] vertsices = { new Vertex(0, 0, z, 0.5f, 0, 0), new Vertex(w, 0, z, 0.5f, 1, 0), new Vertex(0, h, z, 0.5f, 0, 1), new Vertex(w, h, z, 0.5f, 1, 1) };
                m_Device.VertexFormat = VertexFormat.PositionRhw | VertexFormat.Texture1;
                m_Device.SetTextureStageState(0, TextureStage.ColorOperation, TextureOperation.SelectArg1);
                m_Device.SetTextureStageState(0, TextureStage.ColorArg1, TextureArgument.Texture);
                m_Device.SetRenderState(RenderState.CullMode, Cull.None);
                m_Device.SetRenderState(RenderState.ZFunc, Compare.Always);

                //m_Device.SetTexture(0, leftTex);
                //m_Device.SetTexture(1, rightTex);
                m_Device.SetSamplerState(0, SamplerState.BorderColor, 0x00000000);
                m_Device.SetSamplerState(0, SamplerState.AddressU, TextureAddress.Border);
                m_Device.SetSamplerState(0, SamplerState.AddressV, TextureAddress.Border);

                /*
                 * EffectHandle hmdWarpParam = m_distortionEffect.GetParameter(null, "HmdWarpParam");
                 * EffectHandle texCoordOffset = m_distortionEffect.GetParameter(null, "TexCoordOffset");
                 * EffectHandle tcScaleMat = m_distortionEffect.GetParameter(null, "TCScaleMat");
                 * EffectHandle aspectRatio = m_distortionEffect.GetParameter(null, "AspectRatio");
                 * EffectHandle scale = m_distortionEffect.GetParameter(null, "Scale");
                 * EffectHandle pupilOffset = m_distortionEffect.GetParameter(null, "PupilOffset");
                 */
                EffectHandle hmdWarpParam     = m_distortionEffect.GetParameter(null, "HmdWarpParam");
                EffectHandle lensCenterOffset = m_distortionEffect.GetParameter(null, "LensCenterOffset");
                EffectHandle aspectRatio      = m_distortionEffect.GetParameter(null, "AspectRatio");
                EffectHandle scale            = m_distortionEffect.GetParameter(null, "Scale");


                //m_font.DrawString(null, "Hello", 200+640, 200, Color.White);

                for (int j = 0; j < 2; j++)
                {
                    Vertex[] verts;

                    if (j == 0)
                    {
                        verts = lverts;
                        m_Device.SetTexture(0, leftTex);
                    }
                    else
                    {
                        verts = rverts;
                        m_Device.SetTexture(0, rightTex);
                    }

                    //verts = vertsices;
                    float texCoordOffsetValue = ((j == 0) ^ !!m_swap) ? 0.0f : 0.5f;
                    //Vector4 scaleMat = (j == 0) ? (new Vector4(0.0f, -1.0f, 1.0f, 0.0f)) : (new Vector4(0.0f, 1.0f, -1.0f, 0.0f));
                    Vector4 scaleMat              = new Vector4(1.0f, 0.0f, 0.0f, 1.0f);
                    float   pupilOffsetValue      = (j == 0) ? m_pupilOffset : -m_pupilOffset;
                    float   lensCenterOffsetValue = (j == 0) ? -m_lensCenterOffset : m_lensCenterOffset;
                    int     numPasses             = m_distortionEffect.Begin();
                    for (int i = 0; i < numPasses; i++)
                    {
                        m_distortionEffect.BeginPass(i);

                        /*
                         * m_distortionEffect.SetValue(hmdWarpParam, new Vector4(1.0f, 0.22f, 0.24f, 0.0f));
                         * m_distortionEffect.SetValue(tcScaleMat, scaleMat);
                         * m_distortionEffect.SetValue(texCoordOffset, new Vector2(texCoordOffsetValue, 0.0f));
                         * m_distortionEffect.SetValue(scale, new Vector2(0.25f / m_scale, 0.5f / m_scale));
                         * m_distortionEffect.SetValue(aspectRatio, aspectRatioValue);
                         * m_distortionEffect.SetValue(pupilOffset, pupilOffsetValue);
                         */
                        m_distortionEffect.SetValue(hmdWarpParam, new Vector4(1.0f, 0.22f, 0.24f, 0.0f));
                        m_distortionEffect.SetValue(lensCenterOffset, lensCenterOffsetValue);
                        m_distortionEffect.SetValue(scale, new Vector2(m_scale, m_scale));
                        m_distortionEffect.SetValue(aspectRatio, aspectRatioValue);
                        m_Device.DrawUserPrimitives <Vertex>(PrimitiveType.TriangleStrip, 2, verts);
                        m_font.DrawString(null, "Scale: " + m_scale.ToString(), 0, 0, Color.Green);
                        m_font.DrawString(null, "Lens Offset: " + m_lensCenterOffset.ToString(), 0, 50, Color.Green);
                        m_font.DrawString(null, "FPS: " + fps.ToString(), 0, 100, Color.Green);
                        m_font.DrawString(null, "Left cam FPS: " + c1fps.ToString(), 0, 150, Color.Green);
                        m_font.DrawString(null, "Right cam FPS: " + c2fps.ToString(), 0, 200, Color.Green);
                        m_distortionEffect.EndPass();
                    }
                    m_distortionEffect.End();
                }

                m_Device.EndScene();
                m_Device.Present();
            }
        }
        // Called every frame from the DirectX API. We draw our overlay here (on top of everything).
        int EndSceneHook(IntPtr devicePtr)
        {
            // Used to debug whether or not the EndScene is called.
            if (!EndSceneCalled)
            {
                EndSceneCalled = true;
                Interface.Debug("EndScene called successfully!");
            }

            using (Device device = Device.FromPointer(devicePtr))
            {
                // Retrieve the current time.
                DateTime now = DateTime.Now;

                // Retrieve the width and height of the surface.
                int width, height = 0;
                using (Surface renderTargetTemp = device.GetRenderTarget(0))
                {
                    width  = renderTargetTemp.Description.Width;
                    height = renderTargetTemp.Description.Height;

                    _renderTarget = renderTargetTemp;
                }

                // Re-calculate overlay position and dimension if the width or height changes.
                if (PreviousWidth != width || PreviousHeight != height)
                {
                    // Refresh position and dimension.
                    CalculatePositions(width, height);
                    PreviousWidth  = width;
                    PreviousHeight = height;

                    // Reset font.
                    OverlayFont = null;
                }

                try
                {
                    // Render a success message to indicate that the overlay was added successfully.
                    long millisSinceAdd = (now - TimeAdded).Ticks / TimeSpan.TicksPerMillisecond;
                    if (millisSinceAdd < SuccessMessageTime)
                    {
                        // Scale the font to the current resolution.
                        using (SlimDX.Direct3D9.Font successFont = new SlimDX.Direct3D9.Font(device, new System.Drawing.Font("Times New Roman", 80.0f / 1920f * width)))
                        {
                            // Draw the font with an alpha value related to the time passed since the overlay was added. The font will be completely invisible when the time has passed.
                            successFont.DrawString(null, "Overlay added!", 50, 50, Color.FromArgb((int)((SuccessMessageTime - millisSinceAdd) / SuccessMessageTime * 255.0), TextColor));
                        }
                    }

                    // Don't render the overlay if it's in auto hide mode and hidden.
                    if (!Hide || !AutoHide)
                    {
                        // Refresh the font if the settings has been changed or create a font if null.
                        if (OverlayFont == null || !FontName.Equals(LastFontName) || LastMessagesShown != MessagesShown || AutoMessageHeight != LastAutoMessageHeight || MessageHeight != LastMessageHeight)
                        {
                            LastFontName          = FontName;
                            LastMessagesShown     = MessagesShown;
                            LastAutoMessageHeight = AutoMessageHeight;
                            LastMessageHeight     = MessageHeight;
                            LoadFont(device);
                        }

                        // Draw the last messages received. Amount defined by MessagesShown.
                        int y = MessagesShown - 1;
                        int i = Messages.Count - 1;
                        while (y >= 0)
                        {
                            // Abort the loop if there are no more messages available.
                            if (!(i >= Math.Max(0, Messages.Count - MessagesShown)))
                            {
                                break;
                            }

                            Message message = Messages[i];

                            // Wrap the message if it has not been done yet or the font/dimensions has been changed.
                            if (!OverlayFont.Equals(message.FontUsed))
                            {
                                message.WrapMessage(OverlayFont, AvailableTextWidth);
                            }

                            // Store the original text color.
                            Color drawColor = TextColor;

                            // Keep track of whether to draw the shadow or not (The shadow will not be drawn when fading).
                            Boolean drawShadow = true;

                            // Fade the color if in the fading phase.
                            if (FadeMessages && message.Time.AddSeconds(FadeWait) <= now)
                            {
                                if (message.Time.AddSeconds(FadeWait + FadeDuration) <= now)
                                {
                                    // The message has already been faded, don't display it.
                                    i--;
                                    continue;
                                }

                                // Fade the color according to the duration and delay of the fade.
                                float fadeDuration   = (message.Time.AddSeconds(FadeWait + FadeDuration) - message.Time.AddSeconds(FadeWait)).Ticks / TimeSpan.TicksPerMillisecond;
                                float fadeProgress   = (now - message.Time.AddSeconds(FadeWait)).Ticks / TimeSpan.TicksPerMillisecond;
                                float fadePercentage = fadeProgress / fadeDuration;
                                drawColor  = Color.FromArgb((int)((1f - fadePercentage) * 255), drawColor);
                                drawShadow = false;
                            }

                            // Draw the wrapped message from the bottom.
                            for (int j = message.WrappedMessage.Length - 1; j >= 0 && y >= 0; j--)
                            {
                                // Calculate the y position for the string.
                                int stringY = TextStartHeight + (TextEndHeight - TextStartHeight) / MessagesShown * y;

                                if (drawShadow)
                                {
                                    OverlayFont.DrawString(null, message.WrappedMessage[j], TextStartWidth + FontHeight / 2 + message.SenderWidth, stringY + 1, TextShadowColor);
                                }

                                OverlayFont.DrawString(null, message.WrappedMessage[j], TextStartWidth - 1 + FontHeight / 2 + message.SenderWidth, stringY, drawColor);

                                // Only draw the sender on the upmost line.
                                if (j == 0)
                                {
                                    if (drawShadow)
                                    {
                                        OverlayFont.DrawString(null, message.Sender + ": ", TextStartWidth, stringY + 1, TextShadowColor);
                                    }

                                    OverlayFont.DrawString(null, message.Sender + ": ", TextStartWidth - 1, stringY, drawColor);
                                }
                                y--;
                            }

                            i--;
                        }
                    }
                }
                catch
                {
                    // Don't crash the hooked application if an exception is thrown.
                }

                // EasyHook has already repatched the original EndScene so we will not loop our method forever.
                return(device.EndScene().Code);
            }
        }
Beispiel #26
0
        /// <summary>
        /// Hook for IDirect3DDevice9.EndScene
        /// </summary>
        /// <param name="devicePtr">Pointer to the IDirect3DDevice9 instance. Note: object member functions always pass "this" as the first parameter.</param>
        /// <returns>The HRESULT of the original EndScene</returns>
        /// <remarks>Remember that this is called many times a second by the Direct3D application - be mindful of memory and performance!</remarks>
        int EndSceneHook(IntPtr devicePtr)
        {
            using (Device device = Device.FromPointer(devicePtr))
            {
                // If you need to capture at a particular frame rate, add logic here decide whether or not to skip the frame
                try
                {
                    #region Screenshot Request
                    // Is there a screenshot request? If so lets grab the backbuffer
                    lock (_lockRenderTarget)
                    {
                        if (Request != null)
                        {
                            _lastRequestTime = DateTime.Now;
                            DateTime start = DateTime.Now;
                            try
                            {
                                // First ensure we have a Surface to the render target data into
                                if (_renderTarget == null)
                                {
                                    // Create offscreen surface to use as copy of render target data
                                    using (SwapChain sc = device.GetSwapChain(0))
                                    {
                                        _renderTarget = Surface.CreateOffscreenPlain(device, sc.PresentParameters.BackBufferWidth, sc.PresentParameters.BackBufferHeight, sc.PresentParameters.BackBufferFormat, Pool.SystemMemory);
                                    }
                                }

                                #region Prepare lines for overlay
                                if (this.Request.RegionToCapture.Width == 0)
                                {
                                    _lineVectors = new SlimDX.Vector2[] { 
                                        new SlimDX.Vector2(0, 0),
                                        new SlimDX.Vector2(_renderTarget.Description.Width - 1, _renderTarget.Description.Height - 1),
                                        new SlimDX.Vector2(0, _renderTarget.Description.Height - 1),
                                        new SlimDX.Vector2(_renderTarget.Description.Width - 1, 0),
                                        new SlimDX.Vector2(0, 0),
                                        new SlimDX.Vector2(0, _renderTarget.Description.Height - 1),
                                        new SlimDX.Vector2(_renderTarget.Description.Width - 1, _renderTarget.Description.Height - 1),
                                        new SlimDX.Vector2(_renderTarget.Description.Width - 1, 0),
                                    };
                                }
                                else
                                {
                                    _lineVectors = new SlimDX.Vector2[] { 
                                        new SlimDX.Vector2(this.Request.RegionToCapture.X, this.Request.RegionToCapture.Y),
                                        new SlimDX.Vector2(this.Request.RegionToCapture.Right, this.Request.RegionToCapture.Bottom),
                                        new SlimDX.Vector2(this.Request.RegionToCapture.X, this.Request.RegionToCapture.Bottom),
                                        new SlimDX.Vector2(this.Request.RegionToCapture.Right, this.Request.RegionToCapture.Y),
                                        new SlimDX.Vector2(this.Request.RegionToCapture.X, this.Request.RegionToCapture.Y),
                                        new SlimDX.Vector2(this.Request.RegionToCapture.X, this.Request.RegionToCapture.Bottom),
                                        new SlimDX.Vector2(this.Request.RegionToCapture.Right, this.Request.RegionToCapture.Bottom),
                                        new SlimDX.Vector2(this.Request.RegionToCapture.Right, this.Request.RegionToCapture.Y),
                                    };
                                }
                                #endregion

                                using (Surface backBuffer = device.GetBackBuffer(0, 0))
                                {
                                    // Create a super fast copy of the back buffer on our Surface
                                    device.GetRenderTargetData(backBuffer, _renderTarget);

                                    // We have the back buffer data and can now work on copying it to a bitmap
                                    ProcessRequest();
                                }
                            }
                            finally
                            {
                                // We have completed the request - mark it as null so we do not continue to try to capture the same request
                                // Note: If you are after high frame rates, consider implementing buffers here to capture more frequently
                                //         and send back to the host application as needed. The IPC overhead significantly slows down 
                                //         the whole process if sending frame by frame.
                                Request = null;
                            }
                            DateTime end = DateTime.Now;
                            this.DebugMessage("EndSceneHook: Capture time: " + (end - start).ToString());
                            _lastScreenshotTime = (end - start);
                        }
                    }
                    #endregion

                    #region Example: Draw Overlay (after screenshot so we don't capture overlay as well)

                    if (this.ShowOverlay)
                    {
                        #region Draw fading lines based on last screencapture request
                        if (_lastRequestTime != null && _lineVectors != null)
                        {
                            TimeSpan timeSinceRequest = DateTime.Now - _lastRequestTime.Value;
                            if (timeSinceRequest.TotalMilliseconds < 1000.0)
                            {
                                using (Line line = new Line(device))
                                {
                                    _lineAlpha = (float)((1000.0 - timeSinceRequest.TotalMilliseconds) / 1000.0); // This is our fade out
                                    line.Antialias = true;
                                    line.Width = 1.0f;
                                    line.Begin();
                                    line.Draw(_lineVectors, new SlimDX.Color4(_lineAlpha, 0.5f, 0.5f, 1.0f));
                                    line.End();
                                }
                            }
                            else
                            {
                                _lineVectors = null;
                            }
                        }
                        #endregion

                        #region Draw frame rate
                        using (SlimDX.Direct3D9.Font font = new SlimDX.Direct3D9.Font(device, new System.Drawing.Font("Times New Roman", 16.0f)))
                        {
                            if (_lastFrame != null)
                            {
                                font.DrawString(null, String.Format("{0:N1} fps", (1000.0 / (DateTime.Now - _lastFrame.Value).TotalMilliseconds)), 100, 100, System.Drawing.Color.Red);
                            }
                            _lastFrame = DateTime.Now;
                        }
                        #endregion
                    }

                    #endregion
                }
                catch(Exception e)
                {
                    // If there is an error we do not want to crash the hooked application, so swallow the exception
                    this.DebugMessage("EndSceneHook: Exeception: " + e.GetType().FullName + ": " + e.Message);
                }

                // EasyHook has already repatched the original EndScene - so calling EndScene against the SlimDX device will call the original
                // EndScene and bypass this hook. EasyHook will automatically reinstall the hook after this hook function exits.
                return device.EndScene().Code;
            }
        }
Beispiel #27
0
        public override void Render()
        {
            if (State == eDockState.Hidden)
            {
                return;
            }

            int    xPos = XPosition;
            int    yPos = YPosition;
            double pct  = Math.Min(1, Math.Max(0, 1 - (-Power / 60)));

            if (PositionUpdated || PowerUpdated)
            {
                PositionUpdated = false;
                PowerUpdated    = false;

                BodyVertexesUsed = 0;

                /* dark background */
                BodyVertexesUsed = BuildFilledRectangle(BodyVertexes, BodyVertexesUsed, xPos, (int)(xPos + Width), yPos, yPos + Height, 0x7F000000);

                /* background gradient */
                double relPos = 0;
                double delta  = 0.33f;

                /* gradient blue -> cyan */
                BodyVertexesUsed = BuildFilledRectangle(BodyVertexes, BodyVertexesUsed, (int)(xPos + Width * relPos), (int)(xPos + Width * (relPos + delta)), yPos, yPos + Height, 0x3F0000FF, 0x3F00FFFF);
                relPos          += delta;

                /* gradient cyan -> yellow */
                BodyVertexesUsed = BuildFilledRectangle(BodyVertexes, BodyVertexesUsed, (int)(xPos + Width * relPos), (int)(xPos + Width * (relPos + delta)), yPos, yPos + Height, 0x3F00FFFF, 0x3FFFFF00);
                relPos          += delta;

                /* gradient yellow -> red */
                BodyVertexesUsed = BuildFilledRectangle(BodyVertexes, BodyVertexesUsed, (int)(xPos + Width * relPos), (int)(xPos + Width * (relPos + delta)), yPos, yPos + Height, 0x3FFFFF00, 0x3FFF0000);
                relPos           = 0;

                /* bar gradient */
                double maxDelta = 0;
                double colorPct = 0;

                if (pct > 0)
                {
                    /* gradient blue -> cyan */
                    maxDelta         = Math.Max(0, Math.Min(delta, pct));
                    colorPct         = maxDelta / delta;
                    BodyVertexesUsed = BuildFilledRectangle(BodyVertexes, BodyVertexesUsed, (int)(xPos + Width * relPos), (int)(xPos + Width * (relPos + maxDelta)), yPos, yPos + Height, 0xFF0000FF, 0xFF0000FF | (((uint)(255.0f * colorPct)) << 8));
                    relPos          += delta;
                }

                if (pct > 0.33f)
                {
                    /* gradient cyan -> yellow */
                    maxDelta         = Math.Max(0, Math.Min(delta, pct - relPos));
                    colorPct         = maxDelta / delta;
                    BodyVertexesUsed = BuildFilledRectangle(BodyVertexes, BodyVertexesUsed, (int)(xPos + Width * relPos), (int)(xPos + Width * (relPos + maxDelta)), yPos, yPos + Height, 0xFF00FFFF, 0xFF00FF00 | (((uint)(255.0f * colorPct)) << 16) | ((uint)(255.0f * (1 - colorPct))));
                    relPos          += delta;
                }

                if (pct > 0.66f)
                {
                    /* gradient yellow -> red */
                    maxDelta         = Math.Max(0, Math.Min(delta, pct - relPos));
                    colorPct         = maxDelta / delta;
                    BodyVertexesUsed = BuildFilledRectangle(BodyVertexes, BodyVertexesUsed, (int)(xPos + Width * relPos), (int)(xPos + Width * (relPos + maxDelta)), yPos, yPos + Height, 0xFFFFFF00, 0xFFFF0000 | (((uint)(255.0f * (1 - colorPct))) << 8));
                }
            }

            if (BodyVertexesUsed - 2 > 0)
            {
                Panel.MainPlot.Device.DrawUserPrimitives(PrimitiveType.TriangleStrip, BodyVertexesUsed - 2, BodyVertexes);
            }

            TextRect.X            = XPosition;
            TextRect.Y            = YPosition;
            TextRect.Width        = (int)Width;
            TextRect.Height       = (int)Height;
            TextShadowRect.X      = XPosition + 1;
            TextShadowRect.Y      = YPosition + 1;
            TextShadowRect.Width  = (int)Width;
            TextShadowRect.Height = (int)Height;

            string text = Power.ToString("#0.0 ") + Unit;

            DisplayFont.DrawString(null, text, TextShadowRect, DrawTextFormat.Center | DrawTextFormat.VerticalCenter, (int)ShadowColor);
            DisplayFont.DrawString(null, text, TextRect, DrawTextFormat.Center | DrawTextFormat.VerticalCenter, (int)TextColor);
        }
Beispiel #28
0
        public override void Render()
        {
            if (!Visible)
            {
                return;
            }

            int xPos = AbsoluteXPosition;
            int yPos = AbsoluteYPosition;

            if (PositionUpdated)
            {
                PositionUpdated = false;

                BorderVertexesUsed = 0;
                BorderVertexesUsed = BuildRectangle(BorderVertexes, BorderVertexesUsed, xPos, xPos + AbsoluteWidth, yPos, yPos + AbsoluteHeight, (uint)BorderColor.ToArgb());

                switch (AreaMode)
                {
                case eAreaMode.LSB:
                    BodyVertexesUsed = 0;
                    BodyVertexesUsed = BuildFilledRectangle(BodyVertexes, BodyVertexesUsed, xPos, xPos + AbsoluteWidth, yPos, yPos + AbsoluteHeight, (uint)BodyColor.ToArgb() & 0x1F000000, (uint)BodyColor.ToArgb());
                    break;

                case eAreaMode.USB:
                    BodyVertexesUsed = 0;
                    BodyVertexesUsed = BuildFilledRectangle(BodyVertexes, BodyVertexesUsed, xPos, xPos + AbsoluteWidth, yPos, yPos + AbsoluteHeight, (uint)BodyColor.ToArgb(), (uint)BodyColor.ToArgb() & 0x1F000000);
                    break;

                case eAreaMode.Normal:
                    BodyVertexesUsed = 0;
                    BodyVertexesUsed = BuildFilledRectangle(BodyVertexes, BodyVertexesUsed, xPos, xPos + AbsoluteWidth, yPos, yPos + AbsoluteHeight, (uint)BodyColor.ToArgb());
                    break;
                }


                /* we dont care about the maximum size anymore */
                TextRect.X      = xPos + 10;
                TextRect.Y      = yPos + 3;
                TextRect.Width  = 200; // (int)AbsoluteWidth - 10;
                TextRect.Height = 200; // (int)AbsoluteHeight - 3;

                double carrierWidth = (double)AbsoluteWidth / Carriers;

                CarrierVertexesUsed = 0;
                for (int carrier = 0; carrier < Carriers; carrier++)
                {
                    CarrierVertexes[CarrierVertexesUsed].Color         = (uint)CarrierColor.ToArgb();
                    CarrierVertexes[CarrierVertexesUsed].PositionRhw.X = (float)(xPos + carrier * carrierWidth + carrierWidth / 2);
                    CarrierVertexes[CarrierVertexesUsed].PositionRhw.Y = (float)(yPos);
                    CarrierVertexes[CarrierVertexesUsed].PositionRhw.Z = 0.5f;
                    CarrierVertexes[CarrierVertexesUsed].PositionRhw.W = 1;
                    CarrierVertexesUsed++;

                    CarrierVertexes[CarrierVertexesUsed].Color         = (uint)CarrierColor.ToArgb();
                    CarrierVertexes[CarrierVertexesUsed].PositionRhw.X = (float)(xPos + carrier * carrierWidth + carrierWidth / 2);
                    CarrierVertexes[CarrierVertexesUsed].PositionRhw.Y = (float)(yPos + AbsoluteHeight);
                    CarrierVertexes[CarrierVertexesUsed].PositionRhw.Z = 0.5f;
                    CarrierVertexes[CarrierVertexesUsed].PositionRhw.W = 1;
                    CarrierVertexesUsed++;
                }
            }

            switch (Mode)
            {
            case eOperationMode.Area:
                if (BodyVertexesUsed - 2 > 0)
                {
                    MainPlot.Device.DrawUserPrimitives(PrimitiveType.TriangleStrip, BodyVertexesUsed - 2, BodyVertexes);
                }
                if (BorderVertexesUsed > 0)
                {
                    MainPlot.Device.DrawUserPrimitives(PrimitiveType.LineList, BorderVertexesUsed / 2, BorderVertexes);
                }
                break;

            case eOperationMode.Carriers:
                if (BodyVertexesUsed - 2 > 0)
                {
                    MainPlot.Device.DrawUserPrimitives(PrimitiveType.TriangleStrip, BodyVertexesUsed - 2, BodyVertexes);
                }
                if (CarrierVertexesUsed > 0)
                {
                    MainPlot.Device.DrawUserPrimitives(PrimitiveType.LineList, CarrierVertexesUsed / 2, CarrierVertexes);
                }
                break;
            }

            if (Text != "")
            {
                DisplayFontNormal.DrawString(null, Text, TextRect, DrawTextFormat.Left | DrawTextFormat.Top, (int)TextColor);
            }
        }
Beispiel #29
0
        private void PresentFrame()
        {
            if (disposed)
            {
                isRendering = false; return;
            }
            if (!initialized)
            {
                isRendering = false; return;
            }
            if (!NesEmu.EmulationON)
            {
                if (fullScreen)
                {
                    fullScreen = false;
                    Reset();
                    Program.FormMain.ApplyVideoStretch();
                }
                // Make a snow buffer when emulation is off
                for (int i = 0; i < currentBuffer.Length; i++)
                {
                    c = (byte)r.Next(0, 255);
                    currentBuffer[i] = c | (c << 8) | (c << 16) | (255 << 24);
                }
            }
            // Render the buffer
            if (isRendering)
            {
                isRendering = false; return;
            }
            if (!canRender)
            {
                isRendering = false; return;
            }

            if (frame_timer > 0)
            {
                frame_timer--;
            }
            else
            {
                frame_timer = 60;
            }
            isRendering = true;
            var result = displayDevice.TestCooperativeLevel();

            switch (result.Code)
            {
            case -2005530510:
            case -2005530520: deviceLost = true; isRendering = false; break;

            case -2005530519: deviceLost = false; isRendering = false; ResetDirect3D(); break;
            }
            // Render current buffer
            if (!deviceLost)
            {
                DataRectangle rect = bufferedSurface.LockRectangle(LockFlags.Discard);

                rect.Data.WriteRange(currentBuffer, linesToSkip * 256, 256 * scanlines);

                rect.Data.Close();
                bufferedSurface.UnlockRectangle();
                // copy the surface data to the device one with stretch.
                if (canRender && !disposed)
                {
                    if (keep_aspect_ratio)
                    {
                        displayDevice.StretchRectangle(bufferedSurface, originalRect, frontSurface, destinationRect, filter);
                    }
                    else
                    {
                        displayDevice.StretchRectangle(bufferedSurface, frontSurface, filter);
                    }
                }


                displayDevice.BeginScene();

                displaySprite.Begin(SpriteFlags.AlphaBlend);
                // fps
                if (NesEmu.EmulationON)
                {
                    if (NesEmu.EmulationPaused)
                    {
                        switch (NesEmu.EmuStatus)
                        {
                        case NesEmu.EmulationStatus.HARDRESET:
                        {
                            font_BIG.DrawString(displaySprite, "HARD RESETING ...", 20, 20, Color.Lime);
                            break;
                        }

                        case NesEmu.EmulationStatus.LOADINGSTATE:
                        {
                            font_BIG.DrawString(displaySprite, "LOADING STATE ...", 20, 20, Color.Lime);
                            break;
                        }

                        case NesEmu.EmulationStatus.PAUSED:
                        {
                            font_BIG.DrawString(displaySprite, "PAUSED", 20, 20, Color.Lime);
                            break;
                        }

                        case NesEmu.EmulationStatus.SAVINGSNAP:
                        {
                            font_BIG.DrawString(displaySprite, "SAVING SNAPSHOT ...", 20, 20, Color.Lime);
                            break;
                        }

                        case NesEmu.EmulationStatus.SAVINGSRAM:
                        {
                            font_BIG.DrawString(displaySprite, "SAVING SRAM ...", 20, 20, Color.Lime);
                            break;
                        }

                        case NesEmu.EmulationStatus.SAVINGSTATE:
                        {
                            font_BIG.DrawString(displaySprite, "SAVING STATE ...", 20, 20, Color.Lime);
                            break;
                        }

                        case NesEmu.EmulationStatus.SOFTRESET:
                        {
                            font_BIG.DrawString(displaySprite, "SOFT RESETTING ...", 20, 20, Color.Lime);
                            break;
                        }
                        }
                    }
                    else if (Program.FormMain.audio != null)
                    {
                        if (Program.FormMain.audio.IsRecording)
                        {
                            font.DrawString(displaySprite, "RECORDING SOUND [" + TimeSpan.FromSeconds(Program.FormMain.audio.Recorder.Time) + "]", 20, 20, Color.OrangeRed);
                        }
                        // Debug sound sync by calculating the difference between pointers and show it
                        // font.DrawString(displaySprite, (Program.FormMain.audio.CurrentWritePosition -
                        //     NesEmu.audio_playback_w_pos).ToString(), 20, 20, Color.OrangeRed);
                    }
                    if (show_emulation_status_timer > 0)
                    {
                        show_emulation_status_timer--;
                        font.DrawString(displaySprite, "GAME: " + emulation_status_game_name, 20, 20, Color.Lime);
                        font.DrawString(displaySprite,
                                        "TV SYS: " + NesEmu.TVFormat.ToString() +
                                        (NesEmu.IsGameGenieActive ? " | GAME GENIE ON" : "")
                                        , 20, 50, Color.Lime);

                        font.DrawString(displaySprite, "FPS Can Make: " + (1.0 / NesEmu.CurrentFrameTime).ToString("F2"),
                                        20, 80, Color.Lime);
                    }

                    if (show_fps)
                    {
                        if (!NesEmu.EmulationPaused)
                        {
                            font.DrawString(displaySprite,
                                            "FPS: " + emu_fps + " / " + (1.0 / NesEmu.CurrentFrameTime).ToString("F2"),
                                            20, 20, Color.Lime);
                        }
                    }
                    if (!NesEmu.SpeedLimitterON)
                    {
                        if (frame_timer > 30)
                        {
                            font_BIG.DrawString(displaySprite, "TURBO !", 20, ScreenHeight - 100, Color.Lime);
                        }
                    }
                }

                if (notification_appearance > 0)
                {
                    notification_appearance--;

                    // Draw the string
                    font.DrawString(displaySprite, notification_text, notification_x, notification_y, notification_color);
                }

                displaySprite.End();

                displayDevice.EndScene();
                displayDevice.Present();
            }
            isRendering = false;
        }
Beispiel #30
0
        public int CompositeImage(IntPtr pD3DDevice, IntPtr pddsRenderTarget, AMMediaType pmtRenderTarget, long rtStart, long rtEnd, int dwClrBkGnd, VMR9VideoStreamInfo[] pVideoStreamInfo, int cStreams)
        {
            try
            {
                // Just in case the filter call CompositeImage before InitCompositionDevice (this sometime occure)
                if (unmanagedDevice != pD3DDevice)
                {
                    SetManagedDevice(pD3DDevice);
                }

                // Create a managed Direct3D surface (the Render Target) from the unmanaged pointer.
                // The constructor don't call IUnknown.AddRef but the "destructor" seem to call IUnknown.Release
                // Direct3D seem to be happier with that according to the DirectX log
                Marshal.AddRef(pddsRenderTarget);
                Surface            renderTarget     = Surface.FromPointer(pddsRenderTarget);
                SurfaceDescription renderTargetDesc = renderTarget.Description;
                Rectangle          renderTargetRect = new Rectangle(0, 0, renderTargetDesc.Width, renderTargetDesc.Height);

                // Same thing for the first video surface
                // WARNING : This Compositor sample only use the video provided to the first pin.
                Marshal.AddRef(pVideoStreamInfo[0].pddsVideoSurface);
                Surface            surface     = Surface.FromPointer(pVideoStreamInfo[0].pddsVideoSurface);
                SurfaceDescription surfaceDesc = surface.Description;
                Rectangle          surfaceRect = new Rectangle(0, 0, surfaceDesc.Width, surfaceDesc.Height);


                // Set the device's render target (this doesn't seem to be needed)
                device.SetRenderTarget(0, renderTarget);

                // Copy the whole video surface into the render target
                // it's a de facto surface cleaning...
                device.StretchRectangle(surface, surfaceRect, renderTarget, renderTargetRect, TextureFilter.None);

                // sprite's methods need to be called between device.BeginScene and device.EndScene
                device.BeginScene();

                // Init the sprite engine for AlphaBlending operations
                sprite.Begin(SpriteFlags.AlphaBlend | SpriteFlags.DoNotSaveState);

                //mouse
                if (_mouseTrack != null)
                {
                    if (_mouseTrack.Count > 1)
                    {
                        if (_mouseTrackDraw)
                        {
                            _d3dMouseTrackLine.Width = _mouseTrackLineWidth;
                            _d3dMouseTrackLine.Begin();
                            _d3dMouseTrackLine.Draw(_mouseTrack.ToArray(), _mouseTrackColor);
                            _d3dMouseTrackLine.End();
                        }
                    }
                    if (_mouseTrack.Count > 0)
                    {
                        if (_mouseCursorCircleDraw)
                        {
                            _d3dMouseCursorCircleLine.Width = _mouseCursorCircleLineWidth;
                            _d3dMouseCursorCircleLine.Begin();
                            _d3dMouseCursorCircleLine.Draw(InitCircle(100, _mouseTrack[_mouseTrack.Count - 1], 50), _mouseCursorCircleColor);
                            _d3dMouseCursorCircleLine.End();
                        }

                        if (_mouseCursorDraw)
                        {
                            Vector3 cursorPos = new Vector3(_mouseTrack[_mouseTrack.Count - 1], 0.5f);
                            sprite.Draw(_mouseCursorTex, Vector3.Zero, cursorPos, Color.White);
                        }
                    }
                }
                if (_mouseFixationDraw && _mouseFixation != null)
                {
                    if (_mouseFixation.Count > 0)
                    {
                        List <Vector2> scanpath = new List <Vector2>();
                        for (int i = 0; i < _mouseFixation.Count; i++)
                        {
                            //Fixation
                            _d3dMouseFixationLine.Width = _mouseFixationLineWidth;
                            _d3dMouseFixationLine.Begin();
                            _d3dMouseFixationLine.Draw(InitCircle(100, _mouseFixation[i].fixation, _mouseFixation[i].fsize), _mouseFixationColor);
                            _d3dMouseFixationLine.End();

                            //ScanPath
                            scanpath.Add(_mouseFixation[i].fixation);
                            if (i >= 1 && _mouseScanpathDraw)
                            {
                                _d3dMouseScanpathLine.Width = _mouseScanpathLineWidth;
                                _d3dMouseScanpathLine.Begin();
                                _d3dMouseScanpathLine.Draw(scanpath.ToArray(), _mouseScanpathColor);
                                _d3dMouseScanpathLine.End();
                            }

                            //Fixation ID
                            if (_mouseFixationIDDraw)
                            {
                                _d3dMouseFixtionFont.DrawString(sprite, (i + 1).ToString(), new Rectangle(new Point((int)_mouseFixation[i].fixation.X, (int)_mouseFixation[i].fixation.Y), new Size(50, 50)), 0, _mouseFixationIDColor);
                            }
                        }
                    }
                }
                //gaze
                if (_gazeTrack != null)
                {
                    if (_gazeTrack.Count > 1)
                    {
                        if (_gazeTrackDraw)
                        {
                            _d3dGazeTrackLine.Width = _gazeTrackLineWidth;
                            _d3dGazeTrackLine.Begin();
                            _d3dGazeTrackLine.Draw(_gazeTrack.ToArray(), _gazeTrackColor);
                            _d3dGazeTrackLine.End();
                        }
                    }
                    if (_gazeTrack.Count > 0)
                    {
                        if (_gazeCursorCircleDraw)
                        {
                            _d3dGazeCursorCircleLine.Width = _gazeCursorCircleLineWidth;
                            _d3dGazeCursorCircleLine.Begin();
                            _d3dGazeCursorCircleLine.Draw(InitCircle(100, _gazeTrack[_gazeTrack.Count - 1], 50), _gazeCursorCircleColor);
                            _d3dGazeCursorCircleLine.End();
                        }

                        if (_gazeCursorDraw)
                        {
                            Vector3 cursorPos = new Vector3(_gazeTrack[_gazeTrack.Count - 1], 0.5f);
                            sprite.Draw(_gazeCursorTex, Vector3.Zero, cursorPos, Color.White);
                        }
                    }
                }
                if (_gazeFixationDraw && _gazeFixation != null)
                {
                    if (_gazeFixation.Count > 0)
                    {
                        List <Vector2> scanpath = new List <Vector2>();
                        for (int i = 0; i < _gazeFixation.Count; i++)
                        {
                            //Fixation
                            _d3dGazeFixationLine.Width = _gazeFixationLineWidth;
                            _d3dGazeFixationLine.Begin();
                            _d3dGazeFixationLine.Draw(InitCircle(100, _gazeFixation[i].fixation, _gazeFixation[i].fsize), _gazeFixationColor);
                            _d3dGazeFixationLine.End();

                            //ScanPath
                            scanpath.Add(_gazeFixation[i].fixation);
                            if (i >= 1 && _gazeScanpathDraw)
                            {
                                _d3dGazeScanpathLine.Width = _gazeScanpathLineWidth;
                                _d3dGazeScanpathLine.Begin();
                                _d3dGazeScanpathLine.Draw(scanpath.ToArray(), _gazeScanpathColor);
                                _d3dGazeScanpathLine.End();
                            }
                            //Fixation ID
                            if (_gazeFixationIDDraw)
                            {
                                _d3dGazeFixtionFont.DrawString(sprite, (i + 1).ToString(), new Rectangle(new Point((int)_gazeFixation[i].fixation.X, (int)_gazeFixation[i].fixation.Y), new Size(50, 50)), 0, _gazeFixationIDColor);
                            }
                        }
                    }
                }


                // End the spite engine (drawings take place here)
                sprite.Flush();
                sprite.End();


                // End the sceen.
                device.EndScene();

                // No Present requiered because the rendering is on a render target...
                // device.Present();

                // Dispose the managed surface
                surface.Dispose();
                surface = null;

                // and the managed render target
                renderTarget.Dispose();
                renderTarget = null;
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
            }

            // return a success to the filter
            return(0);
        }
Beispiel #31
0
        public override void Render()
        {
            if (!Active)
            {
                return;
            }

            int xPos = AbsoluteXPosition;
            int yPos = AbsoluteYPosition;

            if (PositionUpdated)
            {
                DisplayFont.MeasureString(null, Text, DrawTextFormat.Center, ref SizeRect);
                AbsoluteHeight = SizeRect.Height;
                AbsoluteWidth  = SizeRect.Width;
            }

            if (xPos < 0)
            {
                xPos += MainPlot.DirectXWidth - AbsoluteWidth;
            }

            if (yPos < 0)
            {
                yPos += MainPlot.DirectXHeight - AbsoluteHeight;
            }

            if (PositionUpdated)
            {
                PositionUpdated = false;

                BorderVertexesUsed = 0;
                BorderVertexesUsed = BuildRectangle(BorderVertexes, BorderVertexesUsed, xPos - 7, xPos + 7 + AbsoluteWidth, yPos - 4, yPos + 4 + AbsoluteHeight, 0x7FFF0000);
                BorderVertexesUsed = BuildRectangle(BorderVertexes, BorderVertexesUsed, xPos - 6, xPos + 6 + AbsoluteWidth, yPos - 3, yPos + 3 + AbsoluteHeight, 0xFFFF0000);
                BorderVertexesUsed = BuildRectangle(BorderVertexes, BorderVertexesUsed, xPos - 5, xPos + 5 + AbsoluteWidth, yPos - 2, yPos + 2 + AbsoluteHeight, 0x7FFF0000);

                BodyVertexesUsed = 0;
                BodyVertexesUsed = BuildFilledRectangle(BodyVertexes, BodyVertexesUsed, xPos - 6, xPos + 6 + AbsoluteWidth, yPos - 3, yPos + 3 + AbsoluteHeight, 0x1FFF0000);
            }

            if (Pulsing)
            {
                double maxAngle = 10 * Math.PI;
                /* -1 .. 1 -> 0.5 .. 1 */
                double sinVal = (Math.Sin(UpdateCounter++ / maxAngle) + 1) / 4 + 0.5;

                TextColor.Alpha   = (float)Math.Max(0, Math.Min(1, sinVal));
                ShadowColor.Alpha = (float)Math.Max(0, TextColor.Alpha - 0.5);
            }
            else
            {
                TextColor.Alpha   = 1;
                ShadowColor.Alpha = 1;
            }

            MainPlot.Device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, BodyVertexes);
            if (BorderVertexesUsed > 0)
            {
                MainPlot.Device.DrawUserPrimitives(PrimitiveType.LineList, BorderVertexesUsed / 2, BorderVertexes);
            }

            DisplayFont.DrawString(null, Text, xPos + 2, yPos + 2, ShadowColor);
            DisplayFont.DrawString(null, Text, xPos, yPos, TextColor);
        }
        // Called every frame from the DirectX API. We draw our overlay here (on top of everything).
        int EndSceneHook(IntPtr devicePtr)
        {
            // Used to debug whether or not the EndScene is called.
            if (!EndSceneCalled)
            {
                EndSceneCalled = true;
                Interface.Debug("EndScene called successfully!");
            }

            using (Device device = Device.FromPointer(devicePtr))
            {
                // Retrieve the current time.
                DateTime now = DateTime.Now;

                // Retrieve the width and height of the surface.
                int width, height = 0;
                using (Surface renderTargetTemp = device.GetRenderTarget(0))
                {
                    width = renderTargetTemp.Description.Width;
                    height = renderTargetTemp.Description.Height;

                    _renderTarget = renderTargetTemp;
                }

                // Re-calculate overlay position and dimension if the width or height changes.
                if (PreviousWidth != width || PreviousHeight != height)
                {
                    // Refresh position and dimension.
                    CalculatePositions(width, height);
                    PreviousWidth = width;
                    PreviousHeight = height;

                    // Reset font.
                    OverlayFont = null;
                }

                try
                {
                    // Render a success message to indicate that the overlay was added successfully.
                    long millisSinceAdd = (now - TimeAdded).Ticks / TimeSpan.TicksPerMillisecond;
                    if (millisSinceAdd < SuccessMessageTime)
                    {
                        // Scale the font to the current resolution.
                        using (SlimDX.Direct3D9.Font successFont = new SlimDX.Direct3D9.Font(device, new System.Drawing.Font("Times New Roman", 80.0f / 1920f * width)))
                        {
                            // Draw the font with an alpha value related to the time passed since the overlay was added. The font will be completely invisible when the time has passed.
                            successFont.DrawString(null, "Overlay added!", 50, 50, Color.FromArgb((int)((SuccessMessageTime - millisSinceAdd) / SuccessMessageTime * 255.0), TextColor));
                        }
                    }

                    // Don't render the overlay if it's in auto hide mode and hidden.
                    if (!Hide || !AutoHide)
                    {
                        // Refresh the font if the settings has been changed or create a font if null.
                        if (OverlayFont == null || !FontName.Equals(LastFontName) || LastMessagesShown != MessagesShown || AutoMessageHeight != LastAutoMessageHeight || MessageHeight != LastMessageHeight)
                        {
                            LastFontName = FontName;
                            LastMessagesShown = MessagesShown;
                            LastAutoMessageHeight = AutoMessageHeight;
                            LastMessageHeight = MessageHeight;
                            LoadFont(device);
                        }

                        // Draw the last messages received. Amount defined by MessagesShown.
                        int y = MessagesShown - 1;
                        int i = Messages.Count - 1;
                        while (y >= 0)
                        {
                            // Abort the loop if there are no more messages available.
                            if (!(i >= Math.Max(0, Messages.Count - MessagesShown)))
                                break;

                            Message message = Messages[i];

                            // Wrap the message if it has not been done yet or the font/dimensions has been changed.
                            if (!OverlayFont.Equals(message.FontUsed))
                            {
                                message.WrapMessage(OverlayFont, AvailableTextWidth);
                            }

                            // Store the original text color.
                            Color drawColor = TextColor;

                            // Keep track of whether to draw the shadow or not (The shadow will not be drawn when fading).
                            Boolean drawShadow = true;

                            // Fade the color if in the fading phase.
                            if (FadeMessages && message.Time.AddSeconds(FadeWait) <= now)
                            {
                                if (message.Time.AddSeconds(FadeWait + FadeDuration) <= now)
                                {
                                    // The message has already been faded, don't display it.
                                    i--;
                                    continue;
                                }

                                // Fade the color according to the duration and delay of the fade.
                                float fadeDuration = (message.Time.AddSeconds(FadeWait + FadeDuration) - message.Time.AddSeconds(FadeWait)).Ticks / TimeSpan.TicksPerMillisecond;
                                float fadeProgress = (now - message.Time.AddSeconds(FadeWait)).Ticks / TimeSpan.TicksPerMillisecond;
                                float fadePercentage = fadeProgress / fadeDuration;
                                drawColor = Color.FromArgb((int) ((1f - fadePercentage)*255), drawColor);
                                drawShadow = false;
                            }
                            
                            // Draw the wrapped message from the bottom.
                            for (int j = message.WrappedMessage.Length - 1; j >= 0 && y >= 0; j--)
                            {
                                // Calculate the y position for the string.
                                int stringY = TextStartHeight + (TextEndHeight - TextStartHeight) / MessagesShown * y; 

                                if (drawShadow)
                                    OverlayFont.DrawString(null, message.WrappedMessage[j], TextStartWidth + FontHeight / 2 + message.SenderWidth, stringY + 1, TextShadowColor);

                                OverlayFont.DrawString(null, message.WrappedMessage[j], TextStartWidth - 1 + FontHeight / 2 + message.SenderWidth, stringY, drawColor);

                                // Only draw the sender on the upmost line.
                                if (j == 0)
                                {
                                    if (drawShadow)
                                        OverlayFont.DrawString(null, message.Sender + ": ", TextStartWidth, stringY + 1, TextShadowColor);

                                    OverlayFont.DrawString(null, message.Sender + ": ", TextStartWidth - 1, stringY, drawColor);
                                }
                                y--;
                            }

                            i--;
                        }
                    }
                   
                }
                catch
                {
                    // Don't crash the hooked application if an exception is thrown.
                }

                // EasyHook has already repatched the original EndScene so we will not loop our method forever.
                return device.EndScene().Code;
            }
        }
Beispiel #33
0
        /// <summary>
        /// Sets the render states and draws the selected objects to scene.
        /// </summary>
        /// <param name="direct3DDevice">The direct 3D device pointer.</param>
        /// <returns><see cref="int"/></returns>
        public int EndSceneHook(IntPtr direct3DDevice)
        {
            // Do the first scan.
            if (!_opened)
            {
                _memory.OpenSF4Process();
                _memory.RunScan();

                _interface.WriteConsole("Street Fighter 4 Process hooked.");

                _opened = true;
            }

            if (_device == null)
            {
                _device = Device.FromPointer(direct3DDevice);

                _interface.WriteConsole(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\uiBackground.png");

                _background = Texture.FromFile(
                    _device,
                    Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\Resources\Images\uiBackground.png");

                _interface.WriteConsole("Device created.");

                // Attempting to scale the font.
                _fontSize = _device.Viewport.Height / 48;
                _interface.WriteConsole(string.Format("Font size set to {0}", _fontSize));

                _font = new Font(_device, new System.Drawing.Font("Consolas", _fontSize));
            }

            // The game calls endscene twice a frame. We only need to draw once.
            // We should just return as normal the other time.
            if (_endsceneSkip)
            {
                _endsceneSkip = false;
                return(_device.EndScene().Code);
            }

            _endsceneSkip = true;

            //// _device.SetRenderState(RenderState.Lighting, false);
            //// _device.SetRenderState(RenderState.SpecularEnable, false);

            _device.SetRenderState(RenderState.CullMode, Cull.None);
            _device.SetRenderState(RenderState.AlphaBlendEnable, true);
            _device.SetRenderState(RenderState.VertexBlend, VertexBlend.Disable);
            _device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha);
            _device.SetRenderState(RenderState.DestinationBlend, Blend.InverseSourceAlpha);
            _device.SetRenderState(RenderState.BlendOperationAlpha, BlendOperation.Minimum);
            _device.SetRenderState(RenderState.FillMode, FillMode.Solid);
            _device.SetRenderState(RenderState.ColorWriteEnable, 0xF);
            _device.SetRenderState(RenderState.MultisampleAntialias, false);

            // Setting up the camera
            Vector3 eye = new Vector3 {
                X = _memory.GetCamX(), Y = _memory.GetCamY(), Z = _memory.GetCamZ()
            };
            Vector3 target = new Vector3 {
                X = _memory.GetCamXp(), Y = _memory.GetCamYp(), Z = _memory.GetCamZp()
            };

            float zoom = _memory.GetCamZoom();

            _device.SetRenderState(RenderState.Lighting, false); // We don't need light for this...
            _device.SetTransform(TransformState.View, Matrix.LookAtLH(eye, target, new Vector3(0, 1, 0)));

            // Fix this shit later!
            _device.SetTransform(
                TransformState.Projection,
                Matrix.PerspectiveLH(0.1f * 16 / 9 * zoom + 0.008f, 0.1f * zoom + 0.008f, 0.1F, 100.0F));

            _playerOneBoxes = _memory.ReadMemoryByteArrayWithBase(0x00688E6C, new int[] { 0x8, 0x2190 }, 25248);
            _playerTwoBoxes = _memory.ReadMemoryByteArrayWithBase(0x00688E6C, new int[] { 0xC, 0x2190 }, 25248);

            // Draw everything...
            if (_interface.DrawBasic1)
            {
                DrawHurtBoxes(_playerOneBoxes, _device);
            }

            if (_interface.DrawBasic2)
            {
                DrawHurtBoxes(_playerTwoBoxes, _device);
            }

            if (_interface.DrawPhysics1)
            {
                DrawPhysicsBoxes(_playerOneBoxes, _device);
            }

            if (_interface.DrawPhysics2)
            {
                DrawPhysicsBoxes(_playerTwoBoxes, _device);
            }

            if (_interface.DrawGrab1)
            {
                DrawThrowVulnerableBoxes(_playerOneBoxes, _device);
            }

            if (_interface.DrawGrab2)
            {
                DrawThrowVulnerableBoxes(_playerTwoBoxes, _device);
            }

            if (_interface.DrawHit1)
            {
                DrawHitbox(1, _device);
            }

            if (_interface.DrawHit2)
            {
                DrawHitbox(2, _device);
            }

            if (_interface.DrawGrab1)
            {
                DrawGrabBox(1, _device);
            }

            if (_interface.DrawGrab2)
            {
                DrawGrabBox(2, _device);
            }

            if (_interface.DrawProjectile1)
            {
                DrawProjectileBox(1, _device);
            }

            if (_interface.DrawProjectile2)
            {
                DrawProjectileBox(2, _device);
            }

            if (_interface.DrawProx1)
            {
                DrawProxBox(1, _device);
            }

            if (_interface.DrawProx2)
            {
                DrawProxBox(2, _device);
            }

            if (_interface.DrawInfo)
            {
                DrawInfo(_device);
            }

            _interface.FrameNumber = _memory.GetFrameCount();

            // This does not use the sprite we use for all the other text...
            _font.DrawString(null, "Frame Trapped Lab Active", 20, 20, _textColor);

            return(_device.EndScene().Code);
        }