public SceneGrid() { MaterialDX11 mat = new MaterialDX11(); TImage timage = new TImage(401, 401); for (int i = 0; i < timage.Height; i++) { for (int j = 0; j < timage.Width; j++) { if (i % 40 == 0 || j % 40 == 0 || i == 1 || i == 399 || j == 1 || j == 399) { timage.SetPixel(j, i, 1.0f, 1.0f, 1.0f, 1.0f); } else { timage.SetPixel(j, i, 0.0f, 0.0f, 0.0f, 0.0f); } } } SamplerState state = new SamplerState(ApplicationDX11.Instance.Device, new SamplerStateDescription() { AddressU = TextureAddressMode.Wrap, AddressV = TextureAddressMode.Wrap, AddressW = TextureAddressMode.Wrap, BorderColor = new Color4(0.0f, 1.0f, 0.0f, 1.0f), ComparisonFunction = Comparison.LessEqual, Filter = Filter.MinLinearMagMipPoint, MaximumAnisotropy = 0, MaximumLod = 0, MinimumLod = 0, MipLodBias = 0 }); float scaleValue = 40.0f; mat.AddTexture(timage.GetTexture2D()); mat.SetTextureHeight(0.1f * scaleValue); mat.SetTextureWidth(0.1f * scaleValue); mat.samplers.Add(state); //modelrenderer_ = new MeshRenderer( mat, Quad.GetMesh() ); transform_.RotateEuler(0.0f, 3.141592f / 2.0f, 0.0f); transform_.SetScale(scaleValue, scaleValue, 1.0f); IsPickingActivated = false; }
public void SetText(string text) { float offset = 0.0f; Width = 0.0f; Height = 0.0f; for (int i = 0; i < text.Length; i++) { float coef = 0.1f; AtlasNode atlasnode = atlasfont.atlas.GetNode(text[i]); MaterialDX11 mat = new MaterialDX11("vDefault.cso", "pText.cso"); mat.SetMainColor(1.0f, 0.0f, 0.0f, 1.0f); mat.AddShaderResourceView(atlasfont.atlas.SRV); Entity entity = new Entity(); // On utilise XOffset et xadvance pour déterminer la position des caractères dans la ligne offset += atlasnode.XOffset * coef; entity.transform_.Translate( offset + (( float )atlasnode.Width / 2.0f * coef), -(atlasnode.Height * coef / 2.0f) - atlasnode.YOffset * coef, 0.0f); offset += atlasnode.XAdvance * coef; entity.transform_.SetScale( atlasnode.Width * coef, atlasnode.Height * coef, 1.0f); Width += atlasnode.Width * coef + atlasnode.XOffset * coef + atlasnode.XAdvance * coef; Height = atlasnode.Height * coef + atlasnode.YOffset * coef; Append(entity); //entity.modelrenderer_ = new MeshRenderer( mat, Quad.GetMesh() ); SamplerState state = new SamplerState(ApplicationDX11.Instance.Device, new SamplerStateDescription() { AddressU = TextureAddressMode.Wrap, AddressV = TextureAddressMode.Wrap, AddressW = TextureAddressMode.Wrap, BorderColor = new Color4(0.0f, 1.0f, 0.0f, 1.0f), ComparisonFunction = Comparison.LessEqual, Filter = Filter.MinLinearMagMipPoint, MaximumAnisotropy = 0, MaximumLod = 0, MinimumLod = 0, MipLodBias = 0 }); mat.samplers.Add(state); mat.SetTextureXOffset(( float )atlasnode.X / ( float )atlasfont.atlas.Width); mat.SetTextureYOffset(( float )atlasnode.Y / ( float )atlasfont.atlas.Height); mat.SetTextureWidth(( float )atlasnode.Width / ( float )atlasfont.atlas.Width); mat.SetTextureHeight(( float )atlasnode.Height / ( float )atlasfont.atlas.Height); } if (CenterText) { transform_.Translate(-Width / 4.0f, Height / 2.0f, 0.0f); } }