/// <summary> /// Sets the directx render states and project matrices. /// </summary> public static void SetRenderState() { _device.SetRenderState(RenderState.CullMode, Cull.None); _device.SetRenderState(RenderState.Lighting, false); _device.SetRenderState(RenderState.ZEnable, false); _device.SetRenderState(RenderState.ZWriteEnable, false); _device.SetRenderState(RenderState.FillMode, FillMode.Solid); _device.SetRenderState(RenderState.AlphaBlendEnable, true); _device.SetRenderState(RenderState.SourceBlend, Blend.One); _device.SetRenderState(RenderState.DestinationBlend, Blend.InverseSourceAlpha); if (_dxCapabilities.SupportsAlphaBlend) { _device.SetRenderState(RenderState.AlphaTestEnable, true); _device.SetRenderState(RenderState.AlphaRef, 0x05); _device.SetRenderState(RenderState.AlphaFunc, Compare.GreaterEqual); } for (int sampler = 0; sampler < 3; sampler++) { _device.SetSamplerState(sampler, SamplerState.MinFilter, TextureFilter.Linear); _device.SetSamplerState(sampler, SamplerState.MagFilter, TextureFilter.Linear); _device.SetSamplerState(sampler, SamplerState.MipFilter, TextureFilter.None); } // Projection onto screen space SetCameraProjection(Width, Height); }
/// <summary> /// Sets the directx render states and project matrices. /// </summary> public static void SetRenderState() { _device.SetRenderState(RenderState.CullMode, Cull.None); _device.SetRenderState(RenderState.Lighting, false); _device.SetRenderState(RenderState.ZEnable, false); _device.SetRenderState(RenderState.ZWriteEnable, false); _device.SetRenderState(RenderState.FillMode, FillMode.Solid); EnableDefaultAlphaBlending(); if (_dxCapabilities.SupportsAlphaBlend) { EnableAlphaTest(); } for (int sampler = 0; sampler < 3; sampler++) { _device.SetSamplerState(sampler, SamplerState.MinFilter, TextureFilter.Linear); _device.SetSamplerState(sampler, SamplerState.MagFilter, TextureFilter.Linear); _device.SetSamplerState(sampler, SamplerState.MipFilter, TextureFilter.None); } // Projection onto screen space SetCameraProjection(Width, Height); }
private void InitializePointTexture() { int width = 64; int height = width; g_pTexture = new Texture(device, width, height, 0, Usage.AutoGenerateMipMap | Usage.Dynamic, Format.A8R8G8B8, Pool.Default); DataRectangle rect = g_pTexture.LockRectangle(0, LockFlags.None); rect.Data.Position = 0; for (int y = -height / 2; y < height / 2; ++y) { float yf = y + 0.5f; int counter = 0; for (int x = -width / 2; x < width / 2; ++x) { float xf = x + 0.5f; float radius = (float)width / 32; float dist = (float)Math.Sqrt(xf * xf + yf * yf) / radius; float n = 0.1f; float value; if (dist < 1) { value = 1 - 0.5f * (float)Math.Pow(dist, n); } else if (dist < 2) { value = 0.5f * (float)Math.Pow(2 - dist, n); } else { value = 0; } value *= 75; rect.Data.Write <byte>((byte)value); rect.Data.Write <byte>((byte)value); rect.Data.Write <byte>((byte)value); rect.Data.Write <byte>((byte)value); counter += 4; } rect.Data.Position += rect.Pitch - counter; } g_pTexture.UnlockRectangle(0); device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Linear); device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Linear); }