private void SetFillMode(int mode) { if (mode >= 0) { fillMode = mode % 3; } switch (fillMode) { case 0: { device.Material = colorMaterial; device.SetTexture(0, null); device.RenderState.FillMode = FillMode.Solid; } break; case 1: { device.Material = textureMaterial; device.SetTexture(0, currentTexture); device.RenderState.FillMode = FillMode.Solid; } break; case 2: { device.Material = wireframeMaterial; device.SetTexture(0, null); device.RenderState.FillMode = FillMode.WireFrame; } break; } }
/// <summary> /// Restore the font after a device has been reset /// </summary> public void RestoreDeviceObjects(object sender, EventArgs e) { vertexBuffer = new VertexBuffer(typeof(CustomVertex.TransformedColoredTextured), MaxNumfontVertices, device, Usage.WriteOnly | Usage.Dynamic, 0, Pool.Default); // Create the state blocks for rendering text for (int which = 0; which < 2; which++) { device.BeginStateBlock(); device.SetTexture(0, fontTexture); if (isZEnable) { renderState.ZBufferEnable = true; } else { renderState.ZBufferEnable = false; } renderState.AlphaBlendEnable = true; renderState.SourceBlend = Blend.SourceAlpha; renderState.DestinationBlend = Blend.InvSourceAlpha; renderState.AlphaTestEnable = true; renderState.ReferenceAlpha = 0x08; renderState.AlphaFunction = Compare.GreaterEqual; renderState.FillMode = FillMode.Solid; renderState.CullMode = Cull.CounterClockwise; renderState.StencilEnable = false; renderState.Clipping = true; device.ClipPlanes.DisableAll(); renderState.VertexBlend = VertexBlend.Disable; renderState.IndexedVertexBlendEnable = false; renderState.FogEnable = false; renderState.ColorWriteEnable = ColorWriteEnable.RedGreenBlueAlpha; textureState0.ColorOperation = TextureOperation.Modulate; textureState0.ColorArgument1 = TextureArgument.TextureColor; textureState0.ColorArgument2 = TextureArgument.Diffuse; textureState0.AlphaOperation = TextureOperation.Modulate; textureState0.AlphaArgument1 = TextureArgument.TextureColor; textureState0.AlphaArgument2 = TextureArgument.Diffuse; textureState0.TextureCoordinateIndex = 0; textureState0.TextureTransform = TextureTransform.Disable; // REVIEW textureState1.ColorOperation = TextureOperation.Disable; textureState1.AlphaOperation = TextureOperation.Disable; samplerState0.MinFilter = TextureFilter.Point; samplerState0.MagFilter = TextureFilter.Point; samplerState0.MipFilter = TextureFilter.None; if (which == 0) { savedStateBlock = device.EndStateBlock(); } else { drawTextStateBlock = device.EndStateBlock(); } } }
private void DrawMesh(Mesh mesh, Material[] meshmaterials, Texture[] meshtextures) { for (int i = 0; i < meshmaterials.Length; i++) { device.Material = meshmaterials[i]; device.SetTexture(0, meshtextures[i]); mesh.DrawSubset(i); } }
private void Form1_Paint(object sender, PaintEventArgs e) { device.Clear(ClearFlags.Target, Color.Chartreuse, 1, 0); device.BeginScene(); device.SetTexture(0, texture); device.VertexFormat = CustomVertex.PositionTextured.Format; device.DrawUserPrimitives(PrimitiveType.TriangleList, vertex.Length / 3, vertex); device.EndScene(); device.Present(); }
public static void DrawSpriteArray(SpriteAccess[] Sprites) { Direct3D.Device CurrDevice = null; //For each associated sprite on the screen for (int i = 0; i < Sprites.Length; i++) { if (CurrDevice != Sprites[i].ParentDevice) { CurrDevice = Sprites[i].ParentDevice; CurrDevice.VertexFormat = Direct3D.CustomVertex.PositionTextured.Format; } CurrDevice.Transform.World = Matrix.RotationYawPitchRoll(Sprites[i].RotationX / (float)Math.PI, Sprites[i].RotationY / (float)Math.PI * 2.0f, Sprites[i].RotationZ / (float)Math.PI / 4.0f) * Matrix.Translation(Sprites[i].X, Sprites[i].Y, Sprites[i].Z) * SpaceAndTime.ScaleStandard; CurrDevice.SetTexture(0, Sprites[i].textures[Sprites[i].Frame]); CurrDevice.DrawUserPrimitives(Direct3D.PrimitiveType.TriangleStrip, 2, Sprites[i].Verticies); } }
/// <summary> /// The render. /// </summary> /// <remarks></remarks> private void Render() { if (pause) { return; } device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); device.BeginScene(); cam.move(); SetupMatrices(); device.Material = DefaultMaterial; device.Transform.World = Matrix.Identity; device.RenderState.CullMode = Cull.Clockwise; // Raw.ParsedModel.DisplayedInfo.Draw(ref device, ref bsp.SkyBox); Material m = new Material(); device.RenderState.CullMode = Cull.None; device.RenderState.FillMode = FillMode.WireFrame; device.RenderState.AlphaBlendEnable = false; device.RenderState.AlphaTestEnable = false; device.Material = DefaultMaterial; dxcoll.DrawMeshes(ref device); if (sphereDisplayAll) { device.Material = BlueMaterial; dxcoll.DrawSpheres(ref device); device.Transform.World = Matrix.Identity; } if (planeDisplayAll) { for (int i = 0; i < mList.Count; i++) { m.Ambient = Color.FromArgb(130, (24 - (i % 25)) * 10, i % 25 * 10); m.Diffuse = m.Ambient; device.Material = m; device.SetTexture(0, null); device.RenderState.AlphaBlendEnable = true; device.RenderState.AlphaTestEnable = true; device.RenderState.DestinationBlend = Blend.Zero; device.RenderState.SourceBlend = Blend.One; device.RenderState.FillMode = FillMode.Solid; mList[i].DrawSubset(0); } // Draw normals device.SetStreamSource(0, Vb, 0); device.Transform.World = Matrix.Identity; device.VertexFormat = CustomVertex.PositionColored.Format; device.DrawPrimitives(PrimitiveType.LineList, 0, normalVertices.Length / 2); } else { m.Ambient = Color.Red; m.Diffuse = Color.Red; device.Material = m; device.SetTexture(0, null); device.RenderState.AlphaBlendEnable = true; device.RenderState.AlphaTestEnable = true; device.RenderState.DestinationBlend = Blend.Zero; device.RenderState.SourceBlend = Blend.One; device.RenderState.FillMode = FillMode.Solid; mList[planeDisplay].DrawSubset(0); // Draw normals device.SetStreamSource(0, Vb, 0); device.Transform.World = Matrix.Identity; device.VertexFormat = CustomVertex.PositionColored.Format; int tpd = planeDisplay; int mesh = 0; while (tpd >= coll.Meshes[mesh].SurfaceData.Length) { tpd -= coll.Meshes[mesh++].SurfaceData.Length; } short s = (short)coll.Meshes[mesh].SurfaceData[tpd].Plane; if (s >= 0) { device.DrawPrimitives(PrimitiveType.LineList, coll.Meshes[mesh].SurfaceData[tpd].Plane * 2, 1); } } device.EndScene(); // Update the screen device.Present(); }
public static void renderBackground(Texture texture) { // To store the converted video // no longer required - textures now saved out and sent to a memory stream. //convertedVideo[frameCounter++] = texture; // Prevent anything from being rendered until ready if (globalSettings.videoPortal_eRenderReady == false) { return; } // Origionaly split out but more stable as part of this method if (device == null || device.Disposed) { return; } device.BeginScene(); // Renders to a flat plane - i.e. the screen CustomVertex.TransformedTextured[] screenVert = new CustomVertex.TransformedTextured[4]; screenVert[0] = new CustomVertex.TransformedTextured(0, 0, 0, 1, 0, 0); screenVert[1] = new CustomVertex.TransformedTextured(clientForm.Width, 0, 0, 1, 1, 0); screenVert[2] = new CustomVertex.TransformedTextured(clientForm.Width, clientForm.Height, 0, 1, 1, 1); screenVert[3] = new CustomVertex.TransformedTextured(0, clientForm.Height, 0, 1, 0, 1); // To tile textures, use the wrap texture type - It's used by default... // device.SamplerState[1].AddressU = TextureAddress.Wrap; device.SamplerState[1].AddressV = TextureAddress.Wrap; // Then set the U&V co-ordinates to the number of times you want the texture replicated // i.e. if you change both the U&V co-ords to 2 then you will see the texture tiled 4 times, 2 across and 2 down // Turn off while drawing the background //device.RenderState.ZBufferEnable = false; // Test with vertex buffer // buffer.SetData(screenVert, 0, LockFlags.None); // -----------Stuffn with -------------------------------- //SamplerStateManager sam = new SamplerStateManager(); //sam = TextureAddress.Border; //device.SetSamplerState(0,SamplerStageStates.SrgbTexture, true); //TextureAddress tex = new TextureAddress(); //tex = TextureAddress.Border; // -----------Stuffn with -------------------------------- //// These would probably work if the textures were first copied to a newly created texture in this //// transactions scope //fUtil.addFrame(device.GetTexture(0)); //fUtil.addFrame(texture); //// This works to save the rendered frame to a BMP //Bitmap bmp = SaveToBitmap(device); //fUtil.addBmpFrame(bmp); // Attemptng to save the frame as a memory stream in the DDS format //SaveToDDSFile(device); //fUtil.addDDSFrame("TempDDSConv.dds"); //fUtil.addMSFrame(aMS); // Set the texture to render to the background device.SetTexture(0, texture); if (lastFrame != null) { // For Vertex Buffer //device.SetStreamSource(0, buffer, 0,0); device.SetTexture(1, lastFrame); // Sets the U&V co-ordinates for the '1' (i.e. second) texture stage to the same as the first! // I wish ths was better f*****g documented, seriosuly device.TextureState[1].TextureCoordinateIndex = 0; // For Vertex Buffer //device.SetStreamSource(1, buffer, 0,0); //-------------- more stuffn //device.SamplerState[0].AddressU = TextureAddress.Border; //device.SamplerState[0].AddressV = TextureAddress.Border; // wrap is the default mode device.SamplerState[1].AddressU = TextureAddress.Wrap; device.SamplerState[1].AddressV = TextureAddress.Wrap; //------------- //// Blend and mix - around 50% transperancy device.SetTextureStageState(0, TextureStageStates.ColorArgument1, (int)TextureArgument.TextureColor); device.SetTextureStageState(0, TextureStageStates.ColorOperation, (int)TextureOperation.SelectArg1); device.SetTextureStageState(1, TextureStageStates.ColorArgument1, (int)TextureArgument.Current); device.SetTextureStageState(1, TextureStageStates.ColorArgument2, (int)TextureArgument.TextureColor); device.SetTextureStageState(1, TextureStageStates.ColorOperation, (int)TextureOperation.Add); // Lighter blend //device.SetTextureStageState(0, TextureStageStates.ColorArgument1, (int)TextureArgument.TextureColor); //device.SetTextureStageState(0, TextureStageStates.ColorOperation, (int)TextureOperation.SelectArg1); //device.SetTextureStageState(1, TextureStageStates.ColorArgument1, (int)TextureArgument.Current); //device.SetTextureStageState(1, TextureStageStates.ColorArgument2, (int)TextureArgument.TextureColor); //device.SetTextureStageState(1, TextureStageStates.ColorOperation, (int)TextureOperation.MultiplyAdd); // Subtract the darker colour from the lighter colour //device.SetTextureStageState(0, TextureStageStates.ColorArgument1, (int)TextureArgument.TextureColor); //device.SetTextureStageState(0, TextureStageStates.ColorOperation, (int)TextureOperation.SelectArg1); //device.SetTextureStageState(1, TextureStageStates.ColorArgument1, (int)TextureArgument.Current); //device.SetTextureStageState(1, TextureStageStates.ColorArgument2, (int)TextureArgument.TextureColor); //device.SetTextureStageState(1, TextureStageStates.ColorOperation, (int)TextureOperation.Subtract); // Add with a darker tinge //device.SetTextureStageState(0, TextureStageStates.ColorArgument1, (int)TextureArgument.TextureColor); //device.SetTextureStageState(0, TextureStageStates.ColorOperation, (int)TextureOperation.SelectArg1); //device.SetTextureStageState(1, TextureStageStates.ColorArgument1, (int)TextureArgument.Current); //device.SetTextureStageState(1, TextureStageStates.ColorArgument2, (int)TextureArgument.TextureColor); //device.SetTextureStageState(1, TextureStageStates.ColorOperation, (int)TextureOperation.AddSigned); // Add with highted highlights and darkened shadows //device.SetTextureStageState(0, TextureStageStates.ColorArgument1, (int)TextureArgument.TextureColor); //device.SetTextureStageState(0, TextureStageStates.ColorOperation, (int)TextureOperation.SelectArg1); //device.SetTextureStageState(1, TextureStageStates.ColorArgument1, (int)TextureArgument.Current); //device.SetTextureStageState(1, TextureStageStates.ColorArgument2, (int)TextureArgument.TextureColor); //device.SetTextureStageState(1, TextureStageStates.ColorOperation, (int)TextureOperation.AddSigned2X); // Add with a lighter mix //device.SetTextureStageState(0, TextureStageStates.ColorArgument1, (int)TextureArgument.TextureColor); //device.SetTextureStageState(0, TextureStageStates.ColorOperation, (int)TextureOperation.SelectArg1); //device.SetTextureStageState(1, TextureStageStates.ColorArgument1, (int)TextureArgument.Current); //device.SetTextureStageState(1, TextureStageStates.ColorArgument2, (int)TextureArgument.TextureColor); //device.SetTextureStageState(1, TextureStageStates.ColorOperation, (int)TextureOperation.AddSmooth); // Use colour to tint image mix //device.SetTextureStageState(0, TextureStageStates.ColorArgument1, (int)TextureArgument.TextureColor); //device.SetTextureStageState(0, TextureStageStates.ColorOperation, (int)TextureOperation.SelectArg1); //device.SetTextureStageState(1, TextureStageStates.ColorArgument1, (int)TextureArgument.Current); //device.SetTextureStageState(1, TextureStageStates.ColorArgument2, (int)TextureArgument.TextureColor); //device.SetTextureStageState(1, TextureStageStates.ColorOperation, (int)TextureOperation.Modulate); // Add image and inverse white parts of the image being added //device.SetTextureStageState(0, TextureStageStates.ColorArgument1, (int)TextureArgument.TextureColor); //device.SetTextureStageState(0, TextureStageStates.ColorOperation, (int)TextureOperation.SelectArg1); //device.SetTextureStageState(1, TextureStageStates.ColorArgument1, (int)TextureArgument.Current); //device.SetTextureStageState(1, TextureStageStates.ColorArgument2, (int)TextureArgument.TextureColor); //device.SetTextureStageState(1, TextureStageStates.ColorOperation, (int)TextureOperation.Lerp); // Black and white image add. //device.SetTextureStageState(0, TextureStageStates.ColorArgument1, (int)TextureArgument.TextureColor); //device.SetTextureStageState(0, TextureStageStates.ColorOperation, (int)TextureOperation.SelectArg1); //device.SetTextureStageState(1, TextureStageStates.ColorArgument1, (int)TextureArgument.Current); //device.SetTextureStageState(1, TextureStageStates.ColorArgument2, (int)TextureArgument.TextureColor); //device.SetTextureStageState(1, TextureStageStates.ColorOperation, (int)TextureOperation.DotProduct3); //if (secondLastFrame != null) //{ // device.TextureState[2].TextureCoordinateIndex = 0; // device.SetTextureStageState(1, TextureStageStates.ColorOperation, (int)TextureOperation.SelectArg1); // device.SetTexture(2, secondLastFrame); // device.SetTextureStageState(2, TextureStageStates.ColorArgument1, (int)TextureArgument.Current); // device.SetTextureStageState(2, TextureStageStates.ColorArgument2, (int)TextureArgument.TextureColor); // device.SetTextureStageState(2, TextureStageStates.ColorOperation, (int)TextureOperation.Add); //} } //secondLastFrame = lastFrame; lastFrame = texture; //device.VertexFormat = CustomVertex.TransformedTextured.Format; device.VertexFormat = vertexFormat; device.DrawUserPrimitives(PrimitiveType.TriangleFan, 2, screenVert); // Turn it back on // device.RenderState.ZBufferEnable = true; // Origionaly split out but more stable in the same method device.EndScene(); device.Present(); }
/// <summary> /// The render. /// </summary> /// <remarks></remarks> private void Render() { if (pause) { return; } device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); device.BeginScene(); cam.move(); SetupMatrices(); MoveSpawnsWithKeyboard(); device.RenderState.FillMode = FillMode.WireFrame; device.Material = DefaultMaterial; device.RenderState.Lighting = true; device.RenderState.CullMode = Cull.None; render.device.SetTexture(0, null); render.device.RenderState.AlphaBlendEnable = true; render.device.RenderState.AlphaTestEnable = true; render.device.RenderState.DestinationBlend = Blend.DestinationAlpha; render.device.RenderState.SourceBlend = Blend.SourceAlpha; device.Transform.World = Matrix.Identity; //Raw.ParsedModel.DisplayedInfo.Draw(ref device, ref bsp.SkyBox); dxcoll.Draw(ref device); if (currentMode == editingModes.Point) { device.RenderState.FillMode = FillMode.Point; device.Material = BlueMaterial; device.RenderState.PointSize = 4; dxcoll.Draw(ref device); #region Render Spheres over selected points device.Material = GreenMaterial; device.RenderState.FillMode = FillMode.WireFrame; device.VertexFormat = CustomVertex.PositionColored.Format; device.RenderState.AlphaBlendEnable = false; device.RenderState.AlphaTestEnable = false; device.SetTexture(0, null); for (int i = 0; i < SelectedPoints.Count; i++) { device.Transform.World = Matrix.Translation(coll.Vertices[SelectedPoints[i]].X, coll.Vertices[SelectedPoints[i]].Y, coll.Vertices[SelectedPoints[i]].Z); sphere.DrawSubset(0); } #endregion } else if (currentMode == editingModes.Surface) { if (currentSurface != -1) { device.RenderState.Lighting = false; device.RenderState.ZBufferEnable = false; device.RenderState.CullMode = Cull.None; device.RenderState.AlphaBlendEnable = true; device.TextureState[0].ColorOperation = TextureOperation.SelectArg1; device.TextureState[0].AlphaOperation = TextureOperation.SelectArg1; device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor; device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor; //device.Material = GreenMaterial; device.RenderState.FillMode = FillMode.Solid; device.Transform.World = Matrix.Identity; device.DrawIndexedUserPrimitives(PrimitiveType.TriangleFan, 0, coll.Vertices.Length, polygons[currentSurface].indices.Length - 2, polygons[currentSurface].indices, true, coll.Vertices); } } device.EndScene(); // Update the screen device.Present(); }
public void DrawWall() { // Disable alpha blend setting GameDevice.RenderState.AlphaBlendEnable = false; // Apply shaders to wall int numPasses = WallEffect.Begin(0); for (int iPass = 0; iPass < numPasses; iPass++) { WallEffect.BeginPass(iPass); for (int i = 0; i < WallMaterials.Length; i++) { // Set texture tiling properties for parts of the wall. if (i == 6) // Drain Texture { WallEffect.SetValue("xMultiply", 20.0f); WallEffect.SetValue("yMultiply", 1.0f); } else if (i == 4) // Wall Texture { WallEffect.SetValue("xMultiply", 5.0f); WallEffect.SetValue("yMultiply", 5.0f); } else if (i == 7) // Catwalk Texture { WallEffect.SetValue("xMultiply", 3.0f); WallEffect.SetValue("yMultiply", 3.0f); } else { WallEffect.SetValue("xMultiply", 3.0f); WallEffect.SetValue("yMultiply", 3.0f); } WallEffect.CommitChanges(); GameDevice.SetTexture(0, WallTextures[i]); WallMesh.DrawSubset(i); } WallEffect.EndPass(); } WallEffect.End(); numPasses = PipeEffect.Begin(0); for (int iPass = 0; iPass < numPasses; iPass++) { PipeEffect.BeginPass(iPass); // Set texture tiling properties for parts of the pipe. for (int i = 0; i < PipeMaterials.Length; i++) { if (i == 6) // Bars Texture { PipeEffect.SetValue("xMultiply", 1.0f); PipeEffect.SetValue("yMultiply", 1.0f); } else if (i == 5) // Outside pipe { PipeEffect.SetValue("xMultiply", 1.0f); PipeEffect.SetValue("yMultiply", 2.0f); } else if (i == 3) // Inside pipe { PipeEffect.SetValue("xMultiply", 3.0f); PipeEffect.SetValue("yMultiply", 3.0f); } else { PipeEffect.SetValue("xMultiply", 1.0f); PipeEffect.SetValue("yMultiply", 1.0f); } PipeEffect.CommitChanges(); GameDevice.SetTexture(0, PipeTextures[i]); PipeMesh.DrawSubset(i); } PipeEffect.EndPass(); } PipeEffect.End(); // Restore alpha blend setting GameDevice.RenderState.AlphaBlendEnable = true; }