public override void Intro( params object [] args ) { Core.GraphicsDevice.ImmediateContext.CullMode = CullMode.ClockWise; contentManager = new ResourceTable ( FileSystemManager.GetFileSystem ( "ManifestFileSystem" ) ); contentManager.AddDefaultContentLoader (); texture1 = contentManager.Load<ITexture2D> ( "Resources/Terrain/terrain_02.png" ); texture2 = contentManager.Load<ITexture2D> ( "Resources/Terrain/terrain_01.png" ); Color [] colours = texture2.Buffer; effect = contentManager.Load<IEffect> ( "Resources/Terrain/TerrainShader.xml" ); textureArgs = new SamplerState ( texture1, TextureFilter.Anisotropic, TextureAddressing.Clamp, Core.GraphicsDevice.Information.MaximumAnisotropicLevel ); vertexBuffer = Core.GraphicsDevice.CreateBuffer ( BufferType.VertexBuffer, typeof ( TerrainVertex ), texture2.Width * texture2.Height ); vertexDeclaration = Core.GraphicsDevice.CreateVertexDeclaration ( Utilities.CreateVertexElementArray<TerrainVertex> () ); numOfIndices = ( texture2.Width - 1 ) * ( texture2.Height - 1 ) * 2; indexBuffer = Core.GraphicsDevice.CreateBuffer ( BufferType.IndexBuffer, typeof ( TerrainIndex ), numOfIndices ); TerrainVertex [] vertices = new TerrainVertex [ texture2.Width * texture2.Height ]; int index = 0; for ( int x = 0; x < texture2.Height; x++ ) { for ( int z = 0; z < texture2.Width; z++ ) { int location = x * texture2.Width + z; vertices [ index ] = new TerrainVertex () { Position = new Vector3 ( ( x - texture2.Height / 2 ) * 5.0f, colours [ location ].RedValue * 5.0f / 3, ( z - texture2.Width / 2 ) * 5.0f ), UV = new Vector2 ( z / ( float ) texture2.Width, x / ( float ) texture2.Height ) }; ++index; } } vertexBuffer.SetBufferDatas<TerrainVertex> ( vertices ); TerrainIndex [] indices = new TerrainIndex [ numOfIndices ]; index = 0; for ( int z = 0; z < texture2.Height - 1; z++ ) { for ( int x = 0; x < texture2.Width - 1; x++ ) { indices [ index ]._0 = z * texture2.Width + x; indices [ index ]._1 = z * texture2.Width + ( x + 1 ); indices [ index ]._2 = ( z + 1 ) * texture2.Width + x; ++index; indices [ index ]._0 = ( z + 1 ) * texture2.Width + x; indices [ index ]._1 = z * texture2.Width + ( x + 1 ); indices [ index ]._2 = ( z + 1 ) * texture2.Width + ( x + 1 ); ++index; } } indexBuffer.SetBufferDatas<TerrainIndex> ( indices ); proj = new PerspectiveFieldOfViewProjection ( 3.141592f / 4, 4 / 3f, 1, 10000 ); look = new LookAt ( new Vector3 ( 1000, 2000, 1000 ), new Vector3 ( 0, 0, 0 ), new Vector3 ( 0, 1, 0 ) ); world = new World3 (); sprite = new Sprite ( null ); spriteWorld = new World2 (); Add ( new FpsCalculator () ); base.Intro ( args ); }
public override void Intro( params object [] args ) { IFileSystem fileSystem = FileSystemManager.GetFileSystem ( "ManifestFileSystem" ); contentManager = new ContentManager ( fileSystem ); contentManager.AddDefaultContentLoader (); ImageInfo imageInfo = new PngDecoder ().Decode ( fileSystem.OpenFile ( "Test.Game.Terrain.Resources.terrain_01.png" ) ); Color [] decoded = imageInfo.GetPixel ( null ); terrainVertex = LiqueurSystem.GraphicsDevice.CreateVertexBuffer<TerrainVertex> ( FlexibleVertexFormat.PositionXYZ | FlexibleVertexFormat.Diffuse | FlexibleVertexFormat.TextureUV1, imageInfo.Width * imageInfo.Height ); TerrainVertex [] tempVertices = new TerrainVertex [ terrainVertex.Length ]; int index = 0; for ( int x = 0; x < imageInfo.Height; x++ ) { for ( int z = 0; z < imageInfo.Width; z++ ) { int location = x * imageInfo.Width + z; tempVertices [ index ] = new TerrainVertex ( ( x - imageInfo.Width / 2 ) * 5.0f, ( decoded [ location ].AlphaValue ) * 5.0f / 2, ( z - imageInfo.Width / 2 ) * 5.0f, z / ( float ) imageInfo.Width, x / ( float ) imageInfo.Height ); ++index; } } terrainVertex.Vertices = tempVertices; terrainIndex = LiqueurSystem.GraphicsDevice.CreateIndexBuffer ( imageInfo.Width * imageInfo.Height * 2 * 3 ); int [] tempIndices = new int [ terrainIndex.Length ]; index = 0; for ( int z = 0; z < imageInfo.Height - 1; z++ ) { for ( int x = 0; x < imageInfo.Width - 1; x++ ) { tempIndices [ index++ ] = z * imageInfo.Width + x; tempIndices [ index++ ] = z * imageInfo.Width + ( x + 1 ); tempIndices [ index++ ] = ( z + 1 ) * imageInfo.Width + x; tempIndices [ index++ ] = ( z + 1 ) * imageInfo.Width + x; tempIndices [ index++ ] = z * imageInfo.Width + ( x + 1 ); tempIndices [ index++ ] = ( z + 1 ) * imageInfo.Width + ( x + 1 ); } } terrainIndex.Indices = tempIndices; terrainEffect = new SpriteEffect (); texture = contentManager.Load<ITexture2D> ( "Test.Game.Terrain.Resources.terrain_02.png" ); LiqueurSystem.GraphicsDevice.CullingMode = CullingMode.None; LiqueurSystem.GraphicsDevice.IsZWriteEnable = true; LiqueurSystem.GraphicsDevice.BlendState = true; LiqueurSystem.GraphicsDevice.BlendOperation = BlendOperation.AlphaBlend; base.Intro ( args ); }