Creates texture from file on disk or in memory.
Inheritance: Texture
Example #1
0
        /// <summary>
        ///
        /// </summary>
        public override void Initialize()
        {
            lightingCB      = new ConstantBuffer(Game.GraphicsDevice, typeof(LightingParams));
            omniLightBuffer = new StructuredBuffer(Game.GraphicsDevice, typeof(OMNILIGHT), RenderSystem.MaxOmniLights, StructuredBufferFlags.None);
            spotLightBuffer = new StructuredBuffer(Game.GraphicsDevice, typeof(SPOTLIGHT), RenderSystem.MaxSpotLights, StructuredBufferFlags.None);
            envLightBuffer  = new StructuredBuffer(Game.GraphicsDevice, typeof(ENVLIGHT), RenderSystem.MaxEnvLights, StructuredBufferFlags.None);
            decalBuffer     = new StructuredBuffer(Game.GraphicsDevice, typeof(DECAL), RenderSystem.MaxDecals, StructuredBufferFlags.None);

            using (var ms = new MemoryStream(Properties.Resources.envLut)) {
                envLut = UserTexture.CreateFromTga(rs, ms, false);
            }

            CreateShadowMaps();

            LoadContent();
            Game.Reloading += (s, e) => LoadContent();
        }
Example #2
0
        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="rs"></param>
        /// <param name="capacity">Number of sprites</param>
        public SpriteLayer(RenderSystem rs, int capacity)
        {
            this.rs = rs;

            Order = 0;

            Visible    = true;
            Transform  = Matrix.Identity;
            Color      = Color.White;
            BlendMode  = SpriteBlendMode.AlphaBlend;
            FilterMode = SpriteFilterMode.LinearClamp;
            StereoMode = SpriteStereoMode.All;

            defaultTexture = new DynamicTexture(rs, 16, 16, typeof(Color), false, false);
            defaultTexture.SetData(Enumerable.Range(0, 16 * 16).Select(i => Color.White).ToArray());

            using (var ms = new MemoryStream(Properties.Resources.conchars)) {
                fontTexture = UserTexture.CreateFromTga(rs, ms, false);
            }

            ReallocGpuBuffers(capacity);

            framesBuffer = new ConstantBuffer(rs.Device, typeof(SpriteFrame), MaxSpriteFrames);
        }
Example #3
0
        /// <summary>
        /// Constrcutor
        /// </summary>
        /// <param name="device"></param>
        /// <param name="fileName"></param>
        public SpriteFont(RenderSystem rs, Stream stream)
        {
            this.rs = rs.Device;

            using (var br = new BinaryReader(stream)) {
                var      xml   = br.ReadString();
                FontFile input = FontLoader.LoadFromString(xml);

                int numGlyphs = input.Chars.Max(ch => ch.ID);

                //	create charInfo and kernings :
                fontInfo.kernings = new Dictionary <Tuple <char, char>, float>();
                fontInfo.charInfo = new SpriteFontInfo.CharInfo[numGlyphs + 1];

                //	check one-page bitmap fonts :
                if (input.Pages.Count != 1)
                {
                    throw new GraphicsException("Only one page of font image is supported");
                }

                //	create path for font-image :
                string fontImagePath = input.Pages[0].File;

                //	skip two bytes :
                var texData = stream.ReadAllBytes();
                fontTexture = new UserTexture(rs.Game.RenderSystem, texData, false);

                //	Fill structure :
                fontInfo.fontFace    = input.Info.Face;
                fontInfo.baseLine    = input.Common.Base;
                fontInfo.lineHeight  = input.Common.LineHeight;
                fontInfo.scaleWidth  = input.Common.ScaleW;
                fontInfo.scaleHeight = input.Common.ScaleH;

                float scaleWidth  = fontInfo.scaleWidth;
                float scaleHeight = fontInfo.scaleHeight;

                //	process character info :
                for (int i = 0; i < input.Chars.Count; i++)
                {
                    FontChar ch = input.Chars[i];

                    int id = ch.ID;

                    if (id < 0)
                    {
                        continue;
                    }

                    int x     = ch.X;
                    int y     = ch.Y;
                    int xoffs = ch.XOffset;
                    int yoffs = ch.YOffset;
                    int w     = ch.Width;
                    int h     = ch.Height;

                    fontInfo.charInfo[ch.ID].validChar = true;
                    fontInfo.charInfo[ch.ID].xAdvance  = ch.XAdvance;
                    fontInfo.charInfo[ch.ID].srcRect   = new RectangleF(x, y, w, h);
                    fontInfo.charInfo[ch.ID].dstRect   = new RectangleF(xoffs, yoffs, w, h);
                }


                var letterHeights = input.Chars
                                    .Where(ch1 => char.IsUpper((char)(ch1.ID)))
                                    .Select(ch2 => ch2.Height)
                                    .OrderBy(h => h)
                                    .ToList();
                CapHeight = letterHeights[letterHeights.Count / 2];



                //	process kerning info :
                for (int i = 0; i < input.Kernings.Count; i++)
                {
                    var pair    = new Tuple <char, char>((char)input.Kernings[i].First, (char)input.Kernings[i].Second);
                    int kerning = input.Kernings[i].Amount;
                    fontInfo.kernings.Add(pair, kerning);
                }

                SpaceWidth = MeasureString(" ").Width;
                LineHeight = MeasureString(" ").Height;
            }
        }
Example #4
0
		/// <summary>
		/// Constrcutor
		/// </summary>
		/// <param name="device"></param>
		/// <param name="fileName"></param>
		public SpriteFont ( GraphicsDevice rs, Stream stream )
		{
			this.rs	=	rs;

			using (var br = new BinaryReader(stream)) {

				var xml = br.ReadString();
				FontFile input = FontLoader.LoadFromString( xml );

				int numGlyphs	=	input.Chars.Max( ch => ch.ID );

				//	create charInfo and kernings :
				fontInfo.kernings = new Dictionary<Tuple<char,char>, float>();
				fontInfo.charInfo = new SpriteFontInfo.CharInfo[numGlyphs+1];

				//	check one-page bitmap fonts :
				if (input.Pages.Count!=1) {
					throw new GraphicsException("Only one page of font image is supported");
				}

				//	create path for font-image :
				string fontImagePath	=	input.Pages[0].File;

				//	skip two bytes :
				var texData				=	stream.ReadAllBytes();
				fontTexture				=	new UserTexture( rs.Game.RenderSystem, texData, false );
			
				//	Fill structure :
				fontInfo.fontFace		=	input.Info.Face;
				fontInfo.baseLine		=	input.Common.Base;
				fontInfo.lineHeight		=	input.Common.LineHeight;
				fontInfo.scaleWidth		=	input.Common.ScaleW;
				fontInfo.scaleHeight	=	input.Common.ScaleH;

				float scaleWidth = fontInfo.scaleWidth;
				float scaleHeight = fontInfo.scaleHeight;

				//	process character info :
				for ( int i=0; i<input.Chars.Count; i++) {
					FontChar ch = input.Chars[i];

					int id = ch.ID;

					if (id<0) continue;

					int x = ch.X;
					int y = ch.Y;
					int xoffs = ch.XOffset;
					int yoffs = ch.YOffset;
					int w = ch.Width;
					int h = ch.Height;

					fontInfo.charInfo[ ch.ID ].validChar	=	true;
					fontInfo.charInfo[ ch.ID ].xAdvance		=	ch.XAdvance;
					fontInfo.charInfo[ ch.ID ].srcRect		=	new RectangleF(x, y, w, h);
					fontInfo.charInfo[ ch.ID ].dstRect		=	new RectangleF(xoffs, yoffs, w, h);
				}


				var letterHeights = input.Chars
						.Where( ch1 => char.IsUpper( (char)(ch1.ID) ) )
						.Select( ch2 => ch2.Height )
						.OrderBy( h => h )
						.ToList();
				CapHeight	=	letterHeights[ letterHeights.Count/2 ];



				//	process kerning info :
				for ( int i=0; i<input.Kernings.Count; i++) {
					var pair	=	new Tuple<char,char>( (char)input.Kernings[i].First, (char)input.Kernings[i].Second);
					int kerning =	input.Kernings[i].Amount;
					fontInfo.kernings.Add( pair, kerning );
				}

				SpaceWidth	=	MeasureString(" ").Width;
				LineHeight	=	MeasureString(" ").Height;
			}
		}