예제 #1
0
 public TextManager(Device device, int screenWidth, int screenHeight)
 {
     _fontShader = new FontShader(device);
     _fontDictionary = new Dictionary<string, Font>();
     _screenWidth = screenWidth;
     _screenHeight = screenHeight;
     _device = device;
 }
예제 #2
0
        public void BuildVertexArray(String text, int positionX, int positionY, ref FontShader.Vertex[] vertices, out int width, out int height)
        {
            width = 0;
            height = Characters.First().Value.height;
            for (int i = 0; i < text.Length; i++)
            {
                Character c = Characters[text[i]];
                vertices[i * 4] = new FontShader.Vertex { position = new Vector3(positionX, positionY, 0.0f), texture = new Vector2(c.uLeft, c.vTop) }; //Top left
                vertices[i * 4 + 1] = new FontShader.Vertex { position = new Vector3(positionX + c.width, positionY - c.height, 0.0f), texture = new Vector2(c.uRight, c.vBottom) }; //Right bottom
                vertices[i * 4 + 2] = new FontShader.Vertex { position = new Vector3(positionX, positionY - c.height, 0.0f), texture = new Vector2(c.uLeft, c.vBottom) }; //Left bottom
                vertices[i * 4 + 3] = new FontShader.Vertex { position = new Vector3(positionX + c.width, positionY, 0.0f), texture = new Vector2(c.uRight, c.vTop) }; //Top right

                positionX += c.width + 1;
                width += c.width + 1;
            }
        }
예제 #3
0
 public AirplaneOverlay(Game game, Renderer renderer, Airplane airplane, Airplane playerAirplane)
     : base(game, renderer, airplane.UpdateOrder+1, false, true)
 {
     _airplane = airplane;
     _playerAirplane = playerAirplane;
     _shader = Renderer.FontShader;
     _overlay = new Bitmap(Renderer.DirectX.Device, Renderer.TextureManager.Create("Circle.png").TextureResource, Renderer.ScreenSize, new Vector2I(100, 100))
     {
         Position = new Vector2I(0,0),
         Size = new Vector2I(40, 40)
     };
     _color = new Vector4(0.2f, 0, 0, 0.4f);
     _distanceText = Renderer.TextManager.Create("Courrier", 14, 8, _color);
     _distanceText.Position = new Vector2I(0,0);
     _nameText = Renderer.TextManager.Create("Courrier", 14, 20, _color);
     _nameText.Position = new Vector2I(0,0);
     _nameText.Content = airplane.Name;
     _modelNameText = Renderer.TextManager.Create("Courrier", 14, 20, _color);
     _modelNameText.Position = new Vector2I(0, 0);
     _modelNameText.Content = airplane.ModelName;
 }
예제 #4
0
        public Text(Device device, FontShader shader, int screenWidth, int screenHeight, Font font, Int32 maxLength, Vector4 color)
        {
            Font = font;
            MaxLength = maxLength;
            Color = color;
            _shader = shader;
            _screenHeight = screenHeight;
            _screenWidth = screenWidth;
            // The index buffer is static and do not change when the text changes
            UInt32[] indices = new UInt32[maxLength * 6]; // 6 indices per character

            for (UInt32 i = 0; i < maxLength; i++)
            {
                indices[i * 6] = i * 4;
                indices[i * 6 + 1] = i * 4 + 1;
                indices[i * 6 + 2] = i * 4 + 2;
                indices[i * 6 + 3] = i * 4;
                indices[i * 6 + 4] = i * 4 + 3;
                indices[i * 6 + 5] = i * 4 + 1;
            }

            IndexBuffer = Buffer.Create(device, BindFlags.IndexBuffer, indices);

            // The vertex buffer is initialized empty
            _vertices = new FontShader.Vertex[maxLength * 4]; // 4 vertices per character

            var vertexBufferDesc = new BufferDescription
            {
                Usage = ResourceUsage.Dynamic,
                SizeInBytes = Utilities.SizeOf<FontShader.Vertex>() * maxLength * 4,
                BindFlags = BindFlags.VertexBuffer,
                CpuAccessFlags = CpuAccessFlags.Write,
                OptionFlags = ResourceOptionFlags.None,
                StructureByteStride = 0
            };

            // Create the vertex buffer.
            VertexBuffer = Buffer.Create(device, _vertices, vertexBufferDesc);
        }
예제 #5
0
 public Renderer()
 {
     CreateWindow();
     DirectX = new Dx11(Form);
     ScreenSize = new Vector2I(ConfigurationManager.Config.Width, ConfigurationManager.Config.Height);
     Light = new Light
     {
         Direction = new Vector3(1.0f, -1.0f, 0.0f),
         Color = new Vector4(1.0f, 1.0f, 1.0f, 1.0f),
         AmbiantColor = new Vector4(0.16f, 0.16f, 0.16f, 1.0f),
         SpecularPower = 32.0f,
         SpecularColor = new Vector4(1.0f, 1.0f, 0.7f, 1.0f)
     };
     ColorShader = new ColorShader(DirectX.Device);
     TextureShader = new TextureShader(DirectX.Device);
     LightShader = new LightShader(DirectX.Device);
     TranslateShader = new TranslateShader(DirectX.Device);
     CircleShader = new FontShader(DirectX.Device);
     FontShader = new FontShader(DirectX.Device);
     TextManager = new TextManager(DirectX.Device, ConfigurationManager.Config.Width, ConfigurationManager.Config.Height);
     TextureManager = new TextureManager(DirectX.Device);
     _renderables = new List<RenderableGameComponent>();
 }