public static void initialize1() { Graphics2D.Instance.Create(); color(ColorCode.White); _rasterizerState.Create(CullMode.None, FillMode.Solid); _depthStencilState.Create(false, false, false); }
/// <summary> /// Ensures that the geometry buffers exist and have sufficient size. /// </summary> private void EnsureBuffers(ref ImDrawDataPtr drawDataPtr) { var dirty = false; var vtxCount = 0; var idxCount = 0; for (var i = 0; i < drawDataPtr.CmdListsCount; i++) { var cmd = drawDataPtr.CmdListsRange[i]; vtxCount = Math.Max(vtxCount, cmd.VtxBuffer.Size); idxCount = Math.Max(idxCount, cmd.IdxBuffer.Size); } if (vertexBuffer == null || vertexBuffer.VertexCount < vtxCount) { if (vertexBuffer != null) { vertexBuffer.Dispose(); } vertexBuffer = DynamicVertexBuffer.Create(ImGuiVertex.VertexDeclaration, vtxCount); dirty = true; } if (indexBuffer == null || indexBuffer.IndexCount < idxCount) { if (indexBuffer != null) { indexBuffer.Dispose(); } indexBuffer = DynamicIndexBuffer.Create(IndexBufferElementType.Int16, idxCount); dirty = true; } if (rasterizerState == null) { rasterizerState = RasterizerState.Create(); rasterizerState.ScissorTestEnable = true; } if (geometryStream == null || dirty) { this.geometryStream = GeometryStream.Create(); this.geometryStream.Attach(this.vertexBuffer); this.geometryStream.Attach(this.indexBuffer); } }
public static void initialize0() { NoBlend.Create(BlendOperation.None); Addition.Create(BlendOperation.Add, BlendFactor.One, BlendFactor.One); HalfAddition.Create(BlendOperation.Add, BlendFactor.One, BlendFactor.InvSrcAlpha); Subtraction.Create(BlendOperation.RevSubtract, BlendFactor.One, BlendFactor.One); Multiplication.Create(BlendOperation.Add, BlendFactor.Zero, BlendFactor.SrcColor); Reverse.Create(BlendOperation.Add, BlendFactor.InvDestColor, BlendFactor.InvSrcColor); AlphaBlend.Create(BlendOperation.Add, BlendFactor.SrcAlpha, BlendFactor.InvSrcAlpha); Wrap.Create(TextureAddressMode.Wrap, TextureAddressMode.Wrap, TextureAddressMode.Wrap); Mirror.Create(TextureAddressMode.Mirror, TextureAddressMode.Mirror, TextureAddressMode.Mirror); CullingOn.Create(CullMode.Back, FillMode.Solid); CullingOff.Create(CullMode.None, FillMode.Solid); ZTestOn.Create(true, false, true); ZTestOnWriteOff.Create(true, false, false); ZTestOff.Create(false, false, false); }
public static void initialize() { MeiryoUI.Create("Meiryo UI", 64); MSMincho.Create("MS 明朝", 64); NoBlend.Create(BlendOperation.None); Addition.Create(BlendOperation.Add, BlendFactor.One, BlendFactor.One); HalfAddition.Create(BlendOperation.Add, BlendFactor.One, BlendFactor.InvSrcAlpha); Subtraction.Create(BlendOperation.RevSubtract, BlendFactor.One, BlendFactor.One); Multiplication.Create(BlendOperation.Add, BlendFactor.Zero, BlendFactor.SrcColor); Reverse.Create(BlendOperation.Add, BlendFactor.InvDestColor, BlendFactor.InvSrcColor); AlphaBlend.Create(BlendOperation.Add, BlendFactor.SrcAlpha, BlendFactor.InvSrcAlpha); Wrap.Create(TextureAddressMode.Wrap, TextureAddressMode.Wrap, TextureAddressMode.Wrap); Mirror.Create(TextureAddressMode.Mirror, TextureAddressMode.Mirror, TextureAddressMode.Mirror); CullingOn.Create(CullMode.Back, FillMode.Solid); CullingOff.Create(CullMode.None, FillMode.Solid); ZTestOn.Create(true, false, true); ZTestOnWriteOff.Create(true, false, false); ZTestOff.Create(false, false, false); font(MeiryoUI); ExplosionSound.Create("res/sound/explosion1.wav"); LargeExplosionSound.Create("res/sound/explosion2.wav"); JetSound.Create("res/sound/burner_f15.wav"); LockonSound.Create("res/sound/lockon4.wav"); LockonSound.Volume = 0.25; AlertSound.Create("res/sound/alert2.wav"); AlertSound.Volume = 0.25; BulletSound.Create("res/sound/bullet.wav"); BulletHitSound.Create("res/sound/bulletHit.wav"); BulletHitSound.Volume = 0.1; Graphics2D.Instance.Create(); color(ColorCode.White); _rasterizerState.Create(CullMode.None, FillMode.Solid); _depthStencilState.Create(false, false, false); }
/// <summary> /// Loads 3D geometry used for testing. /// </summary> protected void LoadTestGeometry() { /* * vertexBuffer = VertexBuffer.Create<VertexPositionColorTexture>(5); * vertexBuffer.SetData(new VertexPositionColorTexture[] * { * new VertexPositionColorTexture { Position = new Vector3(-1f, 0f, -1f), Color = Color.Red, TextureCoordinate = new Vector2(1, 0) }, * new VertexPositionColorTexture { Position = new Vector3( 1f, 0f, -1f), Color = Color.Lime, TextureCoordinate = new Vector2(0, 1) }, * new VertexPositionColorTexture { Position = new Vector3( 1f, 0f, 1f), Color = Color.Blue }, * new VertexPositionColorTexture { Position = new Vector3(-1f, 0f, 1f), Color = Color.Yellow }, * new VertexPositionColorTexture { Position = new Vector3( 0f, 1.5f, 0f), Color = Color.Magenta, TextureCoordinate = new Vector2(0, 0) }, * }); */ vertexBuffer = VertexBuffer.Create <VertexPositionNormalTexture>(36); vertexBuffer.SetData(new VertexPositionNormalTexture[] { new VertexPositionNormalTexture { Position = new Vector3(1f, 0f, 1f), Normal = new Vector3(0, -1f, 0) }, new VertexPositionNormalTexture { Position = new Vector3(1f, 0f, -1f), Normal = new Vector3(0, -1f, 0) }, new VertexPositionNormalTexture { Position = new Vector3(-1f, 0f, -1f), Normal = new Vector3(0, -1f, 0) }, new VertexPositionNormalTexture { Position = new Vector3(-1f, 0f, -1f), Normal = new Vector3(0, -1f, 0) }, new VertexPositionNormalTexture { Position = new Vector3(-1f, 0f, 1f), Normal = new Vector3(0, -1f, 0) }, new VertexPositionNormalTexture { Position = new Vector3(1f, 0f, 1f), Normal = new Vector3(0, -1f, 0) }, new VertexPositionNormalTexture { Position = new Vector3(1f, 2f, -1f), Normal = new Vector3(0, 0f, -1f) }, new VertexPositionNormalTexture { Position = new Vector3(-1f, 2f, -1f), Normal = new Vector3(0, 0f, -1f) }, new VertexPositionNormalTexture { Position = new Vector3(-1f, 0f, -1f), Normal = new Vector3(0, 0f, -1f) }, new VertexPositionNormalTexture { Position = new Vector3(-1f, 0f, -1f), Normal = new Vector3(0, 0f, -1f) }, new VertexPositionNormalTexture { Position = new Vector3(1f, 0f, -1f), Normal = new Vector3(0, 0f, -1f) }, new VertexPositionNormalTexture { Position = new Vector3(1f, 2f, -1f), Normal = new Vector3(0, 0f, -1f) }, new VertexPositionNormalTexture { Position = new Vector3(1f, 0f, -1f), Normal = new Vector3(1f, 0f, 0f) }, new VertexPositionNormalTexture { Position = new Vector3(1f, 2f, 1f), Normal = new Vector3(1f, 0f, 0f) }, new VertexPositionNormalTexture { Position = new Vector3(1f, 2f, -1f), Normal = new Vector3(1f, 0f, 0f) }, new VertexPositionNormalTexture { Position = new Vector3(1f, 0f, 1f), Normal = new Vector3(1f, 0f, 0f) }, new VertexPositionNormalTexture { Position = new Vector3(1f, 2f, 1f), Normal = new Vector3(1f, 0f, 0f) }, new VertexPositionNormalTexture { Position = new Vector3(1f, 0f, -1f), Normal = new Vector3(1f, 0f, 0f) }, new VertexPositionNormalTexture { Position = new Vector3(-1f, 0f, 1f), Normal = new Vector3(0, 0f, 1f) }, new VertexPositionNormalTexture { Position = new Vector3(-1f, 2f, 1f), Normal = new Vector3(0, 0f, 1f) }, new VertexPositionNormalTexture { Position = new Vector3(1f, 2f, 1f), Normal = new Vector3(0, 0f, 1f) }, new VertexPositionNormalTexture { Position = new Vector3(1f, 2f, 1f), Normal = new Vector3(0, 0f, 1f) }, new VertexPositionNormalTexture { Position = new Vector3(1f, 0f, 1f), Normal = new Vector3(0, 0f, 1f) }, new VertexPositionNormalTexture { Position = new Vector3(-1f, 0f, 1f), Normal = new Vector3(0, 0f, 1f) }, new VertexPositionNormalTexture { Position = new Vector3(-1f, 2f, -1f), Normal = new Vector3(-1f, 0f, 0f) }, new VertexPositionNormalTexture { Position = new Vector3(-1f, 2f, 1f), Normal = new Vector3(-1f, 0f, 0f) }, new VertexPositionNormalTexture { Position = new Vector3(-1f, 0f, -1f), Normal = new Vector3(-1f, 0f, 0f) }, new VertexPositionNormalTexture { Position = new Vector3(-1f, 0f, -1f), Normal = new Vector3(-1f, 0f, 0f) }, new VertexPositionNormalTexture { Position = new Vector3(-1f, 2f, 1f), Normal = new Vector3(-1f, 0f, 0f) }, new VertexPositionNormalTexture { Position = new Vector3(-1f, 0f, 1f), Normal = new Vector3(-1f, 0f, 0f) }, new VertexPositionNormalTexture { Position = new Vector3(-1f, 2f, -1f), Normal = new Vector3(0, 1f, 0) }, new VertexPositionNormalTexture { Position = new Vector3(1f, 2f, -1f), Normal = new Vector3(0, 1f, 0) }, new VertexPositionNormalTexture { Position = new Vector3(1f, 2f, 1f), Normal = new Vector3(0, 1f, 0) }, new VertexPositionNormalTexture { Position = new Vector3(1f, 2f, 1f), Normal = new Vector3(0, 1f, 0) }, new VertexPositionNormalTexture { Position = new Vector3(-1f, 2f, 1f), Normal = new Vector3(0, 1f, 0) }, new VertexPositionNormalTexture { Position = new Vector3(-1f, 2f, -1f), Normal = new Vector3(0, 1f, 0) }, }); //indexBuffer = IndexBuffer.Create(IndexBufferElementType.Int16, 18); //indexBuffer.SetData(new Int16[] { 2, 1, 0, 0, 3, 2, 0, 1, 4, 1, 2, 4, 2, 3, 4, 3, 0, 4 }); geometryStream = GeometryStream.Create(); geometryStream.Attach(vertexBuffer); //geometryStream.Attach(indexBuffer); effect = BasicEffect.Create(); effect.EnableStandardLighting(); rasterizerStateSolid = RasterizerState.Create(); rasterizerStateSolid.CullMode = CullMode.CullCounterClockwiseFace; rasterizerStateSolid.FillMode = FillMode.Solid; rasterizerStateWireframe = RasterizerState.Create(); rasterizerStateWireframe.CullMode = CullMode.CullCounterClockwiseFace; rasterizerStateWireframe.FillMode = FillMode.Wireframe; texture = content.Load <Texture2D>(@"Textures\Triangle"); }
public void BasicEffect_RendersACubeCorrectly(BasicEffectTestParameters parameters) { void DrawGeometry(IUltravioletGraphics gfx, Effect eff, RasterizerState rasterizerState, DepthStencilState depthStencilState, Int32 count) { foreach (var pass in eff.CurrentTechnique.Passes) { pass.Apply(); gfx.SetRasterizerState(rasterizerState); gfx.SetDepthStencilState(depthStencilState); gfx.DrawPrimitives(PrimitiveType.TriangleList, 0, count); } } var effect = default(BasicEffect); var vbuffer = default(VertexBuffer); var gstream = default(GeometryStream); var rasterizerStateSolid = default(RasterizerState); var rasterizerStateWireframe = default(RasterizerState); var result = GivenAnUltravioletApplication() .WithContent(content => { rasterizerStateSolid = RasterizerState.Create(); rasterizerStateSolid.CullMode = CullMode.CullCounterClockwiseFace; rasterizerStateSolid.FillMode = FillMode.Solid; rasterizerStateWireframe = RasterizerState.Create(); rasterizerStateWireframe.CullMode = CullMode.CullCounterClockwiseFace; rasterizerStateWireframe.FillMode = FillMode.Wireframe; effect = BasicEffect.Create(); effect.FogEnabled = parameters.FogEnabled; effect.TextureEnabled = parameters.TextureEnabled; effect.Texture = content.Load <Texture2D>("Textures\\Cube"); effect.VertexColorEnabled = parameters.VertexColorEnabled; effect.LightingEnabled = parameters.LightingEnabled; effect.PreferPerPixelLighting = parameters.PreferPerPixelLighting; if (effect.FogEnabled) { effect.FogColor = Color.Black; effect.FogStart = 5f; effect.FogEnd = 5.5f; } if (effect.LightingEnabled) { effect.EnableStandardLighting(); } vbuffer = VertexBuffer.Create <BasicEffectTestVertex>(36); vbuffer.SetData(new BasicEffectTestVertex[] { // Bottom face new BasicEffectTestVertex { Position = new Vector3(1f, 0f, 1f), Normal = new Vector3(0, -1f, 0), TextureCoordinate = new Vector2(0.25f, 0.75f), Color = Color.Red }, new BasicEffectTestVertex { Position = new Vector3(1f, 0f, -1f), Normal = new Vector3(0, -1f, 0), TextureCoordinate = new Vector2(0.50f, 0.75f), Color = Color.Red }, new BasicEffectTestVertex { Position = new Vector3(-1f, 0f, -1f), Normal = new Vector3(0, -1f, 0), TextureCoordinate = new Vector2(0.50f, 1.00f), Color = Color.Red }, new BasicEffectTestVertex { Position = new Vector3(-1f, 0f, -1f), Normal = new Vector3(0, -1f, 0), TextureCoordinate = new Vector2(0.50f, 1.00f), Color = Color.Red }, new BasicEffectTestVertex { Position = new Vector3(-1f, 0f, 1f), Normal = new Vector3(0, -1f, 0), TextureCoordinate = new Vector2(0.25f, 1.00f), Color = Color.Red }, new BasicEffectTestVertex { Position = new Vector3(1f, 0f, 1f), Normal = new Vector3(0, -1f, 0), TextureCoordinate = new Vector2(0.25f, 0.75f), Color = Color.Red }, // Forward face new BasicEffectTestVertex { Position = new Vector3(1f, 2f, -1f), Normal = new Vector3(0, 0f, -1f), TextureCoordinate = new Vector2(0.00f, 0.50f), Color = Color.Cyan }, new BasicEffectTestVertex { Position = new Vector3(-1f, 2f, -1f), Normal = new Vector3(0, 0f, -1f), TextureCoordinate = new Vector2(0.25f, 0.50f), Color = Color.Cyan }, new BasicEffectTestVertex { Position = new Vector3(-1f, 0f, -1f), Normal = new Vector3(0, 0f, -1f), TextureCoordinate = new Vector2(0.25f, 0.75f), Color = Color.Cyan }, new BasicEffectTestVertex { Position = new Vector3(-1f, 0f, -1f), Normal = new Vector3(0, 0f, -1f), TextureCoordinate = new Vector2(0.25f, 0.75f), Color = Color.Cyan }, new BasicEffectTestVertex { Position = new Vector3(1f, 0f, -1f), Normal = new Vector3(0, 0f, -1f), TextureCoordinate = new Vector2(0.00f, 0.75f), Color = Color.Cyan }, new BasicEffectTestVertex { Position = new Vector3(1f, 2f, -1f), Normal = new Vector3(0, 0f, -1f), TextureCoordinate = new Vector2(0.00f, 0.50f), Color = Color.Cyan }, // Right face new BasicEffectTestVertex { Position = new Vector3(1f, 2f, 1f), Normal = new Vector3(1f, 0f, 0f), TextureCoordinate = new Vector2(0.25f, 0.50f), Color = Color.Magenta }, new BasicEffectTestVertex { Position = new Vector3(1f, 2f, -1f), Normal = new Vector3(1f, 0f, 0f), TextureCoordinate = new Vector2(0.50f, 0.50f), Color = Color.Magenta }, new BasicEffectTestVertex { Position = new Vector3(1f, 0f, -1f), Normal = new Vector3(1f, 0f, 0f), TextureCoordinate = new Vector2(0.50f, 0.75f), Color = Color.Magenta }, new BasicEffectTestVertex { Position = new Vector3(1f, 0f, -1f), Normal = new Vector3(1f, 0f, 0f), TextureCoordinate = new Vector2(0.50f, 0.75f), Color = Color.Magenta }, new BasicEffectTestVertex { Position = new Vector3(1f, 0f, 1f), Normal = new Vector3(1f, 0f, 0f), TextureCoordinate = new Vector2(0.25f, 0.75f), Color = Color.Magenta }, new BasicEffectTestVertex { Position = new Vector3(1f, 2f, 1f), Normal = new Vector3(1f, 0f, 0f), TextureCoordinate = new Vector2(0.25f, 0.50f), Color = Color.Magenta }, // Backward face new BasicEffectTestVertex { Position = new Vector3(-1f, 2f, 1f), Normal = new Vector3(0, 0f, 1f), TextureCoordinate = new Vector2(0.50f, 0.50f), Color = Color.Yellow }, new BasicEffectTestVertex { Position = new Vector3(1f, 2f, 1f), Normal = new Vector3(0, 0f, 1f), TextureCoordinate = new Vector2(0.75f, 0.50f), Color = Color.Yellow }, new BasicEffectTestVertex { Position = new Vector3(1f, 0f, 1f), Normal = new Vector3(0, 0f, 1f), TextureCoordinate = new Vector2(0.75f, 0.75f), Color = Color.Yellow }, new BasicEffectTestVertex { Position = new Vector3(1f, 0f, 1f), Normal = new Vector3(0, 0f, 1f), TextureCoordinate = new Vector2(0.75f, 0.75f), Color = Color.Yellow }, new BasicEffectTestVertex { Position = new Vector3(-1f, 0f, 1f), Normal = new Vector3(0, 0f, 1f), TextureCoordinate = new Vector2(0.50f, 0.75f), Color = Color.Yellow }, new BasicEffectTestVertex { Position = new Vector3(-1f, 2f, 1f), Normal = new Vector3(0, 0f, 1f), TextureCoordinate = new Vector2(0.50f, 0.50f), Color = Color.Yellow }, // Left face new BasicEffectTestVertex { Position = new Vector3(-1f, 2f, -1f), Normal = new Vector3(-1f, 0f, 0f), TextureCoordinate = new Vector2(0.75f, 0.50f), Color = Color.Blue }, new BasicEffectTestVertex { Position = new Vector3(-1f, 2f, 1f), Normal = new Vector3(-1f, 0f, 0f), TextureCoordinate = new Vector2(1.00f, 0.50f), Color = Color.Blue }, new BasicEffectTestVertex { Position = new Vector3(-1f, 0f, 1f), Normal = new Vector3(-1f, 0f, 0f), TextureCoordinate = new Vector2(1.00f, 0.75f), Color = Color.Blue }, new BasicEffectTestVertex { Position = new Vector3(-1f, 0f, 1f), Normal = new Vector3(-1f, 0f, 0f), TextureCoordinate = new Vector2(1.00f, 0.75f), Color = Color.Blue }, new BasicEffectTestVertex { Position = new Vector3(-1f, 0f, -1f), Normal = new Vector3(-1f, 0f, 0f), TextureCoordinate = new Vector2(0.75f, 0.75f), Color = Color.Blue }, new BasicEffectTestVertex { Position = new Vector3(-1f, 2f, -1f), Normal = new Vector3(-1f, 0f, 0f), TextureCoordinate = new Vector2(0.75f, 0.50f), Color = Color.Blue }, // Top face new BasicEffectTestVertex { Position = new Vector3(-1f, 2f, 1f), Normal = new Vector3(0, 1f, 0), TextureCoordinate = new Vector2(0.25f, 0.25f), Color = Color.Lime }, new BasicEffectTestVertex { Position = new Vector3(-1f, 2f, -1f), Normal = new Vector3(0, 1f, 0), TextureCoordinate = new Vector2(0.50f, 0.25f), Color = Color.Lime }, new BasicEffectTestVertex { Position = new Vector3(1f, 2f, -1f), Normal = new Vector3(0, 1f, 0), TextureCoordinate = new Vector2(0.50f, 0.50f), Color = Color.Lime }, new BasicEffectTestVertex { Position = new Vector3(1f, 2f, -1f), Normal = new Vector3(0, 1f, 0), TextureCoordinate = new Vector2(0.50f, 0.50f), Color = Color.Lime }, new BasicEffectTestVertex { Position = new Vector3(1f, 2f, 1f), Normal = new Vector3(0, 1f, 0), TextureCoordinate = new Vector2(0.25f, 0.50f), Color = Color.Lime }, new BasicEffectTestVertex { Position = new Vector3(-1f, 2f, 1f), Normal = new Vector3(0, 1f, 0), TextureCoordinate = new Vector2(0.25f, 0.25f), Color = Color.Lime }, }); gstream = GeometryStream.Create(); gstream.Attach(vbuffer); }) .Render(uv => { var gfx = uv.GetGraphics(); var window = uv.GetPlatform().Windows.GetCurrent(); var aspectRatio = window.DrawableSize.Width / (Single)window.DrawableSize.Height; effect.World = Matrix.CreateRotationY((float)(2.0 * Math.PI * 0.45f)); effect.View = Matrix.CreateLookAt(new Vector3(0, 3, 6), new Vector3(0, 1f, 0), Vector3.Up); effect.Projection = Matrix.CreatePerspectiveFieldOfView((float)Math.PI / 4f, aspectRatio, 1f, 1000f); gfx.SetGeometryStream(gstream); DrawGeometry(gfx, effect, rasterizerStateSolid, DepthStencilState.Default, vbuffer.VertexCount / 3); effect.FogEnabled = false; effect.TextureEnabled = false; effect.VertexColorEnabled = false; effect.LightingEnabled = false; effect.PreferPerPixelLighting = false; effect.DiffuseColor = Color.Black; DrawGeometry(gfx, effect, rasterizerStateWireframe, DepthStencilState.None, vbuffer.VertexCount / 3); }); TheResultingImage(result).WithinAbsoluteThreshold(32) .ShouldMatch($@"Resources/Expected/Graphics/BasicEffect_RendersACubeCorrectly({parameters}).png"); }