Example #1
0
        public void Draw(Matrix world, Matrix view, Matrix projection, Color newcolor, float scale, float hoveringHeight)
        {
            // Set BasicEffect parameters.
            Matrix worldMatrix = Matrix.CreateScale(scale) *
                Matrix.CreateRotationX((float)(Math.PI)) *
                Matrix.CreateTranslation(new Vector3(0, 0, hoveringHeight)) *
                world;

            basicEffect.World = worldMatrix;
            basicEffect.View = view;
            basicEffect.Projection = projection;
            basicEffect.DiffuseColor = newcolor.ToVector3();
            // basicEffect.VertexColorEnabled = true;

            //basicEffect.Alpha = color.A / 255.0f;
            basicEffect.EmissiveColor = newcolor.ToVector3();

            GraphicsDevice device = basicEffect.GraphicsDevice;
            device.DepthStencilState = DepthStencilState.Default;
            device.BlendState = BlendState.AlphaBlend;

            // Draw the model, using BasicEffect.

            foreach (ModelMesh mesh in ship.Meshes)
            {
                mesh.Draw();
            }
        }
Example #2
0
        public static void Draw(Matrix world, Matrix view, Matrix projection, Color newcolor, float scale)
        {
            // Set BasicEffect parameters.
            basicEffect.World =  Matrix.CreateRotationZ((float) (Math.PI))  * Matrix.CreateScale(2.0f) * world;
            basicEffect.View = view;
            basicEffect.Projection = projection;
            basicEffect.DiffuseColor = newcolor.ToVector3();
            //basicEffect.VertexColorEnabled = true;

            basicEffect.Alpha = newcolor.A / 255.0f;
            basicEffect.EmissiveColor = newcolor.ToVector3();
            //basicEffect.EmissiveColor = new Color(100,100,0).ToVector3();
            basicEffect.SpecularColor = new Color(255, 255, 0).ToVector3();
            basicEffect.SpecularPower = 10f;
            //basicEffect.Texture = Texture2D.FromStream(Game1.device, new FileStream(@"Content\suntexture.png", FileMode.Open));
            // basicEffect.TextureEnabled = true;

            GraphicsDevice device = basicEffect.GraphicsDevice;
            device.DepthStencilState = DepthStencilState.Default;
            device.BlendState = BlendState.AlphaBlend;

            // Draw the model, using BasicEffect.
            Matrix translationMatrix = Matrix.CreateRotationY((float)(Math.PI / 2.0f));
            foreach (ModelMesh mesh in beam.Meshes)
            {
                mesh.Draw();
            }
        }
        public int AddFace(Face.Facing facing, float x, float y, float z, Vector3 size, ref Color color)
        {
            if (color == Color.Black) Console.WriteLine("Black detected.");
                for (int i = 0; i < buffers.Count; i++)
                {
                    if (!buffers[i].Full)
                    {
                        //int k = buffers[i].AddFace(Face.getFace(facing, new Vector3(x, y, z), size, color.ToVector3()));
                        int k = buffers[i].AddFace(Face.getInstancedFace(facing, new Vector3(x, y, z), size, color.ToVector3()));

                        if (k > -1)
                            return (i * Size) + k;

                        return -1;
                    }
                }

                buffers.Add(new BatchBuffer(Size));

                int j = buffers[buffers.Count - 1].AddFace(Face.getInstancedFace(facing, new Vector3(x, y, z), size, color.ToVector3()));

                if (j > -1)
                    return ((buffers.Count - 1) * Size) + j;

                return -1;
        }
Example #4
0
		public void AnnotateAvoidNeighbor(IVehicle threat, Vector3 ourFuture, Vector3 threatFuture)
		{
			Color green = new Color((byte)(255.0f * 0.15f), (byte)(255.0f * 0.6f), 0);

            annotation.Line(Position, ourFuture, green.ToVector3().FromXna());
            annotation.Line(threat.Position, threatFuture, green.ToVector3().FromXna());
            annotation.Line(ourFuture, threatFuture, Color.Red.ToVector3().FromXna());
            annotation.CircleXZ(Radius, ourFuture, green.ToVector3().FromXna(), 12);
            annotation.CircleXZ(Radius, threatFuture, green.ToVector3().FromXna(), 12);
		}
Example #5
0
 /// <summary>
 /// Button Row Constructor
 /// </summary>
 /// <param name="name">Control Name</param>
 /// <param name="position">Control Position</param>
 /// <param name="width">Control Width</param>
 /// <param name="titles">Button Titles</param>
 /// <param name="backColor">Backcolor</param>
 /// <param name="foreColor">Forecolor</param>
 public ButtonRow(string name, Vector2 position, float width, string[] titles, Color backColor, Color foreColor)
     : base(name)
 {
     this.Position = position;
     this.size = new Vector2(width, 0f);
     this.titles = titles;
     this.BackColor = backColor;
     this.highlight = new Color(backColor.ToVector3() * 0.9f);
     this.dimColor = new Color(backColor.ToVector3() * 0.85f);
     this.ForeColor = foreColor;
 }
Example #6
0
 public static void NightSettings()
 {
     SunPosition = new Vector3(0, -0.4f, -0.6f); //The moon in this case.
     SunColor = new Vector3(0.05f, 0.15f, 0.2f);
     SkyColor = new Color(0.06f, 0.06f, 0.15f);
     FogColor = SkyColor.ToVector3();
 }
Example #7
0
 public ActDye(Color TargetColor, float Time, bool isSolid = true, bool isRelative = false)
     : base(isSolid)
 {
     this.targetColor = TargetColor.ToVector3();
     this.frames = (int)(Time * Tool.GetFPS());
     this.isRelative = isRelative;
 }
Example #8
0
 public static void DaySettings()
 {
     SunPosition = new Vector3(0,-0.8f,-0.2f);
     SunColor = new Vector3(.8f, .8f, .8f);
     SkyColor = new Color(0, 0.8f, 1);
     FogColor = SkyColor.ToVector3();
 }
Example #9
0
        public static void DrawCube(Matrix W, Matrix V, Matrix P, Color color)
        {
            foreach (ModelMesh mesh in cube.Meshes)
            {
                foreach (ModelMeshPart part in mesh.MeshParts)
                {
                    // fontos a sorrend !!
                    // ha a forgatást a mozgatás után végeznénk el akkor is a (0, 0, 0) pont körül forgatna de mivel az már
                    //	nem a középpontja ezért teljesen más eredményt kapnánk
                    // ha előbb skáláznánk aztán mozgatnánk akkor a skálázás arányának megfelelően kéne változtatni
                    //	a mozgatást is
                    // a forgatást a skálázás után kell elvégezni valószinüleg..mármint hogy ne legyen semmi féle szétnyúlás
                    //	ami valószinüleg nem kívánt

                    basicEffect.EnableDefaultLighting();

                    basicEffect.DiffuseColor = color.ToVector3();

                    basicEffect.World = W;

                    basicEffect.View = V;
                    basicEffect.Projection = P;

                    part.Effect = basicEffect;
                }

                mesh.Draw();
            }
        }
        public void Draw(Matrix world, Matrix view, Matrix projection, Color color)
        {
            // Set BasicEffect parameters.
            basicEffect.World = world;
            basicEffect.View = view;
            basicEffect.Projection = projection;
            basicEffect.DiffuseColor = color.ToVector3();
            basicEffect.Alpha = color.A / 255.0f;

            GraphicsDevice device = basicEffect.GraphicsDevice;
            device.DepthStencilState = DepthStencilState.Default;

            if (color.A < 255)
            {
                // Set renderstates for alpha blended rendering.
                device.BlendState = BlendState.AlphaBlend;
            }
            else
            {
                // Set renderstates for opaque rendering.
                device.BlendState = BlendState.Opaque;
            }

            // Draw the model, using BasicEffect.
            Draw(basicEffect);
        }
        public static void Render(BoundingSphere sphere,
                                  GraphicsDevice graphicsDevice,
                                  Matrix view,
                                  Matrix projection,
                                  Color color,
                                  Guid id)
        {
            var subscription = Subscriptions[id];

            graphicsDevice.SetVertexBuffer(subscription.VertexBuffer);
            subscription.BasicEffect.World = Matrix.CreateScale(sphere.Radius)*
                                                   Matrix.CreateTranslation(sphere.Center);
            subscription.BasicEffect.View = view;
            subscription.BasicEffect.Projection = projection;
            subscription.BasicEffect.DiffuseColor = color.ToVector3();

            foreach (var pass in subscription.BasicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                graphicsDevice.DrawPrimitives(PrimitiveType.LineStrip, 0, SphereResolution);
                graphicsDevice.DrawPrimitives(PrimitiveType.LineStrip,
                                              SphereResolution + 1,
                                              SphereResolution);
                graphicsDevice.DrawPrimitives(PrimitiveType.LineStrip,
                                              (SphereResolution + 1)*2,
                                              SphereResolution);
            }
        }
Example #12
0
 public void ShouldConvertToVector3()
 {
     var color = new Color(0.1f, 0.2f, 0.3f);
     var vector = color.ToVector3();
     Assert.AreEqual(vector.X, color.R);
     Assert.AreEqual(vector.Y, color.G);
     Assert.AreEqual(vector.Z, color.B);
 }
 public LambertPointLightMaterial(Color ambientColor, Color lightColor, Vector3 lightPosition, float attenuation, float falloff)
 {
     AmbientLightColor = ambientColor.ToVector3();
     LightColor = lightColor.ToVector3();
     LightPosition = lightPosition;
     LightAttenuation = attenuation;
     LightFalloff = falloff;
 }
Example #14
0
 public Label( string name, Vector2 position, string text, Color color, float scale )//, Font font)
 {
     this.Type = ControlType.Label;
     this.name = name;
     this.position = position;
     this.text = text;
     this.scale = scale;
     this.color = new Color( new Vector4( color.ToVector3(), 1f ) );
 }
        public static void Draw(this BoundingBox boundingBox, RenderContext renderContext, Color color)
        {
            if (_basicEffect == null)
                _basicEffect = new BasicEffect(renderContext.GraphicsDevice);

            var lineList = new VertexPositionColor[8];
            var lineListIndices = new short[24];

            var index = 0;
            var min = boundingBox.Min;
            var max = boundingBox.Max;

            var boundingCorners = boundingBox.GetCorners();

            for (var i = 0; i < 8; ++i)
                lineList[i] = new VertexPositionColor(boundingCorners[i], color);

            index = 0;
            lineListIndices[index] = 0;
            lineListIndices[++index] = 1;
            lineListIndices[++index] = 1;
            lineListIndices[++index] = 2;
            lineListIndices[++index] = 2;
            lineListIndices[++index] = 3;
            lineListIndices[++index] = 3;
            lineListIndices[++index] = 0;

            lineListIndices[++index] = 4;
            lineListIndices[++index] = 5;
            lineListIndices[++index] = 5;
            lineListIndices[++index] = 6;
            lineListIndices[++index] = 6;
            lineListIndices[++index] = 7;
            lineListIndices[++index] = 7;
            lineListIndices[++index] = 4;

            lineListIndices[++index] = 0;
            lineListIndices[++index] = 4;
            lineListIndices[++index] = 1;
            lineListIndices[++index] = 5;
            lineListIndices[++index] = 2;
            lineListIndices[++index] = 6;
            lineListIndices[++index] = 3;
            lineListIndices[++index] = 7;

            _basicEffect.Projection = renderContext.Camera.Projection;
            _basicEffect.View = renderContext.Camera.View;
            _basicEffect.DiffuseColor = color.ToVector3();

            foreach (var pass in _basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                renderContext.GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.LineList, lineList, 0, lineList.Length, lineListIndices, 0, 12);
            }
        }
 /// <summary>
 /// Adiciona uma luz ao interpolador
 /// As cores das luzes adicionadas serao gerenciadas por este component
 /// </summary>
 /// <param name="dl">luz</param>
 /// <param name="c1">Cor original</param>
 /// <param name="c2">Cor destino</param>
 /// <param name="duration">Duracao da interpolacao em SEGUNDOS</param>
 public void AddLight(DeferredLight dl, Color c1, Color c2, double duration)
 {
     lightInterpolation l = new lightInterpolation();
     l.dl = dl;
     l.duration = duration;
     l.v1 = c1.ToVector3();
     l.v2 = c2.ToVector3();
     lights.Add(l);
     l.vi = new Vec3Interpolator();
     l.vi.Start(l.v1, l.v2, duration, true);
 }
 public XNABasicShaderDescription(Color AmbientColor, Color EmissiveColor, Color SpecularColor, float specularPower = 50, float alpha = 1, bool EnableLightning = true, bool EnableTexture = true)
 {
     this.AmbientColor = AmbientColor.ToVector3();
     this.EmissiveColor = EmissiveColor.ToVector3();
     this.SpecularColor = SpecularColor.ToVector3();
     this.SpecularPower = specularPower;
     this.alpha = alpha;
     this.EnableLightning = EnableLightning;
     this.EnableTexture = EnableTexture;
     DefaultLightning = false;
 }
Example #18
0
        public Obstacle(Vector3 position, Color color)
        {
            unitCube = GameMultiVerse.Instance.Content.Load<Model>("Models/cube");
            basicEffect = new BasicEffect(GameMultiVerse.Instance.GraphicsDevice);

            Matrix W = Matrix.CreateTranslation(position);
            boundingBox = Collision.UpdateBoundingBox(unitCube, W);

            basicEffect.EnableDefaultLighting();
            basicEffect.World = W;
            basicEffect.DiffuseColor = color.ToVector3();
        }
Example #19
0
        public static Texture2D Create(GraphicsDevice graphicsDevice, int width, int height, Color color)
        {
            Texture2D texture = new Texture2D(graphicsDevice, width, height, true, SurfaceFormat.Color);

            Color[] colors = new Color[width * height];
            for (int i = 0; i < width * height; i++)
                colors[i] = new Color(color.ToVector3());

            texture.SetData(colors);

            return texture;
        }
Example #20
0
        public Hoop(GraphicsDeviceManager g, ContentManager c, Vector3 position, Vector3 scale, Color color)
        {
            this.Scale = scale;
            this.Position = position;
            this.color = color.ToVector3();

            graphics = g;
            Content = c;

            aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio;

            cuboidModel = Content.Load<Model>("Models\\hoop");
        }
Example #21
0
        public static Texture2D Create(GraphicsDevice graphicsDevice, int width, int heigth, Color color)
        {
            Texture2D texture = new Texture2D(graphicsDevice, width, heigth, false, SurfaceFormat.Color);

            Color[] colors = new Color[width * heigth];
            for (int i = 0; i < colors.Length; i++)
            {
                colors[i] = new Color(color.ToVector3());

            }
            texture.SetData(colors);

            return texture;
        }
Example #22
0
        public static void Draw(Matrix world, Matrix view, Matrix projection, Color newcolor, float scale, bool isPopulated, float curAngle)
        {
            // Set BasicEffect parameters.
            Matrix worldMatrix = Matrix.CreateScale(scale) *
                 Matrix.CreateRotationZ( (float) ((curAngle / 360.0) * 2 * Math.PI)) *
                 world;
            basicEffect.World = worldMatrix;
            basicEffect.View = view;
            basicEffect.Projection = projection;
            basicEffect.DiffuseColor = newcolor.ToVector3();
            //basicEffect.VertexColorEnabled = true;

            //basicEffect.Alpha = color.A / 255.0f;
            basicEffect.EmissiveColor = newcolor.ToVector3();

            GraphicsDevice device = basicEffect.GraphicsDevice;
            device.DepthStencilState = DepthStencilState.Default;
            device.BlendState = BlendState.AlphaBlend;

            // Draw the model, using BasicEffect.

            if (isPopulated)
            {
                foreach (ModelMesh mesh in poplulatedPlanet.Meshes)
                {
                    mesh.Draw();
                }
            }
            else
            {
                foreach (ModelMesh mesh in unpoplulatedPlanet.Meshes)
                {
                    mesh.Draw();
                }
            }
        }
Example #23
0
        public SpaceshipCursor(Scene scene, Vector3 initialPosition, float speed, double visualPriority, Color color, string image, bool visible)
            : base(scene, initialPosition, speed, visualPriority, image, false)
        {
            FrontImage.SizeX = 4;

            SetBackImage(image + "Back", 4, color);
            Circle.Radius = FrontImage.Size.X / 2;

            FiringCursor = new Image("FiringDirection")
            { 
                SizeX = 4,
                Alpha = 150,
                VisualPriority = visualPriority + 0.00001
            };


            FiringCursor.Origin = new Vector2(FiringCursor.Center.X, FrontImage.Center.Y + 7);

            Color = color;

            ShowTrail = true;

            TrailEffect = Scene.Particles.Get(@"spaceshipTrail");
            TrailEffect.Model[0].ReleaseColour = Color.ToVector3();
            TrailEffect.VisualPriority = BackImage.VisualPriority + 0.00001;

            TrailEffect2 = Scene.Particles.Get(@"spaceshipTrail2");
            TrailEffect2.VisualPriority = BackImage.VisualPriority + 0.00002;

            LastPosition = Position;

            NotMovingReleaseSpeed = new ProjectMercury.VariableFloat()
            {
                Value = 50,
                Variation = 0
            };

            MovingReleaseSpeed = new ProjectMercury.VariableFloat()
            {
                Value = 0,
                Variation = 25
            };

            TrailEffect.Model[0].ReleaseSpeed = NotMovingReleaseSpeed;
            TrailEffect2.Model[0].ReleaseSpeed = NotMovingReleaseSpeed;

            ShowFiringCursor = false;
        }
Example #24
0
        public void InitBeginState(Model block, Model startBlock)
        {
            _block = block;

            _previousColor = _colors[0];
            _currentColor = _previousColor;
            Block.CurrentColor = _currentColor.ToVector3();

            _activeBlocks.Clear();
            _activeBlocks.Add(new StartBlock(startBlock, Vector3.Zero, _world, _view, _projection));

            while (_activeBlocks.Last().GetPositionZ() > -16*MHelper.Sqrt2)
            {
                CreateNextBlock();
            }
        }
Example #25
0
        /// <summary>Create a texture which has C0 in the upper left corner,
        /// C1 in the upper right corner, C2 in the lower left corner,
        /// and C3 in the lower right corner, with a smooth shading 
        /// between all points.</summary>
        public static Texture2D ShadedCornerColor(
            GraphicsDevice graphicsDevice, 
            Vector2 size, 
            Color c0, 
            Color c1, 
            Color c2, 
            Color c3)
        {
            HoloDebug.Assert(size.X > 0);
            HoloDebug.Assert(size.Y > 0);

            Vector3 v0 = c0.ToVector3();
            Vector3 v1 = c1.ToVector3();
            Vector3 v2 = c2.ToVector3();
            Vector3 v3 = c3.ToVector3();

            // The maximum sum of all distances is 2 + (2 ^ 0.5) (any corner).
            float sqrt2 = (float)Math.Sqrt(2);

            // RGBA32 format
            Color[] data = new Color[(int)size.X * (int)size.Y];

            for (int j = 0; j < size.Y; j++) {
                for (int i = 0; i < size.X; i++) {
                    float fi = (float)i / (float)(size.X - 1);
                    float fj = (float)j / (float)(size.Y - 1);

                    Vector2 currentPoint = new Vector2(fi, fj);

                    float dist0 = Math.Max(0, 1 - Vector2.Distance(new Vector2(0, 0), currentPoint));
                    float dist1 = Math.Max(0, 1 - Vector2.Distance(new Vector2(1, 0), currentPoint));
                    float dist2 = Math.Max(0, 1 - Vector2.Distance(new Vector2(0, 1), currentPoint));
                    float dist3 = Math.Max(0, 1 - Vector2.Distance(new Vector2(1, 1), currentPoint));

                    Vector3 vectorSum = (v0 * dist0) + (v1 * dist1) + (v2 * dist2) + (v3 * dist3);
                    Vector4 vectorSum1 = new Vector4(vectorSum, 1.0f);
                    Color color = new Color(vectorSum1);

                    data[i + (j * (int)size.X)] = color;
                }
            }

            Texture2D ret = new Texture2D(graphicsDevice, (int)size.X, (int)size.Y, mipMap: true, format: SurfaceFormat.Color);
            ret.SetData(data);
            return ret;
        }
Example #26
0
        public static void Draw(Matrix world, Matrix view, Matrix projection, Color newcolor)
        {
            // Set BasicEffect parameters.
            basicEffect.World = world;
            basicEffect.View = view;
            basicEffect.Projection = projection;
            basicEffect.DiffuseColor = newcolor.ToVector3();
            basicEffect.VertexColorEnabled = true;

            //basicEffect.Alpha = color.A / 255.0f;
            //basicEffect.EmissiveColor = newcolor.ToVector3();

            GraphicsDevice device = basicEffect.GraphicsDevice;
            device.DepthStencilState = DepthStencilState.Default;
            device.BlendState = BlendState.AlphaBlend;

            // Draw the model, using BasicEffect.
            Draw(basicEffect);
        }
Example #27
0
        public HSVColor(Color color)
            : this()
        {
            Vector3 rgb = color.ToVector3();
            A = color.A / 255f;
            if (A == 0)
            {
                rgb = Vector3.Zero;
            }
            else
            {
                rgb /= A;
            }

            float max = Math.Max(rgb.X, Math.Max(rgb.Y, rgb.Z));
            float min = Math.Min(rgb.X, Math.Min(rgb.Y, rgb.Z));
            V = max;
            if (max == 0)
            {
                H = 0;
                S = 0;
                return;
            }
            S = (max - min) / max;
            if (S == 0)
            {
                H = 0;
                return;
            }
            if (max == rgb.X)
            {
                H = 60f * (rgb.Y - rgb.Z) / (max - min);
            }
            else if (max == rgb.Y)
            {
                H = 60f * (rgb.Z - rgb.X) / (max - min) + 120f;
            }
            else
            {
                H = 60f * (rgb.X - rgb.Y) / (max - min) + 240f;
            }
        }
Example #28
0
        /// <summary>
        /// Renders a Ray for debugging purposes.
        /// </summary>
        /// <param name="ray">The ray to render.</param>
        /// <param name="length">The distance along the ray to render.</param>
        /// <param name="graphicsDevice">The graphics device to use when rendering.</param>
        /// <param name="view">The current view matrix.</param>
        /// <param name="projection">The current projection matrix.</param>
        /// <param name="color">The color to use drawing the ray.</param>
        public static void Render(Ray ray, float length, GraphicsDevice graphicsDevice, Matrix view, Matrix projection, Color color)
        {
            if (effect == null)
            {
                effect = new BasicEffect(graphicsDevice);
                effect.VertexColorEnabled = false;
                effect.LightingEnabled = false;
            }

            verts[0] = new VertexPositionColor(ray.Position, Color.White);
            verts[1] = new VertexPositionColor(ray.Position + (ray.Direction * length), Color.White);

            effect.DiffuseColor = color.ToVector3();
            effect.Alpha = (float)color.A / 255f;

            effect.World = Matrix.Identity;
            effect.View = view;
            effect.Projection = projection;

            //note you may wish to comment these next 2 lines out and set the RasterizerState elswehere in code 
            //rather than here for every ray draw call. 
            RasterizerState rs = graphicsDevice.RasterizerState;
            graphicsDevice.RasterizerState = RasterizerState.CullNone;

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();

                graphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, verts, 0, 1);

                effect.World = Matrix.Invert(Matrix.CreateLookAt(
                    verts[1].Position,
                    verts[0].Position,
                    (ray.Direction != Vector3.Up) ? Vector3.Up : Vector3.Left));

                graphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.LineList, arrowVerts, 0, 5, arrowIndexs, 0, 4);
            }

            //note you may wish to comment the next line out and set the RasterizerState elswehere in code 
            //rather than here for every ray draw call. 
            graphicsDevice.RasterizerState = rs;
        }
Example #29
0
        public static Texture2D Create(GraphicsDevice graphicsDevice, int width, int height, Color color)
        {
            string key = color.ToString () + width + "x" + height;
            if (textureCache.ContainsKey (key)) {
                return textureCache [key];
            }
            else {
                // create a texture with the specified size
                Texture2D texture = new Texture2D (graphicsDevice, width, height);

                // fill it with the specified colors
                Color[] colors = new Color[width * height];
                for (int i = 0; i < colors.Length; i++) {
                    colors [i] = new Color (color.ToVector3 ());
                }
                texture.SetData (colors);
                textureCache [key] = texture;
                return texture;
            }
        }
Example #30
0
        /// <summary>
        /// Creates a texture of the specified color.
        /// </summary>
        /// <param name="graphicsDevice">The graphics device to use.</param>
        /// <param name="width">The width of the texture.</param>
        /// <param name="height">The height of the texture.</param>
        /// <param name="color">The color to set the texture to.</param>
        /// <returns>The newly created texture.</returns>
        public static Texture2D Create(GraphicsDevice graphicsDevice, int width, int height, Color color)
        {
            // create the rectangle texture without colors
            Texture2D texture = new Texture2D(
                graphicsDevice,
                width,
                height,
                false, //mipmap
                SurfaceFormat.Color);

            // Create a color array for the pixels
            Color[] colors = new Color[width * height];
            for (int i = 0; i < colors.Length; i++) {
                colors[i] = new Color(color.ToVector3());
            }

            // Set the color data for the texture
            texture.SetData(colors);

            return texture;
        }