public ToolsetGame(GraphicsDevice graphics) : base(graphics) { _graphics = new WpfGraphicsDeviceService(this); Content.RootDirectory = "Compiled"; }
protected override void Initialize() { _disposed = false; _diviceService = new WpfGraphicsDeviceService(this); base.Initialize(); }
protected override void Initialize() { // must be initialized. required by Content loading and rendering (will add itself to the Services) // note that MonoGame requires this to be initialized in the constructor, while WpfInterop requires it to // be called inside Initialize (before base.Initialize()) graphicsDeviceManager = new WpfGraphicsDeviceService(this); // must be called after the WpfGraphicsDeviceService instance was created base.Initialize(); // Create a spritebatch for drawing sprites spriteBatch = new SpriteBatch(GraphicsDevice); //graphicsDeviceManager.PreferMultiSampling = false; //graphicsDeviceManager.ApplyChanges(); // wpf and keyboard need reference to the host control in order to receive input // this means every WpfGame control will have it's own keyboard & mouse manager which will only react if the mouse is in the control keyboard = new WpfKeyboard(this); mouse = new WpfMouse(this); spriteFrames = new List <Texture2D>(); Texture2D tex = new Texture2D(GraphicsDevice, 1, 1); tex.SetData(new Color[] { Color.Red }); texRectangle = new TextureSprite(tex); tex = new Texture2D(GraphicsDevice, 1, 1); tex.SetData(new Color[] { Color.LightBlue }); texPixel = new TextureSprite(tex); // content loading now possible }
public GameViewPort() { Graphics = new WpfGraphicsDeviceService(this); Content.RootDirectory = "Content"; _keyboard = new WpfKeyboard(this); _mouse = new WpfMouse(this); // must be called after the WpfGraphicsDeviceService instance was created base.Initialize(); }
protected override void Dispose(bool disposing) { if (_disposed) { return; } _disposed = true; _diviceService = null; base.Dispose(disposing); Components.Clear(); }
protected override void Initialize() { _disposed = false; _graphicsDeviceService = new WpfGraphicsDeviceService(this) { PreferMultiSampling = true }; Components.Add(new FpsComponent(this)); Components.Add(new TimingComponent(this)); _msaaMessage = new TextComponent(this, GetMsaaMessage(), new Vector2(1, 0), HorizontalAlignment.Right); Components.Add(_msaaMessage); float tilt = MathHelper.ToRadians(0); // 0 degree angle // Use the world matrix to tilt the cube along x and y axes. _worldMatrix = Matrix.CreateRotationX(tilt) * Matrix.CreateRotationY(tilt); _viewMatrix = Matrix.CreateLookAt(new Vector3(25, 25, 25), Vector3.Zero, Vector3.Up); _basicEffect = new BasicEffect(GraphicsDevice); _basicEffect.World = _worldMatrix; _basicEffect.View = _viewMatrix; RefreshProjection(); // primitive color _basicEffect.AmbientLightColor = new Vector3(0.1f, 0.1f, 0.1f); _basicEffect.DiffuseColor = new Vector3(1.0f, 1.0f, 1.0f); _basicEffect.SpecularColor = new Vector3(0.25f, 0.25f, 0.25f); _basicEffect.SpecularPower = 5.0f; _basicEffect.Alpha = 1.0f; // get a bunch of white cubes _basicEffect.LightingEnabled = false; _filled = new RasterizerState { CullMode = CullMode.None, FillMode = FillMode.Solid }; _wireframe = new RasterizerState { CullMode = CullMode.None, FillMode = FillMode.WireFrame }; SetupCube(); _keyboard = new WpfKeyboard(this); base.Initialize(); }
/// <summary> /// Graphics initialization callback. /// </summary> protected override void Initialize() { _graphics = new WpfGraphicsDeviceService(this); _graphics.PreferMultiSampling = true; _traceUpdater = new Thread(context => { while (Thread.CurrentThread.IsAlive) { (context as SynchronizationContext)?.Post(state => Trace.Step(0.002F), null); Thread.Sleep(2); } }); _traceUpdater.Start(SynchronizationContext.Current); base.Initialize(); }
protected override void Initialize() { TargetElapsedTime = TimeSpan.FromSeconds(1.0f / 60.0f); _graphicsDeviceManager = new WpfGraphicsDeviceService(this); _basicEffect = new BasicEffect(GraphicsDevice); _keyboard = new WpfKeyboard(this); _mouse = new WpfMouse(this); _gameScope = _parentScope.BeginLifetimeScope(gameScopeBuilder => { var assembly = Assembly.GetExecutingAssembly(); gameScopeBuilder.RegisterAssemblyTypes(assembly) .As <ISystem>() .AsSelf() .SingleInstance() .PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies); gameScopeBuilder.RegisterType <SystemManager>() .AsSelf() .SingleInstance() .PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies); gameScopeBuilder.RegisterType <InputManager>() .AsSelf() .SingleInstance() .PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies); gameScopeBuilder.RegisterInstance(GraphicsDevice).AsSelf().SingleInstance(); gameScopeBuilder.RegisterInstance(_basicEffect).AsSelf().SingleInstance(); gameScopeBuilder.RegisterInstance(_keyboard).AsSelf().SingleInstance(); gameScopeBuilder.RegisterInstance(_mouse).AsSelf().SingleInstance(); gameScopeBuilder.RegisterInstance(this).AsSelf().SingleInstance(); }); _systemManager = _gameScope.Resolve <SystemManager>(); _systemManager.Initialize(); base.Initialize(); }
public EditorGame(GraphicsDevice graphics) : base(graphics) { _graphics = new WpfGraphicsDeviceService(this); Loaded += EditorGame_Loaded; }
protected override void Initialize() { _disposed = false; _graphicsDeviceService = new WpfGraphicsDeviceService(this); Components.Add(new FpsComponent(this)); Components.Add(new TimingComponent(this)); Components.Add(new DpiScalingTextComponent(this, false, new Vector2(5, 50))); Components.Add(new DpiScalingTextComponent(this, true, new Vector2(5, 75))); Components.Add(new TextComponent(this, "Leftclick anywhere in the game to change dpi scaling", new Vector2(1, 0), HorizontalAlignment.Right)); float tilt = MathHelper.ToRadians(0); // 0 degree angle // Use the world matrix to tilt the cube along x and y axes. _worldMatrix = Matrix.CreateRotationX(tilt) * Matrix.CreateRotationY(tilt); _viewMatrix = Matrix.CreateLookAt(new Vector3(5, 5, 5), Vector3.Zero, Vector3.Up); _basicEffect = new BasicEffect(GraphicsDevice); _basicEffect.World = _worldMatrix; _basicEffect.View = _viewMatrix; RefreshProjection(); // primitive color _basicEffect.AmbientLightColor = new Vector3(0.1f, 0.1f, 0.1f); _basicEffect.DiffuseColor = new Vector3(1.0f, 1.0f, 1.0f); _basicEffect.SpecularColor = new Vector3(0.25f, 0.25f, 0.25f); _basicEffect.SpecularPower = 5.0f; _basicEffect.Alpha = 1.0f; _basicEffect.LightingEnabled = true; if (_basicEffect.LightingEnabled) { _basicEffect.DirectionalLight0.Enabled = true; // enable each light individually if (_basicEffect.DirectionalLight0.Enabled) { // x direction _basicEffect.DirectionalLight0.DiffuseColor = new Vector3(1, 0, 0); // range is 0 to 1 _basicEffect.DirectionalLight0.Direction = Vector3.Normalize(new Vector3(-1, 0, 0)); // points from the light to the origin of the scene _basicEffect.DirectionalLight0.SpecularColor = Vector3.One; } _basicEffect.DirectionalLight1.Enabled = true; if (_basicEffect.DirectionalLight1.Enabled) { // y direction _basicEffect.DirectionalLight1.DiffuseColor = new Vector3(0, 0.75f, 0); _basicEffect.DirectionalLight1.Direction = Vector3.Normalize(new Vector3(0, -1, 0)); _basicEffect.DirectionalLight1.SpecularColor = Vector3.One; } _basicEffect.DirectionalLight2.Enabled = true; if (_basicEffect.DirectionalLight2.Enabled) { // z direction _basicEffect.DirectionalLight2.DiffuseColor = new Vector3(0, 0, 0.5f); _basicEffect.DirectionalLight2.Direction = Vector3.Normalize(new Vector3(0, 0, -1)); _basicEffect.DirectionalLight2.SpecularColor = Vector3.One; } } _vertexDeclaration = new VertexDeclaration( new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0), new VertexElement(24, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0) ); Vector3 topLeftFront = new Vector3(-1.0f, 1.0f, 1.0f); Vector3 bottomLeftFront = new Vector3(-1.0f, -1.0f, 1.0f); Vector3 topRightFront = new Vector3(1.0f, 1.0f, 1.0f); Vector3 bottomRightFront = new Vector3(1.0f, -1.0f, 1.0f); Vector3 topLeftBack = new Vector3(-1.0f, 1.0f, -1.0f); Vector3 topRightBack = new Vector3(1.0f, 1.0f, -1.0f); Vector3 bottomLeftBack = new Vector3(-1.0f, -1.0f, -1.0f); Vector3 bottomRightBack = new Vector3(1.0f, -1.0f, -1.0f); Vector2 textureTopLeft = new Vector2(0.0f, 0.0f); Vector2 textureTopRight = new Vector2(1.0f, 0.0f); Vector2 textureBottomLeft = new Vector2(0.0f, 1.0f); Vector2 textureBottomRight = new Vector2(1.0f, 1.0f); Vector3 frontNormal = new Vector3(0.0f, 0.0f, 1.0f); Vector3 backNormal = new Vector3(0.0f, 0.0f, -1.0f); Vector3 topNormal = new Vector3(0.0f, 1.0f, 0.0f); Vector3 bottomNormal = new Vector3(0.0f, -1.0f, 0.0f); Vector3 leftNormal = new Vector3(-1.0f, 0.0f, 0.0f); Vector3 rightNormal = new Vector3(1.0f, 0.0f, 0.0f); var cubeVertices = new VertexPositionNormalTexture[36]; // Front face. cubeVertices[0] = new VertexPositionNormalTexture(topLeftFront, frontNormal, textureTopLeft); cubeVertices[1] = new VertexPositionNormalTexture(bottomLeftFront, frontNormal, textureBottomLeft); cubeVertices[2] = new VertexPositionNormalTexture(topRightFront, frontNormal, textureTopRight); cubeVertices[3] = new VertexPositionNormalTexture(bottomLeftFront, frontNormal, textureBottomLeft); cubeVertices[4] = new VertexPositionNormalTexture(bottomRightFront, frontNormal, textureBottomRight); cubeVertices[5] = new VertexPositionNormalTexture(topRightFront, frontNormal, textureTopRight); // Back face. cubeVertices[6] = new VertexPositionNormalTexture(topLeftBack, backNormal, textureTopRight); cubeVertices[7] = new VertexPositionNormalTexture(topRightBack, backNormal, textureTopLeft); cubeVertices[8] = new VertexPositionNormalTexture(bottomLeftBack, backNormal, textureBottomRight); cubeVertices[9] = new VertexPositionNormalTexture(bottomLeftBack, backNormal, textureBottomRight); cubeVertices[10] = new VertexPositionNormalTexture(topRightBack, backNormal, textureTopLeft); cubeVertices[11] = new VertexPositionNormalTexture(bottomRightBack, backNormal, textureBottomLeft); // Top face. cubeVertices[12] = new VertexPositionNormalTexture(topLeftFront, topNormal, textureBottomLeft); cubeVertices[13] = new VertexPositionNormalTexture(topRightBack, topNormal, textureTopRight); cubeVertices[14] = new VertexPositionNormalTexture(topLeftBack, topNormal, textureTopLeft); cubeVertices[15] = new VertexPositionNormalTexture(topLeftFront, topNormal, textureBottomLeft); cubeVertices[16] = new VertexPositionNormalTexture(topRightFront, topNormal, textureBottomRight); cubeVertices[17] = new VertexPositionNormalTexture(topRightBack, topNormal, textureTopRight); // Bottom face. cubeVertices[18] = new VertexPositionNormalTexture(bottomLeftFront, bottomNormal, textureTopLeft); cubeVertices[19] = new VertexPositionNormalTexture(bottomLeftBack, bottomNormal, textureBottomLeft); cubeVertices[20] = new VertexPositionNormalTexture(bottomRightBack, bottomNormal, textureBottomRight); cubeVertices[21] = new VertexPositionNormalTexture(bottomLeftFront, bottomNormal, textureTopLeft); cubeVertices[22] = new VertexPositionNormalTexture(bottomRightBack, bottomNormal, textureBottomRight); cubeVertices[23] = new VertexPositionNormalTexture(bottomRightFront, bottomNormal, textureTopRight); // Left face. cubeVertices[24] = new VertexPositionNormalTexture(topLeftFront, leftNormal, textureTopRight); cubeVertices[25] = new VertexPositionNormalTexture(bottomLeftBack, leftNormal, textureBottomLeft); cubeVertices[26] = new VertexPositionNormalTexture(bottomLeftFront, leftNormal, textureBottomRight); cubeVertices[27] = new VertexPositionNormalTexture(topLeftBack, leftNormal, textureTopLeft); cubeVertices[28] = new VertexPositionNormalTexture(bottomLeftBack, leftNormal, textureBottomLeft); cubeVertices[29] = new VertexPositionNormalTexture(topLeftFront, leftNormal, textureTopRight); // Right face. cubeVertices[30] = new VertexPositionNormalTexture(topRightFront, rightNormal, textureTopLeft); cubeVertices[31] = new VertexPositionNormalTexture(bottomRightFront, rightNormal, textureBottomLeft); cubeVertices[32] = new VertexPositionNormalTexture(bottomRightBack, rightNormal, textureBottomRight); cubeVertices[33] = new VertexPositionNormalTexture(topRightBack, rightNormal, textureTopRight); cubeVertices[34] = new VertexPositionNormalTexture(topRightFront, rightNormal, textureTopLeft); cubeVertices[35] = new VertexPositionNormalTexture(bottomRightBack, rightNormal, textureBottomRight); _vertexBuffer = new VertexBuffer(GraphicsDevice, _vertexDeclaration, cubeVertices.Length, BufferUsage.None); _vertexBuffer.SetData(cubeVertices); _keyboard = new WpfKeyboard(this); _mouse = new WpfMouse(this); base.Initialize(); }