当前位置: 首页>>代码示例>>C#>>正文


C# Device.SetTextureStageState方法代码示例

本文整理汇总了C#中Device.SetTextureStageState方法的典型用法代码示例。如果您正苦于以下问题:C# Device.SetTextureStageState方法的具体用法?C# Device.SetTextureStageState怎么用?C# Device.SetTextureStageState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Device的用法示例。


在下文中一共展示了Device.SetTextureStageState方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DrawScene

        public int DrawScene(Device d3dDev, Texture texture)
        {
            if (vertexBuffer == null)
            return E_FAIL;

              // get the difference in time
              int currentTime = GetTickCount();
              double difference = time - currentTime ;

              // figure out the rotation of the plane
              float x = (float) (-Math.Cos(difference / 2000.0));
              float y = (float) (Math.Cos(difference / 2000.0));
              float z = (float) (Math.Sin(difference / 2000.0));

              // update the two rotating vertices with the new position
              vertices[0].Position = new Vector3(x, y, z);
              vertices[3].Position = new Vector3(-x, -y, -z);

              // Adjust the color so the blue is always on the bottom.
              // As the corner approaches the bottom, get rid of all the other
              // colors besides blue
              int mask0 = (int) (255 * (( y + 1.0) / 2.0));
              int mask3 = (int) (255 * (( -y + 1.0 ) / 2.0));
              vertices[0].Color = unchecked((int) 0xff0000ff | (mask0 << 16) | (mask0 << 8));
              vertices[3].Color = unchecked((int) 0xff0000ff | (mask3 << 16) | (mask3 << 8));

              try
              {
            // write the new vertex information into the buffer
            vertexBuffer.SetData(vertices, 0, LockFlags.None);

            // clear the scene so we don't have any articats left
            d3dDev.Clear(ClearFlags.Target, 0x00ffffff, 1.0f, 0);

            d3dDev.BeginScene();
            d3dDev.SetTexture(0, texture);

            d3dDev.SetTextureStageState(0, TextureStageStates.AlphaOperation, (int)TextureOperation.Modulate);
            d3dDev.SetTextureStageState(0, TextureStageStates.AlphaArgument1, (int)TextureArgument.TextureColor);
            d3dDev.SetTextureStageState(0, TextureStageStates.AlphaArgument2, (int)TextureArgument.Diffuse);
            d3dDev.SetTextureStageState(0, TextureStageStates.ColorArgument1, (int)TextureArgument.TextureColor);

            d3dDev.SetStreamSource(0, vertexBuffer, 0);
            d3dDev.VertexFormat = CustomVertex.PositionColoredTextured.Format;
            d3dDev.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
            d3dDev.SetTexture(0, null);
            d3dDev.EndScene();
              }
              catch(DirectXException e)
              {
            return e.ErrorCode;
              }
              catch
              {
            return E_FAIL;
              }

              return 0;
        }
开发者ID:coolsula,项目名称:vidplaycorder,代码行数:59,代码来源:PlaneScene.cs

示例2: Render

		/// <summary>
		/// Render one of the 4 quadrants with optional download indicator
		/// </summary>
		void Render(Device device, CustomVertex.PositionNormalTextured[] verts, QuadTile child)
		{
			bool isMultitexturing = false;
			
			if(!World.Settings.EnableSunShading)
			{
				if (World.Settings.ShowDownloadIndicator && child != null)
				{
					// Check/display download activity
					GeoSpatialDownloadRequest request = child.DownloadRequest;
					if (child.isDownloadingTerrain)
					{
						device.SetTexture(1, QuadTileSet.DownloadTerrainTexture);
						isMultitexturing = true;
					}
						//else if (request != null)
					else if(child.WaitingForDownload)
					{
						if (child.IsDownloadingImage)
							device.SetTexture(1, QuadTileSet.DownloadInProgressTexture);
						else
							device.SetTexture(1, QuadTileSet.DownloadQueuedTexture);
						isMultitexturing = true;
					}
				}
			}
			
			if (isMultitexturing)
				device.SetTextureStageState(1, TextureStageStates.ColorOperation, (int)TextureOperation.BlendTextureAlpha);

			if(verts != null && vertexIndexes != null)
			{
                if (QuadTileSet.Effect != null)
                {
                    Effect effect = QuadTileSet.Effect;

                    // FIXME: just use the first technique for now
                    effect.Technique = effect.GetTechnique(0);
                    effect.SetValue("WorldViewProj", Matrix.Multiply(device.Transform.World, Matrix.Multiply(device.Transform.View, device.Transform.Projection)));
                    try
                    {
                        effect.SetValue("Tex0", textures[0]);
                        effect.SetValue("Tex1", textures[1]);
                        effect.SetValue("Brightness", QuadTileSet.GrayscaleBrightness);
                        float opacity = (float)QuadTileSet.Opacity / 255.0f;
                        effect.SetValue("Opacity", opacity);
                    }
                    catch
                    {
                    }

                    int numPasses = effect.Begin(0);
                    for (int i = 0; i < numPasses; i++)
                    {
                        effect.BeginPass(i);
                        device.DrawIndexedUserPrimitives(PrimitiveType.TriangleList, 0,
                            verts.Length, vertexIndexes.Length / 3, vertexIndexes, true, verts);

                        effect.EndPass();
                    }

                    effect.End();
                }
                else if (!QuadTileSet.RenderGrayscale || (device.DeviceCaps.PixelShaderVersion.Major < 1))
                {
                    if (World.Settings.EnableSunShading)
                    {
                        Point3d sunPosition = SunCalculator.GetGeocentricPosition(TimeKeeper.CurrentTimeUtc);
                        Vector3 sunVector = new Vector3(
                            (float)sunPosition.X,
                            (float)sunPosition.Y,
                            (float)sunPosition.Z);

                        device.RenderState.Lighting = true;
                        Material material = new Material();
                        material.Diffuse = System.Drawing.Color.White;
                        material.Ambient = System.Drawing.Color.White;

                        device.Material = material;
                        device.RenderState.AmbientColor = World.Settings.ShadingAmbientColor.ToArgb();
                        device.RenderState.NormalizeNormals = true;
                        device.RenderState.AlphaBlendEnable = true;

                        device.Lights[0].Enabled = true;
                        device.Lights[0].Type = LightType.Directional;
                        device.Lights[0].Diffuse = System.Drawing.Color.White;
                        device.Lights[0].Direction = sunVector;

                        device.TextureState[0].ColorOperation = TextureOperation.Modulate;
                        device.TextureState[0].ColorArgument1 = TextureArgument.Diffuse;
                        device.TextureState[0].ColorArgument2 = TextureArgument.TextureColor;
                    }
                    else
                    {
                        device.RenderState.Lighting = false;
                        device.RenderState.Ambient = World.Settings.StandardAmbientColor;
                    }
//.........这里部分代码省略.........
开发者ID:jpespartero,项目名称:WorldWind,代码行数:101,代码来源:QuadTile.cs

示例3: Render

        /// <summary>
        /// Render one of the 4 quadrants with optional download indicator
        /// </summary>
        private void Render(Device device, CustomVertex.PositionNormalTextured[] verts, QuadTile child)
        {
            bool isMultitexturing = false;

            if (!World.Settings.EnableSunShading)
            {
                if (World.Settings.ShowDownloadIndicator && child != null)
                {
                    // Check/display download activity
                    //GeoSpatialDownloadRequest request = child.DownloadRequest;
                    if (child.isDownloadingTerrain)
                    {
                        device.SetTexture(1, QuadTileSet.DownloadTerrainTexture);
                        isMultitexturing = true;
                    }
                    //else if (request != null)
                    else if (child.WaitingForDownload)
                    {
                        if (child.IsDownloadingImage)
                            device.SetTexture(1, QuadTileSet.DownloadInProgressTexture);
                        else
                            device.SetTexture(1, QuadTileSet.DownloadQueuedTexture);
                        isMultitexturing = true;
                    }
                }
            }

            if (isMultitexturing)
                device.SetTextureStageState(1, TextureStageStates.ColorOperation,
                                                     (int)TextureOperation.BlendTextureAlpha);

            if (verts != null && vertexIndexes != null)
            {
                if (quadTileSet.Effect != null)
                {
                    Effect effect = quadTileSet.Effect;

                    int tc1 = device.GetTextureStageStateInt32(1, TextureStageStates.TextureCoordinateIndex);
                    device.SetTextureStageState(1, TextureStageStates.TextureCoordinateIndex, 1);

                    // FIXME: just use the first technique for now
                    effect.Technique = effect.GetTechnique(0);
                    EffectHandle param;
                    param = (EffectHandle)quadTileSet.EffectParameters["WorldViewProj"];
                    if (param != null)
                        effect.SetValue(param,
                                             Matrix.Multiply(device.Transform.World,
                                                                  Matrix.Multiply(device.Transform.View,
                                                                                        device.Transform.Projection)));
                    try
                    {
                        param = (EffectHandle)quadTileSet.EffectParameters["World"];
                        if (param != null)
                            effect.SetValue(param, device.Transform.World);
                        param = (EffectHandle)quadTileSet.EffectParameters["ViewInverse"];
                        if (param != null)
                        {
                            Matrix viewInv = Matrix.Invert(device.Transform.View);
                            effect.SetValue(param, viewInv);
                        }

                        // set textures as available
                        for (int i = 0; i < textures.Length; i++)
                        {
                            string name = string.Format("Tex{0}", i);
                            param = (EffectHandle)quadTileSet.EffectParameters[name];
                            if (param != null)
                            {
                                effect.SetValue(param, textures[i]);
                            }
                        }

                        // brightness & opacity values
                        param = (EffectHandle)quadTileSet.EffectParameters["Brightness"];
                        if (param != null)
                            effect.SetValue(param, quadTileSet.GrayscaleBrightness);

                        param = (EffectHandle)quadTileSet.EffectParameters["Opacity"];
                        if (param != null)
                        {
                            float opacity = (float)quadTileSet.Opacity / 255.0f;
                            effect.SetValue(param, opacity);
                        }

                        param = (EffectHandle)quadTileSet.EffectParameters["LayerRadius"];
                        if (param != null)
                        {
                            effect.SetValue(param, (float)quadTileSet.LayerRadius);
                        }

                        param = (EffectHandle)quadTileSet.EffectParameters["TileLevel"];
                        if (param != null)
                        {
                            effect.SetValue(param, level);
                        }

                        param = (EffectHandle)quadTileSet.EffectParameters["LocalOrigin"];
//.........这里部分代码省略.........
开发者ID:paladin74,项目名称:Dapple,代码行数:101,代码来源:QuadTile.cs

示例4: Initialize

    public static void Initialize(IntPtr windowHandle)
    {
        handle = windowHandle;

        device = new Device(new Direct3D(), 0, DeviceType.Hardware, handle, CreateFlags.SoftwareVertexProcessing, new PresentParameters()
        {
            //PresentationInterval = PresentInterval.One,
            BackBufferWidth = 512,
            BackBufferHeight = 512
        });
        device.SetDialogBoxMode(false);

        device.SetTextureStageState(0, TextureStage.ColorOperation, TextureOperation.SelectArg1);
        device.SetTextureStageState(0, TextureStage.ColorArg1, TextureArgument.Texture);
        device.SetTextureStageState(0, TextureStage.ColorArg2, TextureArgument.Diffuse);

        device.SetTextureStageState(0, TextureStage.AlphaOperation, TextureOperation.SelectArg1);
        device.SetTextureStageState(0, TextureStage.AlphaArg1, TextureArgument.Texture);
        device.SetTextureStageState(0, TextureStage.AlphaArg2, TextureArgument.Diffuse);

        device.SetRenderState(RenderState.Lighting, false);
        device.SetRenderState(RenderState.ZEnable, false);
        device.SetRenderState(RenderState.CullMode, Cull.None);

        device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha);
        device.SetRenderState(RenderState.DestinationBlend, Blend.InverseSourceAlpha);
        device.SetRenderState(RenderState.AlphaBlendEnable, false);

        device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Linear);
        device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Linear);

        device.VertexFormat = VertexFormat.PositionRhw | VertexFormat.Texture1;

        vertex = new VertexBuffer(device, 4 * 24, Usage.WriteOnly | Usage.Dynamic, VertexFormat.None, Pool.Default);
        texture = new Texture(device, 512, 512, 1, Usage.Dynamic, Format.X8R8G8B8, Pool.Default);

        device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
        device.Present();
    }
开发者ID:saturnki,项目名称:saturnki,代码行数:39,代码来源:main.cs

示例5: Render

        /// <summary>
        /// Render one of the 4 quadrants with optional download indicator
        /// </summary>
        private void Render(Device device, CustomVertex.PositionTextured[] verts, QuadTile child)
        {
            bool isMultitexturing = false;
            if (World.Settings.ShowDownloadIndicator
                && child != null) {
                // Check/display download activity
                GeoSpatialDownloadRequest request = child.DownloadRequest;
                if (child.isDownloadingTerrain) {
                    device.SetTexture(1, QuadTileSet.DownloadTerrainTexture);
                    isMultitexturing = true;
                }
                    //else if (request != null)
                else if (child.WaitingForDownload) {
                    if (child.IsDownloadingImage) {
                        device.SetTexture(1, QuadTileSet.DownloadInProgressTexture);
                    }
                    else {
                        device.SetTexture(1, QuadTileSet.DownloadQueuedTexture);
                    }
                    isMultitexturing = true;
                }
            }

            if (isMultitexturing) {
                device.SetTextureStageState(1, TextureStageStates.ColorOperation, (int) TextureOperation.BlendTextureAlpha);
            }

            if (verts != null
                && vertexIndexes != null) {
                device.DrawIndexedUserPrimitives(PrimitiveType.TriangleList, 0, verts.Length, vertexIndexes.Length/3, vertexIndexes, true, verts);
            }

            if (isMultitexturing) {
                device.SetTextureStageState(1, TextureStageStates.ColorOperation, (int) TextureOperation.Disable);
            }
        }
开发者ID:beginor,项目名称:WorldWind,代码行数:39,代码来源:QuadTile.cs


注:本文中的Device.SetTextureStageState方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。