1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| pres.Windowed = true;
pres.SwapEffect = SwapEffect.Discard;
pres.BackBufferCount = 2;
pres.BackBufferFormat = Format.Unknown; // default for windowed mode, so not needed. Oh well!
pres.EnableAutoDepthStencil = true;
pres.AutoDepthStencilFormat = DepthFormat.D16;
// Set up the device's RenderStates
device.RenderState.Lighting = false;
device.RenderState.ShadeMode = ShadeMode.Gouraud;
device.RenderState.ZBufferEnable = false;
device.RenderState.CullMode = Cull.None;
device.RenderState.FillMode = FillMode.Solid;
device.RenderState.Lighting = false;
device.RenderState.SourceBlend = Blend.SourceAlpha;
device.RenderState.DestinationBlend = Blend.InvSourceAlpha;
device.RenderState.AlphaBlendEnable = true;
//Set texture pipeline with parameters for masked texture
// Layer 0 is alpha part
// Layer 1 is color part
device.TextureState[0].ColorOperation = TextureOperation.SelectArg2;
device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse;
device.TextureState[0].AlphaOperation = TextureOperation.Modulate;
device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor;
device.TextureState[0].AlphaArgument2 = TextureArgument.Diffuse;
device.TextureState[0].TextureCoordinateIndex = 0; //only one UV
device.SetSamplerState(0, SamplerStageStates.MagFilter, (int)TextureFilter.Linear);
device.SetSamplerState(0, SamplerStageStates.MinFilter, (int)TextureFilter.Linear);
device.SetSamplerState(0, SamplerStageStates.AddressU, (int)TextureAddress.Clamp);
device.SetSamplerState(0, SamplerStageStates.AddressV, (int)TextureAddress.Clamp);
device.TextureState[1].ColorOperation = TextureOperation.Modulate;
device.TextureState[1].ColorArgument1 = TextureArgument.TextureColor;
device.TextureState[1].ColorArgument2 = TextureArgument.Current;
device.TextureState[1].AlphaOperation = TextureOperation.SelectArg1;
device.TextureState[1].AlphaArgument1 = TextureArgument.Current;
device.TextureState[1].TextureCoordinateIndex = 0; //only one UV
device.SetSamplerState(1, SamplerStageStates.MagFilter, (int)TextureFilter.Linear);
device.SetSamplerState(1, SamplerStageStates.MinFilter, (int)TextureFilter.Linear);
device.SetSamplerState(1, SamplerStageStates.AddressU, (int)TextureAddress.Clamp);
device.SetSamplerState(1, SamplerStageStates.AddressV, (int)TextureAddress.Clamp);
device.TextureState[2].ColorOperation = TextureOperation.Disable;
device.TextureState[2].AlphaOperation = TextureOperation.Disable;
try
{
device.SetTexture(0, oAlphaTexture);
device.SetTexture(1, oTexture);
device.SetTexture(2, null);
}
catch (DirectXException e)
{
MessageBox.Show("DirectXException " + e.ToString());
}
CustomVertex.TransformedColoredTextured[] verts = new CustomVertex.TransformedColoredTextured[10];
float x = rect.X;
float y = rect.Y;
float w = rect.Width;
float h = rect.Height;
verts[0].Position = new Vector4(x, y, 0, 1);
verts[0].Tu = 0;
verts[0].Tv = 0;
verts[0].Color = -1;
verts[1].Position = new Vector4(x, y + h, 0, 1);
verts[1].Tu = 0;
verts[1].Tv = 1;
verts[1].Color = -1;
verts[2].Position = new Vector4(x + w, y, 0, 1);
verts[2].Tu = 1;
verts[2].Tv = 0;
verts[2].Color = -1;
verts[3].Position = new Vector4(x + w, y + h, 0, 1);
verts[3].Tu = 1;
verts[3].Tv = 1;
verts[3].Color = -1;
device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, verts);
device.SetTexture(0, null);
device.SetTexture(1, null); |
Partager