OpenBve.TextureManager.RegisterTexture C# (CSharp) Method

RegisterTexture() static private method

static private RegisterTexture ( Bitmap Bitmap, World TransparentColor ) : int
Bitmap System.Drawing.Bitmap
TransparentColor World
return int
		internal static int RegisterTexture(Bitmap Bitmap, World.ColorRGB TransparentColor)
		{
			int i = GetFreeTexture();
			int[] a = new int[1];
			GL.GenTextures(1, a);
			Textures[i] = new Texture();
			Textures[i].Queried = false;
			Textures[i].OpenGlTextureIndex = a[0];
			Textures[i].Transparency = TextureTransparencyMode.TransparentColor;
			Textures[i].TransparentColor = TransparentColor;
			Textures[i].TransparentColorUsed = 1;
			Textures[i].FileName = null;
			Textures[i].Loaded = true;
			Textures[i].DontAllowUnload = true;
			LoadTextureRGBAforData(Bitmap, Textures[i].TransparentColor, Textures[i].TransparentColorUsed, i);
			LoadTextureRGBAforOpenGl(i);
			return i;
		}

Same methods

TextureManager::RegisterTexture ( Bitmap Bitmap, bool Alpha ) : int
TextureManager::RegisterTexture ( string FileName, TextureWrapMode WrapModeX, TextureWrapMode WrapModeY, bool DontAllowUnload ) : int
TextureManager::RegisterTexture ( string FileName, World TransparentColor, byte TransparentColorUsed, TextureLoadMode LoadMode, TextureWrapMode WrapModeX, TextureWrapMode WrapModeY, bool DontAllowUnload, int ClipLeft, int ClipTop, int ClipWidth, int ClipHeight ) : int
TextureManager::RegisterTexture ( string FileName, World TransparentColor, byte TransparentColorUsed, TextureWrapMode WrapModeX, TextureWrapMode WrapModeY, bool DontAllowUnload ) : int

Usage Example

コード例 #1
0
        // get opengl texture index
        internal static int GetTextureIndex(FontType FontType, int Codepoint)
        {
            int    Font = (int)FontType;
            string t    = char.ConvertFromUtf32(Codepoint);
            int    i    = char.ConvertToUtf32(t, 0);

            if (i >= Characters[Font].Length || Characters[Font][i].Texture == -1)
            {
                if (Characters[Font].Length == 0)
                {
                    Characters[Font] = new Character[i + 1];
                    for (int j = 0; j <= i; j++)
                    {
                        Characters[Font][j].Texture = -1;
                    }
                }
                while (i >= Characters[Font].Length)
                {
                    int n = Characters[Font].Length;
                    Array.Resize <Character>(ref Characters[Font], 2 * n);
                    for (int j = n; j < 2 * n; j++)
                    {
                        Characters[Font][j].Texture = -1;
                    }
                }
                float s1;
                switch (Font)
                {
                case 0: s1 = ExtraSmallFontSize; break;

                case 1: s1 = SmallFontSize; break;

                case 2: s1 = MediumFontSize; break;

                case 3: s1 = LargeFontSize; break;

                case 4: s1 = ExtraLargeFontSize; break;

                default: s1 = SmallFontSize; break;
                }
                int       s0w = Interface.RoundToPowerOfTwo((int)Math.Ceiling((double)s1 * 1.25));
                int       s0h = s0w;
                FontStyle fs  = Font == 0 ? FontStyle.Regular : FontStyle.Regular;
                Bitmap    b   = new Bitmap(s0w, s0h, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                Graphics  g   = Graphics.FromImage(b);
                g.Clear(Color.Black);
                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
                Font  f = new Font(FontFamily.GenericSansSerif, s1, fs, GraphicsUnit.Pixel);
                SizeF s = g.MeasureString(t, f, s0w, StringFormat.GenericTypographic);
                g.DrawString(t, f, Brushes.White, 0.0f, 0.0f);
                g.Dispose();
                Characters[Font][i].Texture = TextureManager.RegisterTexture(b, false);
                Characters[Font][i].Width   = s.Width <= 0.05f ? 4.0f : (float)Math.Ceiling((double)s.Width);
                Characters[Font][i].Height  = s.Height <= 0.05f ? 4.0f : (float)Math.Ceiling((double)s.Height);
                b.Dispose();
            }
            return(Characters[Font][i].Texture);
        }
All Usage Examples Of OpenBve.TextureManager::RegisterTexture