Beispiel #1
0
        public override void OnRender(Canvas canvas)
        {
            canvas.DrawFillRect(_background, _background_color_material);
            canvas.DrawRect(_background, Color.White);
            if (DDD_Global.Instance.IsConnected)
            {
                if (_loading_textures)
                {
                    //player_rect.Height = (font_small.MeasureString(null, DDD_Global.Instance.PlayerBrief, DrawTextFormat.WordBreak, Color.Yellow)).Height;
                    canvas.DrawFillRect(player_rect, _background_window_material);
                    font_small.DrawText(null, DDD_Global.Instance.PlayerBrief, player_rect, DrawTextFormat.WordBreak, Color.Yellow);
                    _continue_btn.SetClientArea(player_rect.Left,
                                                player_rect.Bottom + 2,
                                                player_rect.Right,
                                                player_rect.Bottom + 27);

                    _continue_btn.Text = "Start Game";
                }
                _continue_btn.OnRender(canvas);
            }

            font_small.DrawText(null, Program.Build_ID, 12, 12, Color.Yellow);
            font_large.DrawText(null, Message, bounding_rect, DrawTextFormat.None, MsgColor);

            base.OnRender(canvas);
        }
Beispiel #2
0
        } // MostrarTitulo().fim

        // [---
        private void MostrarMouseInfo()
        {
            // Variáveis string para coletar informações do mouse
            string btn_info  = null;
            string eixo_info = null;

            // Verifica o estado do mouse
            DirectInput.MouseState estadoMouse = mouse.CurrentMouseState;

            // Obtém e mostra informação sobre os eixos do mouse
            eixo_info = string.Format("X:{0} Y:{1} Z:{2}\r\n",
                                      estadoMouse.X, estadoMouse.Y, estadoMouse.Z);

            dxfMensagem.DrawText(null, eixo_info, new Rectangle(20, 70, 0, 0),
                                 DrawTextFormat.NoClip, Color.Blue);

            // Obtém e mostra estado dos botões
            byte[] buttons = estadoMouse.GetMouseButtons();

            btn_info += string.Format(" Btn[0]:{0}  ", buttons[0].ToString());
            btn_info += string.Format(" Btn[1]:{0}  ", buttons[1].ToString());
            btn_info += string.Format(" Btn[2]:{0}  ", buttons[2].ToString());

            dxfMensagem.DrawText(null, btn_info, new Rectangle(120, 70, 0, 0),
                                 DrawTextFormat.NoClip, Color.Blue);
        } // MostrarMouseInfo().fim
Beispiel #3
0
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            if (device.Disposed)
            {
                return;
            }

            // Get elapsed time to calculate FPS
            ElapsedTime = DXUtil.Timer(DirectXTimer.GetElapsedTime);
            device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.CornflowerBlue, 1.0f, 0);

            device.BeginScene();

            Draw();

            // Drawing multiple lines of text on the same sprite is more efficient
            using (Sprite s = new Sprite(device))
            {
                s.Begin(SpriteFlags.AlphaBlend);
                int y = 5;
                font.DrawText(s, string.Format("FPS: {0}", ((int)(1f / ElapsedTime)).ToString()), new Rectangle(4, y, 0, 0), DrawTextFormat.NoClip, Color.FromArgb(64, 255, 255, 255));
                y += 22;
                font.DrawText(s, string.Format("Ambient light: {0}%", (int)(ambient * 100)), new Rectangle(4, y, 0, 0), DrawTextFormat.NoClip, Color.FromArgb(64, 255, 255, 255));
                s.End();
            }

            device.EndScene();

            device.Present();

            // The onPaint event must be called again
            this.Invalidate();
        }
Beispiel #4
0
 private void Render()
 {
     device.Clear(ClearFlags.Target, Color.CornflowerBlue, 0, 1);
     device.BeginScene();
     using (Sprite s = new Sprite(device))
     {
         s.Begin(SpriteFlags.AlphaBlend);
         s.Draw2D(texture_background, new Rectangle(0, 0, 0, 0), new Rectangle(0, 0, device.Viewport.Width, device.Viewport.Height), new Point(0, 0), 0f, new Point(0, 0), Color.White);
         s.Draw2D(texture_score, new Rectangle(0, 0, 0, 0), new Rectangle(0, 0, 200, 200), new Point(0, 0), 0f, new Point(45, -30), Color.White);
         font.DrawText(s, "Level ", new Point(100, 60), Color.Black);
         font.DrawText(s, "Hits ", new Point(100, 90), Color.Black);
         font.DrawText(s, "Score ", new Point(100, 120), Color.Black);
         foreach (Characters c in ch)
         {
             if (c.type == 0)
             {
                 s.Draw2D(texture_cat, new Rectangle(0, 0, 0, 0), new Rectangle(0, 0, 200, 200), new Point(0, 0), 0f, new Point((int)(c.CharacterCoordinates.X), (int)c.CharacterCoordinates.Y), Color.White);
             }
             if (c.type == 1)
             {
                 s.Draw2D(texture_bird, new Rectangle(0, 0, 0, 0), new Rectangle(0, 0, 200, 200), new Point(0, 0), 0f, new Point((int)(c.CharacterCoordinates.X + (int)(0.2)), (int)c.CharacterCoordinates.Y + (int)(0.2)), Color.White);
             }
             if (c.type == 2)
             {
                 s.Draw2D(texture_snake, new Rectangle(0, 0, 0, 0), new Rectangle(0, 0, 200, 200), new Point(0, 0), 0f, new Point((int)(c.CharacterCoordinates.X + (int)(0.8)), (int)c.CharacterCoordinates.Y + (int)(0.8)), Color.White);
             }
         }
         s.Draw2D(texture_milk, new Rectangle(0, 0, 0, 0), new Rectangle(0, 0, 200, 200), new Point(0, 0), 0f, new Point((int)x2, (int)y2), Color.White);
         s.End();
     }
     device.EndScene();
     device.Present();
 }
Beispiel #5
0
        void Render()
        {
            m_d3DDevice.BeginScene();

            // Render target needs to be set to 640x360 for optimal scaling. However the pixel coordinates for
            // Direct3D 9 render target is actually (-0.5,-0.5) to (639.5,359.5).  As such the Viewport is set
            // to 639x359 to account for the pixel coordinate offset of render target
            tagRECT rect;

            rect.top    = m_d3DDevice.Viewport.Y;
            rect.left   = m_d3DDevice.Viewport.X;
            rect.bottom = m_d3DDevice.Viewport.Y + m_d3DDevice.Viewport.Height;
            rect.right  = m_d3DDevice.Viewport.X + m_d3DDevice.Viewport.Width;

            m_previewHelper.Render(rect);

            // Draw the timecode top-center with a slight drop-shadow
            Rectangle rc = m_d3DFont.MeasureString(null, m_timeCodeString, Direct3D.DrawTextFormat.Center, Color.Black);
            int       x  = (m_d3DDevice.Viewport.Width / 2) - (rc.Width / 2);
            int       y  = 10;

            m_d3DFont.DrawText(null, m_timeCodeString, x + 1, y + 1, Color.Black);
            m_d3DFont.DrawText(null, m_timeCodeString, x, y, Color.White);

            m_d3DDevice.EndScene();
            m_d3DDevice.Present();
        }
Beispiel #6
0
        protected override void PerformRender( )
        {
            Matrix transformMatrix = d3d.View * d3d.Projection;

            d3d.Dx.Transform.World = Matrix.Translation(origin);

            lineRender.Antialias = true;
            lineRender.Width     = Direct3dRender.DefaultLineWidth;

            if (xAxis.Count == 2)
            {
                lineRender.DrawTransform(xAxis.ToArray( ), transformMatrix, Direct3dRender.DefaultXAxisColor);
                font.DrawText(null, "X", (int)xAxisText.X, (int)xAxisText.Y, Direct3dRender.DefaultXAxisColor);


                if (xAxisCone != null)
                {
                    d3d.Dx.Transform.World = xAxisConeMatrix;
                    d3d.Dx.Material        = xAxisConeMatrial;

                    xAxisCone.M.DrawSubset(0);

                    d3d.Dx.Transform.World = Matrix.Identity;
                }
            }

            if (yAxis.Count == 2)
            {
                lineRender.DrawTransform(yAxis.ToArray( ), transformMatrix, Direct3dRender.DefaultYAxisColor);
                font.DrawText(null, "Y", (int)yAxisText.X, (int)yAxisText.Y, Direct3dRender.DefaultYAxisColor);

                if (yAxisCone != null)
                {
                    d3d.Dx.Transform.World = yAxisConeMatrix;
                    d3d.Dx.Material        = yAxisConeMatrial;

                    yAxisCone.M.DrawSubset(0);

                    d3d.Dx.Transform.World = Matrix.Identity;
                }
            }

            if (zAxis.Count == 2)
            {
                lineRender.DrawTransform(zAxis.ToArray( ), transformMatrix, Direct3dRender.DefaultZAxisColor);
                font.DrawText(null, "Z", (int)zAxisText.X, (int)zAxisText.Y, Direct3dRender.DefaultZAxisColor);

                if (zAxisCone != null)
                {
                    d3d.Dx.Transform.World = zAxisConeMatrix;
                    d3d.Dx.Material        = zAxisConeMatrial;

                    zAxisCone.M.DrawSubset(0);

                    d3d.Dx.Transform.World = Matrix.Identity;
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Called once per frame, the call is the entry point for 3d rendering. This
        /// function sets up render states, clears the viewport, and renders the scene.
        /// </summary>
        protected override void Render()
        {
            // Clear the viewport
            device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);

            device.BeginScene();

            // Demonstration 1
            // Draw a simple line
            firstFont.DrawText(null, "Font.DrawText", new Rectangle(150, 200, 0, 0), DrawTextFormat.NoClip, Color.Red);

            // Demonstration 2
            // Allow multiple draw calls to sort by texture changes by Sprite
            // When drawing 2D text use flags: SpriteFlags.AlphaBlend | SpriteFlags.SortTexture
            // When drawing 3D text use flags: SpriteFlags.AlphaBlend | SpriteFlags.SortDepthBackToFront
            ourSprite.Begin(SpriteFlags.AlphaBlend | SpriteFlags.SortTexture);
            secondFont.DrawText(ourSprite, "Font now caches letters on one or more textures.",
                                new Rectangle(10, presentParams.BackBufferHeight - 15 * 5, 0, 0), DrawTextFormat.NoClip,
                                Color.White);

            secondFont.DrawText(ourSprite, "In order to sort by texture state changes on muliple",
                                new Rectangle(10, presentParams.BackBufferHeight - 15 * 4, 0, 0), DrawTextFormat.NoClip,
                                Color.White);

            secondFont.DrawText(ourSprite, "draw calls to DrawText() pass a Sprite and use",
                                new Rectangle(10, presentParams.BackBufferHeight - 15 * 3, 0, 0), DrawTextFormat.NoClip,
                                Color.White);

            secondFont.DrawText(ourSprite, "flags SpriteFlags.AlphaBlend | SpriteFlags.SortTexture",
                                new Rectangle(10, presentParams.BackBufferHeight - 15 * 2, 0, 0), DrawTextFormat.NoClip,
                                Color.White);

            ourSprite.End();

            // Demonstration 3:
            // Word wrapping and unicode text.
            // Note that not all fonts support dynamic font linking.
            Rectangle rc = new Rectangle(10, 60, presentParams.BackBufferWidth, presentParams.BackBufferHeight);

            secondFont.DrawText(null, BigText, rc,
                                DrawTextFormat.Left | DrawTextFormat.WordBreak | DrawTextFormat.ExpandTabs,
                                Color.Purple);

            // Output statistics
            statsFont.DrawText(null, frameStats, new Rectangle(2, 0, 0, 0), DrawTextFormat.NoClip, Color.Yellow);
            statsFont.DrawText(null, deviceStats, new Rectangle(2, 15, 0, 0), DrawTextFormat.NoClip, Color.Yellow);

            // Draw D3DXFont mesh in 3D (blue)
            if (mesh3DText != null)
            {
                Material mtrl3d = GraphicsUtility.InitMaterial(Color.Blue);
                device.Material        = mtrl3d;
                device.Transform.World = objectTwo;
                mesh3DText.DrawSubset(0);
            }

            device.EndScene();
        }
        /// <summary>
        /// Renders the statistic-box.
        /// </summary>
        /// <param name="state"><see cref="SimulationState"/></param>
        public void RenderInfobox(SimulationState state)
        {
            int player = 0;

            for (int i = 0; i < state.TeamStates.Count; i++)
            {
                player += state.TeamStates[i].ColonyStates.Count;
            }

            int height   = ROWHEIGHT * player + 60;
            int position = (height / 2) + 10;

            line.Width = height;
            line.Begin();
            line.Draw
            (
                new Vector2[] { new Vector2(10, position), new Vector2(500, position) },
                Color.FromArgb(100, Color.White).ToArgb());
            line.End();

            fontNormal.DrawText(null, Resource.InfoboxColumnColony2, 20, ROWHEIGHT + 20, Color.Black);

            fontNormal.DrawText(null, Resource.InfoboxColumnCollectedFood1, 200, 20, Color.Green);
            fontNormal.DrawText(null, Resource.InfoboxColumnCollectedFood2, 200, ROWHEIGHT + 20, Color.Green);

            fontNormal.DrawText(null, Resource.InfoboxColumnKilledAnts1, 290, 20, Color.Red);
            fontNormal.DrawText(null, Resource.InfoboxColumnKilledAnts2, 290, ROWHEIGHT + 20, Color.Red);

            fontNormal.DrawText(null, Resource.InfoboxColumnKilledBugs1, 370, 20, Color.Blue);
            fontNormal.DrawText(null, Resource.InfoboxColumnKilledBugs2, 370, ROWHEIGHT + 20, Color.Blue);

            fontNormal.DrawText(null, Resource.InfoboxColumnPoints2, 440, ROWHEIGHT + 20, Color.Black);

            int count = 0;

            for (int i = 0; i < state.TeamStates.Count; i++)
            {
                for (int j = 0; j < state.TeamStates[i].ColonyStates.Count; j++)
                {
                    ColonyState colony     = state.TeamStates[i].ColonyStates[j];
                    int         killedAnts = colony.StarvedAnts + colony.EatenAnts + colony.BeatenAnts;

                    fontBold.DrawText
                        (null, colony.ColonyName, 20, count * ROWHEIGHT + 55, antMaterial[count].Emissive);
                    fontNormal.DrawText
                        (null, colony.CollectedFood.ToString(), 200, count * ROWHEIGHT + 55, Color.Green);
                    fontNormal.DrawText
                        (null, killedAnts.ToString(), 290, count * ROWHEIGHT + 55, Color.Red);
                    fontNormal.DrawText
                        (null, colony.KilledBugs.ToString(), 370, count * ROWHEIGHT + 55, Color.Blue);
                    fontBold.DrawText
                        (null, colony.Points.ToString(), 440, count * ROWHEIGHT + 55, Color.Black);
                    count++;
                }
            }
        }
Beispiel #9
0
 public void DrawText(string text)
 {
     if (textFont == null)
     {
         throw new InvalidOperationException("You cannot draw text.  There is no font object.");
     }
     // Create the rectangle to draw to
     System.Drawing.Rectangle rect = new System.Drawing.Rectangle(point, System.Drawing.Size.Empty);
     textFont.DrawText(null, text, rect,
                       DrawTextFormat.NoClip | DrawTextFormat.ExpandTabs | DrawTextFormat.WordBreak, color);
 }
Beispiel #10
0
        //Display flying score
        public void DisplayScore(Microsoft.DirectX.Direct3D.Font font)
        {
            if (scorenum > 0)
            {
                font.DrawText(null, "+" + scorenum, pos, Color.LightCyan);
            }

            if (scorenum < 0)
            {
                font.DrawText(null, "" + scorenum, pos, Color.LightCyan);
            }
        }
Beispiel #11
0
        /// <summary>
        /// Override the OnPaint method.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaint(PaintEventArgs e)
        {
            //Before this render, we should update any state
            OnFrameUpdate();

            device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
            device.BeginScene();
            //draw the two roads
            DrawRoad(0.0f, 0.0f, RoadDepth0);
            DrawRoad(0.0f, 0.0f, RoadDepth1);
            //draw the car
            car.Draw(device);
            foreach (Obstacle o in obstacles)
            {
                o.Draw(device);
            }

            if (hasGameStarted)
            {
                // Draw the score
                scoreFont.DrawText(null, string.Format("Current score: {0}", score),
                                   new Rectangle(5, 5, 0, 0), DrawTextFormat.NoClip, Color.Yellow);
            }

            if (isGameOver)
            {
                // Game over, man!
                if (hasGameStarted)
                {
                    gameFont.DrawText(null, "You crashed.  The game is over.", new Rectangle(25, 45, 0, 0), DrawTextFormat.NoClip, Color.Red);
                }
                if ((System.Environment.TickCount - gameOverTick) >= 1000)
                {
                    gameFont.DrawText(null, "Press any key to begin.", new Rectangle(25, 100, 0, 0), DrawTextFormat.NoClip, Color.WhiteSmoke);
                }

                // display high scores
                gameFont.DrawText(null, "High Scores: ", new Rectangle(25, 155, 0, 0),
                                  DrawTextFormat.NoClip, Color.CornflowerBlue);

                for (int i = 0; i < highScores.Length; i++)
                {
                    gameFont.DrawText(null, string.Format("Player: {0} : {1}", highScores[i].Name,
                                                          highScores[i].Score),
                                      new Rectangle(25, 210 + (i * 55), 0, 0), DrawTextFormat.NoClip, Color.CornflowerBlue);
                }
            }

            device.EndScene();
            device.Present();
            this.Invalidate();
        }
Beispiel #12
0
        /// <summary>
        /// Draw text outline
        /// </summary>
        /// <param name="font"></param>
        /// <param name="sprite"></param>
        /// <param name="text"></param>
        /// <param name="rect"></param>
        /// <param name="format"></param>
        /// by zzm
        private void DrawOutline(D3Font font, Sprite sprite, string text, ref Rectangle rect, DrawTextFormat format)
        {
            int color = 0xB0 << 24;

            font.DrawText(sprite, text, rect, format, color);
            rect.Offset(2, 0);
            font.DrawText(sprite, text, rect, format, color);
            rect.Offset(0, 2);
            font.DrawText(sprite, text, rect, format, color);
            rect.Offset(-2, 0);
            font.DrawText(sprite, text, rect, format, color);
            rect.Offset(1, -1);
        }
Beispiel #13
0
        public void DisplayScore()
        {
            // Show score in upper left corner
            font.DrawText(null,                 // Because I say so
                          "Score: " + scorenum, // Text to draw
                          new Point(10, 25),    // Location on the display (pixels with 0,0 as upper left)
                          Color.LightCyan);     // Font color

            foreach (ScoreFlying s in FlyingScores)
            {
                s.DisplayScore(font);
            }
        }
Beispiel #14
0
        // --------------------------------------------------------------------
        // Render the current game screen
        // --------------------------------------------------------------------
        protected virtual void Render()
        {
            if (_graphics != null)
            {
                // check to see if the device has been lost. If so, try to get
                // it back.
                if (_graphicslost)
                {
                    try
                    {
                        _graphics.TestCooperativeLevel();
                    }
                    catch (DeviceLostException)
                    {
                        // device cannot be reaquired yet, just return
                        return;
                    }
                    catch (DeviceNotResetException)
                    {
                        // device has not been reset, but it can be reaquired now

                        _graphics.Reset(_graphics.PresentationParameters);
                    }
                    _graphicslost = false;
                }


                try
                {
                    _graphics.Clear(ClearFlags.Target, Color.Blue, 1.0f, 0);

                    _graphics.BeginScene();

                    if (_pendulum != null)
                    {
                        _pendulum.Move(_gametimer);
                        _font.DrawText(null, string.Format(" Angle: {0:0.0}", _pendulum.MaxAngle), new Point(10, 20), Color.White);
                        _font.DrawText(null, string.Format("Length: {0:0.0}", _pendulum.Length), new Point(10, 40), Color.White);
                    }

                    _graphics.EndScene();
                    _graphics.Present();
                }

                // device has been lost, and it cannot be re-initialized yet
                catch (DeviceLostException)
                {
                    _graphicslost = true;
                }
            }
        }
Beispiel #15
0
        private void RenderText()
        {
            int    length  = 70;
            String tsub    = String.Empty;
            int    offsetY = 0;
            int    t       = 0;
            String temp    = String.Empty;

            for (t = 0; t < sentences.Count; t++)
            {
                int count   = (sentences[t].text.Length - (sentences[t].text.Length % length)) / length;
                int offsetX = 0;
                int i       = 0;
                for (i = 0; i < count; i++)
                {
                    tsub = temp + sentences[t].text.Substring(i * length, length);
                    int lastspace = tsub.LastIndexOf(" ");
                    temp = tsub.Substring(lastspace + 1);
                    tsub = tsub.Remove(lastspace);

                    if (i == 0)
                    {
                        tsub = tsub.Insert(0, sentences[t].name + ": ");
                    }
                    else
                    {
                        offsetX = 35;
                    }

                    f2.DrawText(null, tsub, device.Viewport.Width - 500 + offsetX, device.Viewport.Height - 250 + (t + i + offsetY) * 16, sentences[t].color);
                }

                f2.DrawText(null, temp + sentences[t].text.Substring(i * length), device.Viewport.Width - 500 + offsetX, device.Viewport.Height - 250 + (t + i + offsetY) * 16, sentences[t].color);

                temp     = String.Empty;
                offsetY += i;
            }

            bool timeout = false;

            if (sentences.Count > 0)
            {
                timeout = ((Environment.TickCount) - sentences[0].time >= 20000);
            }

            if (device.Viewport.Height - 250 + (t + offsetY) * 16 >= device.Viewport.Height || timeout)
            {
                sentences.RemoveAt(0);
            }
        }
Beispiel #16
0
        public override void OnRender(Canvas c)
        {
            c.DrawFillRect(_client_area, _background_color_material);
            _font.DrawText(null, _text, ClientArea, DrawTextFormat.VerticalCenter | DrawTextFormat.Center, ForegroundColor);

            c.DrawRect(_client_area, BorderColor);
        }
Beispiel #17
0
        public override void OnRender(Canvas canvas)
        {
            font_small.DrawText(null, "Selected Item: " + Item, 300, 10, Color.Yellow);
            menu.OnRender(canvas);

            //base.OnRender(canvas);
        }
Beispiel #18
0
    } // Tela_KeyDown().fim

    // Mostra texto na posição (x, y) da tela
    private void MostrarMensagem(int xpos, int ylin, string txt)
    {
      // Configura posição
      Rectangle position = new Rectangle(xpos, ylin, 0, 0);
      // Mostra texto
      dxfMensagem.DrawText(null, txt, position, DrawTextFormat.NoClip, Color.Blue);
    } // MostrarMensagem().fim   
Beispiel #19
0
        } // mostrarJoystickInfo()

        private void mostrarMensagem(int coluna, int linha, string txt)
        {
            Rectangle pos = new Rectangle(coluna, linha, 0, 0);

            dxfMensagem.DrawText(null, txt, pos,
                                 DrawTextFormat.NoClip, Color.Blue);
        } // Mensagem().fim
 public void Draw(Microsoft.DirectX.Direct3D.Font pText, Color textColor)
 {
     if (this.PosX != 0 || this.PosY != 0)
     {
         pText.DrawText(null, this.Name, new Point(this.PosX, this.PosY), textColor);
     }
 }
Beispiel #21
0
        public void DrawObject(ViewerObjectBase obj)
        {
            var x = 2f * (2f / _scale);

            _device.Transform.World = Matrix.Scaling(x, x, x);

            if (obj.Rotate)
            {
                var transforms1 = _device.Transform;
                transforms1.World *= Matrix.RotationZ(6.283185f - obj.Orientation);
            }

            var transform = _device.Transform;

            transform.World *= Matrix.Translation(obj.Position);

            _device.RenderState.TextureFactor = obj.Color;
            var textureState = _device.TextureState[0];

            textureState.ColorOperation = TextureOperation.Modulate;
            textureState.ColorArgument0 = TextureArgument.TextureColor;
            textureState.ColorArgument1 = TextureArgument.TFactor;
            _device.VertexFormat        = VertexFormats.Diffuse | VertexFormats.Position;
            _device.SetTexture(0, null);
            _device.SetStreamSource(0, obj.VbBuffer, 0);
            _device.DrawPrimitives(PrimitiveType.TriangleList, 0, obj.NumberOfVertexs);

            var v = Vector3.Project(new Vector3(0f, 0f, 0f), _device.Viewport, _device.Transform.Projection, _device.Transform.View, _device.Transform.World);

            obj.Vector2 = new Vector2(v.X, v.Y);
            _font.DrawText(null, obj.ToString(), (int)v.X + 10, (int)v.Y - 4, _textColor);
        }
Beispiel #22
0
        public override void Render(Device device)
        {
            if (Initialized)
            {
                // Draw the Panel
                Background.Begin(SpriteFlags.AlphaBlend);
                if (IsClicked)
                {
                    Background.Draw(Clicked, new Rectangle(0, 0, Size.Width, Size.Height), Vector3.Empty, new Vector3((int)(Position.X + (Parent != null ? Parent.Position.X : 0)), (int)(Position.Y + (Parent != null ? Parent.Position.Y : 0)), 0), BitConverter.ToInt32(new byte[] { 0xFF, 0xFF, 0xFF, (byte)Opacity }, 0));
                }
                else if (IsMouseOver)
                {
                    Background.Draw(Hover, new Rectangle(0, 0, Size.Width, Size.Height), Vector3.Empty, new Vector3((int)(Position.X + (Parent != null ? Parent.Position.X : 0)), (int)(Position.Y + (Parent != null ? Parent.Position.Y : 0)), 0), BitConverter.ToInt32(new byte[] { 0xFF, 0xFF, 0xFF, (byte)Opacity }, 0));
                }
                else
                {
                    Background.Draw(Normal, new Rectangle(0, 0, Size.Width, Size.Height), Vector3.Empty, new Vector3((int)(Position.X + (Parent != null ? Parent.Position.X : 0)), (int)(Position.Y + (Parent != null ? Parent.Position.Y : 0)), 0), BitConverter.ToInt32(new byte[] { 0xFF, 0xFF, 0xFF, (byte)Opacity }, 0));
                }

                // Center and Draw Text
                int y = ((150 - (Text.Length * 2)) / 2) - 19;
                font.DrawText(Background, Text, new Point((int)(Position.X + (Parent != null ? Parent.Position.X : 0)) + y, (int)(Position.Y + (Parent != null ? Parent.Position.Y : 0)) + 3), Color.Black);
                Background.End();
            }
        }
Beispiel #23
0
        public override void DrawText(Point dest_pt, string text)
        {
            if (mSprite == null)
            {
                mSprite = new Microsoft.DirectX.Direct3D.Sprite(mD3DFont.Device);
            }

            Point dest = Origin.Calc(DisplayAlignment, StringDisplaySize(text));


            dest_pt.X -= dest.X;
            dest_pt.Y -= dest.Y;

            double scalex, scaley;

            GetScale(out scalex, out scaley);

            mDisplay.D3D_Device.DrawBuffer.Flush();
            mDisplay.D3D_Device.SetFontRenderState();

            mSprite.Begin(SpriteFlags.AlphaBlend);
            mSprite.Transform = Matrix.Scaling((float)scalex, (float)scaley, 1.0f)
                                * Matrix.Translation(dest_pt.X, dest_pt.Y, 0);

            mD3DFont.DrawText(mSprite, text, new System.Drawing.Point(0, 0), Color.ToArgb());

            mSprite.End();
        }
Beispiel #24
0
        public void Render(Device device, Vector3 cameraPosition, Vehicle selectedVehicle, string time)
        {
            if (!isDeviceInit)
            {
                InitDevice(device);
            }

            //DRAW EDGES
            foreach (var edge in edges)
            {
                device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, edge);
            }

            //DRAW POINTS
            foreach (var vertex in vertexes)
            {
                device.DrawUserPrimitives(PrimitiveType.TriangleFan, ViewConsts.POINT_PRECISION, vertex);
            }

            DrawVehicles(device, cameraPosition, selectedVehicle);

            DrawCarInstersections(device);

            //DRAW TIME
            text.DrawText(null, time, new Point(12, 11), Color.Black);
            line.Draw(lineVertexes, Color.Black);
        }
Beispiel #25
0
        //TODO: Need to render enemies at certain times. Don't know when, but probably need to put that here or in Advance
        public void Render()
        {
            //This is the soundtrack. This can be changed if necessary
            //sounds.Soundtrack();
            if (device == null)
            {
                return;
            }

            device.Clear(ClearFlags.Target, System.Drawing.Color.Blue, 1.0f, 0);

            int   wid    = Width;                         // Width of our display window
            int   hit    = Height;                        // Height of our display window.
            float aspect = (float)wid / (float)hit;       // What is the aspect ratio?

            device.RenderState.ZBufferEnable = false;     // We'll not use this feature
            device.RenderState.Lighting      = false;     // Or this one...
            device.RenderState.CullMode      = Cull.None; // Or this one...

            float widP = playingH * aspect;               // Total width of window

            float winCenter = player.P.X;

            //if (winCenter - widP / 2 < 0)
            winCenter = widP / 2;
            //else if (winCenter + widP / 2 > playingW)
            //winCenter = playingW - widP / 2;

            device.Transform.Projection = Matrix.OrthoOffCenterLH(winCenter - widP / 2,
                                                                  winCenter + widP / 2,
                                                                  0, playingH, 0, 1);

            //Begin the scene
            device.BeginScene();

            // Render the background
            background.Render();

            //score display
            font.DrawText(null,              // Because I say so
                          "Score: " + score, // Text to draw
                          new Point(25, 15), // Location on the display (pixels with 0,0 as upper left)
                          Color.LightCyan);  // Font color

            foreach (Polygon p in lasers)
            {
                p.Render(device);
            }

            foreach (Polygon p in enemies)
            {
                p.Render(device);
            }

            player.Render(device);

            //End the scene
            device.EndScene();
            device.Present();
        }
Beispiel #26
0
        public void FillTextWithFont(Microsoft.DirectX.Direct3D.Font p_font, int x, int y, string text, Color color, int center)
        {
            var device    = D3DDevice.Instance.Device;
            var screen_dx = device.PresentationParameters.BackBufferWidth;
            var screen_dy = device.PresentationParameters.BackBufferHeight;

            // elimino cualquier textura que me cague el modulate del vertex color
            device.SetTexture(0, null);
            // Desactivo el zbuffer
            bool ant_zenable = device.RenderState.ZBufferEnable;

            device.RenderState.ZBufferEnable = false;
            // pongo la matriz identidad
            Microsoft.DirectX.Matrix matAnt = sprite.Transform * Microsoft.DirectX.Matrix.Identity;
            sprite.Transform = Microsoft.DirectX.Matrix.Identity;
            sprite.Begin(SpriteFlags.AlphaBlend);
            switch (center)
            {
            case 1:
            {
                Rectangle rc = new Rectangle(0, y, screen_dx, y + 100);
                p_font.DrawText(sprite, text, rc, DrawTextFormat.Center, color);
            }
            break;

            case 2:
            {
                Rectangle rc = new Rectangle(x - screen_dx, y, x, y + 100);
                p_font.DrawText(sprite, text, rc, DrawTextFormat.NoClip | DrawTextFormat.Top | DrawTextFormat.Right, color);
            }
            break;

            default:
            {
                Rectangle rc = new Rectangle(x, y, x + 600, y + 100);
                p_font.DrawText(sprite, text, rc, DrawTextFormat.NoClip | DrawTextFormat.Top | DrawTextFormat.Left, color);
            }
            break;
            }
            sprite.End();

            // Restauro el zbuffer
            device.RenderState.ZBufferEnable = ant_zenable;
            // Restauro la transformacion del sprite
            sprite.Transform = matAnt;
        }
Beispiel #27
0
        } // onPaint().fim

        // ---]


        // Mostra texto com tamanho de fonte grande para títulos
        private void MostrarTitulo(int xpos, int ylin, string txt, Color font_cor)
        {
            // Configura posição
            Rectangle position = new Rectangle(xpos, ylin, 0, 0);

            // Mostra texto
            dxfTitulo.DrawText(null, txt, position, DrawTextFormat.NoClip, font_cor);
        } // MostrarTitulo().fim
Beispiel #28
0
 public void DisplayLives()
 {
     // Show number of lives in upper left corner
     font.DrawText(null,                  // Because I say so
                   "Lives: " + lives_num, // Text to draw
                   new Point(10, 10),     // Location on the display (pixels with 0,0 as upper left)
                   Color.LightCyan);      // Font color
 }
Beispiel #29
0
 private void DrawLargeText(string text, PointF position, Color color)
 {
     sprite.Begin(SpriteFlags.AlphaBlend);
     {
         largeFont.DrawText(sprite, text, new Point((int)position.X, (int)position.Y), color);
     }
     sprite.End();
 }
        public void render()
        {
            Sprite sprite = GuiController.Instance.Text3d.TextSprite;

            sprite.Begin(SpriteFlags.AlphaBlend);
            d3dFont.DrawText(sprite, text, rectangle, format, color);
            sprite.End();
        }
Beispiel #31
0
 /// <summary>
 /// Draws the given text to the given area of the screen using the given font.
 /// </summary>
 /// <param name="font">The font to write in.</param>
 /// <param name="textRect">Where to display the text on the screen.</param>
 /// <param name="text">The text to write.</param>
 protected void drawText(D3DFont font, Rectangle textRect, string text)
 {
     font.DrawText(null, text, textRect, D3D.DrawTextFormat.WordBreak | D3D.DrawTextFormat.Center, Color.Black);
 }
Beispiel #32
0
        public void Render1()
        {
            dx_device.Clear(ClearFlags.Target | ClearFlags.ZBuffer | ClearFlags.Stencil, Color.Blue, 1.0f, 0);

            dx_device.BeginScene();
            dx_device.SetTexture(0, m_Tex);

            dx_device.SetTransform(TransformType.World, m_Camera.m_World);
            dx_device.SetTransform(TransformType.View, m_Camera.m_View);
            dx_device.SetTransform(TransformType.Projection, m_Camera.m_Projection);

            // 원래 객체를 그린다.
            dx_device.RenderState.ShadeMode = ShadeMode.Gouraud;
            dx_device.RenderState.CullMode = Cull.None;
            dx_device.RenderState.ZBufferWriteEnable = true;
            dx_device.RenderState.StencilEnable = false;
            dx_device.RenderState.AlphaBlendEnable = false;
            //            m_Objects[4].render(dx_device);

            // 그림자 영역을 그린다.
            dx_device.RenderState.ZBufferWriteEnable = false;
            dx_device.RenderState.StencilEnable = true;
            dx_device.RenderState.ShadeMode = ShadeMode.Flat;
            dx_device.RenderState.StencilFunction = Compare.Always;
            dx_device.RenderState.StencilZBufferFail = StencilOperation.Keep;
            dx_device.RenderState.StencilFail = StencilOperation.Keep;
            dx_device.RenderState.ReferenceStencil = 1;
            dx_device.RenderState.StencilMask = -1;
            dx_device.RenderState.StencilWriteMask = -1;
            dx_device.RenderState.StencilPass = StencilOperation.Increment;
            dx_device.RenderState.AlphaBlendEnable = true;
            dx_device.RenderState.SourceBlend = Blend.Zero;
            dx_device.RenderState.DestinationBlend = Blend.One;

            dx_device.Transform.World = m_Camera.m_ShadowWorld;
            m_Objects[4].render(dx_device);
            dx_device.Transform.World = m_Camera.m_World;

            // 원래 객체를 그린다.
            dx_device.RenderState.ShadeMode = ShadeMode.Gouraud;
            dx_device.RenderState.CullMode = Cull.None;
            dx_device.RenderState.ZBufferWriteEnable = true;
            dx_device.RenderState.StencilEnable = false;
            dx_device.RenderState.AlphaBlendEnable = false;
            m_Objects[0].render(dx_device);
            m_Objects[1].render(dx_device);
            m_Objects[4].render(dx_device);

            // 그림자에 해당하는 부분을 다시 그린다.
            dx_device.RenderState.ZBufferEnable = true;
            dx_device.RenderState.ZBufferWriteEnable = false;
            dx_device.RenderState.StencilEnable = true;
            dx_device.RenderState.AlphaBlendEnable = true;
            dx_device.RenderState.SourceBlend = Blend.SourceAlpha;
            dx_device.RenderState.DestinationBlend = Blend.InvSourceAlpha;

            dx_device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
            dx_device.TextureState[0].ColorArgument2 = TextureArgument.Constant;
            dx_device.TextureState[0].ColorOperation = TextureOperation.SelectArg2;
            dx_device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor;
            dx_device.TextureState[0].AlphaArgument2 = TextureArgument.Diffuse;
            dx_device.TextureState[0].AlphaOperation = TextureOperation.Modulate;

            dx_device.RenderState.ReferenceStencil = 1;
            dx_device.RenderState.StencilFunction = Compare.LessEqual;
            dx_device.RenderState.StencilPass = StencilOperation.Keep;

            m_Objects[0].render(dx_device);

            dx_device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
            dx_device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse;
            dx_device.TextureState[0].ColorOperation = TextureOperation.Modulate;
            dx_device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor;
            dx_device.TextureState[0].AlphaArgument2 = TextureArgument.Diffuse;
            dx_device.TextureState[0].AlphaOperation = TextureOperation.Modulate;

            dx_device.RenderState.ShadeMode = ShadeMode.Gouraud;
            dx_device.RenderState.CullMode = Cull.None;
            dx_device.RenderState.ZBufferWriteEnable = true;
            dx_device.RenderState.StencilEnable = false;
            dx_device.RenderState.AlphaBlendEnable = false;

            FontDescription desc = new FontDescription();
            Microsoft.DirectX.Direct3D.Font fnt = new Microsoft.DirectX.Direct3D.Font(dx_device, desc);

            fnt.DrawText(null, m_Camera.ToString() + "\n"
                + m_Cursor.ToString() + "\n"
                + m_Camera.getPicking(m_Cursor.m_MousePoint, dx_device.Viewport) + "\n"
                + m_Count, new Point(5, 5), Color.White);

            m_Count = (m_Count + 1) % 10000;

            fnt.Dispose();

            dx_device.EndScene();

            dx_device.Present();
        }
        public void Render()
        {
            if (!this.m_Paused) {
            this.m_Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0F, 0);
            this.m_Device.BeginScene();

            this.SetupMatrices();

            for (Int32 counter = 0; counter < this.m_Material.Length; counter++) {
              this.m_Device.Material = this.m_Material[counter];
              this.m_Device.SetTexture(0, this.m_Texture[counter]);
              this.m_Mesh.DrawSubset(counter);
            }

            String text = String.Empty;
            switch (this.m_ViewAngle) {
              case ViewAngle.Front:
            text = " Left►\r\nD\r\no\r\nw\r\nn\r\n▼";
            break;

              case ViewAngle.Back:
            text = " Right►\r\nD\r\no\r\nw\r\nn\r\n▼";
            break;

              case ViewAngle.Bottom:
              case ViewAngle.Top:
            text = " Right►\r\nB\r\na\r\nc\r\nk\r\n▼";
            break;

              case ViewAngle.Left:
            text = " Back►\r\nD\r\no\r\nw\r\nn\r\n▼";
            break;

              case ViewAngle.Right:
            text = " Front►\r\nD\r\no\r\nw\r\nn\r\n▼";
            break;
            }

            System.Drawing.Font fontBase = new System.Drawing.Font("Courier New", 12, FontStyle.Regular, GraphicsUnit.Pixel);
            Microsoft.DirectX.Direct3D.Font font = new Microsoft.DirectX.Direct3D.Font(this.m_Device, fontBase);
            font.DrawText(null, text, new Point(0, 0), Color.Blue);
            font.Dispose();

            this.m_Device.EndScene();
            this.m_Device.Present();
              }
        }
Beispiel #34
0
 /// <summary>
 /// Draw text outline
 /// </summary>
 /// <param name="font"></param>
 /// <param name="sprite"></param>
 /// <param name="text"></param>
 /// <param name="rect"></param>
 /// <param name="format"></param>
 /// by zzm
 private void DrawOutline(D3Font font, Sprite sprite, string text, ref Rectangle rect, DrawTextFormat format)
 {
     int color = 0xB0 << 24;
     font.DrawText(sprite, text, rect, format, color);
     rect.Offset(2, 0);
     font.DrawText(sprite, text, rect, format, color);
     rect.Offset(0, 2);
     font.DrawText(sprite, text, rect, format, color);
     rect.Offset(-2, 0);
     font.DrawText(sprite, text, rect, format, color);
     rect.Offset(1, -1);
 }
Beispiel #35
0
        public void Render1()
        {
            dx_device.Clear(ClearFlags.Target | ClearFlags.ZBuffer | ClearFlags.Stencil, Color.Blue, 1.0f, 0);

            dx_device.BeginScene();
            dx_device.SetTexture(0, m_Tex);

            dx_device.SetTransform(TransformType.World, m_Camera.m_World);
            dx_device.SetTransform(TransformType.View, m_Camera.m_View);
            dx_device.SetTransform(TransformType.Projection, m_Camera.m_Projection);

            // 원래 객체를 그린다.
            dx_device.RenderState.ShadeMode = ShadeMode.Gouraud;
            dx_device.RenderState.CullMode = Cull.None;
            dx_device.RenderState.ZBufferWriteEnable = true;
            dx_device.RenderState.StencilEnable = false;
            dx_device.RenderState.AlphaBlendEnable = false;
            //            m_Objects[4].render(dx_device);

            // 그림자 영역을 그린다.
            dx_device.RenderState.ZBufferWriteEnable = false;
            dx_device.RenderState.StencilEnable = true;
            dx_device.RenderState.ShadeMode = ShadeMode.Flat;
            dx_device.RenderState.StencilFunction = Compare.Always;
            dx_device.RenderState.StencilZBufferFail = StencilOperation.Keep;
            dx_device.RenderState.StencilFail = StencilOperation.Keep;
            dx_device.RenderState.ReferenceStencil = 1;
            dx_device.RenderState.StencilMask = -1;
            dx_device.RenderState.StencilWriteMask = -1;
            dx_device.RenderState.StencilPass = StencilOperation.Increment;
            dx_device.RenderState.AlphaBlendEnable = true;
            dx_device.RenderState.SourceBlend = Blend.Zero;
            dx_device.RenderState.DestinationBlend = Blend.One;

            //            dx_device.Transform.World = m_Camera.m_ShadowWorld;
            //            m_Objects[4].render(dx_device);
            //            dx_device.Transform.World = m_Camera.m_World;
            VertexBuffer tmp = m_Walls.m_shadow.BuildShadowVertex(dx_device, m_Camera.m_Position.pos);
            m_Walls.BuildVertexBuffer(dx_device, m_Camera.m_Position.pos);
            dx_device.SetStreamSource(0, tmp, 0);
            dx_device.VertexFormat = tmp.Description.VertexFormat;
            dx_device.DrawPrimitives(PrimitiveType.TriangleList, 0, m_Walls.m_shadow.m_VertexCount / 3);

            // 원래 객체를 그린다.
            dx_device.RenderState.ShadeMode = ShadeMode.Gouraud;
            dx_device.RenderState.CullMode = Cull.None;
            dx_device.RenderState.ZBufferWriteEnable = true;
            dx_device.RenderState.StencilEnable = false;
            dx_device.RenderState.AlphaBlendEnable = false;
            m_Objects[0].render(dx_device);
            m_Objects[1].render(dx_device);
            m_Walls.render(dx_device);

            dx_device.RenderState.Lighting = true;
            dx_device.Material = m_Material;
            dx_device.Transform.World =
                Matrix.Scaling(0.1f,2f,0.1f)
                * Matrix.Translation(m_Camera.m_Position.pos.X, 0, m_Camera.m_Position.pos.Y);
            m_Mesh.DrawSubset(0);
            dx_device.Transform.World = m_Camera.m_World;
            dx_device.RenderState.Lighting = false;

            // 그림자에 해당하는 부분을 다시 그린다.
            dx_device.RenderState.ZBufferEnable = true;
            dx_device.RenderState.ZBufferWriteEnable = false;
            dx_device.RenderState.StencilEnable = true;
            dx_device.RenderState.AlphaBlendEnable = true;
            dx_device.RenderState.SourceBlend = Blend.SourceAlpha;
            dx_device.RenderState.DestinationBlend = Blend.InvSourceAlpha;

            dx_device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
            dx_device.TextureState[0].ColorArgument2 = TextureArgument.Constant;
            dx_device.TextureState[0].ColorOperation = TextureOperation.SelectArg2;
            dx_device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor;
            dx_device.TextureState[0].AlphaArgument2 = TextureArgument.Diffuse;
            dx_device.TextureState[0].AlphaOperation = TextureOperation.Modulate;

            dx_device.RenderState.ReferenceStencil = 1;
            dx_device.RenderState.StencilFunction = Compare.LessEqual;
            dx_device.RenderState.StencilPass = StencilOperation.Keep;

            m_Objects[0].render(dx_device);

            dx_device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
            dx_device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse;
            dx_device.TextureState[0].ColorOperation = TextureOperation.Modulate;
            dx_device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor;
            dx_device.TextureState[0].AlphaArgument2 = TextureArgument.Diffuse;
            dx_device.TextureState[0].AlphaOperation = TextureOperation.Modulate;

            dx_device.RenderState.ShadeMode = ShadeMode.Gouraud;
            dx_device.RenderState.CullMode = Cull.None;
            dx_device.RenderState.ZBufferWriteEnable = true;
            dx_device.RenderState.StencilEnable = false;
            dx_device.RenderState.AlphaBlendEnable = false;

            FontDescription desc = new Microsoft.DirectX.Direct3D.FontDescription();
            Microsoft.DirectX.Direct3D.Font fnt = new Microsoft.DirectX.Direct3D.Font(dx_device, desc);

            fnt.DrawText(null, m_Camera.ToString() + "\n"
                + m_Walls.m_shadow + "\n"
                + m_Camera.getPicking(m_Cursor.m_MousePoint, dx_device.Viewport), new Point(5, 5), Color.Aquamarine);

            fnt.Dispose();

            dx_device.EndScene();

            dx_device.Present();
        }