コード例 #1
0
        protected override void LoadContent()
        {
            // Instantiate a SpriteBatch
            spriteBatch = ToDisposeContent(new SpriteBatch(GraphicsDevice));

            // Loads a sprite font
            // The [Arial16.xml] file is defined with the build action [ToolkitFont] in the project
            arial16Font = Content.Load<SpriteFont>("Arial16");

            // Creates a basic effect
            basicEffect = ToDisposeContent(new BasicEffect(GraphicsDevice));
            basicEffect.DiffuseColor = Color.OrangeRed.ToVector4();
            basicEffect.PreferPerPixelLighting = true;
            basicEffect.EnableDefaultLighting();

            // Creates torus primitive
            sphere = ToDisposeContent(GeometricPrimitive.Sphere.New(GraphicsDevice, 1.75f));

            pixelTexture = Texture2D.New(GraphicsDevice, 1, 1, GraphicsDevice.BackBuffer.Format);
            pixelTexture.SetData<Color>(new Color[] { Color.Green });

            occlusionQuery = new OcclusionQuery(GraphicsDevice);

            offscreenBuffer = RenderTarget2D.New(GraphicsDevice, 128, 128, GraphicsDevice.BackBuffer.Format);

            base.LoadContent();
        }
コード例 #2
0
ファイル: SceneView.xaml.cs プロジェクト: DraTeots/gemini
        /// <summary>
        /// Invoked after either control has created its graphics device.
        /// </summary>
        private void OnGraphicsControlLoadContent(object sender, GraphicsDeviceEventArgs e)
        {
	        _basicEffect = new BasicEffect(e.GraphicsDevice)
	        {
		        View = Matrix.LookAtRH(new Vector3(0, 0, 3), new Vector3(0, 0, 0), Vector3.UnitY),
		        World = Matrix.Identity,
		        PreferPerPixelLighting = true
	        };
	        _basicEffect.EnableDefaultLighting();

            _geometricPrimitives = new[]
            {
                GeometricPrimitive.Cube.New(e.GraphicsDevice),
                GeometricPrimitive.Cylinder.New(e.GraphicsDevice),
                GeometricPrimitive.GeoSphere.New(e.GraphicsDevice),
                GeometricPrimitive.Teapot.New(e.GraphicsDevice),
                GeometricPrimitive.Torus.New(e.GraphicsDevice)
            };
            _primitiveIndex = 0;

	        _texture = Texture2D.Load(e.GraphicsDevice, "Modules/SceneViewer/Resources/tile_aqua.png");
	        _basicEffect.Texture = _texture;
	        _basicEffect.TextureEnabled = true;

            _yaw = 0.5f;
            _pitch = 0.3f;
        }
コード例 #3
0
ファイル: TestCubeRenderer.cs プロジェクト: tomba/dwarrowdelf
        void LoadContent()
        {
            m_basicEffect = ToDispose(new BasicEffect(this.GraphicsDevice));

            m_basicEffect.EnableDefaultLighting(); // enable default lightning, useful for quick prototyping
            m_basicEffect.TextureEnabled = true;   // enable texture drawing

            LoadCube();
        }
コード例 #4
0
		public WarpSceneRenderer(Scene scene, int width, int height)
		{
			_scene = scene;
			_width = width;
			_height = height;
			_aspectRatio = width / (float)height;

			_device = GraphicsDevice.New(DriverType.Warp, DeviceCreationFlags.None, FeatureLevel.Level_10_1);

			var serviceProvider = new ServiceProvider();
			serviceProvider.AddService<IGraphicsDeviceService>(new GraphicsDeviceService(_device));

			_contentManager = new ContentManager(serviceProvider);
			_contentManager.Resolvers.Add(new ContentResolver());

			var viewport = new Viewport(0, 0, _width, _height);
			_device.SetViewports(viewport);

			const MSAALevel msaaLevel = MSAALevel.None;
			_depthStencilTexture = DepthStencilBuffer.New(_device, _width, _height, msaaLevel, DepthFormat.Depth24Stencil8);
			_renderTexture = RenderTarget2D.New(_device, _width, _height, msaaLevel, PixelFormat.R8G8B8A8.UNorm);

			Options = new RenderOptions();

			_effect = new BasicEffect(_device);
			_effect.EnableDefaultLighting();

			_inputLayout = VertexInputLayout.New(0, typeof(VertexPositionNormalTexture));
			_device.SetVertexInputLayout(_inputLayout);

			_meshes = new List<WarpMesh>();
			foreach (Mesh mesh in _scene.Meshes)
			{
				if (!mesh.Positions.Any())
					continue;

				var warpMesh = new WarpMesh(_device, mesh);
				_meshes.Add(warpMesh);

				warpMesh.Initialize(_contentManager);
			}
		}
コード例 #5
0
        protected override void LoadContent()
        {
            // Creates a basic effect
            basicEffect = ToDisposeContent(new BasicEffect(GraphicsDevice)
                {
                    View = Matrix.LookAtRH(new Vector3(0, 0, 5), new Vector3(0, 0, 0), Vector3.UnitY),
                    Projection = Matrix.PerspectiveFovRH((float)Math.PI / 4.0f, (float)GraphicsDevice.BackBuffer.Width / GraphicsDevice.BackBuffer.Height, 0.1f, 100.0f),
                    World = Matrix.Identity
                });

            basicEffect.PreferPerPixelLighting = true;
            basicEffect.EnableDefaultLighting();

            // Creates all primitives
            primitives = new List<GeometricPrimitive>
                             {
                                 ToDisposeContent(GeometricPrimitive.Plane.New(GraphicsDevice)),
                                 ToDisposeContent(GeometricPrimitive.Cube.New(GraphicsDevice)),
                                 ToDisposeContent(GeometricPrimitive.Sphere.New(GraphicsDevice)),
                                 ToDisposeContent(GeometricPrimitive.GeoSphere.New(GraphicsDevice)),
                                 ToDisposeContent(GeometricPrimitive.Cylinder.New(GraphicsDevice)),
                                 ToDisposeContent(GeometricPrimitive.Torus.New(GraphicsDevice)),
                                 ToDisposeContent(GeometricPrimitive.Teapot.New(GraphicsDevice))
                             };

            // Load a SpriteFont
            arial16BMFont = Content.Load<SpriteFont>("Arial16");

            // Instantiate a SpriteBatch
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Load the texture
            texture = Content.Load<Texture2D>("GeneticaMortarlessBlocks");
            basicEffect.Texture = texture;
            basicEffect.TextureEnabled = true;

            base.LoadContent();
        }
コード例 #6
0
        public void Initialize()
        {
            cube = GeometricPrimitive.Cube.New(graphicsDevice);
             var cubeBounds = new OrientedBoundingBox(new Vector3(-0.5f, -0.5f, -0.5f), new Vector3(0.5f, 0.5f, 0.5f));
             cubeMesh = new RenderMesh {
            BoundingBox = cubeBounds,
            IndexBuffer = cube.IndexBuffer,
            IsIndex32Bits = cube.IsIndex32Bits,
            InputLayout = VertexInputLayout.New<VertexPositionNormalTexture>(0),
            ModelTransform = Matrix.Identity,
            VertexBuffer = cube.VertexBuffer
             };

             basicEffect = new BasicEffect(graphicsDevice);
             basicEffect.EnableDefaultLighting(); // enable default lightning, useful for quick prototyping

             var debugEffectCompilerResult = new EffectCompiler().CompileFromFile("shaders/debug_solid.hlsl", EffectCompilerFlags.Debug);
             debugEffect = new Effect(graphicsDevice, debugEffectCompilerResult.EffectData, graphicsDevice.DefaultEffectPool);
             debugBatch = new PrimitiveBatch<VertexPositionColor>(graphicsDevice);
        }
コード例 #7
0
ファイル: HxDXApp.cs プロジェクト: kidveno/HaxeDx
        protected override void LoadContent()
        {
            // Instantiate a SpriteBatch
            spriteBatch = ToDisposeContent(new SpriteBatch(GraphicsDevice));

            // Loads the balls texture (32 textures (32x32) stored vertically => 32 x 1024 ).
            // The [Balls.dds] file is defined with the build action [ToolkitTexture] in the project
            ballsTexture = Content.Load<Texture2D>("Balls");

            // Loads a sprite font
            // The [Arial16.xml] file is defined with the build action [ToolkitFont] in the project
            arial16Font = Content.Load<SpriteFont>("Arial16");

            // Load a 3D model
            // The [Ship.fbx] file is defined with the build action [ToolkitModel] in the project
            model = Content.Load<Model>("Ship");

            // Enable default lighting on model.
            BasicEffect.EnableDefaultLighting(model, true);

            // Creates a basic effect
            basicEffect = ToDisposeContent(new BasicEffect(GraphicsDevice));
            basicEffect.PreferPerPixelLighting = true;
            basicEffect.EnableDefaultLighting();

            // Creates torus primitive
            primitive = ToDisposeContent(GeometricPrimitive.Torus.New(GraphicsDevice));

            base.LoadContent();
        }
コード例 #8
0
        protected GameObject(Project2Game game, Vector3 position, Vector3 orientation, Vector3 scale)
        {
            this.game = game;
            Children = new List<INode>();
            // Just in case...?
            WorldMatrix = Matrix.Identity;

            Scale = scale;
            Orientation = orientation;
            Position = position;

            // Setup rendering effect
            basicEffect = new BasicEffect(game.GraphicsDevice)
            {
                VertexColorEnabled = false,
                View = game.camera.view,
                Projection = game.camera.projection,
                World = Matrix.Identity,
                LightingEnabled = true
            };
            basicEffect.EnableDefaultLighting();
            basicEffect.SpecularPower = 5000f;
        }
コード例 #9
0
ファイル: Landscape.cs プロジェクト: kcostarella/Landscape
        public Landscape(Game game)
        {
            Terrain = new HeightMap(10);

            terrain3D = new VertexPositionNormalColor[Terrain.max * Terrain.max * 6  + 12];
            int index = 0;
            for (int z = 0; z < Terrain.max; z++)
            {
                for (int x = 0; x < Terrain.max; x++)
                {
                    // Front left.
                    terrain3D[index] = new VertexPositionNormalColor(new Vector3(x, Terrain.get(x,z), z), Terrain.getVertexNormal(x,z) , Terrain.getColor(x,z));
                    index++;
                    // Back left.
                    terrain3D[index] = new VertexPositionNormalColor(new Vector3(x, Terrain.get(x, z + 1), z + 1), Terrain.getVertexNormal(x, z + 1), Terrain.getColor(x, z+1));
                    index++;

                    // Back right.
                    terrain3D[index] = new VertexPositionNormalColor(new Vector3(x + 1, Terrain.get(x + 1, z + 1), z + 1), Terrain.getVertexNormal(x + 1, z + 1), Terrain.getColor(x+1, z+1));
                    index++;

                    // Front left.
                    terrain3D[index] = new VertexPositionNormalColor(new Vector3(x, Terrain.get(x, z), z), Terrain.getVertexNormal(x, z), Terrain.getColor(x, z));
                    index++;

                    // Back right.
                    terrain3D[index] = new VertexPositionNormalColor(new Vector3(x + 1, Terrain.get(x + 1, z + 1), z + 1), Terrain.getVertexNormal(x + 1, z + 1), Terrain.getColor(x+1, z+1));
                    index++;

                    // Front right.
                    terrain3D[index] = new VertexPositionNormalColor(new Vector3(x + 1, Terrain.get(x + 1, z), z), Terrain.getVertexNormal(x + 1, z), Terrain.getColor(x+1, z));
                    index++;
                }
            }

            Color blue = Color.MidnightBlue;
            blue.A = 0xC0;

            waterHeight = 0.695f * Terrain.maxHeight;

            //Set Water Polygons
            // Front left.
            terrain3D[index] = new VertexPositionNormalColor(new Vector3(0.0f, waterHeight, 0.0f), new Vector3(0.0f, 1.0f, 0.0f), blue);
            index++;

            // Back left.
            terrain3D[index] = new VertexPositionNormalColor(new Vector3(0.0f, waterHeight, Terrain.max), new Vector3(0.0f, 1.0f, 0.0f), blue);
            index++;

            // Back right.
            terrain3D[index] = new VertexPositionNormalColor(new Vector3(Terrain.max, waterHeight, Terrain.max), new Vector3(0.0f, 1.0f, 0.0f), blue);
            index++;

            // Front left.
            terrain3D[index] = new VertexPositionNormalColor(new Vector3(0.0f, waterHeight, 0.0f), new Vector3(0.0f, 1.0f, 0.0f), blue);
            index++;

            // Back right.
            terrain3D[index] = new VertexPositionNormalColor(new Vector3(Terrain.max, waterHeight, Terrain.max), new Vector3(0.0f, 1.0f, 0.0f), blue);
            index++;

            // Front right.
            terrain3D[index] = new VertexPositionNormalColor(new Vector3(Terrain.max, waterHeight, 0.0f), new Vector3(0.0f, 1.0f, 0.0f), blue);
            index++;

            //water from the bottom
            // Front left.
            terrain3D[index] = new VertexPositionNormalColor(new Vector3(0.0f, waterHeight, 0.0f), new Vector3(0.0f, 1.0f, 0.0f), blue);
            index++;

            // Back right.
            terrain3D[index] = new VertexPositionNormalColor(new Vector3(Terrain.max, waterHeight, Terrain.max), new Vector3(0.0f, 1.0f, 0.0f), blue);
            index++;

            // Back left.
            terrain3D[index] = new VertexPositionNormalColor(new Vector3(0.0f, waterHeight, Terrain.max), new Vector3(0.0f, 1.0f, 0.0f), blue);
            index++;

            // Front left.
            terrain3D[index] = new VertexPositionNormalColor(new Vector3(0.0f, waterHeight, 0.0f), new Vector3(0.0f, 1.0f, 0.0f), blue);
            index++;

            // Front right.
            terrain3D[index] = new VertexPositionNormalColor(new Vector3(Terrain.max, waterHeight, 0.0f), new Vector3(0.0f, 1.0f, 0.0f), blue);
            index++;

            // Back right.
            terrain3D[index] = new VertexPositionNormalColor(new Vector3(Terrain.max, waterHeight, Terrain.max), new Vector3(0.0f, 1.0f, 0.0f), blue);
            index++;

            //initialized here because I wanted the terrain details to place the initial position/target.
            currentPosition = new Vector3(0.0f, Terrain.maxHeight, 0.0f); //start on corner of map at highest point of terrain
            currentTarget = new Vector3(Terrain.max, Terrain.maxHeight, Terrain.max); //looking across to other corner (same height)
            currentUp = Vector3.UnitY;
            prevMouseX = 0.5f;
            prevMouseY = 0.5f;

            vertices = Buffer.Vertex.New(game.GraphicsDevice, terrain3D);

            basicEffect = new BasicEffect(game.GraphicsDevice)
            {
                VertexColorEnabled = true,
                View = Matrix.LookAtLH(currentPosition, currentTarget, currentUp),
                Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, (float)game.GraphicsDevice.BackBuffer.Width / game.GraphicsDevice.BackBuffer.Height, -10.0f, (float)Terrain.size * 2),
                World = Matrix.Identity,
                LightingEnabled = true
            };

            inputLayout = VertexInputLayout.FromBuffer(0, vertices);
            basicEffect.EnableDefaultLighting();

            basicEffect.AmbientLightColor = new Vector3(.1f * 255/255, .1f * 244/255, .1f * 229/255);

            this.game = game;
        }
コード例 #10
0
        protected override void LoadContent()
        {
            base.LoadContent();

            _basicEffect = ToDisposeContent(new BasicEffect(GraphicsDevice));

            _basicEffect.EnableDefaultLighting();
            _basicEffect.SpecularPower = 64;
            var desc = _basicEffect.Sampler.Description;
            desc.Filter = Filter.ComparisonMinMagMipPoint;
            desc.MaximumAnisotropy = 8;
            desc.AddressU = TextureAddressMode.Wrap;
            desc.AddressV = TextureAddressMode.Wrap;
            desc.AddressW = TextureAddressMode.Wrap;
            desc.MaximumLod = float.MaxValue;
            desc.MinimumLod = 0;
            _basicEffect.Sampler = SamplerState.New(GraphicsDevice, desc);

            _manTexture = Content.Load<Texture2D>("textures/mobs/man");
            _man = ToDisposeContent(MeshGenerator.CreateTextureMesh(_manTexture));
            _manTransform = Matrix.Scaling(.6f, 1.6f, .05f)*Matrix.Translation(-.4f, 1.4f, 1);

            _bookshelfTexture = Content.Load<Texture2D>("textures/walls/decorations/bookshelf");
            _bookshelf = ToDisposeContent(MeshGenerator.CreateTextureMesh(_bookshelfTexture));
            _bookshelfTransform = Matrix.Scaling(1.54f, 1f, .5f) * Matrix.Translation(-3.9f, 1f, -5f);

            _windowTexture = Content.Load<Texture2D>("textures/walls/decorations/window outside");
            _window = ToDisposeContent(MeshGenerator.CreateTextureMesh(_windowTexture));
            _windowTransform = Matrix.Scaling(1.5f, 1.5f, .03f) * Matrix.Translation(3f, 1.75f, -5f);

            _curtainTexture = Content.Load<Texture2D>("textures/walls/decorations/red curtain open");
            _curtain = ToDisposeContent(MeshGenerator.CreateTextureMesh(_curtainTexture));
            _curtainTransform = Matrix.Scaling(1.5f, 1.5f, .1f) * Matrix.Translation(3.1f, 1.75f, -5f);

            _curtain2Texture = Content.Load<Texture2D>("textures/walls/decorations/red curtain open inverse");
            _curtain2 = ToDisposeContent(MeshGenerator.CreateTextureMesh(_curtain2Texture));
            _curtain2Transform = Matrix.Scaling(1.5f, 1.5f, .1f) * Matrix.Translation(2.9f, 1.75f, -5f);

            _borderTexture = Content.Load<Texture2D>("textures/floors/moss border");
            _border = ToDisposeContent(MeshGenerator.CreateTextureMesh(_borderTexture));
            _borderTransform = Matrix.RotationX(-MathUtil.PiOverTwo)*Matrix.Scaling(10, 0.1f, 10) * Matrix.Translation(-5, 0, -5);

            _plane = ToDisposeContent(GeometricPrimitive.Plane.New(GraphicsDevice, 10, 10, 1, new Vector2(2)));
            _planeTexture = Content.Load<Texture2D>("textures/floors/floorboards 1 large dds");
            _planeTransform = Matrix.RotationX(-MathUtil.PiOverTwo)*Matrix.Translation(0, 0, 0);

            _carpetTexture = Content.Load<Texture2D>("textures/floors/carpets/carpet brown");
            _carpet = ToDisposeContent(MeshGenerator.CreateTextureMesh(_carpetTexture));
            _carpetTransform = Matrix.Scaling(4f, 2f, .05f) * Matrix.RotationX(-MathUtil.PiOverTwo) * Matrix.Translation(-2, 0f, 0);

            _pumpkinTexture = Content.Load<Texture2D>("textures/misc/pumkin");
            _pumpkin = ToDisposeContent(MeshGenerator.CreateTextureMesh(_pumpkinTexture));
            _pumpkinTransform = Matrix.Scaling(1f, 1f, .5f) * Matrix.Translation(3, 0.9f, -2);

            _wall = ToDisposeContent(GeometricPrimitive.Plane.New(GraphicsDevice, 10, 2, 1, new Vector2(4, 1f)));
            _wallTexture = Content.Load<Texture2D>("textures/walls/wall testure warped");
            _wallTransform1 = Matrix.Translation(0, 1, -5);
            _wallTransform2 = _wallTransform1*Matrix.RotationY(-MathUtil.PiOverTwo);
            _wallTransform3 = _wallTransform2*Matrix.RotationY(-MathUtil.PiOverTwo);
            _wallTransform4 = _wallTransform3*Matrix.RotationY(-MathUtil.PiOverTwo);

            _doorTexture = Content.Load<Texture2D>("textures/walls/doors/door");
            _door = ToDisposeContent(MeshGenerator.CreateTextureMesh(_doorTexture));
            _doorTransform1 = Matrix.Scaling(1f, 1.8f, .1f)*Matrix.Translation(-0.46f, 1.8f, -5)*
                             Matrix.RotationY(-MathUtil.PiOverTwo);
            _doorTransform2 = _doorTransform1*Matrix.RotationY(-MathUtil.PiOverTwo);
            _doorTransform3 = _doorTransform2 * Matrix.RotationY(-MathUtil.PiOverTwo);
            _doorTransform4 = _doorTransform3 * Matrix.RotationY(-MathUtil.PiOverTwo);

            var blendStateDesc = new BlendStateDescription
            {
                AlphaToCoverageEnable = true,
                IndependentBlendEnable = false
            };
            blendStateDesc.RenderTarget[0].IsBlendEnabled = true;
            blendStateDesc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
            blendStateDesc.RenderTarget[0].SourceBlend = BlendOption.SourceAlpha;
            blendStateDesc.RenderTarget[0].DestinationBlend = BlendOption.InverseSourceAlpha;
            blendStateDesc.RenderTarget[0].BlendOperation = BlendOperation.Add;
            blendStateDesc.RenderTarget[0].SourceAlphaBlend = BlendOption.SourceAlpha;
            blendStateDesc.RenderTarget[0].DestinationAlphaBlend = BlendOption.DestinationAlpha;
            blendStateDesc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add;
            blendStateDesc.RenderTarget[0].SourceBlend = BlendOption.One;
            _blend = BlendState.New(GraphicsDevice, blendStateDesc);
        }
コード例 #11
0
        /// <summary>
        /// Load all graphics content here.
        /// </summary>
        protected override void LoadContent()
        {
            base.LoadContent();

            // initialize the basic effect (shader) to draw the geometry, the BasicEffect class is similar to one from XNA
            _basicEffect = ToDisposeContent(new BasicEffect(GraphicsDevice));

            _basicEffect.EnableDefaultLighting(); // enable default lightning, useful for quick prototyping
            _basicEffect.TextureEnabled = true;   // enable texture drawing

            LoadCube();

            LoadPlane();
        }