示例#1
0
 public static void DrawLine(Location from, Location to, Color4 color)
 {
     var vertices = new PositionColored[2];
     vertices[0] = new PositionColored(from.ToVector3(), color.ToArgb());
     vertices[1] = new PositionColored(to.ToVector3(), color.ToArgb());
     Device.DrawUserPrimitives(PrimitiveType.LineList, 1, vertices);
 }
 public void Clear(Color4 clearcolor)
 {
     foreach (IDX11RenderTargetView view in this.rtvs)
     {
         this.context.CurrentDeviceContext.ClearRenderTargetView(view.RTV, clearcolor);
     }
 }
 public VertexPositonNormalColorTexture(Vector3 Position, Vector3 normal, Color4 Color, Vector2 texcoords)
 {
     this.Position = Position;
     this.Color = Color.ToArgb();
     this.texcoords = texcoords;
     this.Normal = normal;
 }
 /**
  * Draws a rectangle
  */
 internal void RenderRectangle(int x, int y, int width, int height, Color4 color)
 {
     RenderLine(x, y, color, x + width, y, color);
     RenderLine(x + width, y, color, x + width, y + height, color);
     RenderLine(x + width, y + height, color, x, y + height, color);
     RenderLine(x, y + height, color, x, y, color);
 }
示例#5
0
        public override void DrawBox(ref Vector3 bbMin, ref Vector3 bbMax, Color4 color)
        {
            var p1 = bbMin;
            var p2 = new Vector3(bbMax.X, bbMin.Y, bbMin.Z);
            var p3 = new Vector3(bbMax.X, bbMax.Y, bbMin.Z);
            var p4 = new Vector3(bbMin.X, bbMax.Y, bbMin.Z);
            var p5 = new Vector3(bbMin.X, bbMin.Y, bbMax.Z);
            var p6 = new Vector3(bbMax.X, bbMin.Y, bbMax.Z);
            var p7 = bbMax;
            var p8 = new Vector3(bbMin.X, bbMax.Y, bbMax.Z);

            int intColor = color.ToArgb();
            PositionColored[] vertices = new PositionColored[] {
                new PositionColored(p1, intColor), new PositionColored(p2, intColor),
                new PositionColored(p2, intColor), new PositionColored(p3, intColor),
                new PositionColored(p3, intColor), new PositionColored(p4, intColor),
                new PositionColored(p4, intColor), new PositionColored(p1, intColor),
                
                new PositionColored(p1, intColor), new PositionColored(p5, intColor),
                new PositionColored(p2, intColor), new PositionColored(p6, intColor),
                new PositionColored(p3, intColor), new PositionColored(p7, intColor),
                new PositionColored(p4, intColor), new PositionColored(p8, intColor),
                
                new PositionColored(p5, intColor), new PositionColored(p6, intColor),
                new PositionColored(p6, intColor), new PositionColored(p7, intColor),
                new PositionColored(p7, intColor), new PositionColored(p8, intColor),
                new PositionColored(p8, intColor), new PositionColored(p5, intColor),
            };

            device.DrawUserPrimitives(PrimitiveType.LineList, 12, vertices);
        }
        public static ShapeDescription DrawFullRectangle(Vector3 position, Size size, IGradientShader linearShader, Color4 fillColor, Thickness borderSize, BorderStyle borderStyle, Color4 borderColor)
        {
            Color4[] shadedColors = linearShader.Method(linearShader, 4,Shape.Rectangle);
            Color4[] borderColors;

            switch (borderStyle)
            {
                case BorderStyle.None:
                    borderColors = LinearShader.FillColorArray(new Color4(0), 4);
                    break;
                case BorderStyle.Flat:
                    borderColors = LinearShader.FillColorArray(borderColor, 4);
                    break;
                case BorderStyle.Raised:
                    borderColors = LinearShader.BorderRaised(borderColor, 4);
                    break;
                case BorderStyle.Sunken:
                    borderColors = LinearShader.BorderSunken(borderColor, 4);
                    break;
                default:
                    throw new ArgumentOutOfRangeException("borderStyle");
            }
            ShapeDescription inside = DrawRectangle(position, size, shadedColors);
            ShapeDescription outline = DrawRectangularOutline(position, size, borderSize.All, borderColors, borderStyle, Borders.All);

            ShapeDescription result = ShapeDescription.Join(inside, outline);
            result.Shape = Shape.RectangleWithOutline;
            return result;
        }
示例#7
0
 public override void DrawLine(ref Vector3 from, ref Vector3 to, Color4 fromColor, Color4 toColor)
 {
     PositionColored[] vertices = new PositionColored[2];
     vertices[0] = new PositionColored(from, fromColor.ToArgb());
     vertices[1] = new PositionColored(to, toColor.ToArgb());
     device.DrawUserPrimitives(PrimitiveType.LineList, 1, vertices);
 }
示例#8
0
文件: SkyBox.cs 项目: maesse/CubeHags
        public SkyBox(SourceMap map, string texturename, Entity light_environment)
        {
            Init(texturename);
            Color4 skyColor = new Color4(2f, 255f, 255f, 255f);

            if (light_environment != null)
            {
                // This makes the skybox blend in better with the rest of the world
                string lightval = light_environment.Values["_light"];
                string[] vals = lightval.Split(' ');
                if (vals.Length == 4)
                {
                    // Try to get sun light color
                    float r, g, b;
                    r = int.Parse(vals[0]);
                    g = int.Parse(vals[1]);
                    b = int.Parse(vals[2]);
                    float brightness = int.Parse(vals[3]);
                    skyColor = new Color4(brightness, r, g, b);
                }
            }

            // Create a tiny lightmap, and take white+ maxExponent from the map as a color
            // Grab brightness of environment light and convert to exponent offset
            tex2 = TextureManager.CreateTexture(1,1,Format.A16B16G16R16F, skyColor);
            SharedTexture2 = true;
        }
示例#9
0
 internal void ClearTarget()
 {
     DayWatch watch = DayWatch.Now;
     BackgroundColor = Color4.Lerp(new Color4(0.8f, 0.8f, 1f), new Color4(0f, 0f, 0f), 1f - watch.SunHeight);
     device.ImmediateContext.ClearRenderTargetView(renderView, BackgroundColor);
     device.ImmediateContext.ClearDepthStencilView(depthView, DepthStencilClearFlags.Depth, 1.0f, 0);
 }
 public override void ClearRenderTarget(DeviceContext context, Color4 color)
 {
     foreach (RenderTargetView view in renderTargetView)
     {
         context.ClearRenderTargetView(view, color);
     }
 }
示例#11
0
        public void Evaluate(int SpreadMax)
        {
            if (this.FInAddressU.IsChanged
                || this.FInAddressV.IsChanged
                || this.FInAddressW.IsChanged
                || this.FInBorderColor.IsChanged
                || this.FInComparison.IsChanged
                || this.FInFilterMode.IsChanged
                || this.FInMaximumAnisotropy.IsChanged
                || this.FInMaximumLod.IsChanged
                || this.FInMinimumLod.IsChanged
                || this.FInMipLodBias.IsChanged)
            {
                this.FOutSampler.SliceCount = 1;
                RGBAColor c = this.FInBorderColor[0];
                Color4 col = new Color4((float)c.R, (float)c.G, (float)c.B, (float)c.A);
                SamplerDescription sampler = new SamplerDescription()
                {
                    AddressU = this.FInAddressU[0],
                    AddressV = this.FInAddressV[0],
                    AddressW = this.FInAddressW[0],
                    BorderColor = col,
                    ComparisonFunction = this.FInComparison[0],
                    Filter = this.FInFilterMode[0],
                    MaximumAnisotropy = this.FInMaximumAnisotropy[0],
                    MaximumLod = this.FInMaximumLod[0],
                    MinimumLod = this.FInMinimumLod[0],
                    MipLodBias = this.FInMipLodBias[0]
                };
                this.FOutSampler.SliceCount = SpreadMax;

                this.FOutSampler[0] = sampler;

            }
        }
示例#12
0
 public Text(int x, int y, string text, Color4 color)
 {
     X = x;
     Y = y;
     String = text;
     Color = color;
 }
示例#13
0
 public override void DrawContactPoint(ref Vector3 pointOnB, ref Vector3 normalOnB, float distance, int lifeTime, Color4 color)
 {
     int intColor = color.ToArgb();
     PositionColored[] vertices = new PositionColored[2];
     vertices[0] = new PositionColored(pointOnB, intColor);
     vertices[1] = new PositionColored(pointOnB + normalOnB, intColor);
     device.DrawUserPrimitives(PrimitiveType.LineList, 1, vertices);
 }
示例#14
0
        public override void PrepareToDraw(RenderingContext context)
        {
            CameraMatrix = context.camMatrix;
            Color = Target.Color;

            Effect.GetTechniqueByIndex(0).GetPassByIndex(0).Apply(Mat3DView.GraphicsDevice.ImmediateContext);
            Mat3DView.GraphicsDevice.ImmediateContext.InputAssembler.InputLayout = VertexLayout;
        }
示例#15
0
        public static Color4[] RadialManual(GradientStop[] gradient, int numVertex, int offsetIndex)
        {
            Color4[] colors = new Color4[numVertex];
            for (int i = 0; i < numVertex; i++)
                colors[i] = gradient[offsetIndex].Color;

            return colors;
        }
示例#16
0
        public static VertexPositionColor[] CreateBox(Vector3 mins, Vector3 maxs, Color4 color)
        {
            VertexPositionColor[] verts = new VertexPositionColor[36];

            // Front face
            verts[0] = new VertexPositionColor(new Vector3(mins.X, maxs.Y, maxs.Z), color);
            verts[1] = new VertexPositionColor(new Vector3(mins.X, mins.Y, maxs.Z), color);
            verts[2] = new VertexPositionColor(new Vector3(maxs.X, maxs.Y, maxs.Z), color);
            verts[3] = new VertexPositionColor(new Vector3(mins.X, mins.Y, maxs.Z), color);
            verts[4] = new VertexPositionColor(new Vector3(maxs.X, mins.Y, maxs.Z), color);
            verts[5] = new VertexPositionColor(new Vector3(maxs.X, maxs.Y, maxs.Z), color);

            // Back face (remember this is facing *away* from the camera, so vertices should be
            //    clockwise order)
            verts[6] = new VertexPositionColor(new Vector3(mins.X, maxs.Y, mins.Z), color);
            verts[7] = new VertexPositionColor(new Vector3(maxs.X, maxs.Y, mins.Z), color);
            verts[8] = new VertexPositionColor(new Vector3(mins.X, mins.Y, mins.Z), color);
            verts[9] = new VertexPositionColor(new Vector3(mins.X, mins.Y, mins.Z), color);
            verts[10] = new VertexPositionColor(new Vector3(maxs.X, maxs.Y, mins.Z), color);
            verts[11] = new VertexPositionColor(new Vector3(maxs.X, mins.Y, mins.Z), color);

            // Top face
            verts[12] = new VertexPositionColor(new Vector3(mins.X, maxs.Y, maxs.Z), color);
            verts[13] = new VertexPositionColor(new Vector3(maxs.X, maxs.Y, mins.Z), color);
            verts[14] = new VertexPositionColor(new Vector3(mins.X, maxs.Y, mins.Z), color);
            verts[15] = new VertexPositionColor(new Vector3(mins.X, maxs.Y, maxs.Z), color);
            verts[16] = new VertexPositionColor(new Vector3(maxs.X, maxs.Y, maxs.Z), color);
            verts[17] = new VertexPositionColor(new Vector3(maxs.X, maxs.Y, mins.Z), color);

            // Bottom face (remember this is facing *away* from the camera, so vertices should be
            //    clockwise order)
            verts[18] = new VertexPositionColor(new Vector3(mins.X, mins.Y, maxs.Z), color);
            verts[19] = new VertexPositionColor(new Vector3(mins.X, mins.Y, mins.Z), color);
            verts[20] = new VertexPositionColor(new Vector3(maxs.X, mins.Y, mins.Z), color);
            verts[21] = new VertexPositionColor(new Vector3(mins.X, mins.Y, maxs.Z), color);
            verts[22] = new VertexPositionColor(new Vector3(maxs.X, mins.Y, mins.Z), color);
            verts[23] = new VertexPositionColor(new Vector3(maxs.X, mins.Y, maxs.Z), color);

            // Left face
            verts[24] = new VertexPositionColor(new Vector3(mins.X, maxs.Y, maxs.Z), color);
            verts[25] = new VertexPositionColor(new Vector3(mins.X, mins.Y, mins.Z), color);
            verts[26] = new VertexPositionColor(new Vector3(mins.X, mins.Y, maxs.Z), color);

            verts[27] = new VertexPositionColor(new Vector3(mins.X, maxs.Y, mins.Z), color);
            verts[28] = new VertexPositionColor(new Vector3(mins.X, mins.Y, mins.Z), color);
            verts[29] = new VertexPositionColor(new Vector3(mins.X, maxs.Y, maxs.Z), color);

            // Right face (remember this is facing *away* from the camera, so vertices should be
            //    clockwise order)
            verts[30] = new VertexPositionColor(new Vector3(maxs.X, maxs.Y, maxs.Z), color);
            verts[31] = new VertexPositionColor(new Vector3(maxs.X, mins.Y, maxs.Z), color);
            verts[32] = new VertexPositionColor(new Vector3(maxs.X, mins.Y, mins.Z), color);
            verts[33] = new VertexPositionColor(new Vector3(maxs.X, maxs.Y, mins.Z), color);
            verts[34] = new VertexPositionColor(new Vector3(maxs.X, maxs.Y, maxs.Z), color);
            verts[35] = new VertexPositionColor(new Vector3(maxs.X, mins.Y, mins.Z), color);

            return verts;
        }
示例#17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FontString" /> struct.
 /// </summary>
 /// <param name="text">The text.</param>
 /// <param name="textBox">The text box.</param>
 /// <param name="alignment">The font alignment.</param>
 /// <param name="fontSize">Size of the font.</param>
 /// <param name="colour">The colour.</param>
 /// <param name="kerning">if set to <c>true</c> [kerning].</param>
 public FontString(string text, Rect textBox, Alignment alignment, float fontSize, Color4 colour, bool kerning)
 {
     Text = text;
     TextBox = textBox;
     Alignment = alignment;
     FontSize = fontSize;
     Colour = colour;
     Kerning = kerning;
 }
示例#18
0
 public RenderService()
 {
     bitmaps = new Dictionary<string, Bitmap>();
     brushes = new Dictionary<Tuple<Color4, float>, SolidColorBrush>();
     writeFactory = new SlimDX.DirectWrite.Factory(SlimDX.DirectWrite.FactoryType.Shared);
     clearColor = new Color4(1, 1, 1);
     PixelFormat pixelFormat = new PixelFormat(SlimDX.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied);
     bitmapProperties = new BitmapProperties() { PixelFormat = pixelFormat };
 }
示例#19
0
 public static Color4 FromColor(Color color)
 {
   Color4 v = new Color4(color.A, color.R, color.G, color.B);
   v.Alpha /= 255.0f;
   v.Red /= 255.0f;
   v.Green /= 255.0f;
   v.Blue /= 255.0f;
   return v;
 }
示例#20
0
 public MaterialBuffer(float kA, float kD, float kS, float sP, Color4 ambient, Color4 diffuse, Color4 specular)
 {
     this.kA = kA;
     this.kD= kD;
     this.kS= kS;
     this.sPower= sP;
     Ambient = ambient;
     Diffuse = diffuse;
     Specular = specular;
 }
示例#21
0
 public override void DrawLine(ref Vector3 from, ref Vector3 to, Color4 color)
 {
     int intColor = color.ToArgb();
     PositionColored[] vertices = new PositionColored[2];
     vertices[0].Position = from;
     vertices[0].Color = intColor;
     vertices[1].Position = to;
     vertices[1].Color = intColor;
     device.DrawUserPrimitives(PrimitiveType.LineList, 1, vertices);
 }
示例#22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Quad" /> class.
 /// </summary>
 /// <param name="x">The x coordinate of the upper-left vertex.</param>
 /// <param name="y">The y coordinate of the upper-left vertex.</param>
 /// <param name="screenWidth">Width of the screen.</param>
 /// <param name="screenHeight">Height of the screen.</param>
 /// <param name="textureFileName">Path to the texture file.</param>
 /// <param name="width">The width of the quad.</param>
 /// <param name="height">The height of the quad.</param>
 /// <param name="colour">The colour to blend this quad's texture with.</param>
 public Quad(int x, int y, int screenWidth, int screenHeight, string textureFileName, int width, int height, Color4 colour)
 {
     this.position = new Vector2Int(x, y);
     this.screenDimensions = new Vector2Int(screenWidth, screenHeight);
     this.width = width;
     this.height = height;
     this.Colour = colour;
     TexturePath = textureFileName;
     vertices = buildVertices();
     indices = buildIndices();
 }
示例#23
0
 public ShaderMaterial(string filename, RenderableCollectionDescription description)
     : base(filename, description)
 {
     kA = 0;
     kD = 1;
     kS = 1;
     sP = 16;
     specularColor = new Color4(1f, 1f, 1f, 1f);
     ambientColor = new Color4(1f, 1f, 1f, 1f);
     diffuseColor = new Color4(1, 0, 0, 1);
 }
示例#24
0
文件: Moon.cs 项目: samuto/HelloWorld
        internal override void OnUpdate()
        {
            DayWatch watch = DayWatch.Now;
            PrevPosition = Position;
            Position = watch.MoonPosition * 180f;
            Color4 c = new Color4(1f, 0.8f, 0.8f, 0.8f);
            Color = c.ToVector4();

            Position.X += World.Instance.Player.Position.X;
            Position.Y += 0;
            Position.Z += World.Instance.Player.Position.Z;
        }
 public static ShapeDescription DrawRectangle(Vector3 position, Size size, Color4[] colors)
 {
     ushort[] indices;
     ColoredVertex[] vertices = PolyMesh.CreateQuad(position.ToVector4(), size.Width, size.Height,
                                          colors, out indices);
     return new ShapeDescription
                {
                    Vertices = vertices,
                    Indices = indices,
                    Primitives = 2,
                    Shape = Shape.Rectangle
                };
 }
示例#26
0
		public ImposterFloat(int width, int height, Format format, Color4 background, ImposterOverlayType overlayType)
		{
			if (Effect == null)
			{
				Effect = SharedEffects.Effects["ImposterFloat"] as ImposterFloatEffect; 
			}

			m_Disposed = true;
			m_BackupState = new RenderTargetBackupState();
			m_ImposterView = new View3D(new System.Drawing.Rectangle(0, 0, width, height), width, height, (float)Math.PI / 4, 1f);
			m_Format = format;
			m_Background = background;
			m_OverlayType = overlayType; 
		}
 public static ShapeDescription DrawEquilateralTriangle(Vector3 leftVertex, float sideLength, Color4[] Color4s,
     bool isTriangleUpside)
 {
     ushort[] indices;
     ColoredVertex[] vertices = PolyMesh.CreateEquilateralTriangle(leftVertex.ToVector4(), sideLength, Color4s,
         isTriangleUpside, out indices);
     return new ShapeDescription
                {
                    Vertices = vertices,
                    Indices = indices,
                    Primitives = 1,
                    Shape = Shape.Triangle
                };
 }
示例#28
0
文件: Core.cs 项目: shaoleibo/DnFile
        public static bool ClearBuffer(bool bZbuffer, bool bTarget, Color4 color)
        {
            UInt32 dwFlags = 0;
            if ( bZbuffer )
            {
                dwFlags |= (UInt32)ClearFlags.ZBuffer;
            }
            if ( bTarget )
            {
                dwFlags |= (UInt32)ClearFlags.Target;
            }

            Result hr = _device.Clear((ClearFlags)dwFlags, color, 1.0f, 0);
            return Failed(hr);
        }
示例#29
0
        /// <summary>
        /// スクリーンキャプチャスタート
        /// </summary>
        /// <param name="clearColor">初期化色</param>
        public void StartCapture(Color4 clearColor)
        {
            if (oldTarget != null || oldDepth != null)
                throw new InvalidOperationException("StartCaptureはすでに開始しています");
            //レンダリングターゲットを退避
            oldTarget = SlimMMDXCore.Instance.Device.GetRenderTarget(0);
            oldDepth = SlimMMDXCore.Instance.Device.DepthStencilSurface;

            //レンダリングターゲットを変更
            SlimMMDXCore.Instance.Device.SetRenderTarget(0, renderSurface[bufferIndex]);
            SlimMMDXCore.Instance.Device.DepthStencilSurface = depthBuffer[bufferIndex];
            bufferIndex = (bufferIndex + 1) % 2;

            //レンダーターゲットをクリア
            SlimMMDXCore.Instance.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, clearColor, 1.0f, 0);
        }
示例#30
0
        // Create a systemmem texture, fill with the given color and copy it to a more hardware-friendly memory pool
        public static Texture CreateTexture(int w, int h, Format format, Color4 color)
        {
            Texture texture = new Texture(Renderer.Instance.device, w, h, 1, Usage.None, format, Pool.SystemMemory);
            DataRectangle drect = texture.LockRectangle(0, LockFlags.None);
            DataStream ds = drect.Data;

            // pixelsize in bytes
            int fieldsize = 8;
            switch (format)
            {
                case Format.A8R8G8B8:
                    fieldsize = 4;
                    break;
                case Format.A16B16G16R16F:
                    fieldsize = 8;
                    break;
            }

            // Fill texture with color
            for (int j = 0; j < (w * h); j++)
            {
                int x = ((j) % (w));
                int y = ((j) / (w));

                ds.Seek((long)(y * fieldsize) + (long)(x * fieldsize), System.IO.SeekOrigin.Begin);

                switch (format)
                {
                    case Format.A8R8G8B8:
                        ds.Write<int>(color.ToArgb());
                        break;
                    case Format.A16B16G16R16F:
                        Half[] half = Half.ConvertToHalf(new float[] { color.Red, color.Green, color.Blue, color.Alpha });
                        ds.Write<Half4>(new Half4(half[0], half[1], half[2], half[3]));
                        break;
                }

            }
            texture.UnlockRectangle(0);
            Texture realtexture = new Texture(Renderer.Instance.device, w, h, 1, Usage.None, format, Pool.Default);
            Renderer.Instance.device.UpdateTexture(texture, realtexture);
            texture.Dispose();
            return realtexture;
        }
示例#31
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="device">Requests the DirectX device.</param>
        public UIButton(D3D.Device device) : base(device)
        {
            Caption = "Caption";
            Color   = new DX.Color4(1.0f, 1.0f, 1.0f, 1.0f);
            System.Drawing.Font systemfont = new System.Drawing.Font("Arial", 12f, System.Drawing.FontStyle.Regular);
            _font = new D3D.Font(device, systemfont);
            systemfont.Dispose();
            _offNoneTexture  = new UITexture(device);
            _offFocusTexture = new UITexture(device);
            _offHoverTexture = new UITexture(device);
            _offDownTexture  = new UITexture(device);
            _onNoneTexture   = new UITexture(device);
            _onFocusTexture  = new UITexture(device);
            _onHoverTexture  = new UITexture(device);
            _onDownTexture   = new UITexture(device);

            // subscribe mouse event handlers
            MouseEnter += UIButton_MouseEnter;
            MouseDown  += UIButton_MouseDown;
        }
示例#32
0
        void DrawFlares(Vector2 lightPosition)
        {
            // Lensflare sprites are positioned at intervals along a line that
            // runs from the 2D light position toward the center of the screen.
            Vector2 screenCenter = Vector2.Zero;
            Vector2 flareVector  = screenCenter - lightPosition;

            foreach (Flare flare in flares)
            {
                SpriteDrawer.SetVisible(flare.id, true);

                // Compute the position of this flare sprite.
                Vector2 flarePosition = lightPosition + flareVector * flare.Position;
                Color4  c             = new SlimDX.Color4(flare.Color);
                c *= new Color4(SkyDome.SunColor);
                c *= occlusionAlpha;

                SpriteDrawer.AddInstance(flare.id, flare.Texture, flarePosition, c, flare.Scale / 2, SpriteBlendMode.Additive);
            }
        }
        // SlimDX.Direct3D10
        private SlimDX.Direct3D10.ShaderResourceView GetTexture(SlimDX.Direct3D10.Device device, int width, int height, SlimDX.Color4 color)
        {
            //create the texture
            SlimDX.Direct3D10.Texture2D            texture = null;
            SlimDX.Direct3D10.Texture2DDescription desc2   = new SlimDX.Direct3D10.Texture2DDescription();
            desc2.SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0);
            desc2.Width             = width;
            desc2.Height            = height;
            desc2.MipLevels         = 1;
            desc2.ArraySize         = 1;
            desc2.Format            = SlimDX.DXGI.Format.R8G8B8A8_UNorm;
            desc2.Usage             = SlimDX.Direct3D10.ResourceUsage.Dynamic;
            desc2.BindFlags         = SlimDX.Direct3D10.BindFlags.ShaderResource;
            desc2.CpuAccessFlags    = SlimDX.Direct3D10.CpuAccessFlags.Write;
            texture = new SlimDX.Direct3D10.Texture2D(device, desc2);


            // fill the texture with rgba values
            SlimDX.DataRectangle rect = texture.Map(0, SlimDX.Direct3D10.MapMode.WriteDiscard, SlimDX.Direct3D10.MapFlags.None);
            if (rect.Data.CanWrite)
            {
                for (int row = 0; row < texture.Description.Height; row++)
                {
                    int rowStart = row * rect.Pitch;
                    rect.Data.Seek(rowStart, System.IO.SeekOrigin.Begin);
                    for (int col = 0; col < texture.Description.Width; col++)
                    {
                        rect.Data.WriteByte((byte)color.Red);
                        rect.Data.WriteByte((byte)color.Green);
                        rect.Data.WriteByte((byte)color.Blue);
                        rect.Data.WriteByte((byte)color.Alpha);
                    }
                }
            }
            texture.Unmap(0);

            // create shader resource that is what the renderer needs
            SlimDX.Direct3D10.ShaderResourceViewDescription desc = new SlimDX.Direct3D10.ShaderResourceViewDescription();
            desc.Format          = texture.Description.Format;
            desc.Dimension       = SlimDX.Direct3D10.ShaderResourceViewDimension.Texture2D;
            desc.MostDetailedMip = 0;
            desc.MipLevels       = 1;


            SlimDX.Direct3D10.ShaderResourceView srv = new SlimDX.Direct3D10.ShaderResourceView(device, texture, desc);

            return(srv);
        }
示例#34
0
 internal static void Convert(ref Color color, out SlimDX.Color4 sdxColor)
 {
     Tesla.Math.Vector4 v = color.ToVector4();
     sdxColor = new Color4(v.W, v.X, v.Y, v.Z);
 }
示例#35
0
        static void Main()
        {
            ReferenceTracker.TrackReferences = true;
            Form form = new Form();

            IDXGIFactory factory = DXGI.CreateFactory();
            IDXGIAdapter adapter = null;

            factory.EnumAdapters(0, out adapter);

            DXGI_SWAP_CHAIN_DESC swapChainDescription = new DXGI_SWAP_CHAIN_DESC
            {
                BufferCount = 1,
                BufferDesc  = new DXGI_MODE_DESC
                {
                    Format      = DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM,
                    Height      = form.ClientSize.Height,
                    RefreshRate = new DXGI_RATIONAL
                    {
                        Denominator = 1,
                        Numerator   = 60
                    },

                    Scaling          = DXGI_MODE_SCALING.DXGI_MODE_SCALING_UNSPECIFIED,
                    ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER.DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED,
                    Width            = form.ClientSize.Width
                },
                BufferUsage  = (int)DXGI_USAGE.DXGI_USAGE_RENDER_TARGET_OUTPUT,
                Flags        = 0,
                OutputWindow = form.Handle,
                SampleDesc   = new DXGI_SAMPLE_DESC
                {
                    Count   = 1,
                    Quality = 0
                },
                SwapEffect = DXGI_SWAP_EFFECT.DXGI_SWAP_EFFECT_DISCARD,
                Windowed   = true
            };

            ID3D11Device   device    = SlimDX.Direct3D11.Direct3D11.CreateDevice(adapter);
            IDXGISwapChain swapChain = null;

            factory.CreateSwapChain(device, swapChainDescription, out swapChain);

            ID3D11Texture2D        backbuffer = swapChain.GetBuffer <ID3D11Texture2D>(0);
            ID3D11RenderTargetView view       = null;

            device.CreateRenderTargetView(backbuffer, null, out view);

            ID3DBlob vertexShaderBytecode = ShaderCompiler.CompileFromString(File.ReadAllText("MiniTri11.fx"), "MiniTri11.fx", "VS", "vs_4_0");
            ID3DBlob pixelShaderBytecode  = ShaderCompiler.CompileFromString(File.ReadAllText("MiniTri11.fx"), "MiniTri11.fx", "PS", "ps_4_0");

            D3D11_INPUT_ELEMENT_DESC[] inputElements = new[] {
                new D3D11_INPUT_ELEMENT_DESC {
                    SemanticName = "POSITION", AlignedByteOffset = 0, SemanticIndex = 0, Format = DXGI_FORMAT.DXGI_FORMAT_R32G32B32A32_FLOAT, InstanceDataStepRate = 0, InputSlot = 0, InputSlotClass = D3D11_INPUT_CLASSIFICATION.D3D11_INPUT_PER_VERTEX_DATA
                },
                new D3D11_INPUT_ELEMENT_DESC {
                    SemanticName = "COLOR", AlignedByteOffset = 16, SemanticIndex = 0, Format = DXGI_FORMAT.DXGI_FORMAT_R32G32B32A32_FLOAT, InstanceDataStepRate = 0, InputSlot = 0, InputSlotClass = D3D11_INPUT_CLASSIFICATION.D3D11_INPUT_PER_VERTEX_DATA
                }
            };

            ID3DBlob inputSignature;

            ShaderCompiler.D3DGetInputSignatureBlob(vertexShaderBytecode.GetBufferPointer(), vertexShaderBytecode.GetBufferSize(), out inputSignature);
            ID3D11InputLayout inputLayout;

            device.CreateInputLayout(inputElements, inputElements.Length, inputSignature.GetBufferPointer(), inputSignature.GetBufferSize(), out inputLayout);

            ByteBuffer vertexData = new ByteBuffer(3 * 32);

            vertexData.Write(0 * Vector4.SizeInBytes, new Vector4(0.0f, 0.5f, 0.5f, 1.0f));
            vertexData.Write(1 * Vector4.SizeInBytes, new Vector4(1.0f, 0.0f, 0.0f, 1.0f));
            vertexData.Write(2 * Vector4.SizeInBytes, new Vector4(0.5f, -0.5f, 0.5f, 1.0f));
            vertexData.Write(3 * Vector4.SizeInBytes, new Vector4(0.0f, 1.0f, 0.0f, 1.0f));
            vertexData.Write(4 * Vector4.SizeInBytes, new Vector4(-0.5f, -0.5f, 0.5f, 1.0f));
            vertexData.Write(5 * Vector4.SizeInBytes, new Vector4(0.0f, 0.0f, 1.0f, 1.0f));

            D3D11_BUFFER_DESC vertexBufferDescription = new D3D11_BUFFER_DESC
            {
                BindFlags           = 1,      //vertex buffer
                ByteWidth           = 3 * 32,
                CPUAccessFlags      = 0,
                MiscFlags           = 0,
                Usage               = D3D11_USAGE.D3D11_USAGE_DEFAULT,
                StructureByteStride = 0
            };
            ID3D11Buffer           vertexBuffer;
            D3D11_SUBRESOURCE_DATA srd = new D3D11_SUBRESOURCE_DATA
            {
                pSysMem          = vertexData.Pin(),
                SysMemPitch      = 0,
                SysMemSlicePitch = 0
            };

            device.CreateBuffer(vertexBufferDescription, srd, out vertexBuffer);
            vertexData.Unpin();

            RenderLoop          loop    = new RenderLoop();
            ID3D11DeviceContext context = null;

            device.GetImmediateContext(out context);

            ID3D11VertexShader vertexShader;
            ID3D11PixelShader  pixelShader;

            device.CreateVertexShader(vertexShaderBytecode.GetBufferPointer(), vertexShaderBytecode.GetBufferSize(), null, out vertexShader);
            device.CreatePixelShader(pixelShaderBytecode.GetBufferPointer(), pixelShaderBytecode.GetBufferSize(), null, out pixelShader);
            context.IASetInputLayout(inputLayout);
            context.VSSetShader(vertexShader, null, 0);
            context.PSSetShader(pixelShader, null, 0);
            context.IASetPrimitiveTopology(4);            //triangle list
            context.IASetVertexBuffers(0, 1, new ID3D11Buffer[] { vertexBuffer }, new int[] { 32 }, new int[] { 0 });
            context.OMSetRenderTargets(1, new ID3D11RenderTargetView[] { view }, IntPtr.Zero);

            D3D11_VIEWPORT vp = new D3D11_VIEWPORT {
                Height   = form.ClientSize.Height,
                Width    = form.ClientSize.Width,
                TopLeftX = 0,
                TopLeftY = 0,
                MinDepth = 0.0f,
                MaxDepth = 1.0f
            };

            context.RSSetViewports(1, new D3D11_VIEWPORT [] { vp });

            loop.Run(form, () =>
            {
                var clearColor = new SlimDX.Color4 {
                    R = 0.0f, G = 0.0f, B = 0.0f, A = 1.0f
                };
                context.ClearRenderTargetView(view, clearColor);
                context.Draw(3, 0);
                swapChain.Present(0, 0);
            });

            view.ReleaseReference();
            backbuffer.ReleaseReference();
            swapChain.ReleaseReference();
            device.ReleaseReference();
            adapter.ReleaseReference();
            factory.ReleaseReference();
        }