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


C# Device.SetTexture方法代码示例

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


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

示例1: SetupRender

 // Prepare for rendercalls
 public void SetupRender(Device device)
 {
     if (SharedTexture1 && tex != null)
         device.SetTexture(0, tex);
     if (SharedTexture2 && tex2 != null)
         device.SetTexture(1, tex2);
 }
开发者ID:maesse,项目名称:CubeHags,代码行数:8,代码来源:SkyBox.cs

示例2: Draw

 public override void Draw(ref Device device)
 {
     device.SetTexture(0, texture);
       Matrix world = device.Transform.World;
       device.Transform.World = worldMatrix;
       device.VertexFormat = CustomVertex.PositionColoredTextured.Format;
       device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, vertices);
       device.Transform.World = world;
 }
开发者ID:stevenandrewcarter,项目名称:Bombard,代码行数:9,代码来源:MousePointer.cs

示例3: draw

        public void draw(Vector3 cameraLocation, Vector3 cameraRotation, Device device)
        {
            Material initialMaterial = device.Material;

            if (particleList.Count > 0)
            {
                sortParticles(particleList, 0, particleList.Count - 1, cameraLocation);
            }

            device.RenderState.AlphaBlendEnable = true;
            device.RenderState.SourceBlend = Blend.SourceAlpha;
            device.RenderState.DestinationBlend = Blend.InvSourceAlpha;

            device.SetTexture(0, particleTexture);

            foreach (ParticleData particle in particleList)
            {
                device.Transform.World =
                    Matrix.RotationYawPitchRoll(cameraRotation.X, cameraRotation.Y, cameraRotation.Z) *
                    Matrix.Translation(particle.location);

                Material material = device.Material;
                Color diffuse = material.Diffuse;
                material.Diffuse = particle.modColor;
                material.Emissive = Color.White;
                device.Material = material;

                VertexBuffer buffer = new VertexBuffer(typeof(CustomVertex.PositionTextured), 4, device, 0, CustomVertex.PositionNormalTextured.Format, Pool.Default);
                CustomVertex.PositionTextured[] vertices = (CustomVertex.PositionTextured[])buffer.Lock(0, 0);

                float particleRadius = particle.size / 2;

                vertices[0] = new CustomVertex.PositionTextured(new Vector3(-particleRadius, -particleRadius, 0f), 0, 1); // bottom right
                vertices[1] = new CustomVertex.PositionTextured(new Vector3(-particleRadius, particleRadius, 0f), 0, 0); // top right
                vertices[2] = new CustomVertex.PositionTextured(new Vector3(particleRadius, -particleRadius, 0f), 1, 1); // bottom left
                vertices[3] = new CustomVertex.PositionTextured(new Vector3(particleRadius, particleRadius, 0), 1, 0); // top left

                buffer.Unlock();

                device.VertexFormat = CustomVertex.PositionTextured.Format;

                device.SetStreamSource(0, buffer, 0);
                device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
            }

            device.RenderState.AlphaBlendEnable = false;
            device.Material = initialMaterial;
        }
开发者ID:newgrounds,项目名称:Clear-Skies,代码行数:48,代码来源:ParticleEmitter.cs

示例4: draw

        public void draw(Vector3 cameraRotation, Device device)
        {
            device.SetTexture(0, particleTexture);

            device.TextureState[0].AlphaOperation = TextureOperation.Modulate;
            device.TextureState[0].AlphaArgument0 = TextureArgument.Current;
            device.TextureState[0].AlphaArgument1 = TextureArgument.Diffuse;
            device.TextureState[0].AlphaArgument2 = TextureArgument.TextureColor;

            device.TextureState[0].ColorArgument0 = TextureArgument.Current;
            device.TextureState[0].ColorArgument1 = TextureArgument.Diffuse;
            device.TextureState[0].ColorArgument2 = TextureArgument.TextureColor;
            device.TextureState[0].ColorOperation = TextureOperation.Modulate;

            Material material = device.Material;
            Color diffuse = material.Diffuse;
            material.Diffuse = fade;
            material.Emissive = Color.White;
            device.Material = material;

            foreach (ParticleData particle in particleList)
            {
                device.Transform.World =
                    Matrix.RotationYawPitchRoll(cameraRotation.X, cameraRotation.Y, cameraRotation.Z) *
                    Matrix.Translation(particle.location);

                VertexBuffer buffer = new VertexBuffer(typeof(CustomVertex.PositionNormalTextured), 4, device, 0, CustomVertex.PositionNormalTextured.Format, Pool.Default);
                CustomVertex.PositionNormalTextured[] vertices = (CustomVertex.PositionNormalTextured[])buffer.Lock(0, 0);

                float particleRadius = particle.size / 2;

                vertices[0] = new CustomVertex.PositionNormalTextured(new Vector3(-particleRadius, -particleRadius, 0f), new Vector3(0, 1, 0), 0, 1); // bottom right
                vertices[1] = new CustomVertex.PositionNormalTextured(new Vector3(-particleRadius, particleRadius, 0f), new Vector3(0, 1, 0), 0, 0); // top right
                vertices[2] = new CustomVertex.PositionNormalTextured(new Vector3(particleRadius, -particleRadius, 0f), new Vector3(0, 1, 0), 1, 1); // bottom left
                vertices[3] = new CustomVertex.PositionNormalTextured(new Vector3(particleRadius, particleRadius, 0), new Vector3(0, 1, 0), 1, 0); // top left

                buffer.Unlock();

                device.VertexFormat = CustomVertex.PositionNormalTextured.Format;
                device.SetStreamSource(0, buffer, 0);
                device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
            }
        }
开发者ID:newgrounds,项目名称:Clear-Skies,代码行数:43,代码来源:ExpolsionParticleEmitter.cs

示例5: Render

        public override void Render(Device device)
        {
            if (verticesV == null)
            {
                verticesV = new VertexBuffer(typeof(CustomVertex.PositionColoredTextured),    // Type of vertex
                   verticesB.Count,      // How many
                   device, // What device
                   0,      // No special usage
                   CustomVertex.PositionColoredTextured.Format,
                   Pool.Managed);

                texture = TextureLoader.FromFile(device, "../../textures/earth.bmp");
            }

            GraphicsStream gs = verticesV.Lock(0, 0, 0);// Lock the background vertex list
            int clr = System.Drawing.Color.Transparent.ToArgb();   // Don't you love all those color names?

            foreach (Vector2 v in verticesB)
            {
                float tu = 0.5f + v.X / 1.8f;
                float tv = 1 - (v.Y - (-0.8f)) / 1.8f;
                gs.Write(new CustomVertex.PositionColoredTextured(v.X, v.Y , 0, clr, tu, tv));
            }

            verticesV.Unlock();
            device.SetTexture(0, texture);
            device.SetStreamSource(0, verticesV, 0);
            device.VertexFormat = CustomVertex.PositionColoredTextured.Format;

            // Head, one triangle
            device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);

            // Body, two triangles
            device.DrawPrimitives(PrimitiveType.TriangleFan, 3, 2);

            device.SetTexture(0, null);
        }
开发者ID:QuirogaM,项目名称:StepDX,代码行数:37,代码来源:Flag.cs

示例6: 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

示例7: DrawCluster

            /// <summary>
            /// The draw cluster.
            /// </summary>
            /// <param name="rawindex">The rawindex.</param>
            /// <param name="outlinecolor">The outlinecolor.</param>
            /// <param name="device">The device.</param>
            /// <param name="bsp">The bsp.</param>
            /// <param name="Textured">The textured.</param>
            /// <param name="WireFrame">The wire frame.</param>
            /// <param name="cam">The cam.</param>
            /// <remarks></remarks>
            public static void DrawCluster(
                int rawindex, 
                Color outlinecolor, 
                ref Device device, 
                ref BSPModel bsp, 
                bool Textured, 
                bool WireFrame, 
                ref Camera2 cam)
            {
                

                if (bsp.BSPRawDataMetaChunks[rawindex].RawDataChunkInfo.Length == 0)
                {
                    return;
                }

                // Vector3 tempv = new Vector3();
                // tempv.X = bsp.Spawns.Spawn[x].X;
                // tempv.Y = bsp.Spawns.Spawn[x].Y;
                // tempv.Z = bsp.Spawns.Spawn[x].Z;
                // if (!cam.SphereInFrustum(tempv, 10f)) { continue; }
                device.SetStreamSource(0, bsp.Display.vertexBuffer[rawindex], 0);
                device.VertexFormat = CustomVertex.PositionNormalTextured.Format;
                device.Indices = bsp.Display.indexBuffer[rawindex];
                for (int xx = 0; xx < bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo.Length; xx++)
                {
                    int tempshade = bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo[xx].ShaderNumber;

                    #region AlphaBlending

                    if (bsp.Shaders.Shader[tempshade].Alpha == ShaderInfo.AlphaType.AlphaBlend)
                    {
                        // MessageBox.Show("test");
                        device.RenderState.AlphaBlendEnable = true;
                        device.RenderState.AlphaTestEnable = false;
                    }
                    else if (bsp.Shaders.Shader[tempshade].Alpha == ShaderInfo.AlphaType.AlphaTest)
                    {
                        // MessageBox.Show("test2");
                        device.RenderState.AlphaBlendEnable = false;
                        device.RenderState.AlphaTestEnable = true;
                    }
                    else
                    {
                        device.RenderState.AlphaBlendEnable = false;
                        device.RenderState.AlphaTestEnable = false;
                    }

                    #endregion

                    #region ChooseTexture

                    if (Textured)
                    {
                        // device.TextureState[0] = device.TextureState[2];
                        device.SetTexture(0, bsp.Shaders.Shader[tempshade].MainTexture);
                    }
                    else
                    {
                        device.SetTexture(0, null);
                    }

                    #endregion

                    #region RenderToScene

                    PrimitiveType pt;
                    pt = PrimitiveType.TriangleList;
                    device.RenderState.FillMode = FillMode.Solid;
                    Material mm = new Material();
                    mm.Diffuse = Color.Black;
                    mm.Ambient = Color.Black;
                    device.Material = mm;
                    device.DrawIndexedPrimitives(
                        pt, 
                        0, 
                        0, 
                        bsp.BSPRawDataMetaChunks[rawindex].VerticeCount, 
                        bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceStart, 
                        bsp.BSPRawDataMetaChunks[rawindex].SubMeshInfo[xx].IndiceCount / 3);

                    #region WireFrame

                    if (WireFrame)
                    {
                        Material m = new Material();
                        m.Diffuse = outlinecolor;
                        m.Ambient = outlinecolor;
                        device.Material = m;
//.........这里部分代码省略.........
开发者ID:troymac1ure,项目名称:Entity,代码行数:101,代码来源:BSPModel.cs

示例8: RenderDatabaseTree

        public static TextureMatrixLayer[] RenderDatabaseTree(RasterDatabase.RasterDatabase db, Device device)
        {
            // setup device
            device.RenderState.ZBufferEnable = false;
            device.Indices = null;
            device.VertexFormat = CustomVertex.TransformedTextured.Format;
            //device.Transform.World = Matrix.Identity;
            Surface rt0 = device.GetRenderTarget(0);

            // setup template quad
            CustomVertex.TransformedTextured[] tQuad = new CustomVertex.TransformedTextured[4];

            foreach(DataLayer layer in db.Layers)
            {
                RectangleGroupQuadTree tree = db.ProduceLayerMipMap(layer, 2048);
                Texture[][] textures = new Texture[tree.Depth][];
                for (int i = 1; i <= tree.Depth; i++)
                {
                    RectangleGroupQuadTree.GroupNode[] nodes;
                    tree.GetNodes(i, out nodes);
                    textures[i] = new Texture[nodes.Length];

                    // render each node to texture
                    int texIdx = 0;
                    foreach (RectangleGroupQuadTree.GroupNode node in nodes)
                    {
                        Texture texture = textures[i][texIdx++] = new Texture(device, node.NodeArea.Width,
                                                                              node.NodeArea.Height, 0,
                                                                              Usage.WriteOnly, Format.X8R8G8B8,
                                                                              Pool.Managed);
                        device.SetRenderTarget(0, texture.GetSurfaceLevel(0));

                        device.Clear(ClearFlags.Target, Color.Black, 1, 0);
                        device.BeginScene();

                        // draw each rectangle quad
                        foreach (DataArea area in node.Rectangles)
                        {
                            // setup quad
                            tQuad[0] = new CustomVertex.TransformedTextured(area.Area.Left, area.Area.Top, 1, 1,
                                                                            area.TexCoords.Left, area.TexCoords.Top);
                            tQuad[1] = new CustomVertex.TransformedTextured(area.Area.Right, area.Area.Top, 1, 1,
                                                                            area.TexCoords.Right, area.TexCoords.Top);
                            tQuad[2] = new CustomVertex.TransformedTextured(area.Area.Left, area.Area.Bottom, 1, 1,
                                                                            area.TexCoords.Left, area.TexCoords.Bottom);
                            tQuad[3] = new CustomVertex.TransformedTextured(area.Area.Right, area.Area.Bottom, 1, 1,
                                                                            area.TexCoords.Right, area.TexCoords.Bottom);

                            // render quad
                            device.SetTexture(0, (Texture)area.Data);
                            device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, tQuad);
                        }
                        device.EndScene();
                    }
                }
            }

            device.SetRenderTarget(0, rt0);
            device.RenderState.ZBufferEnable = true;

            return null;
        }
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:62,代码来源:RasterDatabaseRenderer.cs

示例9: Draw

        public override void Draw(Device device)
        {
            if (!_valid && !_building)
                Rebuild(device);

            if (!_valid || _building)
                return;

            if (_imageSprite != null)
            {
                // Set the material and texture
                device.Material = _imageMaterial;
                device.SetTexture(0, _imageTexture);

                int numSubSets = _imageSprite.GetAttributeTable().Length;

                // Draw the primitive
                for (int i = 0; i < numSubSets; i++)
                {
                    try
                    {
                        _imageSprite.DrawSubset(i);
                    }
                    catch (Exception)
                    {
                        _valid = false;
                    }
                }
            }
        }
开发者ID:TomNZ,项目名称:Console-Wrapper,代码行数:30,代码来源:ImageSprite.cs

示例10: Render

        /// <summary>
        /// Render the textured polygon
        /// </summary>
        /// <param name="device">Device to render onto</param>
        public override void Render(Device device)
        {
            // Get the vertices we will draw
            List<Vector2> vertices = Vertices;

            // Ensure we have at least a triangle
            if (vertices.Count < 3)
                return;

            // Ensure the number of vertices and textures are the same
            System.Diagnostics.Debug.Assert(textureC.Count == vertices.Count);

            if (verticesV == null)
            {
                verticesV = new VertexBuffer(typeof(CustomVertex.PositionColoredTextured), // Type
                   vertices.Count,      // How many
                   device, // What device
                   0,      // No special usage
                   CustomVertex.PositionColoredTextured.Format,
                   Pool.Managed);
            }

            GraphicsStream gs = verticesV.Lock(0, 0, 0);     // Lock the background vertex list
            int clr = color.ToArgb();

            for (int i = 0; i < vertices.Count; i++)
            {
                Vector2 v = vertices[i];
                Vector2 t = textureC[i];
                gs.Write(new CustomVertex.PositionColoredTextured(v.X, v.Y, 0, clr, t.X, t.Y));
            }

            verticesV.Unlock();

            if (transparent)
            {
                device.RenderState.AlphaBlendEnable = true;
                device.RenderState.SourceBlend = Blend.SourceAlpha;
                device.RenderState.DestinationBlend = Blend.InvSourceAlpha;
            }

            device.SetTexture(0, texture);
            device.SetStreamSource(0, verticesV, 0);
            device.VertexFormat = CustomVertex.PositionColoredTextured.Format;
            device.DrawPrimitives(PrimitiveType.TriangleFan, 0, vertices.Count - 2);
            device.SetTexture(0, null);

            if (transparent)
                device.RenderState.AlphaBlendEnable = false;
        }
开发者ID:QuirogaM,项目名称:StepDX,代码行数:54,代码来源:PolygonTextured.cs

示例11: DrawMeshes

        /// <summary>
        /// The draw meshes.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <remarks></remarks>
        public void DrawMeshes(ref Device device)
        {
            for (int i = 0; i < this.vb.Count; i++)
            {
                device.SetStreamSource(0, vb[i], 0);
                device.VertexFormat = CustomVertex.PositionColored.Format;
                device.Indices = ib[i];

                device.RenderState.AlphaBlendEnable = false;
                device.RenderState.AlphaTestEnable = false;

                device.Transform.World = Matrix.Identity;
                device.SetTexture(0, null);

                PrimitiveType pt;

                pt = PrimitiveType.TriangleList;
                device.DrawIndexedPrimitives(pt, 0, 0, this.verticeCount[i], 0, this.faceCount[i] / 3);
            }
        }
开发者ID:nolenfelten,项目名称:Blam_BSP,代码行数:25,代码来源:coll.cs

示例12: Render

        /// <summary>Renders this mesh</summary>
        public void Render(Device device, bool canDrawOpaque, bool canDrawAlpha)
        {
            if (localMemoryMesh == null)
                throw new InvalidOperationException("No local memory mesh.");

            // Frist, draw the subsets without alpha
            if (canDrawOpaque)
            {
                for (int i = 0; i < meshMaterials.Length; i++)
                {
                    if (isUsingMeshMaterials)
                    {
                        if (meshMaterials[i].DiffuseColor.Alpha < 1.0f)
                            continue; // Only drawing opaque right now

                        // set the device material and texture
                        device.Material = meshMaterials[i];
                        device.SetTexture(0, meshTextures[i]);
                    }
                    localMemoryMesh.DrawSubset(i);
                }
            }

            // Then, draw the subsets with alpha
            if (canDrawAlpha)
            {
                for (int i = 0; i < meshMaterials.Length; i++)
                {
                    if (meshMaterials[i].DiffuseColor.Alpha == 1.0f)
                        continue; // Only drawing non-opaque right now

                    // set the device material and texture
                    device.Material = meshMaterials[i];
                    device.SetTexture(0, meshTextures[i]);
                    localMemoryMesh.DrawSubset(i);
                }
            }
        }
开发者ID:JeremiahZhang,项目名称:AKA,代码行数:39,代码来源:dxmutmesh.cs

示例13: DrawBox


//.........这里部分代码省略.........
                    try
                    {
                        dx.Present();
                    }
                    catch
                    {
                    }


                    dx.BeginScene();

                    dx.Transform.World = Matrix.Identity;
                    ScaleMatrices(dx, 0.1f, 1000, 0.1f);

                    dx.VertexFormat = Vertex.FVF_Flags;
                    dx.SetStreamSource(0, lineVertexBuffer, 0);

                    //dx.SetTexture(0, texture);

                    dx.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
                    dx.DrawPrimitives(PrimitiveType.TriangleStrip, 4, 2);

                    dx.EndScene();

                    // this try/catch prevents an error if the scene is being rendered 
                    // whilst the window is being closed
                    try
                    {
                        dx.Present();
                    }
                    catch
                    {
                    }
                    */

                    dx.BeginScene();

                    dx.Transform.World = Matrix.Identity;
                    ScaleMatrices(dx, 0.1f, 0.1f, 1000);

                    dx.VertexFormat = Vertex.FVF_Flags;
                    dx.SetStreamSource(0, lineVertexBuffer, 0);

                    //dx.SetTexture(0, texture);

                    dx.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
                    dx.DrawPrimitives(PrimitiveType.TriangleStrip, 4, 2);

                    dx.EndScene();

                    // this try/catch prevents an error if the scene is being rendered 
                    // whilst the window is being closed
                    try
                    {
                        dx.Present();
                    }
                    catch
                    {
                    }


                    //float xrot = 0;
                    //float yrot = 0;
                    //float zrot = (float)Math.PI / 2;

                    dx.BeginScene();

                    dx.Transform.World = Matrix.Identity; // *Matrix.RotationYawPitchRoll((float)yaw, (float)pitch, (float)pitch);
                    //RotationMatrices(dx, xrot, yrot, zrot);
                    TranslationMatrices(dx, 0.0f, 2.5f, 6.0f);
                    ScaleMatrices(dx, 10, 10, 10);

                    dx.VertexFormat = Vertex.FVF_Flags;
                    dx.SetStreamSource(0, cubeVertexBuffer, 0);

                    dx.SetTexture(0, texture);

                    dx.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
                    dx.DrawPrimitives(PrimitiveType.TriangleStrip, 4, 2);
                    dx.DrawPrimitives(PrimitiveType.TriangleStrip, 8, 2);
                    dx.DrawPrimitives(PrimitiveType.TriangleStrip, 12, 2);
                    dx.DrawPrimitives(PrimitiveType.TriangleStrip, 16, 2);
                    dx.DrawPrimitives(PrimitiveType.TriangleStrip, 20, 2);

                    dx.EndScene();

                    // this try/catch prevents an error if the scene is being rendered 
                    // whilst the window is being closed
                    try
                    {
                        dx.Present();
                    }
                    catch
                    {
                    }

                }
            }
            if (!initialised_3D) Init3D();
        }
开发者ID:iManbot,项目名称:monoslam,代码行数:101,代码来源:frmMain.cs

示例14: Render

        public void Render(Device device)
        {
            if (!Loaded)
            {
                mesh = Mesh.FromFile(Name, MeshFlags.Managed, device, out materialarray);
                if ((materialarray != null) && (materialarray.Length > 0))
                {
                    meshmaterials = new Material[materialarray.Length];
                    meshtextures = new Texture[materialarray.Length];

                    for (int i = 0; i < materialarray.Length; i++)
                    {
                        meshmaterials[i] = materialarray[i].Material3D;
                        meshmaterials[i].Ambient = meshmaterials[i].Diffuse;

                        if ((materialarray[i].TextureFilename != null) && (materialarray[i].TextureFilename != string.Empty))
                        {
                            meshtextures[i] = TextureLoader.FromFile(device, materialarray[i].TextureFilename);
                        }
                    }
                }
                mesh = mesh.Clone(mesh.Options.Value, CustomVertex.PositionNormalTextured.Format, device);
                mesh.ComputeNormals();

                Loaded = true;
            }
            for (int i = 0; i < meshmaterials.Length; i++)
            {
                device.Material = meshmaterials[i];
                device.SetTexture(0, meshtextures[i]);
                mesh.DrawSubset(i);
            }
            //device.DrawUserPrimitives(PrimitiveType.LineList, 12, vertices);
        }
开发者ID:veggielane,项目名称:orts_old,代码行数:34,代码来源:Shapes.cs

示例15: Reset

        public void Reset()
        {
            try
            {
                pps.BackBufferWidth = renderTarget.Width;
                pps.BackBufferHeight = renderTarget.Height;
                if (device != null)
                    device.Dispose();
                if (texture != null)
                    texture.Dispose();
                if (vertexBuffer != null)
                    vertexBuffer.Dispose();
                device = new SlimDX.Direct3D9.Device(d3d, 0, SlimDX.Direct3D9.DeviceType.Hardware, renderTarget.Handle, CreateFlags.HardwareVertexProcessing, pps);
                texture = new Texture(device, imageScaler.ResizedX, imageScaler.ResizedY, 0, Usage.Dynamic, Format.X8R8G8B8, Pool.Default);
                LoadCharSheet();
                vertexBuffer = new VertexBuffer(device, 4 * Marshal.SizeOf(typeof(Vertex)), Usage.WriteOnly, VertexFormat.PositionRhw | VertexFormat.Texture1, Pool.Managed);

                DataStream stream = vertexBuffer.Lock(0, 0, LockFlags.None);
                Vertex[] vertexData = new Vertex[4];

                vertexData[0].PositionRhw = new Vector4(renderTarget.Width, renderTarget.Height, 0f, 1f);
                vertexData[0].Texture1 = new Vector2(1f, 1f);

                vertexData[1].PositionRhw = new Vector4(0f, renderTarget.Height, 0f, 1f);
                vertexData[1].Texture1 = new Vector2(0f, 1f);

                vertexData[2].PositionRhw = new Vector4(renderTarget.Width, 0f, 0f, 1f);
                vertexData[2].Texture1 = new Vector2(1f, 0f);

                vertexData[3].PositionRhw = new Vector4(0f, 0f, 0f, 1f);
                vertexData[3].Texture1 = new Vector2(0f, 0f);

                stream.WriteRange(vertexData);
                vertexBuffer.Unlock();

                device.VertexFormat = VertexFormat.PositionRhw | VertexFormat.Texture1;
                device.SetStreamSource(0, vertexBuffer, 0, Marshal.SizeOf(typeof(Vertex)));
                if (smoothOutput)
                    device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Linear);
                else
                    device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Point);
                device.SetSamplerState(0, SamplerState.AddressU, TextureAddress.Clamp);
                device.SetSamplerState(0, SamplerState.AddressV, TextureAddress.Clamp);
                device.SetSamplerState(0, SamplerState.AddressW, TextureAddress.Clamp);
                device.SetTexture(0, texture);
            }
            catch (Direct3D9Exception e)
            {
                device = null;
            }
        }
开发者ID:nickmass,项目名称:Emu-o-Tron,代码行数:51,代码来源:DX9Renderer.cs


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