public override bool Init() { if (!base.Init()) { return(false); } Effects.InitAll(Device); InputLayouts.InitAll(Device); RenderStates.InitAll(Device); _texMgr = new TextureManager(); _texMgr.Init(Device); _gridModel = new BasicModel(); _gridModel.CreateGrid(Device, 20, 20, 40, 40); _gridModel.Materials[0] = new Material { Diffuse = Color.SaddleBrown, Specular = new Color4(16, .9f, .9f, .9f) }; _gridModel.DiffuseMapSRV[0] = _texMgr.CreateTexture("Textures/floor.dds"); _gridModel.NormalMapSRV[0] = _texMgr.CreateTexture("textures/floor_nmap.dds"); _sphereModel = new BasicModel(); _sphereModel.CreateSphere(Device, 0.3f, 5, 4); _sphereModel.Materials[0] = new Material { Ambient = Color.Blue, Diffuse = Color.Blue, Specular = new Color4(64.0f, 1.0f, 1.0f, 1.0f) }; _sphereModel.NormalMapSRV[0] = _texMgr.CreateTexture("Textures/stones_nmap.dds"); _cylinderModel = new BasicModel(); _cylinderModel.CreateCylinder(Device, 1, 1, 3, 20, 20); _cylinderModel.Materials[0] = new Material { Ambient = Color.Green, Diffuse = Color.Green, Specular = new Color4(64.0f, 1.0f, 1.0f, 1.0f) }; _cylinderModel.NormalMapSRV[0] = _texMgr.CreateTexture("Textures/stones_nmap.dds"); _grid = new BasicModelInstance(_gridModel) { TexTransform = Matrix.Scaling(10, 10, 1), World = Matrix.Scaling(10, 1, 10) * Matrix.Translation(0, 0, 90) }; _sphere = new BasicModelInstance(_sphereModel); _cylinder = new BasicModelInstance(_cylinderModel) { World = Matrix.Translation(0, 1.5f, 0) }; return(true); }
public override bool Init() { if (!base.Init()) { return(false); } Effects.InitAll(Device); InputLayouts.InitAll(Device); RenderStates.InitAll(Device); _sky = new Sky(Device, "Textures/grasscube1024.dds", 5000.0f); _texMgr = new TextureManager(); _texMgr.Init(Device); _gridModel = new BasicModel(); _gridModel.CreateGrid(Device, 20, 20, 40, 40); _gridModel.Materials[0] = new Material { Diffuse = Color.LightGray, Specular = new Color4(16, .9f, .9f, .9f) }; _gridModel.DiffuseMapSRV[0] = _texMgr.CreateTexture("Textures/floor.dds"); _gridModel.NormalMapSRV[0] = _texMgr.CreateTexture("textures/floor_nmap.dds"); _grid = new BasicModelInstance(_gridModel) { TexTransform = Matrix.Scaling(10, 10, 1), World = Matrix.Scaling(10, 1, 10) }; InitFireworksRules(); _cylinderModel = new BasicModel(); _cylinderModel.CreateCylinder(Device, 1, 1, 3, 20, 20); _cylinderModel.Materials[0] = new Material { Ambient = Color.Green, Diffuse = Color.Green, Specular = new Color4(64.0f, 1.0f, 1.0f, 1.0f) }; _cylinderModel.DiffuseMapSRV[0] = _texMgr.CreateTexture("Textures/stones.dds"); _cylinderModel.NormalMapSRV[0] = _texMgr.CreateTexture("Textures/stones_nmap.dds"); _cylinder = new BasicModelInstance(_cylinderModel) { World = Matrix.Translation(0, 1.5f, 0) }; return(true); }
// Use this for initialization void Start() { textureManager = new TextureManager(256); textureManager.CreateTexture("hearts"); textureManager.CreateTexture("diamond"); textureManager.CreateTexture("clubs"); textureManager.CreateTexture("spades"); textureManager.CreateRoundedRectangle("base"); textureManager.CreateRoundedRectangle("back"); textureManager.PackTextures(); SpriteMeshType spriteMeshType = SpriteMeshType.FullRect; Sprite sprite = Sprite.Create(textureManager.PackedTexture, textureManager.GetTextureRectByName("back"), new Vector2(0.5f, 0.5f), 1, 0, spriteMeshType); //Sprite sprite= Sprite.Create(textureManager.TilingTexture,new Rect(0,0,textureManager.TilingTexture.width,textureManager.TilingTexture.height),new Vector2(0.5f,0.5f),1,0,spriteMeshType); //Sprite sprite= Sprite.Create(textureManager.PackedTexture,new Rect(0,0,textureManager.PackedTexture.width,textureManager.PackedTexture.height),new Vector2(0.5f,0.5f),1); //Sprite sprite= Sprite.Create(textureManager.PackedTexture,textureManager.GetTextureRectByName("clubs"),new Vector2(0.5f,0.5f),1); spriteRenderer.sprite = sprite; spriteRenderer.size = new Vector2(183, 256); CreateCard(Random.Range(1, 53)); //CreateCard(10); }
public static FontDrawInfo DrawText(int fontID, int size, string text) { if (fontID < 0 || fontID >= TypefaceCache.Count) { return(null); } if (size < MiniumFontSize) { size = MiniumFontSize; } Tuple <int, int, string> infoId = new Tuple <int, int, string>(fontID, size, text); if (!StringCache.ContainsKey(infoId)) { FontDrawInfo info = new FontDrawInfo(); info.FontID = fontID; info.FontSize = size; info.Text = text; Bitmap stringMap = GetTextBitmap(info); info.CachedTexture = TextureManager.CreateTexture("FONTMAN:" + fontID.ToString() + ":" + size.ToString() + ":" + text, stringMap, TextureInfo.TextureFormats.Text); info.Size = new Vector2(stringMap.Width, stringMap.Height); info.CachedTexture.Tag = info; info.CachedTexture.CacheImageData = false; info.CachedTexture.GenerateImageData = RemakeTextureData; StringCache.Add(infoId, info); return(info); } return(StringCache[infoId]); }
private void BuildShapeGeometryBuffers() { _texMgr = new TextureManager(); _texMgr.Init(Device); _boxModel = new BasicModel(); _boxModel.CreateBox(Device, 1, 1, 1); _boxModel.Materials[0] = new Material { Ambient = Color.White, Diffuse = Color.White, Specular = new Color4(16.0f, 0.8f, 0.8f, 0.8f), Reflect = Color.Black }; _boxModel.DiffuseMapSRV[0] = _texMgr.CreateTexture("Textures/bricks.dds"); _boxModel.NormalMapSRV[0] = _texMgr.CreateTexture("Textures/bricks_nmap.dds"); _gridModel = new BasicModel(); _gridModel.CreateGrid(Device, 20, 30, 40, 60); _gridModel.Materials[0] = new Material { Ambient = new Color4(0.8f, 0.8f, 0.8f), Diffuse = new Color4(0.8f, 0.8f, 0.8f), Specular = new Color4(16.0f, 0.8f, 0.8f, 0.8f), Reflect = Color.Black }; _gridModel.DiffuseMapSRV[0] = _texMgr.CreateTexture("Textures/floor.dds"); _gridModel.NormalMapSRV[0] = _texMgr.CreateTexture("Textures/floor_nmap.dds"); _sphereModel = new BasicModel(); _sphereModel.CreateSphere(Device, 0.5f, 20, 20); _sphereModel.Materials[0] = new Material { Ambient = new Color4(0.6f, 0.8f, 0.9f), Diffuse = new Color4(0.6f, 0.8f, 0.9f), Specular = new Color4(16.0f, 0.9f, 0.9f, 0.9f), Reflect = new Color4(0.4f, 0.4f, 0.4f) }; _cylinderModel = new BasicModel(); _cylinderModel.CreateCylinder(Device, 0.5f, 0.3f, 3.0f, 20, 20); _cylinderModel.Materials[0] = new Material { Ambient = Color.White, Diffuse = Color.White, Specular = new Color4(16.0f, 0.8f, 0.8f, 0.8f), Reflect = Color.Black }; _cylinderModel.DiffuseMapSRV[0] = _texMgr.CreateTexture("Textures/bricks.dds"); _cylinderModel.NormalMapSRV[0] = _texMgr.CreateTexture("Textures/bricks_nmap.dds"); for (var i = 0; i < 5; i++) { _cylinders[i * 2] = new BasicModelInstance(_cylinderModel) { World = Matrix.Translation(-5.0f, 1.5f, -10.0f + i * 5.0f), TexTransform = Matrix.Scaling(1, 2, 1) }; _cylinders[i * 2 + 1] = new BasicModelInstance(_cylinderModel) { World = Matrix.Translation(5.0f, 1.5f, -10.0f + i * 5.0f), TexTransform = Matrix.Scaling(1, 2, 1) }; _spheres[i * 2] = new BasicModelInstance(_sphereModel) { World = Matrix.Translation(-5.0f, 3.5f, -10.0f + i * 5.0f) }; _spheres[i * 2 + 1] = new BasicModelInstance(_sphereModel) { World = Matrix.Translation(5.0f, 3.5f, -10.0f + i * 5.0f) }; } _grid = new BasicModelInstance(_gridModel) { TexTransform = Matrix.Scaling(8, 10, 1), World = Matrix.Identity }; _box = new BasicModelInstance(_boxModel) { TexTransform = Matrix.Scaling(2, 1, 1), World = Matrix.Scaling(3.0f, 1.0f, 3.0f) * Matrix.Translation(0, 0.5f, 0) }; }
public override bool Init() { if (!base.Init()) { return(false); } Effects.InitAll(Device); InputLayouts.InitAll(Device); RenderStates.InitAll(Device); _texMgr = new TextureManager(); _texMgr.Init(Device); _drone = new SkinnedModel(Device, _texMgr, "Models/drone.x", "Textures", true); _droneInstance = new SkinnedModelInstance( "Attack", Matrix.RotationY(MathF.PI), _drone ); foreach (var clip in _droneInstance.Clips) { _droneInstance.AddClip(clip); } _droneInstance.LoopClips = true; _mage = new SkinnedModel(Device, _texMgr, "Models/magician.x", "textures", true); _mageInstance = new SkinnedModelInstance( "Attack", Matrix.RotationY(MathF.PI) * Matrix.Translation(4.0f, 0, 0), _mage ); foreach (var clip in _mageInstance.Clips) { _mageInstance.AddClip(clip); } _mageInstance.LoopClips = true; _soldier = new SkinnedModel(Device, _texMgr, "Models/soldier.x", "Textures", true); _soldierInstance = new SkinnedModelInstance( "Attack", Matrix.RotationY(MathF.PI) * Matrix.Translation(10, 0, 0), _soldier ); foreach (var clip in _soldierInstance.Clips) { _soldierInstance.AddClip(clip); } _soldierInstance.LoopClips = true; _grid = new BasicModel(); _grid.CreateGrid(Device, 30, 30, 60, 60); _grid.DiffuseMapSRV[0] = (_texMgr.CreateTexture("Textures/floor.dds")); _grid.NormalMapSRV[0] = (_texMgr.CreateTexture("Textures/floor_nmap.dds")); _gridInstance = new BasicModelInstance(_grid) { World = Matrix.Translation(0, -1.5f, 0) }; return(true); }
public override void DrawScene() { ImmediateContext.Rasterizer.State = null; ImmediateContext.ClearDepthStencilView( DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0 ); ImmediateContext.Rasterizer.SetViewports(Viewport); _ssao.SetNormalDepthRenderTarget(DepthStencilView); DrawSceneToSsaoNormalDepthMap(); _ssao.ComputeSsao(_camera); _ssao.BlurAmbientMap(4); ImmediateContext.OutputMerger.SetTargets(DepthStencilView, RenderTargetView); ImmediateContext.Rasterizer.SetViewports(Viewport); ImmediateContext.ClearRenderTargetView(RenderTargetView, Color.Silver); ImmediateContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); var viewProj = _camera.ViewProj; var view = _camera.View; var proj = _camera.Proj; Effects.BasicFX.SetDirLights(_dirLights); Effects.BasicFX.SetEyePosW(_camera.Position); //Effects.BasicFX.SetCubeMap(_sky.CubeMapSRV); Effects.NormalMapFX.SetDirLights(_dirLights); Effects.NormalMapFX.SetEyePosW(_camera.Position); //Effects.NormalMapFX.SetCubeMap(_sky.CubeMapSRV); if (!Util.IsKeyDown(Keys.S)) { Effects.BasicFX.SetSsaoMap(_ssao.AmbientSRV); Effects.NormalMapFX.SetSsaoMap(_ssao.AmbientSRV); } else { Effects.BasicFX.SetSsaoMap(_texMgr.CreateTexture("Textures/white.dds")); Effects.NormalMapFX.SetSsaoMap(_texMgr.CreateTexture("Textures/white.dds")); } var toTexSpace = Matrix.Scaling(0.5f, -0.5f, 1.0f) * Matrix.Translation(0.5f, 0.5f, 0); var activeTech = Effects.NormalMapFX.Light3Tech; var activeSphereTech = Effects.BasicFX.Light3ReflectTech; var activeSkullTech = Effects.BasicFX.Light3ReflectTech; ImmediateContext.InputAssembler.InputLayout = InputLayouts.PosNormalTexTan; ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; if (Util.IsKeyDown(Keys.W)) { ImmediateContext.Rasterizer.State = RenderStates.WireframeRS; } for (var p = 0; p < activeTech.Description.PassCount; p++) { // draw grid var pass = activeTech.GetPassByIndex(p); _grid.ToTexSpace = toTexSpace; _grid.Draw(ImmediateContext, pass, view, proj); // draw box _box.ToTexSpace = toTexSpace; _box.Draw(ImmediateContext, pass, view, proj); // draw columns foreach (var cylinder in _cylinders) { cylinder.ToTexSpace = toTexSpace; cylinder.Draw(ImmediateContext, pass, view, proj); } } ImmediateContext.HullShader.Set(null); ImmediateContext.DomainShader.Set(null); ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; for (var p = 0; p < activeSphereTech.Description.PassCount; p++) { var pass = activeSphereTech.GetPassByIndex(p); foreach (var sphere in _spheres) { sphere.ToTexSpace = toTexSpace; sphere.Draw(ImmediateContext, pass, view, proj, RenderMode.Basic); } } ImmediateContext.Rasterizer.State = null; ImmediateContext.InputAssembler.InputLayout = InputLayouts.Basic32; for (var p = 0; p < activeSkullTech.Description.PassCount; p++) { _skull.ToTexSpace = toTexSpace; _skull.Draw(ImmediateContext, activeSkullTech.GetPassByIndex(p), view, proj, RenderMode.Basic); } ImmediateContext.OutputMerger.DepthStencilState = null; ImmediateContext.OutputMerger.DepthStencilReference = 0; DrawScreenQuad(_ssao.AmbientSRV); DrawScreenQuad2(_ssao.NormalDepthSRV); _sky.Draw(ImmediateContext, _camera); ImmediateContext.Rasterizer.State = null; ImmediateContext.OutputMerger.DepthStencilState = null; ImmediateContext.OutputMerger.DepthStencilReference = 0; var srvs = new List <ShaderResourceView>(); for (var i = 0; i < 16; i++) { srvs.Add(null); } ImmediateContext.PixelShader.SetShaderResources(srvs.ToArray(), 0, 16); SwapChain.Present(0, PresentFlags.None); }
public override bool Init() { if (!base.Init()) { return(false); } Effects.InitAll(Device); InputLayouts.InitAll(Device); RenderStates.InitAll(Device); _texMgr = new TextureManager(); _texMgr.Init(Device); _treeModel = new BasicModel(Device, _texMgr, "Models/tree.x", "Textures"); _modelInstance = new BasicModelInstance(_treeModel) { World = Matrix.RotationX(MathF.PI / 2) }; _stoneModel = new BasicModel(Device, _texMgr, "Models/stone.x", "Textures"); _stoneInstance = new BasicModelInstance(_stoneModel) { World = Matrix.Scaling(0.1f, 0.1f, 0.1f) * Matrix.Translation(2, 0, 2) }; _dwarfModel = new BasicModel(Device, _texMgr, "Models/Bob.md5mesh", "Textures", true); for (int i = 0; i < _dwarfModel.Materials.Count; i++) { _dwarfModel.Materials[i] = new Material() { Ambient = Color.DarkGray, Diffuse = Color.White, Specular = new Color4(128, 1f, 1.0f, 1.0f) }; } _dwarfInstance = new BasicModelInstance(_dwarfModel) { World = Matrix.RotationX(-MathF.PI / 2) * Matrix.Scaling(0.05f, 0.05f, 0.05f) * Matrix.Translation(4, 0, 4) }; _towerModel = new BasicModel(Device, _texMgr, "Models/Final Eiffel Tower.STL", "Textures"); _towerModel.DiffuseMapSRV.Add(_texMgr.CreateTexture("Textures/white.png")); _towerModel.NormalMapSRV.Add(_texMgr.CreateTexture("Textures/white_nmap.png")); _towerModel.Materials[0] = new Material() { Ambient = Color.DarkGray, Diffuse = Color.White, Specular = new Color4(128, 1f, 1.0f, 1.0f) }; _towerInstance = new BasicModelInstance(_towerModel) { World = Matrix.Scaling(0.01f, 0.01f, 0.01f) * Matrix.Translation(6, 0, 6) }; return(true); }
public static bool LoadTextures() { if (GameGraphics == null) GameGraphics = new GameImage(512, 346, 4000); sbyte[] _textureData = UnpackData("textures.jag", "Textures", 50); if (_textureData == null) { return false; } var baseInventoryPic = 2000; var baseScrollPic = baseInventoryPic + 100; var baseItemPicture = baseScrollPic + 50; var baseLoginScreenBackgroundPic = baseItemPicture + 1000; var baseProjectilePic = baseLoginScreenBackgroundPic + 10; var baseTexturePic = baseProjectilePic + 50; var subTexturePic = baseTexturePic + 10; sbyte[] indexData = DataOperations.loadData("index.dat", 0, _textureData); //gameCamera.CreateTexture(Data.textureCount, 7, 11); for (int l = 0; l < Data.textureCount; l++) { String s1 = Data.textureName[l]; sbyte[] textureData = DataOperations.loadData(s1 + ".dat", 0, _textureData); var texture = TextureManager.CreateTexture(baseTexturePic + l, textureData, indexData, 1); if (l == 8 || l == 16 || l == 33 || l == 34) { // Rotate clockwise.. if (texture != null && texture.Length == 1) { // var t = texture[0]; // TextureBaker baker = new TextureBaker(Game1.DeviceInstance, new Vector2(t.Height, t.Width)); // baker.BakeTexture(t, RotateFlipType.Rotate90FlipNone); // texture[0] = baker.GetTexture(); texture[0] = TextureManager.Rotate(texture[0], RotateFlipType.Rotate270FlipNone); texture[0] = TextureManager.Rotate(texture[0], RotateFlipType.Rotate180FlipNone); } } String s2 = Data.textureSubName[l]; if (string.IsNullOrEmpty(s2)) { if (texture != null && texture.Length > 0) { for (var j = 0; j < texture.Length; j++) { //var bakerman = new TextureBaker(Game1.DeviceInstance, new Vector2(texture[j].Height, texture[j].Width)); //bakerman.BakeTexture(texture[j], RotateFlipType.Rotate270FlipNone); //texture[j] = bakerman.GetTexture(); /* using (var stream = System.IO.File.Create("c:/jpg/" + (subTexturePic + l) + ".png")) { texture[j].SaveAsPng(stream, texture[j].Width, texture[j].Height); } */ texture[j] = TextureManager.Rotate(texture[j], RotateFlipType.Rotate270FlipNone); texture[j] = TextureManager.Rotate(texture[j], RotateFlipType.Rotate180FlipNone); TextureManager.Textures.Add(new TextureData((subTexturePic + l/*textureIndex*/), texture[j])); } } } if (!string.IsNullOrEmpty(s2)) { Texture2D backTexture = null; if (texture != null && texture.Any()) { backTexture = texture[0]; } sbyte[] subTextureData = DataOperations.loadData(s2 + ".dat", 0, _textureData); var subTexture = TextureManager.CreateTexture(baseTexturePic, subTextureData, indexData, 1, backTexture /*null*/); if (subTexture != null && subTexture.Length > 0) { foreach (var t in subTexture) { /* using (var stream = System.IO.File.Create("c:/jpg/" + (subTexturePic + l) + ".png")) { t.SaveAsPng(stream, t.Width, t.Height); } * */ var t2 = TextureManager.Rotate(t, RotateFlipType.Rotate180FlipNone); TextureManager.Textures.Add(new TextureData((subTexturePic /*baseTexturePic*/+ l /*textureIndex*/), t2)); } } // gameGraphics.unpackImageData(baseTexturePic, abyte3, abyte1, 1); // gameGraphics.drawPicture(0, 0, baseTexturePic); } } TextureManager.GenerateTextureAtlas(); return true; }